github.com/outbrain/consul@v1.4.5/ui-v2/app/mixins/token/with-actions.js (about) 1 import Mixin from '@ember/object/mixin'; 2 import WithBlockingActions from 'consul-ui/mixins/with-blocking-actions'; 3 import { get } from '@ember/object'; 4 import { inject as service } from '@ember/service'; 5 6 export default Mixin.create(WithBlockingActions, { 7 settings: service('settings'), 8 actions: { 9 use: function(item) { 10 return get(this, 'feedback').execute(() => { 11 return get(this, 'repo') 12 .findBySlug(get(item, 'AccessorID'), this.modelFor('dc').dc.Name) 13 .then(item => { 14 return get(this, 'settings') 15 .persist({ 16 token: { 17 AccessorID: get(item, 'AccessorID'), 18 SecretID: get(item, 'SecretID'), 19 }, 20 }) 21 .then(() => { 22 // using is similar to delete in that 23 // if you use from the listing page, stay on the listing page 24 // whereas if you use from the detail page, take me back to the listing page 25 return this.afterDelete(...arguments); 26 }); 27 }); 28 }, 'use'); 29 }, 30 logout: function(item) { 31 return get(this, 'feedback').execute(() => { 32 return get(this, 'settings') 33 .delete('token') 34 .then(() => { 35 // logging out is similar to delete in that 36 // if you log out from the listing page, stay on the listing page 37 // whereas if you logout from the detail page, take me back to the listing page 38 return this.afterDelete(...arguments); 39 }); 40 }, 'logout'); 41 }, 42 clone: function(item) { 43 let cloned; 44 return get(this, 'feedback').execute(() => { 45 return get(this, 'repo') 46 .clone(item) 47 .then(item => { 48 cloned = item; 49 // cloning is similar to delete in that 50 // if you clone from the listing page, stay on the listing page 51 // whereas if you clone from another token, take me back to the listing page 52 // so I can see it 53 return this.afterDelete(...arguments); 54 }) 55 .then(function() { 56 return cloned; 57 }); 58 }, 'clone'); 59 }, 60 }, 61 });