1
|
var indexInspectorControllers = angular.module('indexInspectorControllers', ['LocalStorageModule']);
|
2
|
|
3
|
function common_init($scope, $http, $sce, $location) {
|
4
|
initSpinner();
|
5
|
$scope.showError = function (error) {
|
6
|
show_notification("error", error);
|
7
|
}
|
8
|
$scope.showNotification = function (message) {
|
9
|
show_notification("info", message);
|
10
|
}
|
11
|
$scope.showSpinner = function () {
|
12
|
showSpinner();
|
13
|
}
|
14
|
$scope.hideSpinner = function () {
|
15
|
hideSpinner();
|
16
|
}
|
17
|
$scope.to_trusted = function (html) {
|
18
|
return $sce.trustAsHtml(html);
|
19
|
}
|
20
|
$scope.go = function (path) {
|
21
|
$location.path(path);
|
22
|
}
|
23
|
$scope.encodeValue = function (val) {
|
24
|
return val;
|
25
|
}
|
26
|
}
|
27
|
|
28
|
indexInspectorControllers.directive('compileTemplate', function ($compile, $parse) {
|
29
|
return {
|
30
|
link: function (scope, element, attr) {
|
31
|
var parsed = $parse(attr.ngBindHtml);
|
32
|
|
33
|
function getStringValue() {
|
34
|
return (parsed(scope) || '').toString();
|
35
|
}
|
36
|
|
37
|
//Recompile if the template changes
|
38
|
scope.$watch(getStringValue, function () {
|
39
|
$compile(element, null, -9999)(scope); //The -9999 makes it skip directives so that we do not recompile ourselves
|
40
|
});
|
41
|
}
|
42
|
}
|
43
|
});
|
44
|
|
45
|
|
46
|
indexInspectorControllers.controller('indexmanageController', [
|
47
|
'$scope', '$http', '$sce', '$location',
|
48
|
function ($scope, $http, $sce, $location) {
|
49
|
common_init($scope, $http, $sce, $location);
|
50
|
|
51
|
|
52
|
}]);
|
53
|
|
54
|
indexInspectorControllers.controller('indexdbqController', ['$scope',
|
55
|
'$http', '$sce', '$location', function ($scope, $http, $sce, $location) {
|
56
|
common_init($scope, $http, $sce, $location);
|
57
|
$scope.mdFormats = []
|
58
|
$scope.backends = []
|
59
|
$scope.indices = []
|
60
|
$scope.query = '*=*'
|
61
|
$scope.from = 0
|
62
|
$scope.size = 10
|
63
|
$scope.error = null;
|
64
|
|
65
|
$scope.showSpinner();
|
66
|
|
67
|
$scope.to_trusted = function (html_code) {
|
68
|
return $sce.trustAsHtml(html_code);
|
69
|
}
|
70
|
|
71
|
|
72
|
$http.get('index/indexMetadataFormats.do').success(function (data) {
|
73
|
$scope.hideSpinner();
|
74
|
$scope.mdFormats = data;
|
75
|
}).error(function () {
|
76
|
$scope.showError('Error listing xmldb collections');
|
77
|
$scope.hideSpinner();
|
78
|
});
|
79
|
|
80
|
$http.get('index/backend.do').success(function (data) {
|
81
|
$scope.hideSpinner();
|
82
|
$scope.backends = data;
|
83
|
}).error(function (error) {
|
84
|
$scope.showError(error.message);
|
85
|
$scope.hideSpinner();
|
86
|
});
|
87
|
|
88
|
$scope.backendSelected = function (index) {
|
89
|
|
90
|
if ($scope.selectedbackend != null) {
|
91
|
$http.get('index/indexDatastructures.do', {
|
92
|
params: {
|
93
|
backend: $scope.selectedbackend
|
94
|
}
|
95
|
}).success(function (data) {
|
96
|
$scope.hideSpinner();
|
97
|
$scope.indices = data
|
98
|
|
99
|
}).error(function () {
|
100
|
$scope.showError('Error listing xmldb collections');
|
101
|
$scope.hideSpinner();
|
102
|
});
|
103
|
}
|
104
|
|
105
|
|
106
|
}
|
107
|
|
108
|
|
109
|
$scope.hideSpinner();
|
110
|
|
111
|
$scope.startDelete = function () {
|
112
|
$scope.from = 0;
|
113
|
$scope.size = 10
|
114
|
$scope.deleteByQuery()
|
115
|
}
|
116
|
|
117
|
|
118
|
$scope.deleteByQuery = function () {
|
119
|
|
120
|
if (($scope.selectedMdref == null) || ($scope.selectedbackend == null)) {
|
121
|
alert("You must select a metadata format and a backend identifier")
|
122
|
return;
|
123
|
}
|
124
|
|
125
|
$scope.showSpinner();
|
126
|
$scope.error = null;
|
127
|
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
|
128
|
var selectedId = null;
|
129
|
if ($scope.selectedIndex != null)
|
130
|
selectedId = $scope.selectedIndex.id
|
131
|
$http.post('index/delete.do', $.param({
|
132
|
|
133
|
'backend': $scope.selectedbackend,
|
134
|
'format': $scope.selectedMdref.metadataReference.format,
|
135
|
'layout': $scope.selectedMdref.metadataReference.layout,
|
136
|
'interpretation': $scope.selectedMdref.metadataReference.interpretation,
|
137
|
'query': $scope.query,
|
138
|
'indexidentifier': selectedId
|
139
|
|
140
|
}))
|
141
|
.success(function (data) {
|
142
|
$scope.hideSpinner();
|
143
|
$scope.searchResult = data
|
144
|
console.log(data)
|
145
|
}).error(function (error) {
|
146
|
$scope.error = error;
|
147
|
$scope.hideSpinner();
|
148
|
});
|
149
|
}
|
150
|
|
151
|
$scope.nextPage = function () {
|
152
|
if ($scope.searchResult == null)
|
153
|
return;
|
154
|
if ($scope.from > $scope.searchResult.total)
|
155
|
return;
|
156
|
$scope.from += 10;
|
157
|
$scope.size = $scope.from + 10
|
158
|
$scope.search()
|
159
|
}
|
160
|
|
161
|
$scope.prevPage = function () {
|
162
|
if ($scope.from <= 0) {
|
163
|
return;
|
164
|
}
|
165
|
|
166
|
$scope.from -= 10;
|
167
|
$scope.size -= 10
|
168
|
$scope.search()
|
169
|
}
|
170
|
|
171
|
$scope.range = function (n) {
|
172
|
return new Array(n);
|
173
|
};
|
174
|
|
175
|
|
176
|
}]);
|
177
|
|
178
|
|
179
|
indexInspectorControllers.controller('indexBrowseController', [
|
180
|
'$scope', '$http', '$sce', '$location',
|
181
|
function ($scope, $http, $sce, $location) {
|
182
|
common_init($scope, $http, $sce, $location);
|
183
|
$scope.showSpinner();
|
184
|
$scope.mdFormats = []
|
185
|
$scope.backends = []
|
186
|
$scope.indices = []
|
187
|
$scope.query = '*=*'
|
188
|
$scope.error = null;
|
189
|
|
190
|
$scope.browseFields = [];
|
191
|
$scope.addedBrowseFields = [];
|
192
|
$scope.selectedMdref = "";
|
193
|
|
194
|
$http.get('index/indexMetadataFormats.do').success(function (data) {
|
195
|
$scope.hideSpinner();
|
196
|
$scope.mdFormats = data;
|
197
|
}).error(function () {
|
198
|
$scope.showError('Error listing xmldb collections');
|
199
|
$scope.hideSpinner();
|
200
|
});
|
201
|
|
202
|
$http.get('index/backend.do').success(function (data) {
|
203
|
$scope.hideSpinner();
|
204
|
$scope.backends = data;
|
205
|
}).error(function (error) {
|
206
|
$scope.showError(error.message);
|
207
|
$scope.hideSpinner();
|
208
|
});
|
209
|
|
210
|
$scope.backendSelected = function (index) {
|
211
|
|
212
|
if ($scope.selectedbackend != null) {
|
213
|
$http.get('index/indexDatastructures.do', {
|
214
|
params: {
|
215
|
backend: $scope.selectedbackend
|
216
|
}
|
217
|
}).success(function (data) {
|
218
|
$scope.hideSpinner();
|
219
|
$scope.indices = data
|
220
|
|
221
|
}).error(function () {
|
222
|
$scope.showError('Error listing xmldb collections');
|
223
|
$scope.hideSpinner();
|
224
|
});
|
225
|
}
|
226
|
|
227
|
|
228
|
}
|
229
|
|
230
|
$scope.metadataFormatSelected = function (index) {
|
231
|
if ($scope.selectedMdref == null) {
|
232
|
$scope.addedBrowseFields = [];
|
233
|
$scope.browseFields = []
|
234
|
return;
|
235
|
}
|
236
|
|
237
|
$http.get('index/mdFormatInfo.do', {
|
238
|
params: {
|
239
|
id: $scope.selectedMdref.id,
|
240
|
layout: $scope.selectedMdref.metadataReference.layout
|
241
|
}
|
242
|
}).success(function (data) {
|
243
|
$scope.hideSpinner();
|
244
|
$scope.browseFields = data;
|
245
|
$scope.browseFields.sort()
|
246
|
$scope.addedBrowseFields = [];
|
247
|
$scope.selectedBrowser = '--- Add Field --'
|
248
|
}).error(function () {
|
249
|
$scope.showError('Error listing xmldb collections');
|
250
|
$scope.hideSpinner();
|
251
|
});
|
252
|
};
|
253
|
|
254
|
$scope.startBrowse = function () {
|
255
|
|
256
|
if (($scope.selectedMdref == null) || ($scope.selectedbackend == null)) {
|
257
|
alert("You must select a metadata format and a backend identifier")
|
258
|
return;
|
259
|
}
|
260
|
if ($scope.addedBrowseFields.length == 0) {
|
261
|
alert("You must select at least one browse field")
|
262
|
return;
|
263
|
}
|
264
|
$scope.showSpinner();
|
265
|
$scope.error = null;
|
266
|
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
|
267
|
$http.post('index/browse.do', $.param({
|
268
|
|
269
|
'backend': $scope.selectedbackend,
|
270
|
'format': $scope.selectedMdref.metadataReference.format,
|
271
|
'layout': $scope.selectedMdref.metadataReference.layout,
|
272
|
'interpretation': $scope.selectedMdref.metadataReference.interpretation,
|
273
|
'fields': JSON.stringify($scope.addedBrowseFields),
|
274
|
'query': $scope.query
|
275
|
}))
|
276
|
.success(function (data) {
|
277
|
$scope.hideSpinner();
|
278
|
$scope.browseResult = data
|
279
|
}).error(function (error) {
|
280
|
$scope.error = error;
|
281
|
$scope.hideSpinner();
|
282
|
});
|
283
|
}
|
284
|
|
285
|
|
286
|
$scope.deleteBrowseField = function (item) {
|
287
|
var i = 0
|
288
|
|
289
|
for (; i < $scope.addedBrowseFields.length; i++) {
|
290
|
if ($scope.addedBrowseFields[i] == item)
|
291
|
break;
|
292
|
}
|
293
|
$scope.addedBrowseFields.splice(i, 1)
|
294
|
$scope.browseFields = $scope.browseFields.concat(item)
|
295
|
$scope.browseFields.sort();
|
296
|
|
297
|
}
|
298
|
|
299
|
$scope.browseFieldAdded = function () {
|
300
|
for (i = 0; i < $scope.browseFields.length; i++) {
|
301
|
if ($scope.browseFields[i] == $scope.selectedBrowser) {
|
302
|
var data = $scope.browseFields[i];
|
303
|
$scope.addedBrowseFields = $scope.addedBrowseFields.concat(data)
|
304
|
$scope.browseFields.splice(i, 1)
|
305
|
return;
|
306
|
}
|
307
|
}
|
308
|
}
|
309
|
|
310
|
|
311
|
}]);
|
312
|
|
313
|
function replaceText(str) {
|
314
|
var str1 = String(str);
|
315
|
|
316
|
return str1.replace(/\n/g, "<br/>");
|
317
|
}
|
318
|
|
319
|
|
320
|
function constructMDREFfromString(input) {
|
321
|
if (input == null || input.length == 0)
|
322
|
return null;
|
323
|
var mdrefArr = input.split('-');
|
324
|
if (3 == mdrefArr.length) {
|
325
|
var x = [];
|
326
|
x['format'] = mdrefArr[0];
|
327
|
x['layout'] = mdrefArr[1];
|
328
|
x['interpretation'] = mdrefArr[2];
|
329
|
return x;
|
330
|
}
|
331
|
}
|
332
|
|
333
|
|
334
|
function counstructStringMDREF(item) {
|
335
|
if (item != null && item.hasOwnProperty('format') && item.hasOwnProperty('layout') && item.hasOwnProperty('interpretation'))
|
336
|
return item.format + '-' + item.layout + '-' + item.interpretation;
|
337
|
|
338
|
return null;
|
339
|
}
|
340
|
|
341
|
|
342
|
indexInspectorControllers.controller('indexQueryController', [
|
343
|
'$scope', '$http', '$sce', '$location', '$routeParams',
|
344
|
function ($scope, $http, $sce, $location, $routeParams) {
|
345
|
common_init($scope, $http, $sce, $location);
|
346
|
|
347
|
$scope.mdFormats = []
|
348
|
$scope.backends = []
|
349
|
$scope.indices = []
|
350
|
$scope.query = '*=*'
|
351
|
$scope.from = 0
|
352
|
$scope.size = 10
|
353
|
$scope.error = null;
|
354
|
console.log("Valore location");
|
355
|
|
356
|
|
357
|
if ($routeParams['backend'] != null && $routeParams['backend'].length > 0) {
|
358
|
$scope.selectedbackend_param = $routeParams['backend'];
|
359
|
$scope.selectedIndex_param = $routeParams['index'];
|
360
|
$scope.selectedMdref_param = constructMDREFfromString( $routeParams['mdformat']);
|
361
|
var selectedMdref_param = $routeParams['mdformat'];
|
362
|
$scope.start_param = $routeParams['start'];
|
363
|
$scope.query_param = $routeParams['query'];
|
364
|
|
365
|
$scope.query = $scope.query_param
|
366
|
|
367
|
$scope.showSpinner();
|
368
|
$scope.error = null;
|
369
|
$scope.size = 10;
|
370
|
$scope.from = $scope.start_param;
|
371
|
|
372
|
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
|
373
|
var selectedId = null;
|
374
|
if ($scope.selectedIndex != null)
|
375
|
selectedId = $scope.selectedIndex.id
|
376
|
$http.post('index/search.do', $.param({
|
377
|
|
378
|
'backend': $scope.selectedbackend_param,
|
379
|
'format': $scope.selectedMdref_param.metadataReference.format,
|
380
|
'layout': $scope.selectedMdref_param.metadataReference.layout,
|
381
|
'interpretation': $scope.selectedMdref_param.metadataReference.interpretation,
|
382
|
'query': $scope.query_param,
|
383
|
'from': $scope.start_param,
|
384
|
'number': $scope.size,
|
385
|
'indexidentifier': ""
|
386
|
}))
|
387
|
.success(function (data) {
|
388
|
$scope.hideSpinner();
|
389
|
$scope.searchResult = data
|
390
|
console.log(data)
|
391
|
}).error(function (error) {
|
392
|
$scope.error = error;
|
393
|
$scope.hideSpinner();
|
394
|
});
|
395
|
}
|
396
|
|
397
|
console.log(selectedMdref_param);
|
398
|
|
399
|
$scope.showSpinner();
|
400
|
|
401
|
$scope.to_trusted = function (html_code) {
|
402
|
return $sce.trustAsHtml(html_code);
|
403
|
}
|
404
|
|
405
|
|
406
|
$http.get('index/indexMetadataFormats.do').success(function (data) {
|
407
|
$scope.hideSpinner();
|
408
|
$scope.mdFormats = data;
|
409
|
|
410
|
if (selectedMdref_param != null) {
|
411
|
$scope.mdFormats.forEach(function (item) {
|
412
|
var mdref = counstructStringMDREF(item.metadataReference);
|
413
|
|
414
|
if (mdref === selectedMdref_param) {
|
415
|
$scope.selectedMdref = item;
|
416
|
}
|
417
|
})
|
418
|
}
|
419
|
|
420
|
|
421
|
}).error(function () {
|
422
|
$scope.showError('Error listing xmldb collections');
|
423
|
$scope.hideSpinner();
|
424
|
});
|
425
|
|
426
|
$http.get('index/backend.do').success(function (data) {
|
427
|
$scope.hideSpinner();
|
428
|
$scope.backends = data;
|
429
|
if ($scope.selectedbackend_param != null) {
|
430
|
$scope.backends.forEach(function (item) {
|
431
|
if (item === $scope.selectedbackend_param) {
|
432
|
$scope.selectedbackend = item;
|
433
|
}
|
434
|
})
|
435
|
}
|
436
|
|
437
|
|
438
|
|
439
|
}).error(function (error) {
|
440
|
$scope.showError(error.message);
|
441
|
$scope.hideSpinner();
|
442
|
});
|
443
|
|
444
|
$scope.backendSelected = function (index) {
|
445
|
|
446
|
if ($scope.selectedbackend != null) {
|
447
|
$http.get('index/indexDatastructures.do', {
|
448
|
params: {
|
449
|
backend: $scope.selectedbackend
|
450
|
}
|
451
|
}).success(function (data) {
|
452
|
$scope.hideSpinner();
|
453
|
$scope.indices = data
|
454
|
|
455
|
}).error(function () {
|
456
|
$scope.showError('Error listing xmldb collections');
|
457
|
$scope.hideSpinner();
|
458
|
});
|
459
|
}
|
460
|
|
461
|
|
462
|
}
|
463
|
|
464
|
|
465
|
$scope.hideSpinner();
|
466
|
|
467
|
$scope.startSearch = function () {
|
468
|
$scope.from = 0;
|
469
|
$scope.size = 10
|
470
|
$scope.search()
|
471
|
}
|
472
|
|
473
|
|
474
|
$scope.share = function () {
|
475
|
var currentUrl = $location.$$absUrl;
|
476
|
console.log(currentUrl);
|
477
|
var path = $location.$$path;
|
478
|
currentUrl = currentUrl.replace(path, "");
|
479
|
if ($scope.selectedIndex != null)
|
480
|
selectedId = $scope.selectedIndex.id
|
481
|
else
|
482
|
selectedId = "ALL"
|
483
|
var shareUrl = currentUrl + "/query/" + counstructStringMDREF($scope.selectedMdref) + "/" + $scope.selectedbackend + "/" + selectedId + "/" + $scope.from + "/" + $scope.query;
|
484
|
window.prompt("Copy to clipboard: Ctrl+C, Enter", shareUrl);
|
485
|
}
|
486
|
|
487
|
|
488
|
$scope.search = function () {
|
489
|
if (($scope.selectedMdref == null) || ($scope.selectedbackend == null)) {
|
490
|
alert("You must select a metadata format and a backend identifier")
|
491
|
return;
|
492
|
}
|
493
|
|
494
|
$scope.showSpinner();
|
495
|
$scope.error = null;
|
496
|
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
|
497
|
var selectedId = null;
|
498
|
if ($scope.selectedIndex != null)
|
499
|
selectedId = $scope.selectedIndex.id
|
500
|
$http.post('index/search.do', $.param({
|
501
|
|
502
|
'backend': $scope.selectedbackend,
|
503
|
'format': $scope.selectedMdref.metadataReference.format,
|
504
|
'layout': $scope.selectedMdref.metadataReference.layout,
|
505
|
'interpretation': $scope.selectedMdref.metadataReference.interpretation,
|
506
|
'query': $scope.query,
|
507
|
'from': $scope.from,
|
508
|
'number': $scope.size,
|
509
|
'indexidentifier': selectedId
|
510
|
}))
|
511
|
.success(function (data) {
|
512
|
$scope.hideSpinner();
|
513
|
$scope.searchResult = data
|
514
|
}).error(function (error) {
|
515
|
$scope.error = error;
|
516
|
$scope.hideSpinner();
|
517
|
});
|
518
|
}
|
519
|
|
520
|
$scope.nextPage = function () {
|
521
|
if ($scope.searchResult == null)
|
522
|
return;
|
523
|
if ($scope.from > $scope.searchResult.total)
|
524
|
return;
|
525
|
$scope.from += 10;
|
526
|
$scope.size = $scope.from + 10
|
527
|
$scope.search()
|
528
|
}
|
529
|
|
530
|
$scope.prevPage = function () {
|
531
|
if ($scope.from <= 0) {
|
532
|
return;
|
533
|
}
|
534
|
|
535
|
$scope.from -= 10;
|
536
|
$scope.size -= 10
|
537
|
$scope.search()
|
538
|
}
|
539
|
|
540
|
$scope.range = function (n) {
|
541
|
return new Array(n);
|
542
|
};
|
543
|
|
544
|
|
545
|
}]);
|