Skip to content

Commit

Permalink
#888 Complete the UI settings admin section
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Feb 20, 2019
1 parent 7dd264d commit 27db888
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 15 deletions.
65 changes: 51 additions & 14 deletions ui/app/scripts/controllers/admin/AdminUiSettingsCtrl.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,69 @@
(function() {
'use strict';

angular.module('theHiveControllers').controller('AdminUiSettingsCtrl', function(UiSettingsSrv, uiConfig) {
angular.module('theHiveControllers').controller('AdminUiSettingsCtrl', function($scope, $q, NotificationSrv, UiSettingsSrv, uiConfig) {
var self = this;

self.isDirtySetting = function(key, newValue) {
var currentValue = (self.currentSettings[key] || {}).value;

return newValue !== currentValue;
};

self.save = function(/*form*/) {
var promises = [];

self.settingsKeys.forEach(function(key) {
//if(form[key].$dirty) {
if(!self.currentSettings[key]) {
UiSettingsSrv.create(key, self.configs[key]);
} else {
UiSettingsSrv.update(self.currentSettings[key].id, key, self.configs[key]);
if(self.isDirtySetting(key, self.configs[key])) {
if(!self.currentSettings[key]) {
promises.push(UiSettingsSrv.create(key, self.configs[key]));
} else {
promises.push(UiSettingsSrv.update(self.currentSettings[key].id, key, self.configs[key]));
}
}
//}
});

if(promises.length === 0) {
return;
}

$q.all(promises)
.then(function(/*responses*/) {
self.loadSettings();
NotificationSrv.log('UI Settings updated successfully', 'success');
})
.catch(function(/*errors*/) {
NotificationSrv.error('An error occurred during UI Settings update');
});
};

self.loadSettings = function() {
self.settingsKeys = UiSettingsSrv.keys;
self.currentSettings = uiConfig;
self.loadSettings = function(configurations) {
var notifyRoot = false;
var promise;

self.configs = {};
self.settingsKeys.forEach(function(key) {
self.configs[key] = (uiConfig[key] || {}).value;
if(configurations) {
promise = $q.resolve(configurations);
} else {
promise = UiSettingsSrv.all(true);
notifyRoot = true;
}

promise.then(function(configs) {
self.settingsKeys = UiSettingsSrv.keys;
self.currentSettings = configs;

self.configs = {};
self.settingsKeys.forEach(function(key) {
self.configs[key] = (configs[key] || {}).value;
});

if(notifyRoot) {
$scope.$emit('ui-settings:refresh', configs);
}
});
};

self.loadSettings();
self.loadSettings(uiConfig);

});
})();
4 changes: 3 additions & 1 deletion ui/app/scripts/services/UiSettingsSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

return {
keys: [
'hideEmptyCaseButton'
'hideEmptyCaseButton',
'hideMyTasks',
'hideWaitingTasks'
],
clearCache: function() {
settings = null;
Expand Down
22 changes: 22 additions & 0 deletions ui/app/views/partials/admin/ui-settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,28 @@ <h3 class="box-title">UI Settings</h3>
</div>
</div>

<div class="form-group">
<label class="col-md-3 control-label">Hide <em>My Tasks</em> menu</label>
<div class="col-md-9">
<div class="checkbox">
<label>
<input name="hideMyTasks" type="checkbox" ng-model="$vm.configs.hideMyTasks"> Check this to hide the <em>My Tasks</em> menu from the header
</label>
</div>
</div>
</div>

<div class="form-group">
<label class="col-md-3 control-label">Hide <em>Waiting Task</em> menu</label>
<div class="col-md-9">
<div class="checkbox">
<label>
<input name="hideWaitingTasks" type="checkbox" ng-model="$vm.configs.hideWaitingTasks"> Check this to hide the <em>Waiting Tasks</em> menu from the header
</label>
</div>
</div>
</div>

<div class="mt-s">
<button class="btn btn-primary pull-right" ng-disabled="settingsForm.$invalid" type="submit">Save</button>
</div>
Expand Down

0 comments on commit 27db888

Please sign in to comment.