1
|
var repoControllers = angular.module('repoControllers', []);
|
2
|
|
3
|
repoControllers.controller('repoBrowseCtrl', [
|
4
|
'$scope', '$http', '$timeout', '$sce', '$location',
|
5
|
function ($scope, $http, $timeout, $sce, $location) {
|
6
|
common_init($scope, $http, $sce, $location);
|
7
|
$scope.repoBrowseFields = [];
|
8
|
|
9
|
$scope.searchRepos = function (text) {
|
10
|
$scope.go('/list/__SEARCH__/' + text);
|
11
|
}
|
12
|
|
13
|
$scope.browseRepoFields = function(refresh) {
|
14
|
$scope.repoBrowseFields = [];
|
15
|
$scope.showSpinner();
|
16
|
|
17
|
var url = 'browseRepoFields.do';
|
18
|
if (refresh) {
|
19
|
url += '?refresh=1';
|
20
|
}
|
21
|
$http.get(url).success(
|
22
|
function(data) {
|
23
|
$scope.hideSpinner();
|
24
|
$scope.repoBrowseFields = data;
|
25
|
$('body').trigger('resize'); // patch to adjust the width of ng-grid tables
|
26
|
}
|
27
|
).error(
|
28
|
function() {
|
29
|
$scope.showError('Something really bad must have happened to our fellow hamster..');
|
30
|
$scope.hideSpinner();
|
31
|
}
|
32
|
);
|
33
|
};
|
34
|
|
35
|
$scope.browseRepoFields(false);
|
36
|
}
|
37
|
]);
|
38
|
|
39
|
repoControllers.controller('repoListCtrl', [
|
40
|
'$scope', '$http', '$timeout', '$sce', '$routeParams', '$location',
|
41
|
function ($scope, $http, $timeout, $sce, $routeParams, $location) {
|
42
|
common_init($scope, $http, $sce, $location);
|
43
|
|
44
|
$scope.repos = [];
|
45
|
$scope.filterRepos = { filterText: '' };
|
46
|
$scope.gridRepos = {
|
47
|
data: 'repos',
|
48
|
enableRowSelection: false,
|
49
|
enableCellEditOnFocus: false,
|
50
|
enableHighlighting: true,
|
51
|
filterOptions: $scope.filterRepos,
|
52
|
columnDefs: [
|
53
|
{field: 'name' , displayName: 'Dataprovider', cellTemplate: '<ng-workflows-cell />' },
|
54
|
{field: 'prefix' , displayName: 'Namespace Prefix', width: '140px', cellClass: 'text-center' },
|
55
|
{field: 'country' , displayName: 'Country', width: '80px', headerClass: 'text-center', cellTemplate: '<div class="ngCellText text-center"><img ng-src="../resources/img/flags/{{row.getProperty(col.field)}}.gif" /> {{row.getProperty(col.field)}}</div>' },
|
56
|
{field: 'ifaces' , displayName: 'API Compatibilities', cellTemplate: '<ng-api-cell />' },
|
57
|
{field: 'valid' , displayName: 'Status', width: '200px', headerClass: 'text-center', cellTemplate: '<ng-validate-repo />' }
|
58
|
]
|
59
|
};
|
60
|
|
61
|
$scope.currentRepoSelectionParam = $routeParams.param;
|
62
|
$scope.currentRepoSelectionValue = $routeParams.value;
|
63
|
|
64
|
$scope.updateRepos = function(refresh) {
|
65
|
$scope.showSpinner();
|
66
|
|
67
|
var url = 'listRepositories.do?param=' + $scope.currentRepoSelectionParam + '&value=' + $scope.currentRepoSelectionValue;
|
68
|
if (refresh) {
|
69
|
url += "&refresh=1";
|
70
|
}
|
71
|
$http.get(url).success(
|
72
|
function(data) {
|
73
|
$scope.hideSpinner();
|
74
|
$scope.repos = data;
|
75
|
$scope.resizeMainElement(document.getElementById('reposTable'));
|
76
|
$('body').trigger('resize'); // patch to adjust the width of ng-grid tables
|
77
|
}
|
78
|
).error(
|
79
|
function() {
|
80
|
$scope.showError('Something really bad must have happened to our fellow hamster..');
|
81
|
$scope.hideSpinner();
|
82
|
}
|
83
|
);
|
84
|
};
|
85
|
|
86
|
$scope.setValidation = function(id, valid) {
|
87
|
$scope.showSpinner();
|
88
|
|
89
|
$http.get('validateRepo.do?b=' +valid + "&id=" + id)
|
90
|
.success(
|
91
|
function(data) {
|
92
|
var newId = data;
|
93
|
angular.forEach($scope.repos, function(r) {
|
94
|
if (r.id == id) {
|
95
|
r.id = newId;
|
96
|
r.valid = valid;
|
97
|
}
|
98
|
});
|
99
|
$scope.hideSpinner();
|
100
|
}
|
101
|
).error(
|
102
|
function() {
|
103
|
if (valid == false) {
|
104
|
$scope.showError('An error occurred: please verify that there are no workflows related to this dataprovider');
|
105
|
} else {
|
106
|
$scope.showError('An error occurred validating the dataprovider');
|
107
|
}
|
108
|
$scope.hideSpinner();
|
109
|
}
|
110
|
);
|
111
|
};
|
112
|
|
113
|
$scope.showApi = function (repoId, repoName, ifaceId) {
|
114
|
$scope.go('/api/' + repoId + '/' + repoName + '/' + ifaceId);
|
115
|
}
|
116
|
|
117
|
window.onresize = function() {
|
118
|
var elem = document.getElementById('reposTable');
|
119
|
if (elem) {
|
120
|
angular.element(elem).scope().resizeMainElement(elem);
|
121
|
}
|
122
|
};
|
123
|
|
124
|
$scope.updateRepos(false);
|
125
|
}
|
126
|
]);
|
127
|
|
128
|
repoControllers.controller('repoApiCtrl', [
|
129
|
'$scope', '$http', '$timeout', '$sce', '$routeParams', '$location',
|
130
|
function ($scope, $http, $timeout, $sce, $routeParams, $location) {
|
131
|
common_init($scope, $http, $sce, $location);
|
132
|
|
133
|
$scope.currentRepoId = $routeParams.repoId;
|
134
|
$scope.currentRepoName = $routeParams.repoName;
|
135
|
$scope.currentIfaceId = $routeParams.ifaceId;
|
136
|
$scope.availableRepohiWfs = getAvailableRepohiWfs();
|
137
|
$scope.compatibilityLevels = getCompatibilityLevels();
|
138
|
|
139
|
$scope.currentRepoApi = {};
|
140
|
$scope.currentSets = [];
|
141
|
$scope.selectedSets = [];
|
142
|
|
143
|
$scope.loadApi = function() {
|
144
|
$scope.showSpinner();
|
145
|
$(".btnRefreshApi").attr("disabled", "disabled");
|
146
|
$http.get('repoApi.get?repoId=' + $scope.currentRepoId + "&ifaceId=" + $scope.currentIfaceId)
|
147
|
.success(
|
148
|
function(data) {
|
149
|
$scope.currentRepoApi = data;
|
150
|
|
151
|
if (data.protocol == 'oai') {
|
152
|
var found = false;
|
153
|
angular.forEach(data.accessParams, function(param, pos){
|
154
|
if (param.name == 'set') {
|
155
|
$scope.listSets($scope.currentRepoApi.accessParams);
|
156
|
}
|
157
|
});
|
158
|
}
|
159
|
for (var i=0; i<4; i++) {
|
160
|
$scope.currentRepoApi.extraFields.push({'name':'', 'value':''});
|
161
|
}
|
162
|
|
163
|
$scope.hideSpinner();
|
164
|
|
165
|
$(".btnRefreshApi").removeAttr("disabled");
|
166
|
}
|
167
|
).error(
|
168
|
function() {
|
169
|
$scope.showError('Something really bad must have happened to our fellow hamster..');
|
170
|
$scope.hideSpinner();
|
171
|
}
|
172
|
);
|
173
|
};
|
174
|
|
175
|
$scope.newDataProviderWorkflow = function (wf) {
|
176
|
|
177
|
if (wf == undefined) {
|
178
|
$scope.showError('Please choose a workflow !');
|
179
|
return;
|
180
|
}
|
181
|
|
182
|
$scope.showSpinner();
|
183
|
|
184
|
$scope.currentRepoApi.metaWFs.push({"id":"","name":"Waiting...","status":"MISSING","progress":0});
|
185
|
|
186
|
$http.get('repoMetaWf.new?wf=' + wf + '&iface=' + $scope.currentIfaceId + '&id=' + $scope.currentRepoId + '&name=' + $scope.currentRepoName)
|
187
|
.success(
|
188
|
function(data) {
|
189
|
$scope.hideSpinner();
|
190
|
$(".btnRefreshApi").attr("disabled", "disabled");
|
191
|
$timeout(function () { $scope.loadApi() }, 7000);
|
192
|
}
|
193
|
).error(
|
194
|
function() {
|
195
|
$scope.showError('Something really bad must have happened to our fellow hamster..');
|
196
|
$scope.hideSpinner();
|
197
|
}
|
198
|
);
|
199
|
};
|
200
|
|
201
|
$scope.destroyDataProviderWorkflow = function (metaWf) {
|
202
|
|
203
|
if (metaWf.destroyWorkflow == undefined) {
|
204
|
$scope.showError('Destroy wf is missing !');
|
205
|
return;
|
206
|
}
|
207
|
|
208
|
$scope.showSpinner();
|
209
|
|
210
|
metaWf.deleting = true;
|
211
|
|
212
|
$http.get('repoMetaWf.destroy?destroyWf=' + metaWf.destroyWorkflow)
|
213
|
.success(
|
214
|
function(data) {
|
215
|
$scope.hideSpinner();
|
216
|
$(".btnRefreshApi").attr("disabled", "disabled");
|
217
|
$timeout(function () { $scope.loadApi() }, 7000);
|
218
|
}
|
219
|
).error(
|
220
|
function() {
|
221
|
$scope.showError('Something really bad must have happened to our fellow hamster..');
|
222
|
$scope.hideSpinner();
|
223
|
}
|
224
|
);
|
225
|
};
|
226
|
|
227
|
$scope.testOAI = function (params) {
|
228
|
angular.forEach(params, function(param, pos){
|
229
|
if (param.name == 'baseUrl') {
|
230
|
location.href = "oaiExplorer.do?oaiBaseUrl=" + param.value;
|
231
|
}
|
232
|
});
|
233
|
}
|
234
|
|
235
|
$scope.updateRepoApi = function (type, params) {
|
236
|
$scope.showSpinner();
|
237
|
|
238
|
var map = {};
|
239
|
angular.forEach(params, function(param, pos){
|
240
|
if (param.name) {
|
241
|
map[param.name] = param.value
|
242
|
}
|
243
|
});
|
244
|
var params = {};
|
245
|
params[type] = JSON.stringify(map);
|
246
|
|
247
|
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
|
248
|
$http.post('repoApi.update?id=' + $scope.currentRepoId + '&iface=' + $scope.currentRepoApi.id, $.param(params))
|
249
|
.success(
|
250
|
function(data) {
|
251
|
$scope.showNotification('Api correctly saved !');
|
252
|
$scope.loadApi();
|
253
|
}
|
254
|
).error(
|
255
|
function() {
|
256
|
$scope.showError('Something really bad must have happened to our fellow hamster..');
|
257
|
$scope.hideSpinner();
|
258
|
}
|
259
|
);
|
260
|
};
|
261
|
|
262
|
|
263
|
$scope.updateSets = function(selection, accessParams) {
|
264
|
var s = selection.join();
|
265
|
angular.forEach(accessParams, function(param, pos){
|
266
|
if (param.name == 'set') {
|
267
|
param.value = s;
|
268
|
}
|
269
|
});
|
270
|
}
|
271
|
|
272
|
$scope.listSets = function(accessParams) {
|
273
|
var baseUrl = '';
|
274
|
|
275
|
$scope.selectedSets = [];
|
276
|
$scope.currentSets = [];
|
277
|
|
278
|
angular.forEach(accessParams, function(param, pos){
|
279
|
if (param.name == 'baseUrl') {
|
280
|
baseUrl = param.value
|
281
|
}
|
282
|
if (param.name == 'set') {
|
283
|
$scope.selectedSets = param.value.split(",");
|
284
|
}
|
285
|
});
|
286
|
|
287
|
if (!baseUrl) {
|
288
|
$scope.showError("baseUrl param is missing");
|
289
|
return;
|
290
|
}
|
291
|
|
292
|
$scope.showSpinner();
|
293
|
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
|
294
|
$http.post("wf_obtainValidValues.list?bean=oaiListSets", $.param({
|
295
|
'baseUrl': baseUrl
|
296
|
})).success(function(data) {
|
297
|
$scope.hideSpinner();
|
298
|
$scope.currentSets = data;
|
299
|
angular.forEach($scope.currentSets, function(curr, pos1) {
|
300
|
angular.forEach($scope.selectedSets, function(sel, pos2) {
|
301
|
if (curr.id.trim() == sel.trim()) {
|
302
|
curr.selected = true;
|
303
|
}
|
304
|
});
|
305
|
});
|
306
|
}).error(function() {
|
307
|
$scope.hideSpinner();
|
308
|
$scope.showError("baseUrl param is missing");
|
309
|
});
|
310
|
|
311
|
};
|
312
|
|
313
|
|
314
|
$scope.verifyMetaWf = function(ds, wf) {
|
315
|
var compliance = '';
|
316
|
var type = '';
|
317
|
angular.forEach(ds.commonParams, function(p,pos) {
|
318
|
if (p.id == 'compliance') {
|
319
|
compliance = p.value;
|
320
|
}
|
321
|
if (p.id == 'typology') {
|
322
|
type = p.value;
|
323
|
}
|
324
|
});
|
325
|
|
326
|
return (compliance && type && $scope.isValidTerm(compliance, wf.compliances) && $scope.isValidTerm(type, wf.ifaceTypes));
|
327
|
}
|
328
|
|
329
|
$scope.isValidTerm = function(term, list) {
|
330
|
|
331
|
if (list.length == 0) {
|
332
|
return true;
|
333
|
}
|
334
|
var res = false;
|
335
|
angular.forEach(list, function(curr,pos) {
|
336
|
if (term.lastIndexOf(curr, 0) === 0) { // implementation of term.startsWith(curr)
|
337
|
res = true;
|
338
|
}
|
339
|
});
|
340
|
return res;
|
341
|
}
|
342
|
|
343
|
$scope.overrideApiCompliance = function(level) {
|
344
|
$scope.showSpinner();
|
345
|
$http.get('repoApiCompliance.update?id=' + $scope.currentRepoId + '&iface=' + $scope.currentRepoApi.id + '&compliance=' + level)
|
346
|
.success(
|
347
|
function(data) {
|
348
|
$scope.hideSpinner();
|
349
|
$scope.showNotification('Api correctly updated !');
|
350
|
$scope.loadApi();
|
351
|
}
|
352
|
).error(
|
353
|
function() {
|
354
|
$scope.showError('Something really bad must have happened to our fellow hamster..');
|
355
|
$scope.hideSpinner();
|
356
|
}
|
357
|
);
|
358
|
}
|
359
|
|
360
|
$scope.resetApiCompliance = function() {
|
361
|
$scope.showSpinner();
|
362
|
$http.get('repoApiCompliance.reset?id=' + $scope.currentRepoId + '&iface=' + $scope.currentRepoApi.id)
|
363
|
.success(
|
364
|
function(data) {
|
365
|
$scope.hideSpinner();
|
366
|
$scope.showNotification('Api correctly updated !');
|
367
|
$scope.loadApi();
|
368
|
}
|
369
|
).error(
|
370
|
function() {
|
371
|
$scope.showError('Something really bad must have happened to our fellow hamster..');
|
372
|
$scope.hideSpinner();
|
373
|
}
|
374
|
);
|
375
|
}
|
376
|
|
377
|
$scope.loadApi();
|
378
|
}
|
379
|
|
380
|
]);
|
381
|
|