-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
replication-summary.js
90 lines (81 loc) · 2.33 KB
/
replication-summary.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { inject as service } from '@ember/service';
import { alias } from '@ember/object/computed';
import { get, computed } from '@ember/object';
import Component from '@ember/component';
import decodeConfigFromJWT from 'replication/utils/decode-config-from-jwt';
import ReplicationActions from 'replication/mixins/replication-actions';
import { task } from 'ember-concurrency';
import layout from '../templates/components/replication-summary';
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',
};
export default Component.extend(ReplicationActions, DEFAULTS, {
layout,
wizard: service(),
version: service(),
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'),
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');
}),
actions: {
onSubmit(/*action, mode, data, event*/) {
this.get('submit').perform(...arguments);
},
clear() {
this.reset();
this.setProperties({
token: null,
id: null,
});
},
},
});