Project

General

Profile

1
var wfProcessViewer = angular.module("wfProcessViewer", []);
2

    
3
wfProcessViewer.directive("wfProcessModal", function ($http) {
4
	return {
5
		restrict: 'E',
6
		transclude: true,
7
		replace:true,
8
		scope: {
9
	        'procId'  : '=',
10
	        'worker'  : '=',
11
	        'visible' : '='
12
		},
13
		templateUrl: '/html/wf/wf-process-modal.html',
14
		
15
		link: function (scope, element, attrs, ctrl) {
16
			scope.currentParam = {};
17
			scope.current = {};
18
			scope.contentToShow = '';
19
			scope.currentNode = {};
20
			
21
			$(element).modal({'show': false});
22
		
23
			scope.$watch(function() {
24
				return scope.visible;
25
			}, function(value) {
26
				if (value == true && scope.procId) { 
27
					$(element).modal('show');
28
					scope.visible = false;
29
					scope.proc = {};
30
					scope.currentNode = {};
31
					scope.currentParam = {};
32
					scope.refresh();
33
				}
34
			});
35
			
36
			scope.showContent = function(c) {
37
				scope.contentToShow = c;
38
			};
39
			
40
			scope.showNodeInfo = function(node) {
41
				scope.currentNode = node;
42
			};
43
			
44
			scope.hideNodeInfo = function() {
45
				scope.currentNode = {};
46
			};
47
			
48
			scope.to_trusted = function (html_code) {
49
				return $sce.trustAsHtml(html_code);
50
			};
51

    
52
			scope.refresh = function () {
53
				showSpinner();
54
				$http.get('/ajax/wfs/proc/' + scope.procId + "?worker=" + scope.worker).success(function (data) {
55
					hideSpinner();
56
					scope.proc = data;
57
					
58
					if (data.processNodes && data.processNodes.length > 0) {
59
						scope.contentToShow = 'nodes';
60
					} else if (data.outputParams && data.outputParams.length > 0) {
61
						scope.contentToShow = 'journal';
62
					} else {
63
						scope.contentToShow = '';
64
					}
65
				}).error(function (e) {
66
					show_notification('error', 'Error fetching process info: ' + e);
67
					hideSpinner();
68
				});
69
			}
70

    
71
			scope.kill = function () {
72
				if (confirm("Are you sure ?")) {
73
					showSpinner();
74
					$http.get('/ajax/wfs/kill/' + scope.procId + "?worker=" + scope.worker).success(function (data) {
75
						scope.currentProc = {};
76
						hideSpinner();
77
						$(element).modal('hide');
78
						show_notification('info', 'Workflow killed !');
79
					}).error(function (e) {
80
						show_notification('error', 'Error killing process: ' + e);
81
						hideSpinner();
82
					});
83
				}
84
			}
85
			
86
			scope.calculateDateDiff = function (start, end) {
87
				if (start <= 0 || end <= 0) {
88
					return '-';
89
				}
90
				var seconds = 0;
91
				var minutes = 0;
92
				var hours = 0;
93
				var days = 0;
94
	
95
				if (end > start) {
96
					seconds = Math.round((end - start) / 1000);
97
	
98
					if (seconds > 60) {
99
						minutes = Math.floor(seconds / 60);
100
						seconds = seconds % 60;
101
						if (minutes > 60) {
102
							hours = Math.floor(minutes / 60);
103
							minutes = minutes % 60;
104
							if (hours > 24) {
105
								days = Math.floor(hours / 24);
106
								hours = hours % 24;
107
							}
108
						}
109
					}
110
				}
111
	
112
				var res = '';
113
				if (days > 0) {
114
					if (res) {
115
						res += ', ';
116
					}
117
					res += days + " day(s)"
118
				}
119
				if (hours > 0) {
120
					if (res) {
121
						res += ', ';
122
					}
123
					res += hours + " hour(s)"
124
				}
125
				if (minutes > 0) {
126
					if (res) {
127
						res += ', ';
128
					}
129
					res += minutes + " minute(s)"
130
				}
131
				if (seconds > 0) {
132
					if (res) {
133
						res += ', ';
134
					}
135
					res += seconds + " second(s)"
136
				}
137
	
138
				if (!res) {
139
					res = '0 seconds';
140
				}
141
	
142
				return res;
143
			}
144
			
145
			scope.setCurrentParam  = function (p) {
146
				scope.currentParam = p;
147
			}
148
		}
149
	}
150
});
151

    
152
wfProcessViewer.directive("wfProcessLogModal", function () {
153
	return {
154
		restrict: 'E',
155
		transclude: true,
156
		replace:true,
157
		scope: {
158
	        'entry'   : '=',
159
	        'visible' : '='
160
		},
161
		templateUrl: '/html/wf/wf-process-log-modal.html',
162
		
163
		link: function (scope, element, attrs, ctrl) {
164
			
165
			scope.currentParam = {};
166
			
167
			$(element).modal({'show': false});
168
		
169
			scope.$watch(function() {
170
				return scope.visible;
171
			}, function(value) {
172
				if (value == true && scope.entry && scope.entry.procId) { 
173
					$(element).modal('show');
174
					scope.visible = false;
175
					scope.currentParam = {};
176
				}
177
			});
178
						
179
			scope.to_trusted = function (html_code) {
180
				return $sce.trustAsHtml(html_code);
181
			};
182
		
183
			scope.calculateDateDiff = function (start, end) {
184
				if (start <= 0 || end <= 0) {
185
					return '-';
186
				}
187
				var seconds = 0;
188
				var minutes = 0;
189
				var hours = 0;
190
				var days = 0;
191
	
192
				if (end > start) {
193
					seconds = Math.round((end - start) / 1000);
194
	
195
					if (seconds > 60) {
196
						minutes = Math.floor(seconds / 60);
197
						seconds = seconds % 60;
198
						if (minutes > 60) {
199
							hours = Math.floor(minutes / 60);
200
							minutes = minutes % 60;
201
							if (hours > 24) {
202
								days = Math.floor(hours / 24);
203
								hours = hours % 24;
204
							}
205
						}
206
					}
207
				}
208
	
209
				var res = '';
210
				if (days > 0) {
211
					if (res) {
212
						res += ', ';
213
					}
214
					res += days + " day(s)"
215
				}
216
				if (hours > 0) {
217
					if (res) {
218
						res += ', ';
219
					}
220
					res += hours + " hour(s)"
221
				}
222
				if (minutes > 0) {
223
					if (res) {
224
						res += ', ';
225
					}
226
					res += minutes + " minute(s)"
227
				}
228
				if (seconds > 0) {
229
					if (res) {
230
						res += ', ';
231
					}
232
					res += seconds + " second(s)"
233
				}
234
	
235
				if (!res) {
236
					res = '0 seconds';
237
				}
238
	
239
				return res;
240
			}
241
			
242
			scope.setCurrentParam  = function (p) {
243
				scope.currentParam = p;
244
			}
245
			
246
		}
247
	}
248
});
249

    
(5-5/6)