-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#888 Complete the UI settings admin section
- Loading branch information
Showing
3 changed files
with
76 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters