Project

General

Profile

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

    
3
module.config(function($routeProvider) {
4
	$routeProvider
5
		.when('/list',                          { templateUrl: '/html/is/list.html',          controller: 'listCollectionsCtrl' })
6
		.when('/profiles/:kind/:type',          { templateUrl: '/html/is/profiles.html',      controller: 'profilesCtrl' })
7
		.when('/profile/:kind/:type/:filename', { templateUrl: '/html/is/profile.html',       controller: 'profileCtrl' })
8
		.when('/schemas',                       { templateUrl: '/html/is/schemas.html',       controller: 'schemasCtrl' })
9
		.when('/schema/:name',                  { templateUrl: '/html/is/schema.html',        controller: 'schemaCtrl' })
10
		.when('/q',                             { templateUrl: '/html/is/isQuery.html',       controller: 'isQueryCtrl' })
11
		.when('/register',                      { templateUrl: '/html/is/register.html',      controller: 'registerProfileCtrl' })
12
		.when('/bulk',                          { templateUrl: '/html/is/bulk.html',          controller: 'bulkImporterCtrl' })
13
		.otherwise({ redirectTo: '/list' });
14
});
15

    
16
module.controller('moduleMenuCtrl', function ($scope, $location) {
17
		$scope.isActive = function(regex) {
18
			var re = new RegExp(regex);
19
			return re.test($location.path());
20
		}
21
	}
22
);
23

    
24
module.filter('encodeURIComponent', function() {
25
    return window.encodeURIComponent;
26
});
27

    
28
module.filter('reverse', function () {
29
	return function(items) {
30
		return items.slice().reverse();
31
	}
32
});
33

    
34
function common_init($scope, $http, $sce, $location) {
35
	initSpinner();
36
	$scope.showError        = function(error)   { show_notification("error", error); }
37
	$scope.showNotification = function(message) { show_notification("info", message); }
38
	$scope.showSpinner      = function()        { showSpinner(); }
39
	$scope.hideSpinner      = function()        { hideSpinner(); }
40
	$scope.to_trusted       = function(html)    { return $sce.trustAsHtml(html); }
41
	$scope.go               = function(path)    { $location.path(path); }
42
	$scope.encodeValue      = function(val)     { return val; }
43
}
44

    
45
module.controller('listCollectionsCtrl', function ($scope, $http, $sce, $location, $routeParams) {
46
	common_init($scope, $http, $sce, $location);
47

    
48
	$scope.results = [];
49
	
50
	$scope.showSpinner();
51

    
52
	$http.get('/ajax/is/collections').success(function(data) {
53
		$scope.hideSpinner();
54
		$scope.results = data;
55
	}).error(function() {
56
		$scope.showError('Error listing xmldb collections');
57
		$scope.hideSpinner();
58
    });
59
});
60

    
61
module.controller('profilesCtrl', function ($scope, $http, $sce, $location, $routeParams) {
62
	common_init($scope, $http, $sce, $location);
63

    
64
	$scope.profiles = [];
65
	$scope.path = '/db/DRIVER/' + $routeParams.kind + '/' + $routeParams.type;
66
	
67
	$scope.refresh = function(validation) {
68
		$scope.showSpinner();
69

    
70
		var url = '/ajax/is/profiles/' + $routeParams.kind + '/' + $routeParams.type;
71
		if (validation) { url += '?validation=true'; }
72
	
73
		$http.get(url).success(function(data) {
74
			$scope.hideSpinner();
75
			$scope.profiles = data;
76
			$scope.size = Object.keys(data).length;
77
		}).error(function() {
78
			$scope.showError('Error listing xmldb collections');
79
			$scope.hideSpinner();
80
	    });
81
	}
82
	
83
	$scope.refresh(false);
84
});
85

    
86
module.controller('profileCtrl', function ($scope, $http, $sce, $location, $routeParams) {
87
	common_init($scope, $http, $sce, $location);
88

    
89
	$scope.id = $routeParams.kind + '/' + $routeParams.type + '/' + $routeParams.filename;
90
	$scope.profile = '';
91
	$scope.editProfile = '';
92
		
93
	$scope.showSpinner();
94
		
95
	$http.get('/ajax/is/profile/'+ $scope.id).success(function(data) {
96
		$scope.hideSpinner();
97
		$scope.profile = data;
98
	}).error(function() {
99
		$scope.showError('Error retreiving profile');
100
		$scope.hideSpinner();
101
	});
102
		
103
	$scope.deleteProfile = function() {
104
		if (confirm("Are you sure ?")) {
105
			$scope.showSpinner();
106
			$http.delete('/ajax/is/profile/'+ $scope.id).success(function(data) {
107
				$scope.hideSpinner();
108
				$scope.showNotification('Profile deleted !');
109
				$scope.profile = '';
110
			}).error(function() {
111
				$scope.showError('Error deleting profile');
112
				$scope.hideSpinner();
113
			});
114
		}
115
	}
116

    
117
	$scope.startEditing = function() {
118
		$scope.editProfile = '' + $scope.profile;
119
	}
120
		
121
	$scope.abortEditing = function() {
122
		$scope.editProfile = '';
123
	}
124

    
125
	$scope.saveEditing = function() {
126
		$scope.showSpinner();
127
        $http.defaults.headers.post["Content-Type"] = "application/json; charset=utf-8";
128
		$http.post('/ajax/is/profile/' + $scope.id, $scope.editProfile).success(function(data) {
129
			$scope.hideSpinner();
130
			$scope.showNotification('Profile updated !');
131
			$scope.profile = '' + $scope.editProfile;
132
			$scope.editProfile = '';
133
		}).error(function(err) {
134
			$scope.showError(err.message);
135
			$scope.hideSpinner();
136
		});
137
	}
138
});
139

    
140
module.controller('schemasCtrl', function ($scope, $http, $sce, $location, $routeParams) {
141
	common_init($scope, $http, $sce, $location);
142

    
143
	$scope.schemas = [];
144
		
145
	$scope.showSpinner();
146

    
147
	$http.get('/ajax/is/schemas').success(function(data) {
148
		$scope.hideSpinner();
149
		$scope.schemas = data;
150
	}).error(function() {
151
		$scope.showError('Error retreiving schemas');
152
		$scope.hideSpinner();
153
    });
154
});
155

    
156
module.controller('schemaCtrl', function ($scope, $http, $sce, $location, $routeParams) {
157
	common_init($scope, $http, $sce, $location);
158

    
159
	$scope.name = $routeParams.name;
160
	$scope.schema = '';
161

    
162
	$scope.showSpinner();
163
		
164
	$http.get('/ajax/is/schema/' + $scope.name).success(function(data) {
165
		$scope.hideSpinner();
166
		$scope.schema = data;
167
	}).error(function() {
168
		$scope.showError('Error obtaining schema' + $scope.name);
169
		$scope.hideSpinner();
170
	});
171
});
172

    
173
module.controller('isQueryCtrl', function ($scope, $http, $sce, $location, $routeParams, localStorageService) {
174
	common_init($scope, $http, $sce, $location);
175
		
176
	$scope.history = localStorageService.get('xquery_history');
177
	if (!$scope.history) {
178
		$scope.history = [];
179
	}
180
		
181
	$scope.query = "for $x in collection('/db/DRIVER/dnetService') return $x";
182
	$scope.error = null;
183
	$scope.results = [];
184

    
185
	$scope.searchXQuery = function() {
186
		$scope.results = [];
187
		$scope.error = null;
188
		$scope.showSpinner();
189
		$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
190
		$http.post('/ajax/is/xquery', $.param({
191
			'q' : $scope.query
192
		})).success(function(data) {
193
			$scope.hideSpinner();
194
			$scope.results = data;
195
			$scope.history.push({ 'date' : new Date(), 'query' : $scope.query });
196
			if ($scope.history.length > 100) {
197
				$scope.history = $scope.history.splice($scope.history.length - 100);
198
			}
199
			localStorageService.set('xquery_history', $scope.history);
200
		}).error(function(err) {
201
			$scope.error = err;
202
			$scope.hideSpinner();
203
		});
204
	}
205

    
206
	$scope.updateXQuery = function(q) {
207
       	$scope.query = q;
208
       	$scope.searchXQuery(); 
209
	}
210
	
211
	$scope.clearHistory = function() {
212
       	$scope.history = [];
213
       	localStorageService.set('xquery_history', []);
214
	}
215
});
216

    
217
module.controller('registerProfileCtrl', function ($scope, $http, $sce, $location, $routeParams) {
218
	common_init($scope, $http, $sce, $location);
219

    
220
	$scope.profile = '';
221

    
222
	$scope.register = function() {
223
		$scope.showSpinner();
224
        $http.defaults.headers.post["Content-Type"] = "application/json; charset=utf-8";
225
		$http.post('/ajax/is/profile', $scope.profile).success(function(id) {
226
			$scope.hideSpinner();
227
			$scope.go('/profile/' + id)
228
		}).error(function() {
229
			$scope.showError('Error registerting profile');
230
			$scope.hideSpinner();
231
	    });
232
	}
233
});
234

    
235
module.controller('bulkImporterCtrl', function ($scope, $http, $sce, $location, $routeParams) {
236
	common_init($scope, $http, $sce, $location);
237

    
238
	$scope.path = 'file:///tmp/dnet_import';
239
	$scope.schemas = true;
240
	$scope.profiles = true;
241
		
242
	$scope.response = {};
243
		
244
	$scope.bulkImport = function() {
245
		$scope.response = {};
246
		$scope.showSpinner();
247
		$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
248
		$http.post('/ajax/is/import', $.param({
249
			'path'     : $scope.path,
250
			'schemas'  : $scope.schemas,
251
			'profiles' : $scope.profiles
252
		})).success(function(data) {
253
			$scope.hideSpinner();
254
			$scope.response = data;
255
		}).error(function() {
256
			$scope.showError('Error registerting profile');
257
			$scope.hideSpinner();
258
	    });
259
	}
260
});
261

    
262
module.controller('validateProvilesCtrl', function ($scope, $http, $sce, $location, $routeParams) {
263
	common_init($scope, $http, $sce, $location);
264
		
265
	$scope.metaWfId = '';
266
	$scope.section = '';
267
	$scope.family = '';
268
		
269
	$scope.getValidationMetaWfId = function() {
270
		$scope.metaWfId = '';
271
		$scope.section = '';
272
		$scope.family = '';
273
			
274
		$scope.showSpinner();
275
		$http.get('is/getMetaWfIdForFamily.do?family=IS_VALIDATION').success(function(data) {
276
			$scope.hideSpinner();
277
			$scope.metaWfId = data.id;
278
			$scope.section = data.section;
279
			$scope.family = data.family;
280
		}).error(function() {
281
			$scope.showError('Metaworkflow not registered');
282
			$scope.hideSpinner();
283
		});
284
	}
285
		
286
	$scope.registerValidationWfs = function() {
287
		$scope.metaWfId = '';
288
		$scope.showSpinner();
289
		$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
290
		$http.post('is/import.do', $.param({
291
			'path'     : 'classpath*:/eu/dnetlib/functionality/modular/workflows/validation',
292
			'schemas'  : false,
293
			'profiles' : true
294
		})).success(function(data) {
295
			$scope.hideSpinner();
296
			$scope.showNotification('Profiles are been registered');
297
			$scope.getValidationMetaWfId();
298
		}).error(function() {
299
			$scope.showError('Error registering profiles');
300
			$scope.hideSpinner();
301
	    });
302
	}
303
	
304
	$scope.getValidationMetaWfId();
305
});
306

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