diff --git a/frontend/app/scripts/controllers/dashboard/DashboardViewCtrl.js b/frontend/app/scripts/controllers/dashboard/DashboardViewCtrl.js index 64946c42c8..459a43aae6 100644 --- a/frontend/app/scripts/controllers/dashboard/DashboardViewCtrl.js +++ b/frontend/app/scripts/controllers/dashboard/DashboardViewCtrl.js @@ -1,9 +1,9 @@ -(function() { +(function () { 'use strict'; angular .module('theHiveControllers') - .controller('DashboardViewCtrl', function($scope, $q, $interval, $timeout, $uibModal, AuthenticationSrv, DashboardSrv, NotificationSrv, ModalUtilsSrv, UtilsSrv, dashboard, metadata) { + .controller('DashboardViewCtrl', function ($scope, $q, $interval, $timeout, $uibModal, AuthenticationSrv, DashboardSrv, NotificationSrv, ModalUtilsSrv, UtilsSrv, dashboard, metadata) { var self = this; this.currentUser = AuthenticationSrv.currentUser; @@ -15,13 +15,13 @@ this.autoRefresh = null; this.authRefreshRunner = null; - this.buildDashboardPeriodFilter = function(period) { + this.buildDashboardPeriodFilter = function (period) { return period === 'custom' ? DashboardSrv.buildPeriodQuery(period, 'createdAt', this.definition.customPeriod.fromDate, this.definition.customPeriod.toDate) : DashboardSrv.buildPeriodQuery(period, 'createdAt'); }; - this.loadDashboard = function(dashboard) { + this.loadDashboard = function (dashboard) { this.dashboard = dashboard; this.definition = JSON.parse(dashboard.definition) || { period: 'all', @@ -37,22 +37,22 @@ this.loadDashboard(dashboard); - $scope.$watch('$vm.autoRefresh', function(value) { - if(value === self.authRefreshRunner || self.options.editLayout === true) { + $scope.$watch('$vm.autoRefresh', function (value) { + if (value === self.authRefreshRunner || self.options.editLayout === true) { return; } - if(value === null) { + if (value === null) { $interval.cancel(self.authRefreshRunner); } else { $interval.cancel(self.authRefreshRunner); - self.authRefreshRunner = $interval(function() { + self.authRefreshRunner = $interval(function () { $scope.$broadcast('refresh-chart', self.periodFilter); }, value * 1000); } }); - this.canEditDashboard = function() { + this.canEditDashboard = function () { return (this.createdBy === this.currentUser.login) || this.dashboardStatus === 'Shared'; }; @@ -70,23 +70,23 @@ text: 'Text', multiline: 'Multi Lines' }, - editLayout: !_.find(this.definition.items, function(row) { + editLayout: !_.find(this.definition.items, function (row) { return row.items.length > 0; }) && this.canEditDashboard() }; - this.applyPeriod = function(period) { + this.applyPeriod = function (period) { this.definition.period = period; this.periodFilter = this.buildDashboardPeriodFilter(period); $scope.$broadcast('refresh-chart', this.periodFilter); }; - this.removeContainer = function(index) { + this.removeContainer = function (index) { var row = this.definition.items[index]; var promise; - if(row.items.length === 0) { + if (row.items.length === 0) { // If the container is empty, don't ask for confirmation promise = $q.resolve(); } else { @@ -96,54 +96,55 @@ }); } - promise.then(function() { + promise.then(function () { self.definition.items.splice(index, 1); }); }; - this.saveDashboard = function() { - var copy = _.pick(this.dashboard, 'title', 'description', 'status'); - copy.definition = angular.toJson(this.definition); + this.saveDashboard = function () { + var copy = { + definition: angular.toJson(this.definition) + }; DashboardSrv.update(this.dashboard.id, copy) - .then(function(/*response*/) { + .then(function (/*response*/) { self.options.editLayout = false; self.resizeCharts(); NotificationSrv.log('The dashboard has been successfully updated', 'success'); }) - .catch(function(err) { + .catch(function (err) { NotificationSrv.error('DashboardEditCtrl', err.data, err.status); }); }; - this.removeItem = function(rowIndex, colIndex) { + this.removeItem = function (rowIndex, colIndex) { ModalUtilsSrv.confirm('Remove widget', 'Are you sure you want to remove this item', { okText: 'Yes, remove it', flavor: 'danger' - }).then(function() { + }).then(function () { var row = self.definition.items[rowIndex]; row.items.splice(colIndex, 1); - $timeout(function() { + $timeout(function () { $scope.$broadcast('resize-chart-' + rowIndex); }, 0); }); }; - this.itemInserted = function(item, rows/*, rowIndex, index*/) { - if(!item.id){ + this.itemInserted = function (item, rows/*, rowIndex, index*/) { + if (!item.id) { item.id = UtilsSrv.guid(); } - for(var i=0; i < rows.length; i++) { + for (var i = 0; i < rows.length; i++) { $scope.$broadcast('resize-chart-' + i); } if (this.options.containerAllowedTypes.indexOf(item.type) !== -1 && !item.options.entity) { // The item is a widget - $timeout(function() { + $timeout(function () { $scope.$broadcast('edit-chart-' + item.id); }, 0); } @@ -151,34 +152,34 @@ return item; }; - this.itemDragStarted = function(colIndex, row) { + this.itemDragStarted = function (colIndex, row) { row.items.splice(colIndex, 1); }; - this.exportDashboard = function() { + this.exportDashboard = function () { DashboardSrv.exportDashboard(this.dashboard); }; - this.resizeCharts = function() { - $timeout(function() { - for(var i=0; i < self.definition.items.length; i++) { + this.resizeCharts = function () { + $timeout(function () { + for (var i = 0; i < self.definition.items.length; i++) { $scope.$broadcast('resize-chart-' + i); } }, 100); }; - this.enableEditMode = function() { + this.enableEditMode = function () { this.options.editLayout = true; this.resizeCharts(); }; - this.enableViewMode = function() { + this.enableViewMode = function () { DashboardSrv.get(this.dashboard.id) - .then(function(response) { + .then(function (response) { self.loadDashboard(response.data); self.options.editLayout = false; self.resizeCharts(); - }, function(err) { + }, function (err) { NotificationSrv.error('DashboardViewCtrl', err.data, err.status); }); }; diff --git a/frontend/app/scripts/controllers/dashboard/DashboardsCtrl.js b/frontend/app/scripts/controllers/dashboard/DashboardsCtrl.js index 307c17ba0b..a9f679d18c 100644 --- a/frontend/app/scripts/controllers/dashboard/DashboardsCtrl.js +++ b/frontend/app/scripts/controllers/dashboard/DashboardsCtrl.js @@ -1,28 +1,28 @@ -(function() { +(function () { 'use strict'; angular .module('theHiveControllers') - .controller('DashboardImportCtrl', function($scope, $uibModalInstance) { + .controller('DashboardImportCtrl', function ($scope, $uibModalInstance) { var self = this; this.formData = { fileContent: {} }; - $scope.$watch('vm.formData.attachment', function(file) { - if(!file) { + $scope.$watch('vm.formData.attachment', function (file) { + if (!file) { self.formData.fileContent = {}; return; } var aReader = new FileReader(); aReader.readAsText(self.formData.attachment, 'UTF-8'); aReader.onload = function (evt) { - $scope.$apply(function() { + $scope.$apply(function () { self.formData.fileContent = JSON.parse(aReader.result); }); } aReader.onerror = function (evt) { - $scope.$apply(function() { + $scope.$apply(function () { self.formData.fileContent = {}; }); } @@ -39,23 +39,26 @@ $uibModalInstance.dismiss('cancel'); }; }) - .controller('DashboardModalCtrl', function($uibModalInstance, $state, statuses, dashboard) { + .controller('DashboardModalCtrl', function ($uibModalInstance, AuthenticationSrv, $state, statuses, dashboard) { this.dashboard = dashboard; this.statuses = statuses; + this.currentUser = AuthenticationSrv.currentUser; - this.cancel = function() { + this.cancel = function () { $uibModalInstance.dismiss(); }; - this.ok = function() { + this.ok = function () { return $uibModalInstance.close(dashboard); }; }) - .controller('DashboardsCtrl', function($scope, $state, $uibModal, PaginatedQuerySrv, FilteringSrv, ModalUtilsSrv, NotificationSrv, DashboardSrv, AuthenticationSrv) { + .controller('DashboardsCtrl', function ($scope, $state, $uibModal, PaginatedQuerySrv, FilteringSrv, ModalUtilsSrv, NotificationSrv, DashboardSrv, AuthenticationSrv) { this.dashboards = []; var self = this; - this.$onInit = function() { + this.currentUser = AuthenticationSrv.currentUser; + + this.$onInit = function () { self.filtering = new FilteringSrv('dashboard', 'dashboard.list', { version: 'v0', defaults: { @@ -68,7 +71,7 @@ }); self.filtering.initContext('list') - .then(function() { + .then(function () { self.load(); $scope.$watch('$vm.list.pageSize', function (newValue) { @@ -77,7 +80,7 @@ }); } - this.load = function() { + this.load = function () { self.list = new PaginatedQuerySrv({ name: 'dashboard-list', @@ -88,10 +91,10 @@ pageSize: self.filtering.context.pageSize, filter: this.filtering.buildQuery(), operations: [ - {'_name': 'listDashboard'} + { '_name': 'listDashboard' } ], - onFailure: function(err) { - if(err && err.status === 400) { + onFailure: function (err) { + if (err && err.status === 400) { self.filtering.resetContext(); self.load(); } @@ -99,24 +102,24 @@ }); }; - this.openDashboardModal = function(dashboard) { + this.openDashboardModal = function (dashboard) { return $uibModal.open({ templateUrl: 'views/partials/dashboard/create.dialog.html', controller: 'DashboardModalCtrl', controllerAs: '$vm', size: 'lg', resolve: { - statuses: function() { + statuses: function () { return ['Private', 'Shared']; }, - dashboard: function() { + dashboard: function () { return dashboard; } } }); }; - this.addDashboard = function() { + this.addDashboard = function () { var modalInstance = this.openDashboardModal({ title: null, description: null, @@ -125,79 +128,87 @@ }); modalInstance.result - .then(function(dashboard) { + .then(function (dashboard) { return DashboardSrv.create(dashboard); }) - .then(function(response) { - $state.go('app.dashboards-view', {id: response.data.id}); + .then(function (response) { + $state.go('app.dashboards-view', { id: response.data.id }); NotificationSrv.log('The dashboard has been successfully created', 'success'); }) - .catch(function(err) { + .catch(function (err) { if (err && err.status) { NotificationSrv.error('DashboardsCtrl', err.data, err.status); } }); }; - this.duplicateDashboard = function(dashboard) { + this.duplicateDashboard = function (dashboard) { var copy = _.pick(dashboard, 'title', 'description', 'status', 'definition'); copy.title = 'Copy of ' + copy.title; this.openDashboardModal(copy) - .result.then(function(dashboard) { + .result.then(function (dashboard) { return DashboardSrv.create(dashboard); }) - .then(function(response) { - $state.go('app.dashboards-view', {id: response.data.id}); + .then(function (response) { + $state.go('app.dashboards-view', { id: response.data.id }); NotificationSrv.log('The dashboard has been successfully created', 'success'); }) - .catch(function(err) { + .catch(function (err) { if (err && err.status) { NotificationSrv.error('DashboardsCtrl', err.data, err.status); } }); }; - this.editDashboard = function(dashboard) { + this.editDashboard = function (dashboard) { var copy = _.extend({}, dashboard); - this.openDashboardModal(copy).result.then(function(dashboard) { - return DashboardSrv.update(dashboard.id, _.omit(dashboard, 'id')); - }) - .then(function(response) { - self.load() + this.openDashboardModal(copy).result + .then(function (dashboard) { - NotificationSrv.log('The dashboard has been successfully updated', 'success'); - }) - .catch(function(err) { - if (err && err.status) { - NotificationSrv.error('DashboardsCtrl', err.data, err.status); - } - }); + if (dashboard.createdBy === self.currentUser.login) { + return DashboardSrv.update(dashboard.id, _.omit(dashboard, 'id', 'definition')); + } else { + return DashboardSrv.update(dashboard.id, _.omit(dashboard, 'id', 'status', 'definition')); + } + + + }) + .then(function (response) { + self.load() + + NotificationSrv.log('The dashboard has been successfully updated', 'success'); + }) + .catch(function (err) { + if (err && err.status) { + NotificationSrv.error('DashboardsCtrl', err.data, err.status); + } + }); }; - this.deleteDashboard = function(id) { + this.deleteDashboard = function (id) { ModalUtilsSrv.confirm('Remove dashboard', 'Are you sure you want to remove this dashboard', { okText: 'Yes, remove it', flavor: 'danger' }) - .then(function() { + .then(function () { return DashboardSrv.remove(id); }) - .then(function(response) { + .then(function (response) { self.load(); NotificationSrv.log('The dashboard has been successfully removed', 'success'); }); }; - this.exportDashboard = function(dashboard) { + this.exportDashboard = function (dashboard) { DashboardSrv.exportDashboard(dashboard); } - this.importDashboard = function() { + this.importDashboard = function () { var modalInstance = $uibModal.open({ animation: true, templateUrl: 'views/partials/dashboard/import.dialog.html', @@ -206,19 +217,19 @@ size: 'lg' }); - modalInstance.result.then(function(dashboard) { + modalInstance.result.then(function (dashboard) { return DashboardSrv.create(dashboard); }) - .then(function(response) { - $state.go('app.dashboards-view', {id: response.data.id}); + .then(function (response) { + $state.go('app.dashboards-view', { id: response.data.id }); - NotificationSrv.log('The dashboard has been successfully imported', 'success'); - }) - .catch(function(err) { - if (err && err.status) { - NotificationSrv.error('DashboardsCtrl', err.data, err.status); - } - }); + NotificationSrv.log('The dashboard has been successfully imported', 'success'); + }) + .catch(function (err) { + if (err && err.status) { + NotificationSrv.error('DashboardsCtrl', err.data, err.status); + } + }); } // Filtering @@ -249,28 +260,28 @@ this.search(); }; - this.filterBy = function(field, value) { + this.filterBy = function (field, value) { self.filtering.clearFilters() - .then(function(){ + .then(function () { self.addFilterValue(field, value); }); }; - this.sortBy = function(sort) { + this.sortBy = function (sort) { self.list.sort = sort; self.list.update(); self.filtering.setSort(sort); }; - this.sortByField = function(field) { + this.sortByField = function (field) { var context = this.filtering.context; var currentSort = Array.isArray(context.sort) ? context.sort[0] : context.sort; var sort = null; - if(currentSort.substr(1) !== field) { + if (currentSort.substr(1) !== field) { sort = ['+' + field]; } else { - sort = [(currentSort === '+' + field) ? '-'+field : '+'+field]; + sort = [(currentSort === '+' + field) ? '-' + field : '+' + field]; } self.list.sort = sort; diff --git a/frontend/app/views/directives/dashboard/counter/series.html b/frontend/app/views/directives/dashboard/counter/series.html index 3cf37983b0..bbb3722365 100644 --- a/frontend/app/views/directives/dashboard/counter/series.html +++ b/frontend/app/views/directives/dashboard/counter/series.html @@ -17,7 +17,7 @@
diff --git a/frontend/app/views/directives/dashboard/line/series.html b/frontend/app/views/directives/dashboard/line/series.html index aaf7ea657e..a560ad9662 100644 --- a/frontend/app/views/directives/dashboard/line/series.html +++ b/frontend/app/views/directives/dashboard/line/series.html @@ -16,7 +16,7 @@
diff --git a/frontend/app/views/directives/dashboard/multiline/series.html b/frontend/app/views/directives/dashboard/multiline/series.html index 9f9260c800..593cf13acd 100644 --- a/frontend/app/views/directives/dashboard/multiline/series.html +++ b/frontend/app/views/directives/dashboard/multiline/series.html @@ -29,7 +29,7 @@
diff --git a/frontend/app/views/directives/dashboard/text/series.html b/frontend/app/views/directives/dashboard/text/series.html index e8feec4af8..f1e12a9d65 100644 --- a/frontend/app/views/directives/dashboard/text/series.html +++ b/frontend/app/views/directives/dashboard/text/series.html @@ -22,7 +22,7 @@
diff --git a/frontend/app/views/partials/dashboard/create.dialog.html b/frontend/app/views/partials/dashboard/create.dialog.html index 0c32f324a9..9507a70c1f 100644 --- a/frontend/app/views/partials/dashboard/create.dialog.html +++ b/frontend/app/views/partials/dashboard/create.dialog.html @@ -27,7 +27,8 @@