Skip to content

Commit

Permalink
#485 Disallow clicking on dashboard items in edit mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Feb 12, 2019
1 parent 8b0e157 commit e9ee614
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 32 deletions.
20 changes: 10 additions & 10 deletions ui/app/scripts/controllers/dashboard/DashboardViewCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
this.periodFilter = this.buildDashboardPeriodFilter(period);

$scope.$broadcast('refresh-chart', this.periodFilter);
}
};

this.removeContainer = function(index) {
var row = this.definition.items[index];
Expand All @@ -95,28 +95,28 @@
promise = ModalUtilsSrv.confirm('Remove widget', 'Are you sure you want to remove this item', {
okText: 'Yes, remove it',
flavor: 'danger'
})
});
}

promise.then(function() {
self.definition.items.splice(index, 1)
self.definition.items.splice(index, 1);
});
}
};

this.saveDashboard = function() {
var copy = _.pick(this.dashboard, 'title', 'description', 'status');
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) {
NotificationSrv.error('DashboardEditCtrl', err.data, err.status);
})
}
});
};

this.removeItem = function(rowIndex, colIndex) {

Expand Down Expand Up @@ -151,15 +151,15 @@
}

return item;
}
};

this.itemDragStarted = function(colIndex, row) {
row.items.splice(colIndex, 1);
}
};

this.exportDashboard = function() {
DashboardSrv.exportDashboard(this.dashboard);
}
};

this.resizeCharts = function() {
$timeout(function() {
Expand Down
18 changes: 7 additions & 11 deletions ui/app/scripts/directives/dashboard/counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,25 @@
name: name,
label: serie.label,
value: data[name] || 0
}
};
});

}, function(err) {
}, function(/*err*/) {
scope.error = true;
NotificationSrv.log('Failed to fetch data, please edit the widget definition', 'error');
});
};

scope.openSearch = function(item) {
var criteria = [{ _type: scope.options.entity }, item.serie.query];

if (scope.globalQuery && scope.globalQuery !== '*') {
criteria.push(scope.globalQuery);
if(scope.mode === 'edit') {
return;
}

var searchQuery = {
_and: _.without(criteria, null, undefined, '')
};
var filters = (scope.options.filters || []).concat(item.serie.filters || []);

GlobalSearchSrv.saveSection(scope.options.entity, {
search: null,
filters: scope.options.filters.concat(item.serie.filters)
search: filters.length === 0 ? '*' : null,
filters: filters
});
$state.go('app.search');
};
Expand Down
7 changes: 5 additions & 2 deletions ui/app/scripts/directives/dashboard/donut.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@
names: scope.options.names || {},
colors: scope.options.colors || {},
onclick: function(d) {
if(scope.mode === 'edit') {
return;
}

var fieldDef = scope.entity.attributes[scope.options.field];
var fieldType = fieldDef.type;

var data = {
field: scope.options.field,
Expand All @@ -107,7 +110,7 @@
}
};
},
function(err) {
function(/*err*/) {
scope.error = true;
NotificationSrv.log('Failed to fetch data, please edit the widget definition', 'error');
}
Expand Down
10 changes: 5 additions & 5 deletions ui/app/scripts/directives/dashboard/item.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function() {
'use strict';
angular.module('theHiveDirectives').directive('dashboardItem', function(DashboardSrv, UserSrv, $uibModal, $timeout, $q) {
angular.module('theHiveDirectives').directive('dashboardItem', function(DashboardSrv, UserSrv, $uibModal, $timeout) {
return {
restrict: 'E',
replace: true,
Expand All @@ -13,13 +13,13 @@
autoload: '=',
refreshOn: '@',
resizeOn: '@',
mode: '@',
mode: '=',
showEdit: '=',
showRemove: '=',
onRemove: '&'
},
templateUrl: 'views/directives/dashboard/item.html',
link: function(scope, element) {
link: function(scope/*, element*/) {
scope.typeClasses = DashboardSrv.typeClasses;
scope.timeIntervals = DashboardSrv.timeIntervals;
scope.aggregations = DashboardSrv.aggregations;
Expand All @@ -35,7 +35,7 @@
scope.query = null;

if(scope.component.id) {
scope.$on('edit-chart-' + scope.component.id, function(data) {
scope.$on('edit-chart-' + scope.component.id, function(/*data*/) {
scope.editItem();
});
}
Expand Down Expand Up @@ -72,7 +72,7 @@
if(serie.filters) {
serie.query = DashboardSrv.buildFiltersQuery(scope.metadata[entity || serie.entity].attributes, serie.filters);
}
})
});

scope.component.options = definition;

Expand Down
6 changes: 3 additions & 3 deletions ui/app/views/directives/dashboard/item.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">
<i class="mr-xxs fa" ng-class="typeClasses[component.type]"></i>{{component.options.title || 'No title'}}
<i class="mr-xxs fa" ng-class="typeClasses[component.type]"></i>{{component.options.title || 'No title'}} {{mode}}
</h3>

<div class="box-tools pull-right">
Expand All @@ -13,11 +13,11 @@ <h3 class="box-title">
</a>

</div>
<div class="box-tools pull-right" ng-if="mode === 'edit'">
<!-- <div class="box-tools pull-right" ng-if="mode === 'edit'">
<button type="button" class="btn btn-box-tool" >
<i class="fa fa-save"></i> Save
</button>
</div>
</div> -->
</div>
<div class="box-body" ng-switch="component.type">
<dashboard-donut ng-switch-when="donut"
Expand Down
2 changes: 1 addition & 1 deletion ui/app/views/partials/dashboard/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ <h3 class="box-title">
dnd-drop="$vm.itemInserted(item, $vm.definition.items, rowIndex, index)">
<dashboard-item ng-repeat="(colIndex, component) in row.items"
autoload="true"
mode="view"
mode="$vm.options.editLayout ? 'edit' : 'view'"
row-index="rowIndex"
col-index="colIndex"
component="component"
Expand Down

0 comments on commit e9ee614

Please sign in to comment.