Project

General

Profile

1
var dnetWorkflowsControllers = angular.module('dnetWorkflowsControllers', ['ngGrid']);
2

    
3

    
4
dnetWorkflowsControllers.controller('wfListCtrl', ['$scope', '$http', '$routeParams',
5
	function ($scope, $http, $routeParams) {
6
		$scope.currentSection = $routeParams.section.replace(/(\_|\+)/g, ' ');
7
		$scope.wfList = [];
8
		$http.get('wf/list_workflows.json?section=' + $scope.currentSection).success(function (data) {
9
			$scope.wfList = data;
10
		}).error(function (err) {
11
			show_notification("error", err.message);
12
		});
13
	}
14
]);
15

    
16

    
17
dnetWorkflowsControllers.controller('workflowCtrl', [
18
	'$scope', '$http', '$sce', '$location', '$route', '$routeParams', 'sharedProperties',
19
	function ($scope, $http, $sce, $location, $route, $routeParams, sharedProperties) {
20
		$scope.currentWorkflowId = $routeParams.wf;
21

    
22
		$scope.currentProc = {};
23
		$scope.history = [];
24
		$scope.subWorkflows = [];
25
		$scope.currentProc = {};
26
		$scope.params = {};
27
		$scope.originalParams = {};
28

    
29
		$scope.executeWf = function (wfId) {
30
			$http.get('wf/wf.start?id=' + wfId).success(function (data) {
31
				$scope.currentProc = data;
32
				$('#monitorProcWfModal').modal('show');
33
			}).error(function (err) {
34
				show_notification('error', 'Error executing wf: ' + err.message);
35
			});
36
		};
37

    
38
		$scope.refresh = function () {
39
			$route.reload();
40
		};
41

    
42
		$scope.updateHistory = function (wfId) {
43
			$http.get('wf/journal.find?wfs=' + wfId).success(function (data) {
44
				$scope.history = data;
45
			}).error(function (err) {
46
				show_notification('error', 'Error fetching history: ' + err.message);
47
			});
48
		};
49

    
50
		$scope.updateSubWorkflows = function (wfId) {
51
			$http.get('wf/obtainSubWorkflows.do?id=' + wfId).success(function (data) {
52
				$scope.subWorkflows = data;
53
			}).error(function (err) {
54
				show_notification('error', 'error fetching sub workflows: ' + err.message);
55
			});
56
		};
57

    
58
		$scope.updateParameters = function (wfId, params) {
59
			showSpinner();
60

    
61
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
62
			$http.post('wf/saveParams.do', $.param({
63
				'wf': wfId,
64
				'params': JSON.stringify(params)
65
			})).success(function (b) {
66
				hideSpinner();
67
				show_notification('info', 'Workflow updated !');
68
				$scope.originalParams = angular.copy($scope.params);
69
			}).error(function (err) {
70
				hideSpinner();
71
				show_notification('error', 'Error updating wf: ' + err.message);
72
			});
73
		}
74

    
75
		$scope.resetParameters = function () {
76
			$scope.params = angular.copy($scope.originalParams);
77
		}
78

    
79
		$scope.resetGraph = function () {
80
			sharedProperties.resetGraph();
81
		}
82

    
83
		$scope.redrawGraph = function () {
84
			sharedProperties.rearrangeNodes();
85
		}
86

    
87
	}
88
]);
89

    
90
dnetWorkflowsControllers.controller('repoApiCtrl', [
91
	'$scope', '$http', '$timeout', '$sce', '$route', '$routeParams', '$location',
92
	function ($scope, $http, $timeout, $sce, $route, $routeParams, $location) {
93
		
94
		initSpinner();
95
		
96
		$scope.params = {};
97
		$scope.originalParams = {};
98
		
99
		$scope.availableRepohiWfs = [];
100
		
101
		$scope.refresh = function () {
102
			$route.reload();
103
		};
104
		
105
		$scope.updateCompatibilityLevel = function(repoId, ifaceId, level) {
106
			var url = '';
107
			if (level) { url = 'repo/repoApiCompliance.update?id=' + repoId + '&iface=' + ifaceId + '&compliance=' + level; }
108
			else       { url = 'repo/repoApiCompliance.reset?id=' + repoId + '&iface=' + ifaceId }
109
		
110
			showSpinner();
111
			$http.get(url).success(function (data) {
112
				hideSpinner();
113
				show_notification('info', 'Api correctly updated !');
114
				$route.reload();
115
			}).error(function (err) {
116
				hideSpinner();
117
				show_notification('error', 'Error updating compliance: ' + err.message);
118
			});
119
		};
120
	
121
		$scope.updateRepoApi = function(repoId, ifaceId, p) {
122
			showSpinner();
123
			var map = {};
124
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
125

    
126
			var params = {};
127
			angular.forEach(p, function (value, key) {
128
				if (angular.isArray(value)) {
129
					params[key] = value.join(',')
130
				} else {
131
					params[key] = value; 
132
				}
133
			});
134
			
135
			$http.post('repo/repoApi.update', $.param({
136
				'id': repoId,
137
				'iface': ifaceId,
138
				'accessParams': JSON.stringify(params)
139
			})).success(function (data) {
140
				show_notification('info', 'Api correctly saved !');
141
				hideSpinner();
142
				$route.reload();
143
			}).error(function (err) {
144
				show_notification('error', 'Error saving access parameters: ' + err.message);
145
				hideSpinner();
146
			});
147
		};
148
		
149
		$scope.findRepoHiWorkflows = function(compliance, type) {
150
			showSpinner();
151
			
152
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
153
			$http.post('wf/repohi_wfs.find', $.param({
154
				'compliance' : compliance,
155
				'type' : type
156
			})).success(function (data) {
157
				hideSpinner();
158
				$scope.availableRepohiWfs = data;
159
			}).error(function (err) {
160
				show_notification('error', 'Error listing repo-hi workflows: ' + err.message);
161
				hideSpinner();
162
			});
163
		};
164
		
165
		$scope.newRepoWorkflow = function (repoId, ifaceId, repoHiWfId) {
166
			showSpinner();
167
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
168
			$http.post('wf/repohi.start', $.param({
169
				'id': repoId,
170
				'iface': ifaceId,
171
				'wf': repoHiWfId
172
			})).success(function (data) {
173
				$timeout(function () {
174
					hideSpinner();
175
					$route.reload();
176
				}, 500);
177
			}).error(function (err) {
178
				hideSpinner();
179
				show_notification('error', 'Error starting REPO_HI workflow:' + err.message);
180
			});
181
		};
182
                                    	  
183
                                    	  /*
184
                                       		 common_init($scope, $http, $sce, $location);
185

    
186
                                       		 commonInitialize($scope, $http, $sce);
187
                                       		 wf_init($scope, $http, $sce);
188

    
189
                                       		 $scope.availableRepohiWfs = getAvailableRepohiWfs();
190
                                       		 $scope.compatibilityLevels = getCompatibilityLevels();
191

    
192
                                       		 $scope.currentRepoApi = {};
193
                                       		 $scope.currentSets = [];
194
                                       		 $scope.selectedSets = [];
195

    
196
                                       		 $scope.newRepoWorkflow = function (wf) {
197

    
198
                                       		 if (wf == undefined) {
199
                                       		 $scope.showError('Please choose a workflow !');
200
                                       		 return;
201
                                       		 }
202

    
203
                                       		 $scope.showSpinner();
204

    
205
                                       		 $scope.metaworkflows.push({"id": "", "name": "Waiting...", "status": "MISSING", "progress": 0});
206

    
207
                                       		 $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
208
                                       		 $http.post('repoMetaWf.new', $.param({
209
                                       		 'wf': wf,
210
                                       		 'iface': $scope.currentRepoApi.id,
211
                                       		 'id': $scope.currentRepoApi.repoId,
212
                                       		 'name': $scope.currentRepoApi.repoName
213
                                       		 })).success(
214
                                       		 function (data) {
215
                                       		 $scope.hideSpinner();
216
                                       		 $(".btnRefreshApi").attr("disabled", "disabled");
217
                                       		 $timeout(function () {
218
                                       		 $route.reload();
219
                                       		 }, 7000);
220
                                       		 }
221
                                       		 ).error(
222
                                       		 function () {
223
                                       		 $scope.showError('Something really bad must have happened to our fellow hamster..');
224
                                       		 $scope.hideSpinner();
225
                                       		 }
226
                                       		 );
227
                                       		 };
228

    
229
                                       		 $scope.destroyWorkflow = function (metaWf) {
230

    
231
                                       		 if (metaWf.destroyWorkflow == undefined) {
232
                                       		 $scope.showError('Destroy wf is missing !');
233
                                       		 return;
234
                                       		 }
235

    
236
                                       		 if (!confirm("Are you sure ?")) {
237
                                       		 return;
238
                                       		 }
239

    
240
                                       		 $scope.showSpinner();
241

    
242
                                       		 metaWf.deleting = true;
243

    
244
                                       		 $http.get('repoMetaWf.destroy?destroyWf=' + metaWf.destroyWorkflow)
245
                                       		 .success(
246
                                       		 function (data) {
247
                                       		 $scope.hideSpinner();
248
                                       		 $(".btnRefreshApi").attr("disabled", "disabled");
249
                                       		 $timeout(function () {
250
                                       		 $route.reload();
251
                                       		 }, 7000);
252
                                       		 }
253
                                       		 ).error(
254
                                       		 function () {
255
                                       		 $scope.showError('Something really bad must have happened to our fellow hamster..');
256
                                       		 $scope.hideSpinner();
257
                                       		 }
258
                                       		 );
259
                                       		 };
260

    
261
                                       		 
262

    
263
                                       		                                        		 
264
                                       		 
265

    
266

    
267
                                       		 
268

    
269
                                       		 
270

    
271

    
272
                                       		 */
273
                                       	}
274

    
275
                                       ]);
(10-10/15)