Project

General

Profile

1
var isManagerControllers = angular.module('isManagerControllers', ['LocalStorageModule']);
2

    
3
function common_init($scope, $http, $sce, $location) {
4
	initSpinner();
5
	$scope.showError        = function(error)   { show_notification("error", error); }
6
	$scope.showNotification = function(message) { show_notification("info", message); }
7
	$scope.showSpinner      = function()        { showSpinner(); }
8
	$scope.hideSpinner      = function()        { hideSpinner(); }
9
	$scope.to_trusted       = function(html)    { return $sce.trustAsHtml(html); }
10
	$scope.go               = function(path)    { $location.path(path); }
11
	$scope.encodeValue      = function(val)     { return val; }
12
}
13

    
14
isManagerControllers.controller('listCollectionsCtrl', [
15
	'$scope', '$http', '$sce', '$location', '$routeParams',
16
	function ($scope, $http, $sce, $location, $routeParams) {
17
		common_init($scope, $http, $sce, $location);
18

    
19
		$scope.results = [];
20
		
21
		$scope.showSpinner();
22

    
23
		$http.get('is/listCollections.do').success(function(data) {
24
			$scope.hideSpinner();
25
			$scope.results = data;
26
		}).error(function() {
27
			$scope.showError('Error listing xmldb collections');
28
			$scope.hideSpinner();
29
	    });
30
	}
31
]);
32

    
33

    
34
isManagerControllers.controller('profilesCtrl', [
35
	'$scope', '$http', '$sce', '$location', '$routeParams',
36
	function ($scope, $http, $sce, $location, $routeParams) {
37
		common_init($scope, $http, $sce, $location);
38

    
39
		$scope.profiles = [];
40
		$scope.path = '/db/DRIVER/' + $routeParams.kind + '/' + $routeParams.type;
41
		
42
		$scope.showSpinner();
43
		
44
		$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
45
		$http.post('is/listProfiles.do', $.param({
46
			'kind' :  $routeParams.kind,
47
			'type' :  $routeParams.type
48
		})).success(function(data) {
49
			$scope.hideSpinner();
50
			$scope.profiles = data;
51
		}).error(function() {
52
			$scope.showError('Error listing xmldb collections');
53
			$scope.hideSpinner();
54
	    });
55
	}
56
]);
57

    
58

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

    
64
		$scope.id = $routeParams.id;
65
		$scope.profile = '';
66
		$scope.editProfile = '';
67
		
68
		$scope.showSpinner();
69
		
70
		$http.get('is/getProfile.do?id=' + $scope.id).success(function(data) {
71
			$scope.hideSpinner();
72
			$scope.profile = data;
73
		}).error(function() {
74
			$scope.showError('Error retreiving profile');
75
			$scope.hideSpinner();
76
		});
77
		
78
		$scope.deleteProfile = function() {
79
			if (confirm("Are you sure ?")) {
80
				$scope.showSpinner();
81
				$http.get('is/deleteProfile.do?id=' + $scope.id).success(function(data) {
82
					$scope.hideSpinner();
83
					$scope.showNotification('Profile deleted !');
84
					$scope.profile = '';
85
				}).error(function() {
86
					$scope.showError('Error deleting profile');
87
					$scope.hideSpinner();
88
				});
89
			}
90
		}
91
		
92
		$scope.startEditing = function() {
93
			$scope.editProfile = '' + $scope.profile;
94
		}
95
		
96
		$scope.abortEditing = function() {
97
			$scope.editProfile = '';
98
		}
99

    
100
		$scope.saveEditing = function() {
101
			$scope.showSpinner();
102
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
103
			$http.post('is/updateProfile.do', $.param({
104
				'profile' : $scope.editProfile
105
			})).success(function(data) {
106
				$scope.hideSpinner();
107
				$scope.showNotification('Profile updated !');
108
				$scope.profile = '' + $scope.editProfile;
109
				$scope.editProfile = '';
110
			}).error(function(err) {
111
				$scope.showError(err.message);
112
				$scope.hideSpinner();
113
			});
114
		}
115
	}
116
]);
117

    
118

    
119
isManagerControllers.controller('schemasCtrl', [
120
	'$scope', '$http', '$sce', '$location', '$routeParams',
121
	function ($scope, $http, $sce, $location, $routeParams) {
122
		common_init($scope, $http, $sce, $location);
123

    
124
		$scope.schemas = [];
125
		
126
		$scope.showSpinner();
127

    
128
		$http.get('is/listSchemas.do').success(function(data) {
129
			$scope.hideSpinner();
130
			$scope.schemas = data;
131
		}).error(function() {
132
			$scope.showError('Error retreiving schemas');
133
			$scope.hideSpinner();
134
	    });
135
	}
136
]);
137

    
138

    
139
isManagerControllers.controller('schemaCtrl', [
140
	'$scope', '$http', '$sce', '$location', '$routeParams',
141
	function ($scope, $http, $sce, $location, $routeParams) {
142
		common_init($scope, $http, $sce, $location);
143

    
144
		$scope.name = $routeParams.name;
145
		$scope.schema = '';
146

    
147
		$scope.showSpinner();
148
		
149
		$http.get('is/getSchema.do?name=' + $scope.name).success(function(data) {
150
			$scope.hideSpinner();
151
			$scope.schema = data;
152
		}).error(function() {
153
			$scope.showError('Error obtaining schema' + $scope.name);
154
			$scope.hideSpinner();
155
		});
156
	}
157
]);
158

    
159

    
160
isManagerControllers.controller('servicesCtrl', [
161
	'$scope', '$http', '$sce', '$location', '$routeParams',
162
    function ($scope, $http, $sce, $location, $routeParams) {
163
		common_init($scope, $http, $sce, $location);
164
		$scope.groups = [];
165
		$scope.subscriptions = [];
166
		
167
		$scope.showSpinner();
168
		$http.get('is/listServices.do').success(function(data) {
169
			$scope.hideSpinner();
170
			$scope.groups = data;
171
		}).error(function() {
172
			$scope.showError('Error obtaining services');
173
			$scope.hideSpinner();
174
		});
175
		
176
		$scope.setSubscriptions = function(subscriptions) {
177
			$scope.subscriptions = subscriptions;
178
		}
179
		
180
		$scope.pingServices = function() {
181
			var list = [];
182
			angular.forEach($scope.groups, function(group) {
183
				angular.forEach(group.services, function(service) {
184
					if (service.id && service.wsdl) {
185
						service.status = 'UNKNOWN';
186
						list.push(service);
187
					}
188
				});
189
			});
190
			$scope.ping(list, 0);
191
		}
192
		
193
		$scope.ping = function(list, pos) {
194
			if (list.length == 0)   { return; }
195
			if (pos >= list.length) { $scope.hideSpinner();	return;	}
196
			if (pos == 0)           { $scope.showSpinner(); }
197
			
198
			$http.get('is/ping.do?timeout=1500&url='+encodeURIComponent(list[pos].wsdl)).success(function(data) {
199
				list[pos].status = 'ACTIVE';
200
				$scope.ping(list, pos + 1);
201
			}).error(function() {
202
				list[pos].status = 'NOT_RESPONDING';
203
				$scope.ping(list, pos + 1);
204
			});
205
		}
206
	}
207
]);
208

    
209

    
210

    
211
isManagerControllers.controller('isQueryCtrl', [
212
	'$scope', '$http', '$sce', '$location', '$routeParams', 'localStorageService',
213
	function ($scope, $http, $sce, $location, $routeParams, localStorageService) {
214
		common_init($scope, $http, $sce, $location);
215
		
216
		$scope.history = localStorageService.get('xquery_history');
217
		if (!$scope.history) {
218
			$scope.history = [];
219
		}
220
		
221
		$scope.query = "for $x in collection('/db/DRIVER/VocabularyDSResources/VocabularyDSResourceType') return $x";
222
		$scope.error = null;
223
		$scope.results = [];
224

    
225
        $scope.searchXQuery = function() {
226
			$scope.results = [];
227
			$scope.error = null;
228
			$scope.showSpinner();
229
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
230
			$http.post('is/xquery.do', $.param({
231
				'query' : $scope.query
232
			})).success(function(data) {
233
				$scope.hideSpinner();
234
				$scope.results = data;
235
				$scope.history.push({ 'date' : new Date(), 'query' : $scope.query });
236
				if ($scope.history.length > 100) {
237
					$scope.history = $scope.history.splice($scope.history.length - 100);
238
				}
239
				localStorageService.set('xquery_history', $scope.history);
240
			}).error(function(err) {
241
				$scope.error = err;
242
				$scope.hideSpinner();
243
			});
244
		}
245
        
246
        $scope.updateXQuery = function(q) {
247
        	$scope.query = q;
248
        	$scope.searchXQuery(); 
249
        }
250
        
251
        $scope.clearHistory = function() {
252
        	$scope.history = [];
253
        	localStorageService.set('xquery_history', []);
254
        }
255
	}
256
]);
257
isManagerControllers.controller('registerProfileCtrl', [
258
	'$scope', '$http', '$sce', '$location', '$routeParams',
259
	function ($scope, $http, $sce, $location, $routeParams) {
260
		common_init($scope, $http, $sce, $location);
261

    
262
		$scope.profile = '';
263

    
264
		$scope.register = function() {
265
			$scope.showSpinner();
266
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
267
			$http.post('is/registerProfile.do', $.param({
268
				'profile' : $scope.profile
269
			})).success(function(id) {
270
				$scope.hideSpinner();
271
				$scope.go('/profile/' + id)
272
			}).error(function() {
273
				$scope.showError('Error registerting profile');
274
				$scope.hideSpinner();
275
		    });
276
		}
277
	}
278
]);
279

    
280

    
281
isManagerControllers.controller('bulkImporterCtrl', [
282
	'$scope', '$http', '$sce', '$location', '$routeParams',
283
	function ($scope, $http, $sce, $location, $routeParams) {
284
		common_init($scope, $http, $sce, $location);
285

    
286
		$scope.path = 'file:///tmp/dnet_import';
287
		$scope.schemas = true;
288
		$scope.profiles = true;
289
		
290
		$scope.response = {};
291
		
292
		$scope.bulkImport = function() {
293
			$scope.response = {};
294
			$scope.showSpinner();
295
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
296
			$http.post('is/import.do', $.param({
297
				'path'     : $scope.path,
298
				'schemas'  : $scope.schemas,
299
				'profiles' : $scope.profiles
300
			})).success(function(data) {
301
				$scope.hideSpinner();
302
				$scope.response = data;
303
			}).error(function() {
304
				$scope.showError('Error registerting profile');
305
				$scope.hideSpinner();
306
		    });
307
		}
308
	}
309
]);
310

    
311

    
312
isManagerControllers.controller('validateProvilesCtrl', [
313
	'$scope', '$http', '$sce', '$location', '$routeParams',
314
	function ($scope, $http, $sce, $location, $routeParams) {
315
		common_init($scope, $http, $sce, $location);
316
		
317
		$scope.metaWfId = '';
318
		$scope.section = '';
319
		$scope.family = '';
320
		
321
		$scope.getValidationMetaWfId = function() {
322
			$scope.metaWfId = '';
323
			$scope.section = '';
324
			$scope.family = '';
325
			
326
			$scope.showSpinner();
327
			$http.get('is/getMetaWfIdForFamily.do?family=IS_VALIDATION').success(function(data) {
328
				$scope.hideSpinner();
329
				$scope.metaWfId = data.id;
330
				$scope.section = data.section;
331
				$scope.family = data.family;
332
			}).error(function() {
333
				$scope.showError('Metaworkflow not registered');
334
                $scope.hideSpinner();
335
			});
336
		}
337
		
338
		$scope.registerValidationWfs = function() {
339
			$scope.metaWfId = '';
340
			$scope.showSpinner();
341
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
342
			$http.post('is/import.do', $.param({
343
				'path'     : 'classpath*:/eu/dnetlib/functionality/modular/workflows/validation',
344
				'schemas'  : false,
345
				'profiles' : true
346
			})).success(function(data) {
347
				$scope.hideSpinner();
348
				$scope.showNotification('Profiles are been registered');
349
				$scope.getValidationMetaWfId();
350
			}).error(function() {
351
				$scope.showError('Error registering profiles');
352
				$scope.hideSpinner();
353
		    });
354
		}
355
		
356
		$scope.getValidationMetaWfId();
357
	}
358
]);
359

    
360
isManagerControllers.controller('blackboardCtrl', [
361
	'$scope', '$http', '$sce', '$location', '$routeParams',
362
	function ($scope, $http, $sce, $location, $routeParams) {
363
		common_init($scope, $http, $sce, $location);
364
		
365
		$scope.refresh = function() {
366
			$scope.blackboards = [];
367
			$scope.showSpinner();
368
			$http.get('is/listBlackboards.do').success(function(data) {
369
				$scope.hideSpinner();
370
				$scope.blackboards = data;
371
			}).error(function() {
372
				$scope.showError('Error retreiving schemas');
373
				$scope.hideSpinner();
374
		    });
375
		}
376
		$scope.refresh();
377
	}
378
]);
379

    
380
isManagerControllers.controller('backupCtrl', [
381
	'$scope', '$http', '$sce', '$location', '$routeParams',
382
	function ($scope, $http, $sce, $location, $routeParams) {
383
		common_init($scope, $http, $sce, $location);
384
		
385
		$scope.metaWfId = '';
386
		$scope.section = '';
387
		$scope.family = '';
388
		
389
		$scope.getBackupMetaWfId = function() {
390
			$scope.metaWfId = '';
391
			$scope.section = '';
392
			$scope.family = '';
393
			
394
			$scope.showSpinner();
395
			$http.get('is/getMetaWfIdForFamily.do?family=IS_BACKUP').success(function(data) {
396
				$scope.hideSpinner();
397
				$scope.metaWfId = data.id;
398
				$scope.section = data.section;
399
				$scope.family = data.family;
400
			}).error(function() {
401
				$scope.showError('Metaworkflow not registered');
402
                $scope.hideSpinner();
403
			});
404
		}
405
		
406
		$scope.registerBackupWfs = function() {
407
			$scope.metaWfId = '';
408
			$scope.showSpinner();
409
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
410
			$http.post('is/import.do', $.param({
411
				'path'     : 'classpath*:/eu/dnetlib/functionality/modular/workflows/backup',
412
				'schemas'  : false,
413
				'profiles' : true
414
			})).success(function(data) {
415
				$scope.hideSpinner();
416
				$scope.showNotification('Profiles are been registered');
417
				$scope.getBackupMetaWfId();
418
			}).error(function() {
419
				$scope.showError('Error registering profiles');
420
				$scope.hideSpinner();
421
		    });
422
		}
423
		
424
		$scope.getBackupMetaWfId();
425
	}
426
]);
(14-14/34)