Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
feature(Calendar): limit timeline view with memberOf filter to filter…
Browse files Browse the repository at this point in the history
…ed attendee

Change-Id: I3155f868fc63cfb2973c05f797a2f1dd742505af
  • Loading branch information
corneliusweiss committed May 10, 2021
1 parent 6698bc9 commit 2a51a9c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 26 deletions.
28 changes: 19 additions & 9 deletions tine20/Calendar/js/AttendeeFilterGrid.js
Expand Up @@ -252,28 +252,38 @@ Tine.Calendar.AttendeeFilterGrid = Ext.extend(Tine.Calendar.AttendeeGridPanel, {
/**
* extract attendee filter from filters
*
* @param {Array} filter
* @param {Array} filters
*/
extractFilterValue: function(filters) {
var value = [];

extractFilter: function(filters) {
let attendeeFilters = null;
// use first OR panel in case of filterPanel
Ext.each(filters, function(filterData) {
if (filterData.condition && filterData.condition == 'OR') {
filters = filterData.filters[0].filters;
attendeeFilters = filterData.filters[0].filters;
return false;
}
}, this);

// use first attedee filter
Ext.each(filters, function(filter) {
if (filter.field == 'attender') {
value = filter.value;
let attendeeFilter = null;
Ext.each(attendeeFilters, function(filter) {
if (filter.field === 'attender') {
attendeeFilter = filter;
return false;
}
}, this);

return value;
return attendeeFilter;
},

/**
* extract attendee filter values from filters
*
* @param {Array} filters
*/
extractFilterValue: function(filters) {
let attendeeFilter = this.extractFilter(filters);
return _.get(attendeeFilter, 'value');
},

/**
Expand Down
5 changes: 3 additions & 2 deletions tine20/Calendar/js/MainScreenCenterPanel.js
Expand Up @@ -1586,7 +1586,7 @@ Tine.Calendar.MainScreenCenterPanel = Ext.extend(Ext.Panel, {
* called when store loaded data
*/
onStoreLoad: function (store, options) {
if (this.rendered) {
if (this.rendered && _.get(options, 'keepLoadMask') !== true) {
this.loadMask.hide();
}

Expand Down Expand Up @@ -1920,7 +1920,8 @@ Tine.Calendar.MainScreenCenterPanel = Ext.extend(Ext.Panel, {
period: tbar.periodPicker.getPeriod(),
viewType: whichParts.period,
store: store,
canonicalName: ['Event', 'Timeline']
canonicalName: ['Event', 'Timeline'],
mainScreen: this
});
}

Expand Down
6 changes: 3 additions & 3 deletions tine20/Calendar/js/Model.js
Expand Up @@ -769,14 +769,14 @@ Tine.Calendar.Model.Attender.getSortOrder = function(user_type) {
* @return {Object} default data
* @static
*/
Tine.Calendar.Model.Attender.getDefaultData = function() {
return {
Tine.Calendar.Model.Attender.getDefaultData = function(overrides) {
return _.assign({
// @TODO have some config here? user vs. default?
user_type: 'any',
role: 'REQ',
quantity: 1,
status: 'NEEDS-ACTION'
};
}, overrides);
};

/**
Expand Down
57 changes: 45 additions & 12 deletions tine20/Calendar/js/TimelinePanel.js
Expand Up @@ -130,6 +130,8 @@ Tine.Calendar.TimelinePanel = Ext.extend(Ext.Panel, {
remove: this.onGroupRemove
}
});

this.store.on('beforeload', this.onStoreBeforeLoad, this);
this.store.on('load', this.onStoreLoad, this);

this.initTemplates();
Expand All @@ -140,25 +142,56 @@ Tine.Calendar.TimelinePanel = Ext.extend(Ext.Panel, {
Tine.Calendar.TimelinePanel.superclass.initComponent.apply(this, arguments);
},

onStoreLoad: function(store, records, options) {
onStoreBeforeLoad: function(store, options) {
this.resolveGroupingItemsPromise = Promise.resolve();

// resolve members for memberOf filters
const attendeeFilter = Tine.Calendar.AttendeeFilterGrid.prototype.extractFilterValue(options.params.filter);
const memberIds = _.reduce(attendeeFilter, (memberIds, attendee) => {
return memberIds.concat(memberIds, _.get(attendee, 'user_type') === 'memberOf' ?
_.get(attendee, 'user_id.members', []) : []);
}, []);

if (memberIds.length) {
this.resolveGroupingItemsPromise = Tine.Addressbook.searchContacts([{
field: 'id', operator: 'in', value: _.compact(_.uniq(memberIds))
}]);
}
},

onStoreLoad: async function(store, records, options) {
this.groupingMetadataCache = {};

var fixedGroups = [],
attendeeFilterValue = Tine.Calendar.AttendeeFilterGrid.prototype.extractFilterValue(options.params.filter),
attendeeStore = attendeeFilterValue ? Tine.Calendar.Model.Attender.getAttendeeStore(attendeeFilterValue) : null;


options.keepLoadMask = true;
const members = await this.resolveGroupingItemsPromise;

if (attendeeStore) {
attendeeStore.each(function(attendee) {
// NOTE: we can't cope yet with memberOf entries as we would nee to know
// the listmembers of the list to add them to the group
if (attendee.get('user_type') == 'memberOf') return;

var groupName = attendee.getCompoundId();
fixedGroups.push(groupName);
this.groupingMetadataCache[groupName] = attendee;
}, this);
attendeeStore.each(async (attendee) => {
if (attendee.get('user_type') === 'memberOf') {
// add each list member to fixedGroups
const Attender = Tine.Calendar.Model.Attender;
_.each(_.get(attendee, 'data.user_id.members', []), (memberId) => {
const memberContact = _.find(_.get(members, 'results', {}), {id: memberId});
if (memberContact) {
const memberAttendee = new Attender(Attender.getDefaultData({user_type: 'user', user_id: memberContact}));
const groupName = memberAttendee.getCompoundId();
fixedGroups.push(groupName);
this.groupingMetadataCache[groupName] = memberAttendee;
}
});
} else {
var groupName = attendee.getCompoundId();
fixedGroups.push(groupName);
this.groupingMetadataCache[groupName] = attendee;
}
});
}
this.groupCollection.setFixedGroups(fixedGroups);
this.groupCollection.setFixedGroups(_.uniq(fixedGroups));
this.mainScreen.loadMask.hide();
},

groupingFn: function(event) {
Expand Down

0 comments on commit 2a51a9c

Please sign in to comment.