| 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237 |
1
1
1
2
2
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
| 'use strict';
;require.register("views/common/configs/config_versions_control_view", function (exports, require, module) {
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var App = require('app');
App.ConfigVersionsControlView = Em.View.extend({
templateName: require('templates/common/configs/config_versions_control'),
serviceName: Em.computed.alias('controller.content.serviceName'),
displayedServiceVersion: Em.computed.findBy('serviceVersions', 'isDisplayed', true),
isCompareMode: Em.computed.notEqual('controller.compareServiceVersion', null),
allServiceVersions: function () {
return App.ServiceConfigVersion.find().filterProperty('serviceName', this.get('serviceName'));
}.property('serviceName'),
serviceVersions: function () {
var _this = this;
var isDefaultGroupSelected = this.get('controller.selectedConfigGroup.isDefault');
var groupId = this.get('controller.selectedConfigGroup.id');
var serviceVersions = this.get('allServiceVersions').filter(function (s) {
return s.get('groupId') === groupId || isDefaultGroupSelected && s.get('groupName') === App.ServiceConfigGroup.defaultGroupName;
});
if (!serviceVersions.findProperty('isDisplayed')) {
//recompute serviceVersions if displayed version absent
Em.run.next(function () {
return _this.propertyDidChange('controller.selectedConfigGroup.name');
});
}
return serviceVersions.sort(function (a, b) {
return Em.get(b, 'createTime') - Em.get(a, 'createTime');
});
}.property('controller.selectedConfigGroup.name'),
primaryServiceVersionsInCompare: function () {
var _this2 = this;
return this.get('serviceVersions').filter(function (sv) {
return sv.get('version') !== _this2.get('controller.compareServiceVersion.version');
});
}.property('serviceVersions', 'controller.compareServiceVersion'),
secondaryServiceVersionsInCompare: function () {
var _this3 = this;
if (this.get('controller.compareServiceVersion')) {
return this.get('serviceVersions').filter(function (serviceVersion) {
return !serviceVersion.get('isDisplayed');
}).map(function (serviceVersion) {
var copy = Em.Object.create({
version: serviceVersion.get('version'),
stackVersion: serviceVersion.get('stackVersion'),
authorFormatted: serviceVersion.get('authorFormatted'),
createdDate: serviceVersion.get('createdDate'),
fullNotes: serviceVersion.get('fullNotes'),
isCurrent: serviceVersion.get('isCurrent')
});
copy.set('isDisplayed', serviceVersion.get('version') === _this3.get('controller.compareServiceVersion.version'));
return copy;
});
} else {
return [];
}
}.property('serviceVersions', 'controller.compareServiceVersion'),
willInsertElement: function willInsertElement() {
this.setDisplayVersion();
},
setDisplayVersion: function setDisplayVersion() {
var serviceVersions = this.get('serviceVersions');
var selectedVersion = this.get('controller.selectedVersion');
serviceVersions.forEach(function (serviceVersion) {
serviceVersion.set('isDisplayed', selectedVersion === serviceVersion.get('version'));
});
},
onChangeConfigGroup: function () {
var serviceVersions = this.get('serviceVersions');
var selectedGroupName = this.get('controller.selectedConfigGroup.name');
var preselectedVersion = this.get('controller.selectedVersion');
serviceVersions.forEach(function (serviceVersion) {
var isSelected = serviceVersion.get('version') === preselectedVersion && serviceVersion.get('groupName') === selectedGroupName;
serviceVersion.set('isDisplayed', isSelected);
});
if (!serviceVersions.someProperty('isDisplayed')) {
serviceVersions.forEach(function (serviceVersion) {
if (serviceVersion.get('isCurrent') && serviceVersion.get('groupName') === selectedGroupName) {
serviceVersion.set('isDisplayed', true);
}
});
}
}.observes('controller.selectedConfigGroup'),
/**
* switch configs view version to chosen
*/
switchVersion: function switchVersion(event, stayInCompare) {
var version = event.contexts[0];
if (this.get('serviceVersions').filterProperty('isDisplayed').someProperty('version', version)) {
return;
}
this.get('serviceVersions').forEach(function (serviceVersion) {
serviceVersion.set('isDisplayed', serviceVersion.get('version') === version);
});
this.get('controller').loadSelectedVersion(version, null, true);
},
switchPrimaryInCompare: function switchPrimaryInCompare(event) {
this.switchVersion({ contexts: [event.contexts[0].get('version')] }, true);
},
/**
* add config values of chosen version to view for comparison
* add a second version-info-bar for the chosen version
*/
compare: function compare(event) {
var serviceConfigVersion = event.contexts[0];
this.set('controller.compareServiceVersion', serviceConfigVersion);
var controller = this.get('controller');
controller.get('stepConfigs').clear();
controller.loadCompareVersionConfigs(controller.get('allConfigs')).done(function () {
controller.onLoadOverrides(controller.get('allConfigs'));
});
Iif ($(event.currentTarget).hasClass('compare-button')) {
// after entering Compare mode compare button should be destroyed before "focusOut" event, otherwise JS error will be thrown
event.view.destroy();
}
},
removeCompareVersionBar: function removeCompareVersionBar() {
var displayedVersion = this.get('displayedServiceVersion.version');
this.get('serviceVersions').forEach(function (serviceVersion) {
serviceVersion.set('isDisplayed', serviceVersion.get('version') === displayedVersion);
});
this.get('controller').loadSelectedVersion(displayedVersion);
},
/**
* revert config values to chosen version and apply reverted configs to server
*/
makeCurrent: function makeCurrent() {
var self = this;
var serviceConfigVersion = this.get('displayedServiceVersion');
var versionText = serviceConfigVersion.get('versionText');
return App.ModalPopup.show({
header: Em.I18n.t('dashboard.configHistory.info-bar.makeCurrent.popup.title'),
serviceConfigNote: Em.I18n.t('services.service.config.configHistory.makeCurrent.message').format(versionText),
bodyClass: Em.View.extend({
templateName: require('templates/common/configs/save_configuration'),
classNames: ['col-md-12'],
notesArea: Em.TextArea.extend({
classNames: ['full-width'],
value: Em.I18n.t('services.service.config.configHistory.makeCurrent.message').format(versionText),
onChangeValue: function () {
this.get('parentView.parentView').set('serviceConfigNote', this.get('value'));
}.observes('value')
})
}),
primary: Em.I18n.t('dashboard.configHistory.info-bar.revert.button'),
secondary: Em.I18n.t('common.discard'),
third: Em.I18n.t('common.cancel'),
onPrimary: function onPrimary() {
serviceConfigVersion.set('serviceConfigNote', this.get('serviceConfigNote'));
self.sendRevertCall(serviceConfigVersion);
this.hide();
},
onSecondary: function onSecondary() {
// force <code>serviceVersions</code> recalculating
self.propertyDidChange('controller.selectedConfigGroup.name');
this._super();
},
onThird: function onThird() {
this.onSecondary();
}
});
},
/**
* send PUT call to revert config to selected version
* @param serviceConfigVersion
*/
sendRevertCall: function sendRevertCall(serviceConfigVersion) {
App.ajax.send({
name: 'service.serviceConfigVersion.revert',
sender: this,
data: {
data: {
"Clusters": {
"desired_service_config_versions": {
"service_config_version": serviceConfigVersion.get('version'),
"service_name": serviceConfigVersion.get('serviceName'),
"service_config_version_note": serviceConfigVersion.get('serviceConfigNote')
}
}
}
},
success: 'sendRevertCallSuccess'
});
},
sendRevertCallSuccess: function sendRevertCallSuccess(data, opt, params) {
// revert to an old version would generate a new version with latest version number,
// so, need to loadStep to update
this.get('controller').loadStep();
}
});
}); |