-
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.
#1579 Refactor the UiSettings service and add new ui options related …
…to alert similar cases section
- Loading branch information
Showing
9 changed files
with
87 additions
and
64 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
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
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
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,64 +1,58 @@ | ||
(function() { | ||
'use strict'; | ||
angular.module('theHiveServices').factory('UiSettingsSrv', function($http, $q) { | ||
|
||
var settings = null; | ||
angular.module('theHiveServices').service('UiSettingsSrv', function($http, $q) { | ||
var baseUrl = './api/config/organisation/'; | ||
var self = this; | ||
|
||
var keys = [ | ||
'ui.hideEmptyCaseButton' | ||
]; | ||
this.settings = null; | ||
|
||
var factory = { | ||
keys: keys, | ||
clearCache: function() { | ||
settings = null; | ||
}, | ||
this.keys = [ | ||
'hideEmptyCaseButton', | ||
'disallowMergeAlertInResolvedSimilarCases', | ||
'defaultAlertSimilarCaseFilter' | ||
]; | ||
|
||
get: function(name) { | ||
return settings[name]; | ||
}, | ||
this.clearCache = function() { | ||
self.settings = null; | ||
}; | ||
|
||
save: function(name, value) { | ||
return $http.put(baseUrl + name, {value: value}); | ||
}, | ||
this.get = function(name) { | ||
return self.settings[name]; | ||
}; | ||
|
||
all: function(force) { | ||
var deferred = $q.defer(); | ||
this.save = function(name, value) { | ||
return $http.put(baseUrl + 'ui.' + name, {value: value}); | ||
}; | ||
|
||
if(settings === null || force) { | ||
this.all = function(force) { | ||
var deferred = $q.defer(); | ||
|
||
settings = {}; | ||
if(self.settings === null || force) { | ||
|
||
$q.all(_.map(keys, function(key) { | ||
return $http.get(baseUrl + key); | ||
})).then(function(responses) { | ||
_.each(responses, function(response) { | ||
var data = response.data; | ||
self.settings = {}; | ||
|
||
settings[data.path] = data; | ||
settings[data.path].id = data.path; | ||
}); | ||
$http.get('./api/config/organisation?path=ui') | ||
.then(function(response) { | ||
var data = response.data; | ||
|
||
deferred.resolve(settings); | ||
}).catch(function(responses) { | ||
deferred.reject(responses); | ||
self.settings = data; | ||
deferred.resolve(data); | ||
}) | ||
.catch(function(response) { | ||
deferred.reject(response); | ||
}); | ||
} else { | ||
deferred.resolve(settings); | ||
} | ||
|
||
return deferred.promise; | ||
} else { | ||
deferred.resolve(self.settings); | ||
} | ||
|
||
return deferred.promise; | ||
}; | ||
|
||
keys.forEach(function(key) { | ||
this.keys.forEach(function(key) { | ||
var camelcased = s.camelize(key.replace(/\./gi, '_')); | ||
factory[camelcased] = function() { | ||
return (settings[key] || {}).value; | ||
self[camelcased] = function() { | ||
return (self.settings || {})[key]; | ||
}; | ||
}); | ||
|
||
return factory; | ||
}); | ||
})(); |
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
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