Skip to content

Commit

Permalink
Merge branch 'pu/ss/fixgroupNames' into '2024.11'
Browse files Browse the repository at this point in the history
Fix(Tinebase): GroupNames can not handle htmlProxy

See merge request tine20/tine20!4852
  • Loading branch information
sstamer committed Jan 30, 2024
2 parents 5873cdb + e95adee commit 1277d89
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions tine20/Tinebase/js/data/GroupedStoreCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ Ext.extend(Tine.Tinebase.data.GroupedStoreCollection, Ext.util.MixedCollection,
this.applyGrouping();
},

groupRecords: function(rs, append) {
groupRecords: async function(rs, append) {
// put data into groups
var groups = [];
var records = [];
Ext.each(rs, function(r) {
var groupNames = this.getGroupNames(r);
await [].concat(rs).asyncForEach(async (r) => {
var groupNames = await this.getGroupNames(r);

Ext.each(groupNames, function(groupName) {
var idx = groups.indexOf(groupName);
Expand Down Expand Up @@ -118,8 +118,8 @@ Ext.extend(Tine.Tinebase.data.GroupedStoreCollection, Ext.util.MixedCollection,
}, this);
},

setFixedGroups: function(groupNames) {
groupNames = this.sanitizeGroupNames(groupNames);
setFixedGroups: async function(groupNames) {
groupNames = await this.sanitizeGroupNames(groupNames);

this.fixedGroups = groupNames;
if (groupNames.length) {
Expand Down Expand Up @@ -151,15 +151,15 @@ Ext.extend(Tine.Tinebase.data.GroupedStoreCollection, Ext.util.MixedCollection,
* @param {Ext.data.record} record
* @returns {Array}
*/
getGroupNames: function(record) {
getGroupNames: async function(record) {
var _ = window.lodash,
groupNames = Ext.isFunction(this.group) ? this.group(record) : record.get(this.group);

if (! Ext.isArray(groupNames)) {
groupNames = [groupNames];
}

groupNames = this.sanitizeGroupNames(groupNames);
groupNames = await this.sanitizeGroupNames(groupNames);

if (this.fixedGroups.length) {
groupNames = _.intersection(groupNames, this.fixedGroups);
Expand All @@ -168,16 +168,16 @@ Ext.extend(Tine.Tinebase.data.GroupedStoreCollection, Ext.util.MixedCollection,
return groupNames;
},

sanitizeGroupNames: function(groupNames) {
groupNames = groupNames.map((groupName) => {
sanitizeGroupNames: async function(groupNames) {
groupNames = await Promise.all(groupNames.map((groupName) => {
if (! _.isObject(groupName)) return groupName;
if (_.isFunction(groupName.getTitle)) return groupName.getTitle();
if (_.isFunction(groupName.getTitle)) return groupName.getTitle().asString();
if (_.isString(this.group) && this.store.recordClass) return Tine.widgets.grid.RendererManager.get(
this.store.recordClass.getMeta('appName'),
this.store.recordClass.getMeta('modelName'),
this.group
)(groupName);
});
)(groupName).asString();
}));

if (_.remove(groupNames, (v) => {return [null, undefined, false, Infinity, NaN].indexOf(v) >= 0}).length) {
groupNames.push('');
Expand All @@ -202,11 +202,11 @@ Ext.extend(Tine.Tinebase.data.GroupedStoreCollection, Ext.util.MixedCollection,
}
},

onStoreAdd: function (store, records, index) {
onStoreAdd: async function (store, records, index) {
this.suspendCloneStoreEvents = true;

Ext.each(records, function (record) {
Ext.each(this.getGroupNames(record), function (groupName) {
await [].concat(records).asyncForEach(async (record) => {
Ext.each(await this.getGroupNames(record), function (groupName) {
var store = this.get(groupName),
existingRecord = store && record.id != 0 ? store.getById(record.id) : null;

Expand All @@ -217,16 +217,15 @@ Ext.extend(Tine.Tinebase.data.GroupedStoreCollection, Ext.util.MixedCollection,
this.getCloneStore(groupName).add([record.copy()]);
}
}, this);

}, this);
});

this.suspendCloneStoreEvents = false;
},

onStoreUpdate: function(store, record, operation) {
onStoreUpdate: async function(store, record, operation) {
this.suspendCloneStoreEvents = true;

var groupNames = this.getGroupNames(record);
var groupNames = await this.getGroupNames(record);
this.eachKey(function(groupName) {
var store = this.get(groupName),
existingRecord = store.getById(record.id);
Expand Down

0 comments on commit 1277d89

Please sign in to comment.