Project

General

Profile

1
var module = angular.module('workflowsUI', [
2
                                            'ngRoute', 
3
                                            'wfFormFields', 
4
                                            'cronMaker', 
5
                                            'wfProcessViewer', 
6
                                            'wfGraphViewer', 
7
                                            'repoAccessParamsEditor',
8
                                            'repohi'
9
                                            ]);
10

    
11
module.config(function ($routeProvider) {
12
	$routeProvider
13
	.when('/list/:section*', {
14
		controller: 'wfListCtrl',
15
		templateUrl: '/html/wf/wf-list.html'
16
	})
17
	.when('/wf/:wf*', {
18
		controller: 'workflowCtrl',
19
		templateUrl: function (params) {
20
			if (params.wf == '_') {
21
				return "/html/wf/empty.html";
22
			} else {
23
				return '/page/wf?id=' + params.wf + '&dt=' + new Date().getTime();
24
			}
25
		}
26
	}).when('/ds/:repoId*/api/:ifaceId*', {
27
		controller: 'repoApiCtrl',
28
		templateUrl: function (params) {
29
			return '/html/datasources/api.html';
30
		}
31
	})
32
	.otherwise({redirectTo: '/'});
33
});
34

    
35
module.directive('wfFormUpdate', function ($http) {
36
	return {
37
		restrict: 'E',
38
		templateUrl: '/html/wf/wf-form-update.html',
39
		scope: {
40
			wfId: '@'
41
		},
42
		link: function (scope) {
43
			initSpinner();
44

    
45
			scope.showCronMakerModal = false;
46
			scope.wf = {};
47
			scope.emailMessages = [];
48

    
49
			showSpinner();
50
			$http.defaults.headers.post["Content-Type"] = "application/json; charset=utf-8";
51
			$http.post('/ajax/wfs/validValues/listProfiles', {
52
				'kind'  : 'conf',
53
				'type'  : 'template',
54
				'cond'  : '//TEMPLATE/@type="email"',
55
				'xpath' : '//TEMPLATE_NAME'
56
			}).success(function (data) {
57
				hideSpinner();
58
				scope.emailMessages = data;
59
			}).error(function (err) {
60
				show_notification("error", err.message);
61
				hideSpinner();
62
			});
63

    
64
			scope.reset = function () {
65
				showSpinner();
66
				$http.get('/ajax/wfs/workflowManagementParams?wfId=' + scope.wfId).success(function (data) {
67
					hideSpinner();
68
					scope.wf = data;
69
				}).error(function (err) {
70
					show_notification("error", err.message);
71
					hideSpinner();
72
				})
73

    
74
				scope.wf = angular.copy(scope.originalWf);
75
			};
76

    
77
			scope.addNotification = function() {
78
				if      (!scope.wf)               { scope.wf = { 'notifications': [ {} ] } }
79
				else if (!scope.wf.notifications) { scope.wf.notifications =      [ {} ] }
80
				else                              { scope.wf.notifications.push   ( {} ) }
81
			};
82

    
83
			scope.dropNotification = function(pos) {
84
				if (scope.wf && scope.wf.notifications && pos >= 0 && pos < scope.wf.notifications.length) {
85
					scope.wf.notifications.splice(pos, 1);
86
				}
87
			};
88

    
89
			scope.showCronMaker = function() {
90
				scope.showCronMakerModal = true;
91
			}
92

    
93
			scope.updateWf = function () {
94
				showSpinner();
95
				$http.defaults.headers.post["Content-Type"] = "application/json; charset=utf-8";
96
				$http.post('/ajax/wfs/workflowManagementParams?wfId=' + scope.wfId, scope.wf).success(function (data) {
97
					hideSpinner();
98
					show_notification("info", 'Workflow updated !');
99
				}).error(function (err) {
100
					show_notification("error", err.message);
101
					hideSpinner();
102
				});
103
			};
104

    
105
			scope.reset();
106

    
107
		}
108
	}
109
});
110

    
111
module.directive('bsHasErrorSimple', function () {
112
	return {
113
		restrict: "A",
114
		link: function (scope, element, attrs, ctrl) {
115
			element.toggleClass('has-feedback', true);
116
			var input = element.find('input[ng-model], select[ng-model]');
117
			if (input) {
118
				scope.$watch(function () {
119
					if (input.controller('ngModel').$invalid) {
120
						return 0;
121
					} else {
122
						return 1;
123
					}
124
				}, function (code) {
125
					if (code < 0) return;
126
					element.toggleClass('has-error', (code == 0));
127
					element.toggleClass('has-success', (code == 1));
128
				});
129
			}
130
		}
131
	};
132
});
133

    
134

    
135
module.directive('wfSubWorkflows', function ($http) {
136
	return {
137
		restrict: 'E',
138
		templateUrl: '/html/wf/wf-sub-workflows.html',
139
		scope: {
140
			wfId: '@',
141
			graphId: '=',
142
			showGraphModal: '='
143
		},
144
		link: function (scope) {
145
			scope.currentProcId = '';
146
			scope.currentWorker = '';
147
			scope.showProcModal = false;
148
			scope.subWorkflows = [];
149

    
150
			$http.get('/ajax/wfs/subWorkflows?wfId=' + scope.wfId).success(function (data) {
151
				scope.subWorkflows = data;
152
			}).error(function (err) {
153
				show_notification('error', 'error fetching sub workflows: ' + err.message);
154
			});
155

    
156
			scope.executeWf = function (wfId, name, parent, isTemplate, warning) {
157

    
158
				if (warning && !confirm("You are launching a part of a not well configured workflow. Are you sure ?")) {
159
					show_notification("info", "Execution aborted");
160
					return;
161
				}
162

    
163
				var url = '';
164
				if (isTemplate) {
165
					url = '/ajax/wfs/startWorkflowTemplate?node=' + name + '&parent=' + parent;
166
				} else {
167
					url = '/ajax/wfs/startWorkflow?wfId=' + wfId;
168
				}
169

    
170
				$http.get(url).success(function (data) {
171
					scope.currentProcId = data.procId;
172
					scope.currentWorker = data.worker;
173
					scope.showProcModal = true;
174
				}).error(function (err) {
175
					show_notification("error", "Error executing wf: " + err.message);
176
				});
177
			};
178

    
179
			scope.showGraph = function (wfId) {
180
				scope.graphId = wfId;
181
				scope.showGraphModal = true;
182
			};
183
		}
184
	}
185
});
186

    
187
module.directive('wfHistory', function () {
188
	return {
189
		restrict: 'E',
190
		templateUrl: '/html/wf/wf-history.html',
191
		scope: {
192
			ngModel: '=',
193
			onRefresh: '&'
194
		},
195
		link: function (scope) {
196
			scope.currentId = '';
197
			scope.currentProc = {};
198
			
199
			scope.showGraphModal = false;
200
			scope.showLogModal = false;
201
			
202
			scope.doOnRefesh = function () {
203
				scope.onRefresh();
204
			}
205
			scope.showProcess = function (procId) {
206
				scope.currentId = procId;
207
				scope.showGraphModal = true;
208
			}
209
			scope.showProcessLog = function (proc) {
210
				scope.currentProc = proc;
211
				scope.showLogModal = true;
212
			}
213
		}
214
	}
215
});
216

    
217

    
218
module.controller('wfListCtrl', function ($scope, $http, $routeParams) {
219
	$scope.currentSection = $routeParams.section.replace(/(\_|\+)/g, ' ');
220
	$scope.wfList = [];
221
	$http.get('/ajax/wfs/list?section=' + $scope.currentSection).success(function (data) {
222
		$scope.wfList = data;
223
	}).error(function (err) {
224
		show_notification("error", err.message);
225
	});
226
}
227
);
228

    
229

    
230
module.controller('workflowCtrl', function ($scope, $http, $sce, $location, $route, $routeParams) {
231
	$scope.currentWorkflowId = $routeParams.wf;
232

    
233
	$scope.currentProcId = '';
234
	$scope.currentWorker = '';
235
	$scope.showProcModal = false;
236
	$scope.showAccessParamsModal = false;
237

    
238
	$scope.currentGraphId = '';
239
	$scope.showGraphModal = false;
240

    
241
	$scope.history = [];
242
	$scope.params = {};
243
	$scope.originalParams = {};
244

    
245
	$scope.showGraph = function (wfId) {
246
		$scope.currentGraphId = wfId;
247
		$scope.showGraphModal = true;
248
	};
249

    
250
	$scope.executeWf = function (wfId) {
251
		$http.get('/ajax/wfs/startWorkflow?wfId=' + wfId).success(function (data) {
252
			$scope.currentProcId = data.procId;
253
			$scope.currentWorker = data.worker;
254
			$scope.showProcModal = true;
255
		}).error(function (err) {
256
			show_notification('error', 'Error executing wf: ' + err.message);
257
		});
258
	};
259

    
260
	$scope.editAccessParams = function () {
261
		$scope.showAccessParamsModal = true;
262
	};
263

    
264
	$scope.refresh = function () {
265
		$route.reload();
266
	};
267

    
268
	$scope.updateHistory = function (wfId) {
269
		$http.get('/ajax/wfs/logs?wf=' + wfId).success(function (data) {
270
			$scope.history = data;
271
		}).error(function (err) {
272
			show_notification('error', 'Error fetching history: ' + err.message);
273
		});
274
	};
275

    
276
	$scope.updateParameters = function (wfId, params) {
277
		showSpinner();
278

    
279
		$http.defaults.headers.post["Content-Type"] = "application/json; charset=utf-8";
280
		$http.post('/ajax/wfs/workflowParams?wfId=' + wfId, params).success(function (b) {
281
			hideSpinner();
282
			show_notification('info', 'Workflow updated !');
283
			$scope.originalParams = angular.copy($scope.params);
284
		}).error(function (err) {
285
			hideSpinner();
286
			show_notification('error', 'Error updating wf: ' + err.message);
287
		});
288
	}
289

    
290
	$scope.resetParameters = function () {
291
		$scope.params = angular.copy($scope.originalParams);
292
	}
293

    
294
});
295

    
296
module.controller('repoApiCtrl', function ($scope, $http, $timeout, $sce, $route, $routeParams, $location) {
297

    
298
	initSpinner();
299

    
300
	$scope.params = {};
301
	$scope.originalParams = {};
302

    
303
	$scope.currentProcId = '';
304
	$scope.showProcModal = false;
305
	$scope.showAccessParamsModal = false;
306
	$scope.showRepoHiModal = false;
307
	$scope.selectedRepoHiWf = {};
308
	$scope.selectedMsroWorker = {};
309
	
310
	$scope.currentDsId = $routeParams.repoId;
311
	$scope.currentIfaceId = $routeParams.ifaceId;
312
	
313
	$scope.ds = {};
314
	$scope.api = {};
315
	$scope.wfs = [];
316
	$scope.overrideCompliance = '';
317
	$scope.compatibilityLevels = getCompatibilityLevels();
318
	
319
	$scope.refresh = function () {
320
		showSpinner();
321
		$http.get('/ajax/apis/ds?id=' + $scope.currentDsId).success(function (data) {
322
			hideSpinner();
323
			$scope.ds = data;
324
			for(var i=0; i<data.interfaces.length; i++) {
325
				if (data.interfaces[i].id == $scope.currentIfaceId) {
326
					$scope.api = data.interfaces[i];
327
					if ($scope.api.extraFields['overriding_compliance']) {
328
						$scope.overrideCompliance = $scope.api.extraFields['overriding_compliance'];
329
					}
330
				}
331
			}
332
		}).error(function (err) {
333
			hideSpinner();
334
			show_notification('error', 'Error getting datasource');
335
		});
336
		
337
		$http.get('/ajax/wfs/forApi?dsId=' + $scope.currentDsId + "&ifaceId=" + $scope.currentIfaceId).success(function (data) {
338
			hideSpinner();
339
			$scope.wfs = data;
340
		}).error(function (err) {
341
			hideSpinner();
342
			show_notification('error', 'Error getting wfs');
343
		});
344
	};
345
	
346
	$scope.editAccessParams = function () {
347
		$scope.showAccessParamsModal = true;
348
	};
349
	
350
	$scope.prepareRepoHiModal = function () {
351
		$scope.showRepoHiModal = true;
352
	};
353

    
354
	$scope.updateCompatibilityLevel = function(level) {
355
		var url = '';
356
		if (level) { url = '/ajax/wfs/ds/compliance/override/' + level + '?dsId=' + $scope.currentDsId + '&ifaceId=' + $scope.currentIfaceId }
357
		else       { url = '/ajax/wfs/ds/compliance/reset?dsId=' + $scope.currentDsId + '&ifaceId=' + $scope.currentIfaceId }
358

    
359
		showSpinner();
360
		$http.get(url).success(function (data) {
361
			hideSpinner();
362
			show_notification('info', 'Api correctly updated !');
363
			$route.reload();
364
		}).error(function (err) {
365
			hideSpinner();
366
			show_notification('error', 'Error updating compliance: ' + err.message);
367
		});
368
	};
369

    
370
	$scope.newRepoWorkflow = function() {
371
		showSpinner();
372
		$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
373
		$http.post('/ajax/apis/repohi/start', $.param({
374
			'dsId'     : $scope.currentDsId,
375
			'iface'    : $scope.currentIfaceId,
376
			'wfId'     : $scope.selectedRepoHiWf.id,
377
			'workerId' : $scope.selectedMsroWorker.serviceId
378
		})).success(function (data) {
379
			$scope.currentProcId = data.procId;
380
			$scope.currentWorker = data.worker;
381
			$scope.showProcModal = true;
382
		}).error(function (err) {
383
			hideSpinner();
384
			show_notification('error', 'Error starting REPO_HI workflow:' + err.message);
385
		});
386
	};
387

    
388
	$scope.destroyRepoWorkflow = function (wfId) {
389
		showSpinner();
390
		$http.post('/ajax/apis/repobye?wfId=' + wfId).success(function (data) {
391
			$scope.currentProcId = data.procId;
392
			$scope.currentWorker = data.worker;
393
			$scope.showProcModal = true;
394
		}).error(function (err) {
395
			hideSpinner();
396
			show_notification('error', 'Error starting REPO_BYE workflow:' + err.message);
397
		});
398
	};
399
	
400
	$scope.refresh();
401
});
402

    
(7-7/7)