github.com/outbrain/consul@v1.4.5/ui-v2/app/services/repository/policy.js (about) 1 import Service, { inject as service } from '@ember/service'; 2 import { get } from '@ember/object'; 3 import { typeOf } from '@ember/utils'; 4 import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/policy'; 5 import { Promise } from 'rsvp'; 6 import statusFactory from 'consul-ui/utils/acls-status'; 7 import isValidServerErrorFactory from 'consul-ui/utils/http/acl/is-valid-server-error'; 8 const isValidServerError = isValidServerErrorFactory(); 9 const status = statusFactory(isValidServerError, Promise); 10 const MODEL_NAME = 'policy'; 11 export default Service.extend({ 12 getModelName: function() { 13 return MODEL_NAME; 14 }, 15 getPrimaryKey: function() { 16 return PRIMARY_KEY; 17 }, 18 getSlugKey: function() { 19 return SLUG_KEY; 20 }, 21 store: service('store'), 22 status: function(obj) { 23 return status(obj); 24 }, 25 translate: function(item) { 26 return get(this, 'store').translate('policy', get(item, 'Rules')); 27 }, 28 findAllByDatacenter: function(dc) { 29 return get(this, 'store').query('policy', { 30 dc: dc, 31 }); 32 }, 33 findBySlug: function(slug, dc) { 34 return get(this, 'store').queryRecord('policy', { 35 id: slug, 36 dc: dc, 37 }); 38 }, 39 create: function(obj) { 40 return get(this, 'store').createRecord('policy', obj); 41 }, 42 persist: function(item) { 43 return item.save(); 44 }, 45 remove: function(obj) { 46 let item = obj; 47 if (typeof obj.destroyRecord === 'undefined') { 48 item = obj.get('data'); 49 } 50 if (typeOf(item) === 'object') { 51 item = get(this, 'store').peekRecord('policy', item[PRIMARY_KEY]); 52 } 53 return item.destroyRecord().then(item => { 54 return get(this, 'store').unloadRecord(item); 55 }); 56 }, 57 invalidate: function() { 58 get(this, 'store').unloadAll('policy'); 59 }, 60 });