Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Commit

Permalink
Nested groups order logic (#3206)
Browse files Browse the repository at this point in the history
* Fix sorting of nestedgroups when groups added after initial groups setting

* Fix nesteded groups logic when adding and removing

* Remove empty lines

* Fix comments from PR

* Remove spaces from empty line

* Fix PR review comments
  • Loading branch information
yotamberk authored Aug 16, 2017
1 parent 44ffb44 commit 8c8f21d
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions lib/timeline/component/ItemSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,28 @@ function ItemSet(body, options) {
this.groupListeners = {
'add': function (event, params, senderId) { // eslint-disable-line no-unused-vars
me._onAddGroups(params.items);

if (me.groupsData && me.groupsData.length > 0) {
var groupsData = me.groupsData.getDataSet();
groupsData.get().forEach(function (groupData) {
if (groupData.nestedGroups) {
if (groupData.showNested != false) {
groupData.showNested = true;
}
var updatedGroups = [];
groupData.nestedGroups.forEach(function(nestedGroupId) {
var updatedNestedGroup = groupsData.get(nestedGroupId);
if (!updatedNestedGroup) { return; }
updatedNestedGroup.nestedInGroup = groupData.id;
if (groupData.showNested == false) {
updatedNestedGroup.visible = false;
}
updatedGroups = updatedGroups.concat(updatedNestedGroup);
});
groupsData.update(updatedGroups, senderId);
}
});
}
},
'update': function (event, params, senderId) { // eslint-disable-line no-unused-vars
me._onUpdateGroups(params.items);
Expand Down Expand Up @@ -1662,21 +1684,20 @@ ItemSet.prototype._onGroupClick = function (event) {

if (!group || !group.nestedGroups) return;

var groupsData = this.groupsData;
if (this.groupsData instanceof DataView) {
groupsData = this.groupsData.getDataSet()
}
var groupsData = this.groupsData.getDataSet();

group.showNested = !group.showNested;
var nestingGroup = groupsData.get(group.groupId)
if (nestingGroup.showNested == undefined) { nestingGroup.showNested = true; }
nestingGroup.showNested = !nestingGroup.showNested;

var nestedGroups = groupsData.get(group.nestedGroups).map(function(nestedGroup) {
if (nestedGroup.visible == undefined) { nestedGroup.visible = true; }
nestedGroup.visible = !!group.showNested;
nestedGroup.visible = nestingGroup.showNested;
return nestedGroup;
});
groupsData.update(nestedGroups);

if (group.showNested) {
groupsData.update(nestedGroups.concat(nestingGroup));

if (nestingGroup.showNested) {
util.removeClassName(group.dom.label, 'collapsed');
util.addClassName(group.dom.label, 'expanded');
} else {
Expand Down

0 comments on commit 8c8f21d

Please sign in to comment.