Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#625 add show and hide radio button to calendars list #626

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/esn.calendar.libs/app/app.constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
.constant('CAL_ATTENDEE_LIST_LIMIT', 5)

.constant('CAL_AVAILABLE_VIEWS', ['agendaWeek', 'agendaDay', 'month', 'agendaThreeDays', 'basicDay'])
.constant('TOGGLE_TRANSITION', 200)

.constant('CAL_CALENDAR_SHARED_RIGHT', {
NONE: '0',
Expand Down
59 changes: 53 additions & 6 deletions src/esn.calendar.libs/app/services/calendar-visibility-service.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable space-before-blocks */
require('../app.constants.js');

(function(angular) {
Expand All @@ -11,8 +12,10 @@ require('../app.constants.js');

return {
getHiddenCalendars: getHiddenCalendars,
isHidden: isHidden,
toggle: toggle
isHidden,
toggle,
showAndHideCalendars,
getHiddenCalendarsByType
};

////////////
Expand All @@ -23,18 +26,62 @@ require('../app.constants.js');
});
}

function toggle(calendar) {
function showAndHideCalendars(calendar, status, calendarType) {
var calId = calendar.getUniqueId();

storage.getItem(calId).then(function(hiddenBefore) {
return storage.setItem(calId, !hiddenBefore);
storage.getItem(calendarType + calId).then(function(hiddenBefore) {
return storage.setItem(calendarType + calId, hiddenBefore);
}).then(function(hidden) {
$rootScope.$broadcast(CAL_EVENTS.CALENDARS.TOGGLE_VIEW, {
calendarUniqueId: calId,
calendarType: calendarType,
hidden: status ? true : hidden
});
});
}

function toggle(calendar, calendarType, lengthCalendars) {

var calId = calendar.getUniqueId();

storage.getItem(calendarType + calId).then(function(hiddenBefore) {

return storage.setItem(calendarType + calId, !hiddenBefore);
}).then(function(hidden) {
$rootScope.$broadcast(CAL_EVENTS.CALENDARS.TOGGLE_VIEW, {
calendarUniqueId: calId,
calendarType: calendarType,
hidden: hidden
});

return hidden;
}).then(function(){
return getHiddenCalendarsByType(calendarType);
})
.then(function(hiddenCal) {
let hidden = false;

if (hiddenCal.length === lengthCalendars) {
hidden = true;
}

$rootScope.$broadcast('calendarsAreHidden', {
calendarType: calendarType,
hidden: hidden
});

});
}

function getHiddenCalendarsByType(calendarType) {
var result = [];

return storage.iterate(function(hidden, id) {

if (id.startsWith(calendarType) && hidden) {
result.push(id);
}
}).then(function() {
return result;
});
}

Expand Down
40 changes: 40 additions & 0 deletions src/esn.calendar.libs/app/services/calendar-visibility.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,46 @@ describe('The calendarVisibilityService', function() {
});
});



describe('the showAndHideCalendars function', function() {
it('should broadcast the calendar and it new display status', function() {
var cal = this.getCalendar(42);

this.$rootScope.$broadcast = sinon.spy(this.$rootScope.$broadcast);

this.calendarVisibilityService.toggle(cal);
this.$rootScope.$digest();
expect(this.$rootScope.$broadcast).to.have.been.calledWith(
this.CAL_EVENTS.CALENDARS.TOGGLE_VIEW,
{ calendarUniqueId: cal.uniqueId, hidden: true }
);

this.$rootScope.$broadcast.reset();

this.calendarVisibilityService.toggle(cal);
this.$rootScope.$digest();
expect(this.$rootScope.$broadcast).to.have.been.calledWith(
this.CAL_EVENTS.CALENDARS.TOGGLE_VIEW,
{ calendarUniqueId: cal.uniqueId, hidden: false }
);
});

it('should correctly record hidden calendar in localforage', function() {
var id1 = '1';
var id2 = '2';
var hiddenCalendars = [this.getCalendar(id1), this.getCalendar(id2)];
var thenSpy = sinon.spy();

hiddenCalendars.map(this.calendarVisibilityService.toggle);
this.$rootScope.$digest();
this.calendarVisibilityService.getHiddenCalendars().then(thenSpy);
this.$rootScope.$digest();

expect(thenSpy).to.have.been.calledWith([id1, id2]);
});
});

describe('The isHidden function', function() {
it('should return true if and only if the calendar is hidden', function() {
var cal = this.getCalendar(42);
Expand Down
3 changes: 3 additions & 0 deletions src/linagora.esn.calendar/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ require('./components/calendar-today-button/calendar-today-button.controller.js'
require('./components/calendar/calendar.component.js');
require('./components/calendar/calendar.controller.js');
require('./components/calendars-list/calendars-list.component.js');
require('./components/calendars-list/calendar-list-toggle.directive.js');
require('./components/calendars-list/calendars-list.controller.js');
require('./components/calendars-list/external/external-calendars-list.component.js');
require('./components/calendars-list/items/calendars-list-items.component.js');
Expand All @@ -141,6 +142,8 @@ require('./components/calendars-list/items/item/calendars-list-item.controller.j
require('./components/calendars-list/items/item/configuration/calendars-list-item-configuration.component.js');
require('./components/calendars-list/items/item/configuration/calendars-list-item-configuration.controller.js');
require('./components/calendars-list/user/user-calendars-list.component.js');
require('./components/calendars-list/user/user-calendars-list.controller.js');

require('./components/event-alarm-consultation/event-alarm-consultation.component.js');
require('./components/event-alarm-consultation/event-alarm-consultation.controller.js');
require('./components/event-create-button/event-create-button.component.js');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

'use strict';

angular.module('esn.calendar')

.directive('calendarListToggle', function(TOGGLE_TRANSITION) {

return {
restrict: 'A',
link: function(scope, element, attrs) {
if (attrs.toggled === 'true') {
_toggle(0);
}

element.click(function() {
_toggle(TOGGLE_TRANSITION);
});

function _toggle(toggleTransistion) {
element.parent().parent().parent().toggleClass('toggled');
element.parent().parent().parent().find('ul:not(".not-toggled")').stop(true, false).slideToggle(toggleTransistion);
}
}
};
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable space-before-blocks */
const _ = require('lodash');

(function(angular) {
Expand All @@ -6,7 +7,7 @@ const _ = require('lodash');
angular.module('esn.calendar')
.controller('CalendarsListController', CalendarsListController);

function CalendarsListController(
function CalendarsListController (
$rootScope,
$scope,
$q,
Expand All @@ -15,6 +16,7 @@ const _ = require('lodash');
session,
userAndExternalCalendars,
CAL_EVENTS

) {
var self = this;

Expand All @@ -30,6 +32,10 @@ const _ = require('lodash');
self.sharedCalendars = [];
self.hiddenCalendars = {};
self.toggleCalendar = calendarVisibilityService.toggle;
self.selectAllCalendars = selectAllCalendars;
self.calendarsToggled = false;
self.sharedCalendarsLength = 0;
self.userCalendarsLength = 0;

self.activate();
}
Expand All @@ -42,16 +48,25 @@ const _ = require('lodash');
var destroyCalRemoveEvent = $rootScope.$on(CAL_EVENTS.CALENDARS.REMOVE, onCalendarRemoved);
var destroyCalUpdateEvent = $rootScope.$on(CAL_EVENTS.CALENDARS.UPDATE, onCalendarUpdated);
var deregister = $rootScope.$on(CAL_EVENTS.CALENDARS.TOGGLE_VIEW, function(event, data) {
self.hiddenCalendars[data.calendarUniqueId] = data.hidden;
self.hiddenCalendars[data.calendarType + data.calendarUniqueId] = data.hidden;
});

$scope.$on('$destroy', destroyCalAddEvent);
$scope.$on('$destroy', destroyCalRemoveEvent);
$scope.$on('$destroy', destroyCalUpdateEvent);
$scope.$on('$destroy', deregister);

});
}

function selectAllCalendars(calendarType, status) {
const calendars = userAndExternalCalendars(self.calendars);

calendars[calendarType].forEach(function (calendar) {
calendarVisibilityService.showAndHideCalendars(calendar, status, calendarType);
});
}

function listCalendars() {
return calendarService.listPersonalAndAcceptedDelegationCalendars(session.user._id).then(function(calendars) {
self.calendars = _.clone(calendars);
Expand Down Expand Up @@ -100,6 +115,8 @@ const _ = require('lodash');
self.userCalendars = calendars.userCalendars;
self.sharedCalendars = calendars.sharedCalendars;
self.publicCalendars = calendars.publicCalendars;
self.sharedCalendarsLength = self.sharedCalendars.length;
self.userCalendarsLength = self.userCalendars.length;
}
}
})(angular);
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

.mdi {
font-size: 24px;
color: @primaryColor;
color: grey;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
cal-user-calendars-list(
user-calendars="$ctrl.userCalendars",
toggle-calendar="$ctrl.toggleCalendar",
hidden-calendars="$ctrl.hiddenCalendars"
hidden-calendars="$ctrl.hiddenCalendars",
select-all-calendars="$ctrl.selectAllCalendars",
length-user-calendars="$ctrl.userCalendarsLength"

)

cal-external-calendars-list(
feature-flag="linagora.esn.calendar.features.isSharingCalendarEnabled",
shared-calendars="$ctrl.sharedCalendars",
public-calendars="$ctrl.publicCalendars",
toggle-calendar="$ctrl.toggleCalendar",
hidden-calendars="$ctrl.hiddenCalendars"
hidden-calendars="$ctrl.hiddenCalendars",
select-all-calendars="$ctrl.selectAllCalendars",
length-user-calendars="$ctrl.sharedCalendarsLength"
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
sharedCalendars: '=',
publicCalendars: '=',
toggleCalendar: '=',
hiddenCalendars: '='
hiddenCalendars: '=',
selectAllCalendars: '=',
calendarType: '=',
lengthUserCalendars: '='
}
});
})(angular);
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
.lv-item.calendar-item.calendar-header-title.hidden-md
.media
.pull-left
i.mdi.mdi-calendar
i.mdi.mdi-checkbox-multiple-blank-circle.all-calendars-selected
.media-body
.lv-title {{ 'Shared calendars' | translate }}
.lv-item.calendar-item.calendar-header-title-desktop.visible-md.clickable.toggle-submenu.waves-classic(esn-toggle)
.lv-item.calendar-item.calendar-header-title-desktop.visible-md.clickable.toggle-submenu.waves-classic
.media
.badge-container
.badge-container(calendar-list-toggle)
.caret-submenu
i.mdi.mdi-menu-down
.calendar-item-left
i.mdi.mdi-calendar
i.mdi(ng-class="!$ctrl.calendarsToggled? 'mdi-checkbox-multiple-blank-circle' : 'mdi-checkbox-multiple-blank-circle-outline'",ng-click="$ctrl.selectAllCalendars('sharedCalendars',$ctrl.calendarsToggled=!$ctrl.calendarsToggled)")
.media-body
.lv-title {{ 'Shared calendars' | translate }}

Expand All @@ -21,13 +21,19 @@
toggle-calendar="$ctrl.toggleCalendar",
hidden-calendars="$ctrl.hiddenCalendars",
state-to-go="'calendar.external.shared'",
show-details="true"
show-details="true",
calendar-type="'sharedCalendars'",
length-user-calendars="$ctrl.lengthUserCalendars"

)

calendars-list-items(
calendars="$ctrl.publicCalendars",
toggle-calendar="$ctrl.toggleCalendar",
hidden-calendars="$ctrl.hiddenCalendars",
state-to-go="'calendar.external.shared'",
show-details="true"
show-details="true",
calendar-type="'sharedCalendars'",
length-user-calendars="$ctrl.lengthUserCalendars"

)
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
template: require('./calendars-list-items.pug'),
controller: 'CalendarsListItemsController',
bindings: {
calendars: '=?',
calendars: '=',
toggleCalendar: '=?',
hiddenCalendars: '=?',
showDetails: '=?'
showDetails: '=?',
calendarType: '=',
lengthUserCalendars: '='
}
});
})(angular);
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
.calendar-list-items(ng-repeat="calendar in $ctrl.calendars track by calendar.uniqueId")
cal-calendars-list-item(
calendars="$ctrl.calendars"
calendar="calendar",
on-show-hide-toggle="$ctrl.toggleCalendar(calendar)",
selected="!$ctrl.hiddenCalendars[calendar.getUniqueId()]",
on-show-hide-toggle="$ctrl.toggleCalendar(calendar , $ctrl.calendarType , $ctrl.lengthUserCalendars)",
selected="!$ctrl.hiddenCalendars[$ctrl.calendarType+calendar.getUniqueId()]",
show-details="$ctrl.showDetails"
calendar-type="$ctrl.calendarType",

)
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
template: require('./calendars-list-item.pug'),
controller: 'CalendarsListItemController',
bindings: {
calendars: '=',
calendar: '<',
onShowHideToggle: '&',
selected: '<',
showDetails: '<'
showDetails: '<',
calendarType: '<'
}
});
})(angular);
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
.details(ng-if="$ctrl.details")
span.ellipsis {{ ::$ctrl.details }}
settings-overlay.settings(ng-click="$event.stopImmediatePropagation(); hideAside();", ui-sref-active-eq="selected")
cal-calendars-list-item-configuration(calendar-id="$ctrl.calendar.uniqueId")
cal-calendars-list-item-configuration(calendar-id="$ctrl.calendar.uniqueId",calendars="$ctrl.calendars")
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
template: require('./configuration-list.pug'),
controller: 'CalendarsListItemConfigurationController',
bindings: {
calendarId: '='
calendarId: '=',
calendars: '='
}
});
})(angular);
Loading