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
		$scope.filterBrowseData = { filterText: '' };
9
		$scope.repoBrowseData = { 'data' : [] };
10
		
11
		$scope.gridBrowseData = {
12
				data: 'repoBrowseData.data',
13
				enableRowSelection: false,
14
				enableCellEditOnFocus: false,
15
				enableHighlighting: true,
16
				filterOptions: $scope.filterBrowseData,
17
				sortInfo: { fields: ['term'], directions: ['desc'] },
18
				columnDefs: [
19
				             {field: 'term', displayName: 'Name', cellTemplate: '<div class="ngCellText"><a href="javascript:void(0)" ng-click="browseApis(repoBrowseData.id, row.getProperty(\'term\'))">{{row.getProperty(col.field)}}</a></div>' },
20
				             {field: 'total', displayName: '# datasources', width: '20%', headerClass: 'text-right', cellClass: 'text-right' }
21
				             ]
22
		};
23
		
24
		$scope.searchApis = function (text) {
25
			$scope.go('/list/__SEARCH__/' + text); 
26
		} 
27
		
28
		$scope.browseApis = function (field, value) {
29
			$('#showRepoBrowseData').modal('hide');
30
			$scope.showSpinner();
31
			$timeout(function() {
32
				$scope.go('/list/' + field + '/' + value);
33
			}, 1500);
34
		}
35
		
36
		$scope.browseRepoField = function(field) {
37
			$scope.repoBrowseData = {
38
				'label' : field.label,
39
				'id' :    field.id,
40
				'data'  : []
41
			};
42
			$scope.showSpinner();
43
	      	$http.get('browseRepoField.do?field=' + field.id).success(
44
	            function(data) {
45
	            	$scope.hideSpinner();
46
	            	$scope.repoBrowseData.data = data;
47
	            	$('#showRepoBrowseData').modal('show');
48
	            }
49
	        ).error(
50
	            function() {
51
	            	$scope.showError('Something really bad must have happened to our fellow hamster..');
52
	            	$scope.hideSpinner();
53
	            }
54
	        );
55
		};
56
	}
57
]);
58

    
59
repoControllers.controller('repoListCtrl', [
60
	'$scope', '$http', '$timeout', '$sce', '$routeParams', '$location',
61
	function ($scope, $http, $timeout, $sce, $routeParams, $location) {
62
		common_init($scope, $http, $sce, $location);
63

    
64
		$scope.apis = [];
65
		$scope.filterApis = { filterText: '' };
66
		$scope.gridApis = { 
67
				data: 'apis',
68
				enableRowSelection: false,
69
				enableCellEditOnFocus: false,
70
				enableHighlighting: true,
71
				filterOptions: $scope.filterApis,
72
				columnDefs: [
73
				             {field: 'repoCountry' , displayName: 'Country',               width: '80px',  headerClass: 'text-center', cellTemplate: '<ng-repo-country-cell />' },
74
				             {field: 'repoName'    , displayName: 'Datasource Api',        cellTemplate: '<ng-reponame-cell />' },
75
							 {field: 'repoPrefix'  , displayName: 'Namespace Prefix',      width: '150px', headerClass: 'text-center', cellClass: 'text-center' },
76
				             {field: 'protocol'    , displayName: 'Protocol',        	   width: '160px', headerClass: 'text-center', cellClass: 'text-center' },
77
				             {field: 'aggrDate'    , displayName: 'Last Aggregation Date', width: '200px', headerClass: 'text-center', cellTemplate: '<ng-aggr-date-cell />' },
78
				             {field: 'aggrTotal'   , displayName: 'Total',                 width: '80px',  headerClass: 'text-center', cellTemplate: '<ng-aggr-total-cell />' }
79
				            ]
80
		};
81
		
82
    	$scope.currentApiSelectionParam = $routeParams.param;
83
    	$scope.currentApiSelectionValue = $routeParams.value;
84
    	
85
    	$scope.updateApis = function(refresh) {
86
			$scope.showSpinner();
87
						    
88
			var params = {
89
				'param' : $scope.currentApiSelectionParam,
90
				'value' : $scope.currentApiSelectionValue,
91
			};
92
			if (refresh) {
93
				params.refresh = 1;
94
			}
95

    
96
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
97
			$http.post('listApis.do', $.param(params)).success(
98
	            function(data) {
99
	            	$scope.hideSpinner();
100
	            	$scope.apis = data;
101
	            	$scope.resizeMainElement(document.getElementById('apisTable'));
102
	            }
103
	        ).error(
104
	            function() {
105
	            	$scope.showError('Something really bad must have happened to our fellow hamster..');
106
	            	$scope.hideSpinner();
107
	            }
108
	        );
109
    	};
110
    		
111
		$scope.showApi = function (repoId, ifaceId) {
112
			$scope.go('/api/' + repoId + '/' + ifaceId + "/ALL/ALL"); 
113
		}
114

    
115
		
116
		window.onresize = function() {
117
			var elem = document.getElementById('apisTable');
118
			if (elem) {
119
				angular.element(elem).scope().resizeMainElement(elem);
120
			}
121
		};
122
    	
123
    	$scope.updateApis(false);
124
	}
125
]);
126

    
127
repoControllers.controller('repoApiCtrl', [
128
	'$scope', '$http', '$timeout', '$sce', '$routeParams', '$location',
129
	function ($scope, $http, $timeout, $sce, $routeParams, $location) {
130
		common_init($scope, $http, $sce, $location);
131
		
132
		commonInitialize($scope, $http, $sce);
133
		wf_init($scope, $http, $sce);
134
		
135
		$scope.availableRepohiWfs = getAvailableRepohiWfs();
136
		$scope.compatibilityLevels = getCompatibilityLevels();
137
		
138
		$scope.validatorBlacklistAddress = '';
139
		$scope.validatorBlacklistAddress = '';
140
    			
141
		$scope.currentRepoApi = {};
142
		$scope.currentSets = [];
143
		$scope.selectedSets = [];
144
    	
145
    	$scope.loadApi = function() {
146
    		$scope.showSpinner();
147
    		$(".btnRefreshApi").attr("disabled", "disabled");
148
    		$http.get('repoApi.get?repoId=' + $routeParams.repoId + "&ifaceId=" +  $routeParams.ifaceId)
149
            .success(
150
                function(data) {
151
                	$scope.currentRepoApi = data;
152
                	$scope.metaworkflows = data.metaWFs;
153

    
154
                	angular.forEach(data.otherParams, function(term){
155
                		if (term.id == 'last_validation_job') {
156
                			if (getValidatorAddress()) {
157
                				$scope.validatorDetailsAddress = getValidatorAddress() + "/prepareSummary.action?jobId=" + term.value;
158
                			}
159
                			if (getValidatorServiceAddress()) {
160
                				$scope.validatorBlacklistAddress = getValidatorServiceAddress() + "/workflows?request=GetBlacklistedRecords&datasourceId=" + $routeParams.repoId;
161
                			}
162
                		}                                       
163
                	});
164
                	
165
                	if (data.protocol == 'oai') {
166
    	            	var found = false;
167
    	            	angular.forEach(data.accessParams, function(param, pos){
168
    	                    if (param.name == 'set') {
169
    	                    	$scope.listSets($scope.currentRepoApi.accessParams);
170
    	                    }
171
    	        		});
172
                	}
173
                	$scope.hideSpinner(); 
174
                	            	
175
                	$(".btnRefreshApi").removeAttr("disabled");
176
                	
177
                	if ($routeParams.metawf != 'ALL' && $routeParams.wf != 'ALL') {
178
                		$scope.getAtomicWorkflowAndMetaWf($routeParams.metawf, $routeParams.wf);
179
                		$timeout(function() {
180
                			$("#collapse_" + $routeParams.metawf.substring(0, 36)).collapse('show');
181
                		}, 2000);
182
                	}
183
                }
184
            ).error(
185
                function() {
186
                	$scope.showError('Something really bad must have happened to our fellow hamster..');
187
                	$scope.hideSpinner();
188
                }
189
            );
190
    	};
191
    	
192
    	
193
    	$scope.removeApi = function() {
194
    		if (confirm("You are deleting the current API.\n\nAre you sure?")) {
195
	    		$scope.showSpinner();
196
	    		$http.get('repoApi.delete?repo=' + $routeParams.repoId + "&iface=" +  $routeParams.ifaceId).success(function(data) {
197
	    			alert("The API has been deleted !!!");
198
	    			$scope.hideSpinner();
199
	    			$scope.go("/browse");
200
	    		}).error(function(err) {
201
	    			$scope.showError('Error removing API: '  + err.message);
202
	    			$scope.hideSpinner();
203
	    		});
204
    		}
205
    	};
206
   	
207
    	
208
		$scope.newDataProviderWorkflow = function (wf) {
209
			
210
			if (wf == undefined) {
211
				$scope.showError('Please choose a workflow !');
212
	    		return;
213
			}
214
			
215
			$scope.showSpinner();
216
	
217
			$scope.metaworkflows.push({"id":"","name":"Waiting...","status":"MISSING","progress":0});
218
	    				
219
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
220
			$http.post('repoMetaWf.new', $.param({
221
				'wf'    : wf,
222
				'iface' : $scope.currentRepoApi.id,
223
				'id'    : $scope.currentRepoApi.repoId, 
224
				'name'  : $scope.currentRepoApi.repoName
225
			})).success(
226
	       			function(data) {
227
	       				$scope.hideSpinner();
228
	       				$(".btnRefreshApi").attr("disabled", "disabled");
229
	       				$timeout(function () { $scope.loadApi() }, 7000);
230
		            }
231
	       	).error(
232
	       			function() {
233
	       				$scope.showError('Something really bad must have happened to our fellow hamster..');
234
	       				$scope.hideSpinner();
235
		           }
236
	       	);
237
		};
238
		
239
		$scope.destroyDataProviderWorkflow = function (metaWf) {
240
			
241
			if (metaWf.destroyWorkflow == undefined) {
242
				$scope.showError('Destroy wf is missing !');
243
	    		return;
244
			}
245
			
246
			if (!confirm("Are you sure ?")) {
247
				return;
248
			}
249
					
250
			$scope.showSpinner();
251
			
252
			metaWf.deleting = true;
253
			
254
			$http.get('repoMetaWf.destroy?destroyWf=' + metaWf.destroyWorkflow)
255
	       	.success(
256
	       			function(data) {
257
	       				$scope.hideSpinner();
258
	       				$(".btnRefreshApi").attr("disabled", "disabled");
259
	       				$timeout(function () { $scope.loadApi() }, 7000);
260
		            }
261
	       	).error(
262
	       			function() {
263
	       				$scope.showError('Something really bad must have happened to our fellow hamster..');
264
	       				$scope.hideSpinner();
265
		           }
266
	       	);
267
		};
268
		
269
		$scope.testOAI = function (params) {
270
			angular.forEach(params, function(param, pos){
271
	            if (param.name == 'baseUrl') {
272
	            	location.href = "oaiExplorer.do?oaiBaseUrl=" + param.value;
273
	            }
274
			});
275
		}
276
	
277
		$scope.prepareUpdateRepoApi = function() {
278
			$scope.tempAccessParams = angular.copy($scope.currentRepoApi.accessParams); 
279

    
280
			$scope.tempMdIdPath = '';
281
			angular.forEach($scope.currentRepoApi.otherParams, function(param, pos){
282
	            if (param.name == 'metadata_identifier_path') {
283
	            	$scope.tempMdIdPath = param.value;
284
	            }
285
			});
286
		}
287
		
288
		
289
		$scope.updateRepoApi = function() {
290
			$scope.showSpinner();
291
	
292
			var map = {};
293
			angular.forEach($scope.tempAccessParams, function(param, pos){
294
	            if (param.name) {
295
	            	map[param.name] = param.value
296
	            }
297
			});
298
			
299
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
300
	        $http.post('repoApi.update', $.param({
301
	      		'id'           : $scope.currentRepoApi.repoId,
302
	      		'iface'        : $scope.currentRepoApi.id,
303
	      		'mdIdPath'     : $scope.tempMdIdPath,
304
	      		'accessParams' : JSON.stringify(map)
305
	      	})).success(function(data) {
306
	      		$scope.showNotification('Api correctly saved !');
307
	        	$scope.loadApi(); 
308
	        }).error(function(err) {
309
	        	$scope.hideSpinner();
310
	        	$scope.showError('Error updating api: ' + err.message);
311
	        });
312
		};
313
		
314
		
315
		$scope.updateSets = function(selection, accessParams) {
316
			var s = selection.join();
317
			angular.forEach(accessParams, function(param, pos){
318
	            if (param.name == 'set') {
319
	            	param.value = s;
320
	            }
321
			});
322
		}
323
		
324
		$scope.listSets = function(accessParams) {
325
			var baseUrl = '';
326
			
327
			$scope.selectedSets = [];
328
			$scope.currentSets = [];
329
			
330
			angular.forEach(accessParams, function(param, pos){
331
	            if (param.name == 'baseUrl') {
332
	            	baseUrl = param.value
333
	            }
334
	            if (param.name == 'set') {
335
	            	$scope.selectedSets = param.value.split(",");
336
	            }
337
			});
338
			
339
			if (!baseUrl) {
340
				$scope.showError("baseUrl param is missing");
341
				return;
342
			}
343

    
344
			$scope.showSpinner();
345
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
346
	        $http.post("listValidValuesForParam.do", $.param({
347
	        	'protocol' : 'oai',
348
	        	'param'    : 'set',
349
	        	'baseUrl'  : baseUrl
350
	        })).success(function(data) {
351
				$scope.hideSpinner();
352
	        	$scope.currentSets = data;
353
	        	angular.forEach($scope.currentSets, function(curr, pos1) {
354
		        	angular.forEach($scope.selectedSets, function(sel, pos2) {
355
		        		if (curr.id.trim() == sel.trim()) {
356
		        			curr.selected = true;
357
		        		}
358
		        	});
359
				});
360
	        }).error(function() {
361
				$scope.hideSpinner();
362
				$scope.showError("baseUrl param is missing");
363
			});
364
	        
365
		};
366
		
367
		
368
		$scope.verifyMetaWf = function(ds, wf) {
369
			var compliance = '';
370
			var type = '';
371
			angular.forEach(ds.commonParams, function(p,pos) {
372
	        	if (p.id == 'compliance') {
373
	        		compliance = p.value;
374
	        	}
375
	        	if (p.id == 'typology') {
376
	        		type = p.value;
377
	        	}
378
			});
379
			
380
			return (compliance && type && $scope.isValidTerm(compliance, wf.compliances) && $scope.isValidTerm(type, wf.ifaceTypes)); 
381
		}
382

    
383
		$scope.isValidTerm = function(term, list) {
384
			
385
			if (list.length == 0) {
386
				return true;
387
			}
388
			var res = false;
389
			angular.forEach(list, function(curr,pos) {
390
	        	if (term.lastIndexOf(curr, 0) === 0) { // implementation of term.startsWith(curr)
391
	        		res = true;
392
	        	}
393
			});
394
			return res;
395
		}
396

    
397
		$scope.overrideApiCompliance = function(level) {
398
			$scope.showSpinner();
399
			$http.get('repoApiCompliance.update?id=' + $scope.currentRepoApi.repoId + '&iface=' + $scope.currentRepoApi.id + '&compliance=' + level)
400
	        .success(
401
	        		function(data) {
402
	        			$scope.hideSpinner();
403
	        			$scope.showNotification('Api correctly updated !');
404
	        			$scope.loadApi(); 
405
	        		}
406
	        ).error(
407
	        		function() {
408
	        			$scope.showError('Something really bad must have happened to our fellow hamster..');
409
	        			$scope.hideSpinner();
410
	        		}
411
	        );
412
		}
413
		
414
		$scope.resetApiCompliance = function() {
415
			$scope.showSpinner();
416
			$http.get('repoApiCompliance.reset?id=' + $scope.currentRepoApi.repoId + '&iface=' + $scope.currentRepoApi.id)
417
	        .success(
418
	        		function(data) {
419
	        			$scope.hideSpinner();
420
	        			$scope.showNotification('Api correctly updated !');
421
	        			$scope.loadApi(); 
422
	        		}
423
	        ).error(
424
	        		function() {
425
	        			$scope.showError('Something really bad must have happened to our fellow hamster..');
426
	        			$scope.hideSpinner();
427
	        		}
428
	        );
429
		}
430
				
431
    	$scope.loadApi();
432
	}
433
		
434
 ]);
435

    
(3-3/7)