| 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 |
1
1
1
4
1
1
1
1
1
1
1
1
3
3
3
3
1
1
2
2
2
1
2
2
1
1
| 'use strict';
;require.register("controllers/main/dashboard/config_history_controller", 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.MainConfigHistoryController = Em.ArrayController.extend(App.TableServerMixin, {
name: 'mainConfigHistoryController',
content: App.ServiceConfigVersion.find(),
totalCount: 0,
filteredCount: 0,
resetStartIndex: true,
mockUrl: '/data/configurations/service_versions.json',
realUrl: function () {
return App.apiPrefix + '/clusters/' + App.get('clusterName') + '/configurations/service_config_versions?<parameters>fields=service_config_version,user,group_id,group_name,is_current,createtime,service_name,hosts,service_config_version_note,is_cluster_compatible,stack_id&minimal_response=true';
}.property('App.clusterName'),
/**
* @type {boolean}
* @default false
*/
showFilterConditionsFirstLoad: false,
/**
* associations between host property and column index
* @type {Array}
*/
colPropAssoc: function () {
var associations = [];
associations[1] = 'serviceVersion';
associations[2] = 'configGroup';
associations[3] = 'createTime';
associations[4] = 'author';
associations[5] = 'notes';
return associations;
}.property(),
filterProps: [{
name: 'serviceVersion',
key: 'service_name',
type: 'EQUAL'
}, {
name: 'configGroup',
key: 'group_name',
type: 'EQUAL'
}, {
name: 'createTime',
key: 'createtime',
type: 'MORE'
}, {
name: 'author',
key: 'user',
type: 'MATCH'
}, {
name: 'notes',
key: 'service_config_version_note',
type: 'MATCH'
}],
sortProps: [{
name: 'serviceVersion',
key: 'service_name'
}, {
name: 'configGroup',
key: 'group_name'
}, {
name: 'createTime',
key: 'createtime'
}, {
name: 'author',
key: 'user'
}, {
name: 'notes',
key: 'service_config_version_note'
}],
/**
* load all data components required by config history table
* - total counter of service config versions(called in parallel)
* - current versions
* - filtered versions
* @param {boolean} shouldUpdateCounter
* @return {*}
*/
load: function load() {
var _this = this;
var shouldUpdateCounter = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
var dfd = $.Deferred();
this.loadConfigVersionsToModel().done(function () {
Eif (shouldUpdateCounter) {
_this.updateTotalCounter();
}
dfd.resolve();
});
return dfd.promise();
},
/**
* get filtered service config versions from server and push it to model
* @return {*}
*/
loadConfigVersionsToModel: function loadConfigVersionsToModel() {
var dfd = $.Deferred();
var queryParams = this.getQueryParameters();
App.HttpClient.get(this.getUrl(queryParams), App.serviceConfigVersionsMapper, {
complete: function complete() {
dfd.resolve();
}
});
return dfd.promise();
},
updateTotalCounter: function updateTotalCounter() {
return App.ajax.send({
name: 'service.serviceConfigVersions.get.total',
sender: this,
data: {},
success: 'updateTotalCounterSuccess'
});
},
updateTotalCounterSuccess: function updateTotalCounterSuccess(data, opt, params) {
this.set('totalCount', Number(data.itemTotal));
},
getUrl: function getUrl(queryParams) {
var params = '';
Iif (App.get('testMode')) {
return this.get('mockUrl');
} else {
if (queryParams) {
params = App.router.get('updateController').computeParameters(queryParams);
}
params = params.length > 0 ? params + "&" : params;
return this.get('realUrl').replace('<parameters>', params);
}
},
subscribeToUpdates: function subscribeToUpdates() {
App.StompClient.addHandler('/events/configs', 'history', this.load.bind(this, true));
},
unsubscribeOfUpdates: function unsubscribeOfUpdates() {
App.StompClient.removeHandler('/events/configs', 'history');
},
/**
* get sort properties from local db. A overridden funtion from parent
* @return {Array}
*/
getSortProps: function getSortProps() {
var savedSortConditions = App.db.getSortingStatuses(this.get('name')) || [],
sortProperties = this.get('sortProps'),
sortParams = [];
savedSortConditions.forEach(function (sort) {
var property = sortProperties.findProperty('name', sort.name);
if (property && (sort.status === 'sorting_asc' || sort.status === 'sorting_desc')) {
property.value = sort.status.replace('sorting_', '');
property.type = 'SORT';
if (property.name == 'serviceVersion') {
property.key = "service_name." + sort.status.replace('sorting_', '') + ",service_config_version";
property.value = "desc";
}
if (property.name == 'configGroup') {
property.key = "group_name." + sort.status.replace('sorting_', '') + ",service_config_version";
property.value = "desc";
}
sortParams.push(property);
}
});
return sortParams;
},
/**
*
* @param {string} name
*/
getSearchBoxSuggestions: function getSearchBoxSuggestions(name) {
var dfd = $.Deferred();
var key = this.get('filterProps').findProperty('name', name).key;
App.ajax.send({
name: 'service.serviceConfigVersions.get.suggestions',
sender: this,
data: {
key: key
}
}).done(function (data) {
dfd.resolve(data.items.mapProperty(key).uniq());
}).fail(function () {
dfd.resolve([]);
});
return dfd.promise();
}
});
}); |