Project

General

Profile

1
var isManagerControllers = angular.module('isManagerControllers', ['LocalStorageModule', 'ui.codemirror']);
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('typesCtrl', [
15
	'$scope', '$http', '$sce', '$location', '$routeParams',
16
	function ($scope, $http, $sce, $location, $routeParams) {
17
		common_init($scope, $http, $sce, $location);
18
		$scope.types = [];
19
		$scope.showSpinner();
20
		$http.get('ajax_is/listResourceTypes.do').success(function(data) {
21
			$scope.hideSpinner();
22
			$scope.types = data;
23
		}).error(function() {
24
			$scope.showError('Error listing resource types');
25
			$scope.hideSpinner();
26
	    });
27
	}
28
]);
29

    
30

    
31
isManagerControllers.controller('dsListCtrl', [
32
	'$scope', '$http', '$sce', '$location', '$routeParams',
33
	function ($scope, $http, $sce, $location, $routeParams) {
34
		common_init($scope, $http, $sce, $location);
35
		$scope.list = [];
36
		$scope.type = $routeParams.type;
37
		$scope.format = $routeParams.format;
38
		$scope.showSpinner();
39
		$http.get('ajax_is/listDatastructures.do?type=' + $scope.type).success(function(data) {
40
			$scope.hideSpinner();
41
			$scope.list = data;
42
		}).error(function() {
43
			$scope.showError('Error listing datastructures');
44
			$scope.hideSpinner();
45
	    });
46
	}
47
]);
48

    
49

    
50
isManagerControllers.controller('dsCtrl', [
51
	'$scope', '$http', '$sce', '$location', '$routeParams', '$timeout',
52
	function ($scope, $http, $sce, $location, $routeParams, $timeout) {
53
		common_init($scope, $http, $sce, $location);
54

    
55
		$scope.resource = {};
56
		$scope.format = $routeParams.format;
57
		$scope.parsedContent = '';
58
		
59
		$scope.editorOptions = {
60
			lineWrapping : true,
61
			lineNumbers: true,
62
			mode: {
63
				name: "javascript",
64
				json: true
65
			}
66
		};
67
		
68
		$scope.showSpinner();
69
		$scope.getResource = function(id) {
70
			if (id) {
71
				$scope.showSpinner();
72
				$http.get('ajax_is/getDs.do?id=' + id).success(function(data) {
73
					$scope.hideSpinner();
74
					$scope.resource = data;
75
					$scope.parsedContent = '';
76
				}).error(function() {
77
					$scope.showError('Error retrieving ds');
78
					$scope.hideSpinner();
79
				});
80
			}
81
		}
82
		
83
		$scope.setupEditContent = function () {
84
			$timeout(function() {
85
				try {
86
					if ($scope.format == 'JSON') {
87
						$scope.editorOptions.mode = { name: "javascript", json: true };
88
						$scope.parsedContent = JSON.stringify(JSON.parse($scope.resource.content),null,2);
89
					} else if ($scope.format == 'XML') {
90
						$scope.editorOptions.mode = 'xml';
91
						$scope.parsedContent = $scope.resource.content;
92
					} else {
93
						$scope.editorOptions.mode = null;
94
						$scope.parsedContent = $scope.resource.content;
95
					}
96
				} catch(err) {
97
					$scope.showError('Error parsing content (' + $scope.format + ')');
98
					$scope.parsedContent = $scope.resource.content;
99
				}
100
	        }, 1000);
101
		}
102
		
103
		$scope.deleteResource = function() {
104
			if ($scope.resource && $scope.resource.id && confirm("Are you sure ?")) {
105
				$scope.showSpinner();
106
				$http.get('ajax_is/deleteDs.do?id=' + $scope.resource.id).success(function(data) {
107
					$scope.resource = {};
108
					$scope.parsedContent = '';
109
					$scope.hideSpinner();
110
					$scope.showNotification('Resource deleted !');
111
				}).error(function() {
112
					$scope.showError('Error deleting resource');
113
					$scope.hideSpinner();
114
				});
115
			}
116
		}
117

    
118
		$scope.saveContent = function() {
119
			try {
120
				if ($scope.format == 'JSON') {
121
					$scope.saveDs({
122
						'id'      : $scope.resource.id,
123
						'content' : JSON.stringify(JSON.parse($scope.parsedContent))
124
					});
125
				} else {
126
					$scope.saveDs({
127
						'id'      : $scope.resource.id,
128
						'content' : $scope.parsedContent
129
					});
130
				}
131
			} catch(err) {
132
				$scope.showError('ERROR: Invalid content (' + $scope.format + ')');
133
			}
134
		}
135
		
136
		$scope.saveInfo = function() {
137
			$scope.saveDs({
138
				'id'          : $scope.resource.id,
139
				'name'        : $scope.resource.name,
140
				'description' : $scope.resource.description
141
			});
142
		}
143
		
144
		$scope.saveDs = function(map) {
145
			$scope.showSpinner();
146
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
147
			$http.post('ajax_is/updateDs.do', $.param(map)).success(function(data) {
148
				$scope.hideSpinner();
149
				$scope.showNotification('Resource updated !');
150
				if (map.content) {
151
					$('#contentModal').modal('hide');
152
				}
153
				$scope.getResource($scope.resource.id);
154
			}).error(function(err) {
155
				$scope.showError(err.message);
156
				$scope.hideSpinner();
157
			});
158
		}
159
				
160
		$scope.getResource($routeParams.id);
161
	}
162
]);
163

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

    
213

    
214

    
215
isManagerControllers.controller('isQueryCtrl', [
216
	'$scope', '$http', '$sce', '$location', '$routeParams', 'localStorageService',
217
	function ($scope, $http, $sce, $location, $routeParams, localStorageService) {
218
		common_init($scope, $http, $sce, $location);
219
		
220
		$scope.history = localStorageService.get('sql_query_history');
221
		if (!$scope.history) {
222
			$scope.history = [];
223
		}
224
		
225
		$scope.sqlEditorOptions = {
226
			lineWrapping : true,
227
			lineNumbers: true,
228
			mode: 'sql'
229
		};
230
			
231
		$scope.resultOptions = {
232
			lineWrapping : true,
233
			lineNumbers: true,
234
			readOnly: 'nocursor',
235
			mode: {
236
				name: "javascript",
237
				json: true
238
			}
239
		};
240
		
241
		$scope.query = "select * from resource_types";
242
		$scope.error = null;
243
		$scope.results = [];
244

    
245
        $scope.search = function() {
246
			$scope.results = [];
247
			$scope.error = null;
248
			$scope.showSpinner();
249
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
250
			$http.post('ajax_is/query.do', $.param({
251
				'query' : $scope.query
252
			})).success(function(data) {
253
				$scope.hideSpinner();
254
				$scope.results = [];
255
				angular.forEach(data, function(d) {
256
					$scope.results.push(JSON.stringify(JSON.parse(d),null,2));
257
				});
258
				$scope.history.push({ 'date' : new Date(), 'query' : $scope.query });
259
				if ($scope.history.length > 100) {
260
					$scope.history = $scope.history.splice($scope.history.length - 100);
261
				}
262
				localStorageService.set('sql_query_history', $scope.history);
263
			}).error(function(err) {
264
				$scope.error = err;
265
				$scope.hideSpinner();
266
			});
267
		}
268
        
269
        $scope.updateSqlQuery = function(q) {
270
        	$scope.query = q;
271
        	$scope.search(); 
272
        }
273
        
274
        $scope.clearHistory = function() {
275
        	$scope.history = [];
276
        	localStorageService.set('sql_query_history', []);
277
        }
278
	}
279
]);
280
isManagerControllers.controller('registerProfileCtrl', [
281
	'$scope', '$http', '$sce', '$location', '$routeParams',
282
	function ($scope, $http, $sce, $location, $routeParams) {
283
		common_init($scope, $http, $sce, $location);
284

    
285
		$scope.profile = '';
286

    
287
		$scope.register = function() {
288
			$scope.showSpinner();
289
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
290
			$http.post('ajax_is/registerProfile.do', $.param({
291
				'profile' : $scope.profile
292
			})).success(function(id) {
293
				$scope.hideSpinner();
294
				$scope.go('/profile/' + id)
295
			}).error(function() {
296
				$scope.showError('Error registerting profile');
297
				$scope.hideSpinner();
298
		    });
299
		}
300
	}
301
]);
302

    
303

    
304
isManagerControllers.controller('bulkImporterCtrl', [
305
	'$scope', '$http', '$sce', '$location', '$routeParams',
306
	function ($scope, $http, $sce, $location, $routeParams) {
307
		common_init($scope, $http, $sce, $location);
308

    
309
		$scope.path = 'file:///tmp/dnet_import';
310
		$scope.schemas = true;
311
		$scope.profiles = true;
312
		
313
		$scope.response = {};
314
		
315
		$scope.bulkImport = function() {
316
			$scope.response = {};
317
			$scope.showSpinner();
318
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
319
			$http.post('ajax_is/import.do', $.param({
320
				'path'     : $scope.path,
321
				'schemas'  : $scope.schemas,
322
				'profiles' : $scope.profiles
323
			})).success(function(data) {
324
				$scope.hideSpinner();
325
				$scope.response = data;
326
			}).error(function() {
327
				$scope.showError('Error registerting profile');
328
				$scope.hideSpinner();
329
		    });
330
		}
331
	}
332
]);
333

    
334

    
335
isManagerControllers.controller('validateProvilesCtrl', [
336
	'$scope', '$http', '$sce', '$location', '$routeParams',
337
	function ($scope, $http, $sce, $location, $routeParams) {
338
		common_init($scope, $http, $sce, $location);
339
		
340
		$scope.metaWfId = '';
341
		$scope.section = '';
342
		$scope.family = '';
343
		
344
		$scope.getValidationMetaWfId = function() {
345
			$scope.metaWfId = '';
346
			$scope.section = '';
347
			$scope.family = '';
348
			
349
			$scope.showSpinner();
350
			$http.get('ajax_is/getMetaWfIdForFamily.do?family=IS_VALIDATION').success(function(data) {
351
				$scope.hideSpinner();
352
				$scope.metaWfId = data.id;
353
				$scope.section = data.section;
354
				$scope.family = data.family;
355
			}).error(function() {
356
				$scope.showError('Metaworkflow not registered');
357
                $scope.hideSpinner();
358
			});
359
		}
360
		
361
		$scope.registerValidationWfs = function() {
362
			$scope.metaWfId = '';
363
			$scope.showSpinner();
364
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
365
			$http.post('ajax_is/import.do', $.param({
366
				'path'     : 'classpath*:/eu/dnetlib/functionality/modular/workflows/validation',
367
				'schemas'  : false,
368
				'profiles' : true
369
			})).success(function(data) {
370
				$scope.hideSpinner();
371
				$scope.showNotification('Profiles are been registered');
372
				$scope.getValidationMetaWfId();
373
			}).error(function() {
374
				$scope.showError('Error registering profiles');
375
				$scope.hideSpinner();
376
		    });
377
		}
378
		
379
		$scope.getValidationMetaWfId();
380
	}
381
]);
382

    
383
isManagerControllers.controller('blackboardCtrl', [
384
	'$scope', '$http', '$sce', '$location', '$routeParams',
385
	function ($scope, $http, $sce, $location, $routeParams) {
386
		common_init($scope, $http, $sce, $location);
387
		
388
		$scope.refresh = function() {
389
			$scope.blackboards = [];
390
			$scope.showSpinner();
391
			$http.get('ajax_is/listBlackboards.do').success(function(data) {
392
				$scope.hideSpinner();
393
				$scope.blackboards = data;
394
			}).error(function() {
395
				$scope.showError('Error retreiving schemas');
396
				$scope.hideSpinner();
397
		    });
398
		}
399
		$scope.refresh();
400
	}
401
]);
402

    
403
isManagerControllers.controller('backupCtrl', [
404
	'$scope', '$http', '$sce', '$location', '$routeParams',
405
	function ($scope, $http, $sce, $location, $routeParams) {
406
		common_init($scope, $http, $sce, $location);
407
		
408
		$scope.metaWfId = '';
409
		$scope.section = '';
410
		$scope.family = '';
411
		
412
		$scope.getBackupMetaWfId = function() {
413
			$scope.metaWfId = '';
414
			$scope.section = '';
415
			$scope.family = '';
416
			
417
			$scope.showSpinner();
418
			$http.get('ajax_is/getMetaWfIdForFamily.do?family=IS_BACKUP').success(function(data) {
419
				$scope.hideSpinner();
420
				$scope.metaWfId = data.id;
421
				$scope.section = data.section;
422
				$scope.family = data.family;
423
			}).error(function() {
424
				$scope.showError('Metaworkflow not registered');
425
                $scope.hideSpinner();
426
			});
427
		}
428
		
429
		$scope.registerBackupWfs = function() {
430
			$scope.metaWfId = '';
431
			$scope.showSpinner();
432
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
433
			$http.post('ajax_is/import.do', $.param({
434
				'path'     : 'classpath*:/eu/dnetlib/functionality/modular/workflows/backup',
435
				'schemas'  : false,
436
				'profiles' : true
437
			})).success(function(data) {
438
				$scope.hideSpinner();
439
				$scope.showNotification('Profiles are been registered');
440
				$scope.getBackupMetaWfId();
441
			}).error(function() {
442
				$scope.showError('Error registering profiles');
443
				$scope.hideSpinner();
444
		    });
445
		}
446
		
447
		$scope.getBackupMetaWfId();
448
	}
449
]);
(2-2/2)