Project

General

Profile

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 = getBrowseFields();
8
		
9
		$scope.sortType     = 'term';
10
		$scope.sortReverse  = false;
11
		
12
		$scope.repoBrowseData = { 'data' : [] };
13
			
14
		$scope.searchApis = function (text) {
15
			$scope.go('/list/__SEARCH__/' + text); 
16
		} 
17
		
18
		$scope.browseApis = function (field, value) {
19
			$('#showRepoBrowseData').modal('hide');
20
			$scope.showSpinner();
21
			$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
	      	$http.get('browseRepoField.do?field=' + field.id).success(
34
	            function(data) {
35
	            	$scope.hideSpinner();
36
	            	$scope.repoBrowseData.data = data;
37
	            	$('#showRepoBrowseData').modal('show');
38
	            }
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
		$scope.sortType     = 'repoName';
55
		$scope.sortReverse  = false;
56
		$scope.apis = [];		
57
    	$scope.currentApiSelectionParam = $routeParams.param;
58
    	$scope.currentApiSelectionValue = $routeParams.value;
59
    	
60
    	$scope.updateApis = function(refresh) {
61
			$scope.showSpinner();
62
						    
63
			var params = {
64
				'param' : $scope.currentApiSelectionParam,
65
				'value' : $scope.currentApiSelectionValue
66
			};
67
			if (refresh) {
68
				params.refresh = 1;
69
			}
70

    
71
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
72
			$http.post('listApis.do', $.param(params)).success(
73
	            function(data) {
74
	            	$scope.hideSpinner();
75
	            	$scope.apis = data;
76
	            }
77
	        ).error(
78
	            function() {
79
	            	$scope.showError('Something really bad must have happened to our fellow hamster..');
80
	            	$scope.hideSpinner();
81
	            }
82
	        );
83
    	};
84
        	
85
    	$scope.updateApis(false);
86
	}
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
		commonInitialize($scope, $http, $sce);
95
		wf_init($scope, $http, $sce);
96
		
97
		$scope.availableRepohiWfs = getAvailableRepohiWfs();
98
		$scope.compatibilityLevels = getCompatibilityLevels();
99
		
100
		$scope.validatorBlacklistAddress = '';
101
		$scope.validatorBlacklistAddress = '';
102
    			
103
		$scope.currentRepoApi = {};
104
		$scope.currentSets = [];
105
		$scope.selectedSets = [];
106
    	
107
    	$scope.loadApi = function() {
108
    		$scope.showSpinner();
109
    		$(".btnRefreshApi").attr("disabled", "disabled");
110
    		$http.get('repoApi.get?repoId=' + $routeParams.repoId + "&ifaceId=" +  $routeParams.ifaceId)
111
            .success(
112
                function(data) {
113
                	$scope.currentRepoApi = data;
114
                	$scope.metaworkflows = data.metaWFs;
115

    
116
                	angular.forEach(data.otherParams, function(term){
117
                		if (term.id == 'last_validation_job') {
118
                			if (getValidatorAddress()) {
119
                				$scope.validatorDetailsAddress = getValidatorAddress() + "/" + term.value;
120
                			}
121
                			if (getValidatorServiceAddress()) {
122
                				$scope.validatorBlacklistAddress = getValidatorServiceAddress() + "/workflows?request=GetBlacklistedRecords&datasourceId=" + $routeParams.repoId;
123
                			}
124
                		}                                       
125
                	});
126
                	
127
                	if (data.protocol == 'oai') {
128
    	            	var found = false;
129
    	            	angular.forEach(data.accessParams, function(param, pos){
130
    	                    if (param.name == 'set') {
131
    	                    	$scope.listSets($scope.currentRepoApi.accessParams);
132
    	                    }
133
    	        		});
134
                	}
135
                	$scope.hideSpinner(); 
136
                	            	
137
                	$(".btnRefreshApi").removeAttr("disabled");
138
                	
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
                }
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
    	
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
		$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
			$scope.metaworkflows.push({"id":"","name":"Waiting...","status":"MISSING","progress":0});
180
	    				
181
			$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
	       			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
			if (!confirm("Are you sure ?")) {
209
				return;
210
			}
211
					
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
		$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
		$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
		$scope.updateRepoApi = function() {
252
			$scope.showSpinner();
253
	
254
			var map = {};
255
			angular.forEach($scope.tempAccessParams, function(param, pos){
256
	            if (param.name) {
257
	            	map[param.name] = param.value
258
	            }
259
			});
260
			
261
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
262
	        $http.post('repoApi.update', $.param({
263
	      		'id'           : $scope.currentRepoApi.repoId,
264
	      		'iface'        : $scope.currentRepoApi.id,
265
	      		'mdIdPath'     : $scope.tempMdIdPath,
266
	      		'accessParams' : JSON.stringify(map)
267
	      	})).success(function(data) {
268
	      		$scope.showNotification('Api correctly saved !');
269
	        	$scope.loadApi(); 
270
	        }).error(function(err) {
271
	        	$scope.hideSpinner();
272
	        	$scope.showError('Error updating api: ' + err.message);
273
	        });
274
		};
275
		
276
		
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
		$scope.listSets = function(accessParams) {
287
			var baseUrl = '';
288
			
289
			$scope.selectedSets = [];
290
			$scope.currentSets = [];
291
			
292
			angular.forEach(accessParams, function(param, pos){
293
	            if (param.name == 'baseUrl') {
294
	            	baseUrl = param.value
295
	            }
296
	            if (param.name == 'set') {
297
	            	$scope.selectedSets = param.value.split(",");
298
	            }
299
			});
300
			
301
			if (!baseUrl) {
302
				$scope.showError("baseUrl param is missing");
303
				return;
304
			}
305

    
306
			$scope.showSpinner();
307
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
308
	        $http.post("listValidValuesForParam.do", $.param({
309
	        	'protocol' : 'oai',
310
	        	'param'    : 'set',
311
	        	'baseUrl'  : baseUrl
312
	        })).success(function(data) {
313
				$scope.hideSpinner();
314
	        	$scope.currentSets = data;
315
	        	angular.forEach($scope.currentSets, function(curr, pos1) {
316
		        	angular.forEach($scope.selectedSets, function(sel, pos2) {
317
		        		if (curr.id.trim() == sel.trim()) {
318
		        			curr.selected = true;
319
		        		}
320
		        	});
321
				});
322
	        }).error(function() {
323
				$scope.hideSpinner();
324
				$scope.showError("baseUrl param is missing");
325
			});
326
	        
327
		};
328
		
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
			
342
			return (compliance && type && $scope.isValidTerm(compliance, wf.compliances) && $scope.isValidTerm(type, wf.ifaceTypes)); 
343
		}
344

    
345
		$scope.isValidTerm = function(term, list) {
346
			
347
			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
		$scope.overrideApiCompliance = function(level) {
360
			$scope.showSpinner();
361
			$http.get('repoApiCompliance.update?id=' + $scope.currentRepoApi.repoId + '&iface=' + $scope.currentRepoApi.id + '&compliance=' + level)
362
	        .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
		
376
		$scope.resetApiCompliance = function() {
377
			$scope.showSpinner();
378
			$http.get('repoApiCompliance.reset?id=' + $scope.currentRepoApi.repoId + '&iface=' + $scope.currentRepoApi.id)
379
	        .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
    	$scope.loadApi();
394
	}
395
		
396
 ]);
397

    
(3-3/7)