open-consul/ui-v2/app/services/settings.js
John Cowen b2f84299ca ui: Remove settings.findHeaders now we can use promises in our adapters (#7375)
Previously the API around setting headers wasn't within a Promised like
code path, so we needed a little 'cheat' function to get a token from
localStorage syncronously.

Since we refactored our adapter layer, we now have a Promised codepath
where we need to access this localStorage value and set our headers.
This means we can remove our little 'cheat' function.
2020-05-12 17:14:13 +00:00

33 lines
918 B
JavaScript

import Service from '@ember/service';
import getStorage from 'consul-ui/utils/storage/local-storage';
const SCHEME = 'consul';
const storage = getStorage(SCHEME);
export default Service.extend({
storage: storage,
findAll: function(key) {
return Promise.resolve(this.storage.all());
},
findBySlug: function(slug) {
return Promise.resolve(this.storage.getValue(slug));
},
persist: function(obj) {
const storage = this.storage;
Object.keys(obj).forEach((item, i) => {
storage.setValue(item, obj[item]);
});
return Promise.resolve(obj);
},
delete: function(obj) {
// TODO: Loop through and delete the specified keys
if (!Array.isArray(obj)) {
obj = [obj];
}
const storage = this.storage;
const item = obj.reduce(function(prev, item, i, arr) {
storage.removeValue(item);
return prev;
}, {});
return Promise.resolve(item);
},
});