From 459008f3913aec1cc74b5c0a9312f510701676e8 Mon Sep 17 00:00:00 2001 From: Yotam Berkowitz Date: Sat, 24 Jun 2017 21:07:51 +0300 Subject: [PATCH 1/6] Fix sorting of nestedgroups when groups added after initial groups setting --- lib/timeline/component/ItemSet.js | 35 +++++++++++++++++++------------ 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/lib/timeline/component/ItemSet.js b/lib/timeline/component/ItemSet.js index e5e168a39..6649b4c39 100644 --- a/lib/timeline/component/ItemSet.js +++ b/lib/timeline/component/ItemSet.js @@ -1159,22 +1159,31 @@ ItemSet.prototype._orderGroups = function () { * @private */ ItemSet.prototype._orderNestedGroups = function(groupIds) { + var me = this var newGroupIdsOrder = []; - - groupIds.forEach(function(groupId){ - var groupData = this.groupsData.get(groupId); - if (!groupData.nestedInGroup) { - newGroupIdsOrder.push(groupId) + var nestingGroupsIds = this.groupsData.get({ + filter: function(group) { + return group.nestedGroups } + }).map(function(nestingGroup) { return nestingGroup.id }) + + var allNestedGroupsIds = [] + nestingGroupsIds.forEach(function(groupId) { + var groupData = me.groupsData.get(groupId); + allNestedGroupsIds = allNestedGroupsIds.concat(groupData.nestedGroups) + }) + + var itemsWithoutNestedGroups = groupIds.filter(function(groupId) { return allNestedGroupsIds.indexOf(groupId) == -1 }); + + itemsWithoutNestedGroups.forEach(function(groupId){ + newGroupIdsOrder.push(groupId) + + var groupData = me.groupsData.get(groupId); if (groupData.nestedGroups) { - var nestedGroups = this.groupsData.get({ - filter: function(nestedGroup) { - return nestedGroup.nestedInGroup == groupId; - }, - order: this.options.groupOrder - }); - var nestedGroupIds = nestedGroups.map(function(nestedGroup) { return nestedGroup.id }) - newGroupIdsOrder = newGroupIdsOrder.concat(nestedGroupIds); + var nestedGroupsIds = me.groupsData.get(groupData.nestedGroups, { + order: me.options.groupOrder + }).map(function(group) { return group.id }); + newGroupIdsOrder = newGroupIdsOrder.concat(nestedGroupsIds) } }, this) return newGroupIdsOrder; From 611980890d006347558dfcbf9bb620f50ed3d8a2 Mon Sep 17 00:00:00 2001 From: Yotam Berkowitz Date: Sun, 25 Jun 2017 18:24:17 +0300 Subject: [PATCH 2/6] Fix nesteded groups logic when adding and removing --- lib/timeline/component/ItemSet.js | 72 ++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/lib/timeline/component/ItemSet.js b/lib/timeline/component/ItemSet.js index 6649b4c39..30d12ab1d 100644 --- a/lib/timeline/component/ItemSet.js +++ b/lib/timeline/component/ItemSet.js @@ -146,6 +146,31 @@ function ItemSet(body, options) { this.groupListeners = { 'add': function (event, params, senderId) { me._onAddGroups(params.items); + + if (me.groupsData && me.groupsData.length > 0) { + var groupsData = me.groupsData; + if (me.groupsData instanceof DataView) { + groupsData = me.groupsData.getDataSet() + } + + groupsData.get().forEach(function (groupData) { + if (groupData.nestedGroups) { + if (groupData.showNested != false) { + groupData.showNested = true; + } + groupData.nestedGroups.forEach(function(nestedGroupId) { + var updatedNestedGroup = groupsData.get(nestedGroupId); + if (!updatedNestedGroup) { return; } + updatedNestedGroup.nestedInGroup = groupData.id; + if (groupData.showNested == false) { + updatedNestedGroup.visible = false; + } + groupsData.update(updatedNestedGroup); + }) + groupsData.update(groupData); + } + }); + } }, 'update': function (event, params, senderId) { me._onUpdateGroups(params.items); @@ -1058,6 +1083,7 @@ ItemSet.prototype._onAddGroups = function(ids) { ids.forEach(function (id) { var groupData = me.groupsData.get(id); var group = me.groups[id]; + if (!group) { // check for reserved ids @@ -1092,6 +1118,7 @@ ItemSet.prototype._onAddGroups = function(ids) { } }); + this.body.emitter.emit('_change', {queue: true}); }; @@ -1159,31 +1186,22 @@ ItemSet.prototype._orderGroups = function () { * @private */ ItemSet.prototype._orderNestedGroups = function(groupIds) { - var me = this var newGroupIdsOrder = []; - var nestingGroupsIds = this.groupsData.get({ - filter: function(group) { - return group.nestedGroups - } - }).map(function(nestingGroup) { return nestingGroup.id }) - - var allNestedGroupsIds = [] - nestingGroupsIds.forEach(function(groupId) { - var groupData = me.groupsData.get(groupId); - allNestedGroupsIds = allNestedGroupsIds.concat(groupData.nestedGroups) - }) - - var itemsWithoutNestedGroups = groupIds.filter(function(groupId) { return allNestedGroupsIds.indexOf(groupId) == -1 }); - - itemsWithoutNestedGroups.forEach(function(groupId){ - newGroupIdsOrder.push(groupId) - var groupData = me.groupsData.get(groupId); + groupIds.forEach(function(groupId){ + var groupData = this.groupsData.get(groupId); + if (!groupData.nestedInGroup) { + newGroupIdsOrder.push(groupId) + } if (groupData.nestedGroups) { - var nestedGroupsIds = me.groupsData.get(groupData.nestedGroups, { - order: me.options.groupOrder - }).map(function(group) { return group.id }); - newGroupIdsOrder = newGroupIdsOrder.concat(nestedGroupsIds) + var nestedGroups = this.groupsData.get({ + filter: function(nestedGroup) { + return nestedGroup.nestedInGroup == groupId; + }, + order: this.options.groupOrder + }); + var nestedGroupIds = nestedGroups.map(function(nestedGroup) { return nestedGroup.id }) + newGroupIdsOrder = newGroupIdsOrder.concat(nestedGroupIds); } }, this) return newGroupIdsOrder; @@ -1667,16 +1685,18 @@ ItemSet.prototype._onGroupClick = function (event) { groupsData = this.groupsData.getDataSet() } - group.showNested = !group.showNested; + var nestingGroup = groupsData.get(group.groupId) + 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 { From 1992ab9853d232d764a88e42488fd2e0b272bfd5 Mon Sep 17 00:00:00 2001 From: Yotam Berkowitz Date: Sun, 25 Jun 2017 18:28:28 +0300 Subject: [PATCH 3/6] Remove empty lines --- lib/timeline/component/ItemSet.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/timeline/component/ItemSet.js b/lib/timeline/component/ItemSet.js index c06343057..caeeba1cd 100644 --- a/lib/timeline/component/ItemSet.js +++ b/lib/timeline/component/ItemSet.js @@ -1089,7 +1089,6 @@ ItemSet.prototype._onAddGroups = function(ids) { var groupData = me.groupsData.get(id); var group = me.groups[id]; - if (!group) { // check for reserved ids if (id == UNGROUPED || id == BACKGROUND) { @@ -1123,7 +1122,6 @@ ItemSet.prototype._onAddGroups = function(ids) { } }); - this.body.emitter.emit('_change', {queue: true}); }; From 951647dcc536399cec5e3a267785726c9f533ec5 Mon Sep 17 00:00:00 2001 From: Yotam Berkowitz Date: Sat, 12 Aug 2017 18:18:52 +0300 Subject: [PATCH 4/6] Fix comments from PR --- lib/timeline/component/ItemSet.js | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/lib/timeline/component/ItemSet.js b/lib/timeline/component/ItemSet.js index 50713dbeb..b8f75f830 100644 --- a/lib/timeline/component/ItemSet.js +++ b/lib/timeline/component/ItemSet.js @@ -148,16 +148,14 @@ function ItemSet(body, options) { me._onAddGroups(params.items); if (me.groupsData && me.groupsData.length > 0) { - var groupsData = me.groupsData; - if (me.groupsData instanceof DataView) { - groupsData = me.groupsData.getDataSet() - } - - groupsData.get().forEach(function (groupData) { + var groupsData = me.groupsData.getDataSet(); + console.log(me.groupsData instanceof DataView) + 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; } @@ -165,9 +163,9 @@ function ItemSet(body, options) { if (groupData.showNested == false) { updatedNestedGroup.visible = false; } - groupsData.update(updatedNestedGroup); - }) - groupsData.update(groupData); + updatedGroups = updatedGroups.concat(updatedNestedGroup); + }); + groupsData.update(updatedGroups, senderId); } }); } @@ -1687,17 +1685,13 @@ 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(); var nestingGroup = groupsData.get(group.groupId) nestingGroup.showNested = !nestingGroup.showNested; var nestedGroups = groupsData.get(group.nestedGroups).map(function(nestedGroup) { - if (nestedGroup.visible == undefined) { nestedGroup.visible = true; } - nestedGroup.visible = !!nestingGroup.showNested; + nestedGroup.visible = nestingGroup.showNested; return nestedGroup; }); From add5aacd1ab4301531f7ad2e5ea2a09be7822f67 Mon Sep 17 00:00:00 2001 From: Yotam Berkowitz Date: Sat, 12 Aug 2017 18:21:09 +0300 Subject: [PATCH 5/6] Remove spaces from empty line --- lib/timeline/component/ItemSet.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/timeline/component/ItemSet.js b/lib/timeline/component/ItemSet.js index b8f75f830..e002f000f 100644 --- a/lib/timeline/component/ItemSet.js +++ b/lib/timeline/component/ItemSet.js @@ -1085,7 +1085,7 @@ ItemSet.prototype._onAddGroups = function(ids) { ids.forEach(function (id) { var groupData = me.groupsData.get(id); var group = me.groups[id]; - + if (!group) { // check for reserved ids if (id == UNGROUPED || id == BACKGROUND) { From dd6f035aae406c3cc1cce2cf173312b798b132b6 Mon Sep 17 00:00:00 2001 From: Yotam Berkowitz Date: Sat, 12 Aug 2017 23:51:35 +0300 Subject: [PATCH 6/6] Fix PR review comments --- lib/timeline/component/ItemSet.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/timeline/component/ItemSet.js b/lib/timeline/component/ItemSet.js index e002f000f..3d6e4000f 100644 --- a/lib/timeline/component/ItemSet.js +++ b/lib/timeline/component/ItemSet.js @@ -149,7 +149,6 @@ function ItemSet(body, options) { if (me.groupsData && me.groupsData.length > 0) { var groupsData = me.groupsData.getDataSet(); - console.log(me.groupsData instanceof DataView) groupsData.get().forEach(function (groupData) { if (groupData.nestedGroups) { if (groupData.showNested != false) { @@ -1688,6 +1687,7 @@ ItemSet.prototype._onGroupClick = function (event) { var groupsData = this.groupsData.getDataSet(); 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) {