open-vault/ui/app/components/replication-summary.js

89 lines
2.2 KiB
JavaScript
Raw Normal View History

import { inject as service } from '@ember/service';
import { alias } from '@ember/object/computed';
import { get, computed } from '@ember/object';
import Component from '@ember/component';
2018-04-03 14:16:57 +00:00
import decodeConfigFromJWT from 'vault/utils/decode-config-from-jwt';
import ReplicationActions from 'vault/mixins/replication-actions';
import { task } from 'ember-concurrency';
2018-04-03 14:16:57 +00:00
const DEFAULTS = {
mode: 'primary',
token: null,
id: null,
loading: false,
errors: [],
primary_api_addr: null,
primary_cluster_addr: null,
ca_file: null,
ca_path: null,
replicationMode: 'dr',
};
2018-08-28 05:03:55 +00:00
export default Component.extend(ReplicationActions, DEFAULTS, {
wizard: service(),
version: service(),
2018-04-03 14:16:57 +00:00
didReceiveAttrs() {
this._super(...arguments);
const initialReplicationMode = this.get('initialReplicationMode');
if (initialReplicationMode) {
this.set('replicationMode', initialReplicationMode);
}
},
showModeSummary: false,
initialReplicationMode: null,
cluster: null,
replicationAttrs: alias('cluster.replicationAttrs'),
2018-04-03 14:16:57 +00:00
tokenIncludesAPIAddr: computed('token', function() {
const config = decodeConfigFromJWT(get(this, 'token'));
return config && config.addr ? true : false;
}),
disallowEnable: computed(
'replicationMode',
'version.hasPerfReplication',
'mode',
'tokenIncludesAPIAddr',
'primary_api_addr',
function() {
const inculdesAPIAddr = this.get('tokenIncludesAPIAddr');
if (this.get('replicationMode') === 'performance' && this.get('version.hasPerfReplication') === false) {
return true;
}
if (
this.get('mode') !== 'secondary' ||
inculdesAPIAddr ||
(!inculdesAPIAddr && this.get('primary_api_addr'))
) {
return false;
}
return true;
}
),
reset() {
this.setProperties(DEFAULTS);
},
submit: task(function*() {
yield this.submitHandler(...arguments);
let wizard = this.get('wizard');
wizard.transitionFeatureMachine(wizard.get('featureState'), 'ENABLEREPLICATION');
}),
2018-04-03 14:16:57 +00:00
actions: {
onSubmit(/*action, mode, data, event*/) {
this.get('submit').perform(...arguments);
2018-04-03 14:16:57 +00:00
},
clear() {
this.reset();
this.setProperties({
token: null,
id: null,
});
},
},
});