Project

General

Profile

1 26600 sandro.lab
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 29896 michele.ar
		$scope.repoBrowseFields = getBrowseFields();
8 26600 sandro.lab
9 53965 michele.ar
		$scope.sortType     = 'term';
10
		$scope.sortReverse  = false;
11 29896 michele.ar
12 53965 michele.ar
		$scope.repoBrowseData = { 'data' : [] };
13
14 30812 michele.ar
		$scope.searchApis = function (text) {
15 26600 sandro.lab
			$scope.go('/list/__SEARCH__/' + text);
16
		}
17
18 30812 michele.ar
		$scope.browseApis = function (field, value) {
19 29896 michele.ar
			$('#showRepoBrowseData').modal('hide');
20 26600 sandro.lab
			$scope.showSpinner();
21 29896 michele.ar
			$timeout(function() {
22
				$scope.go('/list/' + field + '/' + value);
23
			}, 1500);
24
		}
25
26
		$scope.browseRepoField = function(field) {
27
			$scope.repoBrowseData = {
28
				'label' : field.label,
29
				'id' :    field.id,
30
				'data'  : []
31
			};
32
			$scope.showSpinner();
33 33846 michele.ar
	      	$http.get('browseRepoField.do?field=' + field.id).success(
34 26600 sandro.lab
	            function(data) {
35
	            	$scope.hideSpinner();
36 29896 michele.ar
	            	$scope.repoBrowseData.data = data;
37
	            	$('#showRepoBrowseData').modal('show');
38 26600 sandro.lab
	            }
39
	        ).error(
40
	            function() {
41
	            	$scope.showError('Something really bad must have happened to our fellow hamster..');
42
	            	$scope.hideSpinner();
43
	            }
44
	        );
45
		};
46
	}
47
]);
48
49
repoControllers.controller('repoListCtrl', [
50
	'$scope', '$http', '$timeout', '$sce', '$routeParams', '$location',
51
	function ($scope, $http, $timeout, $sce, $routeParams, $location) {
52
		common_init($scope, $http, $sce, $location);
53
54 53965 michele.ar
		$scope.sortType     = 'repoName';
55
		$scope.sortReverse  = false;
56
		$scope.apis = [];
57 30812 michele.ar
    	$scope.currentApiSelectionParam = $routeParams.param;
58
    	$scope.currentApiSelectionValue = $routeParams.value;
59 26600 sandro.lab
60 30812 michele.ar
    	$scope.updateApis = function(refresh) {
61 26600 sandro.lab
			$scope.showSpinner();
62 29896 michele.ar
63
			var params = {
64 30812 michele.ar
				'param' : $scope.currentApiSelectionParam,
65 53965 michele.ar
				'value' : $scope.currentApiSelectionValue
66 29896 michele.ar
			};
67 26600 sandro.lab
			if (refresh) {
68 29896 michele.ar
				params.refresh = 1;
69 26600 sandro.lab
			}
70 29896 michele.ar
71
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
72 30812 michele.ar
			$http.post('listApis.do', $.param(params)).success(
73 26600 sandro.lab
	            function(data) {
74
	            	$scope.hideSpinner();
75 30812 michele.ar
	            	$scope.apis = data;
76 26600 sandro.lab
	            }
77
	        ).error(
78
	            function() {
79
	            	$scope.showError('Something really bad must have happened to our fellow hamster..');
80
	            	$scope.hideSpinner();
81
	            }
82
	        );
83
    	};
84 53965 michele.ar
85 30812 michele.ar
    	$scope.updateApis(false);
86 26600 sandro.lab
	}
87
]);
88
89
repoControllers.controller('repoApiCtrl', [
90
	'$scope', '$http', '$timeout', '$sce', '$routeParams', '$location',
91
	function ($scope, $http, $timeout, $sce, $routeParams, $location) {
92
		common_init($scope, $http, $sce, $location);
93
94 30166 michele.ar
		commonInitialize($scope, $http, $sce);
95
		wf_init($scope, $http, $sce);
96
97 26600 sandro.lab
		$scope.availableRepohiWfs = getAvailableRepohiWfs();
98 29884 michele.ar
		$scope.compatibilityLevels = getCompatibilityLevels();
99 42211 michele.ar
100
		$scope.validatorBlacklistAddress = '';
101
		$scope.validatorBlacklistAddress = '';
102 30186 michele.ar
103 29884 michele.ar
		$scope.currentRepoApi = {};
104 27100 michele.ar
		$scope.currentSets = [];
105
		$scope.selectedSets = [];
106 26600 sandro.lab
107
    	$scope.loadApi = function() {
108
    		$scope.showSpinner();
109
    		$(".btnRefreshApi").attr("disabled", "disabled");
110 30820 michele.ar
    		$http.get('repoApi.get?repoId=' + $routeParams.repoId + "&ifaceId=" +  $routeParams.ifaceId)
111 26600 sandro.lab
            .success(
112
                function(data) {
113 28876 michele.ar
                	$scope.currentRepoApi = data;
114 30166 michele.ar
                	$scope.metaworkflows = data.metaWFs;
115 43848 michele.ar
116 42215 michele.ar
                	angular.forEach(data.otherParams, function(term){
117
                		if (term.id == 'last_validation_job') {
118
                			if (getValidatorAddress()) {
119
                				$scope.validatorDetailsAddress = getValidatorAddress() + "/prepareSummary.action?jobId=" + term.value;
120
                			}
121
                			if (getValidatorServiceAddress()) {
122
                				$scope.validatorBlacklistAddress = getValidatorServiceAddress() + "/workflows?request=GetBlacklistedRecords&datasourceId=" + $routeParams.repoId;
123
                			}
124
                		}
125
                	});
126 42211 michele.ar
127 26600 sandro.lab
                	if (data.protocol == 'oai') {
128
    	            	var found = false;
129
    	            	angular.forEach(data.accessParams, function(param, pos){
130
    	                    if (param.name == 'set') {
131 28876 michele.ar
    	                    	$scope.listSets($scope.currentRepoApi.accessParams);
132 26600 sandro.lab
    	                    }
133
    	        		});
134
                	}
135
                	$scope.hideSpinner();
136
137
                	$(".btnRefreshApi").removeAttr("disabled");
138 30186 michele.ar
139
                	if ($routeParams.metawf != 'ALL' && $routeParams.wf != 'ALL') {
140
                		$scope.getAtomicWorkflowAndMetaWf($routeParams.metawf, $routeParams.wf);
141
                		$timeout(function() {
142
                			$("#collapse_" + $routeParams.metawf.substring(0, 36)).collapse('show');
143
                		}, 2000);
144
                	}
145 26600 sandro.lab
                }
146
            ).error(
147
                function() {
148
                	$scope.showError('Something really bad must have happened to our fellow hamster..');
149
                	$scope.hideSpinner();
150
                }
151
            );
152
    	};
153
154 43828 michele.ar
155
    	$scope.removeApi = function() {
156
    		if (confirm("You are deleting the current API.\n\nAre you sure?")) {
157
	    		$scope.showSpinner();
158
	    		$http.get('repoApi.delete?repo=' + $routeParams.repoId + "&iface=" +  $routeParams.ifaceId).success(function(data) {
159
	    			alert("The API has been deleted !!!");
160
	    			$scope.hideSpinner();
161
	    			$scope.go("/browse");
162
	    		}).error(function(err) {
163
	    			$scope.showError('Error removing API: '  + err.message);
164
	    			$scope.hideSpinner();
165
	    		});
166
    		}
167
    	};
168
169
170 26600 sandro.lab
		$scope.newDataProviderWorkflow = function (wf) {
171
172
			if (wf == undefined) {
173
				$scope.showError('Please choose a workflow !');
174
	    		return;
175
			}
176
177
			$scope.showSpinner();
178
179 30166 michele.ar
			$scope.metaworkflows.push({"id":"","name":"Waiting...","status":"MISSING","progress":0});
180 26600 sandro.lab
181 31785 andrea.man
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
182
			$http.post('repoMetaWf.new', $.param({
183
				'wf'    : wf,
184
				'iface' : $scope.currentRepoApi.id,
185
				'id'    : $scope.currentRepoApi.repoId,
186
				'name'  : $scope.currentRepoApi.repoName
187
			})).success(
188 26600 sandro.lab
	       			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 30166 michele.ar
208
			if (!confirm("Are you sure ?")) {
209
				return;
210
			}
211 26600 sandro.lab
212
			$scope.showSpinner();
213
214
			metaWf.deleting = true;
215
216
			$http.get('repoMetaWf.destroy?destroyWf=' + metaWf.destroyWorkflow)
217
	       	.success(
218
	       			function(data) {
219
	       				$scope.hideSpinner();
220
	       				$(".btnRefreshApi").attr("disabled", "disabled");
221
	       				$timeout(function () { $scope.loadApi() }, 7000);
222
		            }
223
	       	).error(
224
	       			function() {
225
	       				$scope.showError('Something really bad must have happened to our fellow hamster..');
226
	       				$scope.hideSpinner();
227
		           }
228
	       	);
229
		};
230
231 27970 michele.ar
		$scope.testOAI = function (params) {
232
			angular.forEach(params, function(param, pos){
233
	            if (param.name == 'baseUrl') {
234
	            	location.href = "oaiExplorer.do?oaiBaseUrl=" + param.value;
235
	            }
236
			});
237
		}
238
239 44426 michele.ar
		$scope.prepareUpdateRepoApi = function() {
240
			$scope.tempAccessParams = angular.copy($scope.currentRepoApi.accessParams);
241
242
			$scope.tempMdIdPath = '';
243
			angular.forEach($scope.currentRepoApi.otherParams, function(param, pos){
244
	            if (param.name == 'metadata_identifier_path') {
245
	            	$scope.tempMdIdPath = param.value;
246
	            }
247
			});
248
		}
249
250
251 43848 michele.ar
		$scope.updateRepoApi = function() {
252 26600 sandro.lab
			$scope.showSpinner();
253
254
			var map = {};
255 44426 michele.ar
			angular.forEach($scope.tempAccessParams, function(param, pos){
256 26600 sandro.lab
	            if (param.name) {
257
	            	map[param.name] = param.value
258
	            }
259
			});
260
261 29685 michele.ar
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
262 30870 michele.ar
	        $http.post('repoApi.update', $.param({
263 43848 michele.ar
	      		'id'           : $scope.currentRepoApi.repoId,
264
	      		'iface'        : $scope.currentRepoApi.id,
265 44426 michele.ar
	      		'mdIdPath'     : $scope.tempMdIdPath,
266 30870 michele.ar
	      		'accessParams' : JSON.stringify(map)
267
	      	})).success(function(data) {
268
	      		$scope.showNotification('Api correctly saved !');
269
	        	$scope.loadApi();
270 43848 michele.ar
	        }).error(function(err) {
271 30870 michele.ar
	        	$scope.hideSpinner();
272 43848 michele.ar
	        	$scope.showError('Error updating api: ' + err.message);
273 30870 michele.ar
	        });
274 26600 sandro.lab
		};
275
276 27100 michele.ar
277
		$scope.updateSets = function(selection, accessParams) {
278
			var s = selection.join();
279
			angular.forEach(accessParams, function(param, pos){
280
	            if (param.name == 'set') {
281
	            	param.value = s;
282
	            }
283
			});
284
		}
285
286 26600 sandro.lab
		$scope.listSets = function(accessParams) {
287
			var baseUrl = '';
288 27100 michele.ar
289
			$scope.selectedSets = [];
290
			$scope.currentSets = [];
291
292 26600 sandro.lab
			angular.forEach(accessParams, function(param, pos){
293
	            if (param.name == 'baseUrl') {
294
	            	baseUrl = param.value
295
	            }
296 27100 michele.ar
	            if (param.name == 'set') {
297
	            	$scope.selectedSets = param.value.split(",");
298
	            }
299 26600 sandro.lab
			});
300
301
			if (!baseUrl) {
302
				$scope.showError("baseUrl param is missing");
303 27100 michele.ar
				return;
304 26600 sandro.lab
			}
305 27100 michele.ar
306
			$scope.showSpinner();
307 29685 michele.ar
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
308 33255 michele.ar
	        $http.post("listValidValuesForParam.do", $.param({
309
	        	'protocol' : 'oai',
310
	        	'param'    : 'set',
311
	        	'baseUrl'  : baseUrl
312 27100 michele.ar
	        })).success(function(data) {
313
				$scope.hideSpinner();
314
	        	$scope.currentSets = data;
315
	        	angular.forEach($scope.currentSets, function(curr, pos1) {
316 28754 michele.ar
		        	angular.forEach($scope.selectedSets, function(sel, pos2) {
317 27100 michele.ar
		        		if (curr.id.trim() == sel.trim()) {
318
		        			curr.selected = true;
319
		        		}
320
		        	});
321 26600 sandro.lab
				});
322 27100 michele.ar
	        }).error(function() {
323
				$scope.hideSpinner();
324
				$scope.showError("baseUrl param is missing");
325
			});
326
327 26600 sandro.lab
		};
328 28754 michele.ar
329
330
		$scope.verifyMetaWf = function(ds, wf) {
331
			var compliance = '';
332
			var type = '';
333
			angular.forEach(ds.commonParams, function(p,pos) {
334
	        	if (p.id == 'compliance') {
335
	        		compliance = p.value;
336
	        	}
337
	        	if (p.id == 'typology') {
338
	        		type = p.value;
339
	        	}
340
			});
341 29884 michele.ar
342 28754 michele.ar
			return (compliance && type && $scope.isValidTerm(compliance, wf.compliances) && $scope.isValidTerm(type, wf.ifaceTypes));
343
		}
344
345
		$scope.isValidTerm = function(term, list) {
346 29884 michele.ar
347 28754 michele.ar
			if (list.length == 0) {
348
				return true;
349
			}
350
			var res = false;
351
			angular.forEach(list, function(curr,pos) {
352
	        	if (term.lastIndexOf(curr, 0) === 0) { // implementation of term.startsWith(curr)
353
	        		res = true;
354
	        	}
355
			});
356
			return res;
357
		}
358
359 29884 michele.ar
		$scope.overrideApiCompliance = function(level) {
360
			$scope.showSpinner();
361 30820 michele.ar
			$http.get('repoApiCompliance.update?id=' + $scope.currentRepoApi.repoId + '&iface=' + $scope.currentRepoApi.id + '&compliance=' + level)
362 29884 michele.ar
	        .success(
363
	        		function(data) {
364
	        			$scope.hideSpinner();
365
	        			$scope.showNotification('Api correctly updated !');
366
	        			$scope.loadApi();
367
	        		}
368
	        ).error(
369
	        		function() {
370
	        			$scope.showError('Something really bad must have happened to our fellow hamster..');
371
	        			$scope.hideSpinner();
372
	        		}
373
	        );
374
		}
375 28754 michele.ar
376 29884 michele.ar
		$scope.resetApiCompliance = function() {
377
			$scope.showSpinner();
378 30820 michele.ar
			$http.get('repoApiCompliance.reset?id=' + $scope.currentRepoApi.repoId + '&iface=' + $scope.currentRepoApi.id)
379 29884 michele.ar
	        .success(
380
	        		function(data) {
381
	        			$scope.hideSpinner();
382
	        			$scope.showNotification('Api correctly updated !');
383
	        			$scope.loadApi();
384
	        		}
385
	        ).error(
386
	        		function() {
387
	        			$scope.showError('Something really bad must have happened to our fellow hamster..');
388
	        			$scope.hideSpinner();
389
	        		}
390
	        );
391
		}
392
393 26600 sandro.lab
    	$scope.loadApi();
394
	}
395 29884 michele.ar
396 26600 sandro.lab
 ]);