From 9fc6d3d6f0656cba4121545d72eb5a6ff0a88819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 12 Feb 2014 14:35:12 +0100 Subject: [PATCH] Fixed tagsinput bug related to shallow clone of dashboard --- src/app/directives/bootstrap-tagsinput.js | 25 ++++++----------------- src/app/services/dashboard.js | 5 +++-- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/app/directives/bootstrap-tagsinput.js b/src/app/directives/bootstrap-tagsinput.js index d893aab1350..fb9954bb3b4 100644 --- a/src/app/directives/bootstrap-tagsinput.js +++ b/src/app/directives/bootstrap-tagsinput.js @@ -53,10 +53,6 @@ function (angular, $) { scope.$parent[attrs.tagclass] : function() { return attrs.tagclass; } }); - for (var i = 0; i < scope.model.length; i++) { - select.tagsinput('add', scope.model[i]); - } - select.on('itemAdded', function(event) { if (scope.model.indexOf(event.item) === -1) { scope.model.push(event.item); @@ -74,25 +70,16 @@ function (angular, $) { // diff when model changes var prev = scope.model.slice(); scope.$watch("model", function() { - - var added = scope.model.filter(function(i) {return prev.indexOf(i) === -1;}), - removed = prev.filter(function(i) {return scope.model.indexOf(i) === -1;}), - i; - - prev = scope.model.slice(); - - // Remove tags no longer in binded model - for (i = 0; i < removed.length; i++) { - select.tagsinput('remove', removed[i]); + if (!angular.isArray(scope.model)) { + scope.model = []; } - // Refresh remaining tags - select.tagsinput('refresh'); + select.tagsinput('removeAll'); - // Add new items in model as tags - for (i = 0; i < added.length; i++) { - select.tagsinput('add', added[i]); + for (var i = 0; i < scope.model.length; i++) { + select.tagsinput('add', scope.model[i]); } + }, true); } diff --git a/src/app/services/dashboard.js b/src/app/services/dashboard.js index 49231f732f4..45a6fe22cd6 100644 --- a/src/app/services/dashboard.js +++ b/src/app/services/dashboard.js @@ -120,7 +120,8 @@ function (angular, $, kbn, _, config, moment, Modernizr) { }; var dash_defaults = function(dashboard) { - _.defaults(dashboard,_dash); + + _.defaults(dashboard, _dash); _.defaults(dashboard.loader,_dash.loader); var filtering = _.findWhere(dashboard.pulldowns, {type: 'filtering'}); @@ -153,7 +154,7 @@ function (angular, $, kbn, _, config, moment, Modernizr) { dashboard = dash_defaults(dashboard); // Set the current dashboard - self.current = _.clone(dashboard); + self.current = angular.copy(dashboard); // Delay this until we're sure that querySrv and filterSrv are ready $timeout(function() {