fixes tags merging by removing duplicates
authorPhilipp Schüle <p.schuele@metaways.de>
Tue, 6 Oct 2015 18:23:09 +0000 (20:23 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 7 Oct 2015 09:36:26 +0000 (11:36 +0200)
... in js duplicate resolve panel

Change-Id: I6b20c4ba78cdecec8babf5e81e493669ff8427c8
Reviewed-on: http://gerrit.tine20.com/customers/2256
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Tinebase/js/widgets/dialog/DuplicateResolveGridPanel.js

index bb236a0..88ffee4 100644 (file)
@@ -508,9 +508,8 @@ Tine.widgets.dialog.DuplicateResolveStore = Ext.extend(Ext.data.GroupingStore, {
             }
 
             // special merge for tags
-            // TODO generalize me
             if (resolveRecord.get('fieldName') == 'tags') {
-                resolveRecord.set('finalValue', Tine.Tinebase.common.assertComparable([].concat(this.resolveStrategy != 'discard' ? mine : []).concat(this.resolveStrategy != 'keep' ? theirs : [])));
+                resolveRecord.set('finalValue', this.mergeTags(mine, theirs));
             } else {
                 resolveRecord.set('finalValue', location === 'mine' ? mine : theirs);
             }
@@ -521,6 +520,30 @@ Tine.widgets.dialog.DuplicateResolveStore = Ext.extend(Ext.data.GroupingStore, {
         
         this.commitChanges();
     },
+
+    /**
+     * merge tags
+     *
+     * @param {Array} mine
+     * @param {Array} theirs
+     *
+     * TODO generalize me for "merge-able" values
+     */
+    mergeTags: function(mine, theirs) {
+        var result = [],
+            records = Tine.Tinebase.common.assertComparable([].concat(this.resolveStrategy != 'discard' ? mine : []).concat(this.resolveStrategy != 'keep' ? theirs : [])),
+            recordIds = [];
+
+        // remove duplicates (TODO should be simplified)
+        Ext.each(records, function(value) {
+            if (recordIds.indexOf(value['id']) < 0) {
+                result.push(value);
+                recordIds.push(value['id']);
+            }
+        });
+
+        return result;
+    },
     
     checkEditGrant: function() {
         var grant = ! this.recordClass.getMeta('containerProperty') ? true : this.duplicates[this.duplicateIdx].get('container_id') ? this.duplicates[this.duplicateIdx].get(this.recordClass.getMeta('containerProperty')).account_grants['editGrant'] : false;