2018-09-25 16:28:26 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import Component from '@ember/component';
|
|
|
|
import { get } from '@ember/object';
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
export default Component.extend({
|
2018-04-03 14:16:57 +00:00
|
|
|
classNames: 'config-pki',
|
2018-09-25 16:28:26 +00:00
|
|
|
flashMessages: service(),
|
2018-04-03 14:16:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* @param String
|
|
|
|
* @public
|
|
|
|
* String corresponding to the route parameter for the current section
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
section: null,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @param DS.Model
|
|
|
|
* @public
|
|
|
|
*
|
|
|
|
* a `pki-config` model - passed in in the component useage
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
config: null,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @param Function
|
|
|
|
* @public
|
|
|
|
*
|
|
|
|
* function that gets called to refresh the config model
|
|
|
|
*
|
|
|
|
*/
|
2018-09-25 16:28:26 +00:00
|
|
|
onRefresh() {},
|
2018-04-03 14:16:57 +00:00
|
|
|
|
|
|
|
loading: false,
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
save(section) {
|
|
|
|
this.set('loading', true);
|
|
|
|
const config = this.get('config');
|
|
|
|
config
|
|
|
|
.save({
|
|
|
|
adapterOptions: {
|
|
|
|
method: section,
|
|
|
|
fields: get(config, `${section}Attrs`).map(attr => attr.name),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
this.get('flashMessages').success(`The ${section} config for this backend has been updated.`);
|
|
|
|
// attrs aren't persistent for Tidy
|
|
|
|
if (section === 'tidy') {
|
|
|
|
config.rollbackAttributes();
|
|
|
|
}
|
|
|
|
this.send('refresh');
|
|
|
|
})
|
2018-09-25 16:28:26 +00:00
|
|
|
.catch(() => {
|
|
|
|
// handle promise rejection - error will be shown by message-error component
|
|
|
|
})
|
2018-04-03 14:16:57 +00:00
|
|
|
.finally(() => {
|
|
|
|
this.set('loading', false);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
refresh() {
|
|
|
|
this.get('onRefresh')();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|