Project

General

Profile

1
function getScope(selector) {
2
	return angular.element($(selector)).scope();
3
}
4

    
5
function addCommonDirectives(module) {
6
	module.directive('compileTemplate', function ($compile, $parse) {
7
		return {
8
			link: function (scope, element, attr) {
9
				var parsed = $parse(attr.ngBindHtml);
10

    
11
				function getStringValue() {
12
					return (parsed(scope) || '').toString();
13
				}
14

    
15
				//Recompile if the template changes
16
				scope.$watch(getStringValue, function () {
17
					$compile(element, null, -9999)(scope);  //The -9999 makes it skip directives so that we do not recompile ourselves
18
				});
19
			}
20
		}
21
	});
22

    
23
	module.directive('tooltip', function () {
24
		return {
25
			restrict: 'A',
26
			link: function (scope, element, attrs) {
27
				$(element).tooltip();
28
			}
29
		}
30
	});
31

    
32
	module.filter('sprintf', function () {
33
		function parse(str) {
34
			var args = [].slice.call(arguments, 1),
35
				i = 0;
36
			return str.replace(/%s/g, function () {
37
				return args[i++];
38
			});
39
		}
40

    
41
		return function (str) {
42
			return parse(str, arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
43
		};
44
	});
45
}
46

    
47
function commonInitialize($scope, $http, $sce) {
48

    
49
	$scope.currentProc = {};
50
	$scope.currentProcNode = {};
51
	$scope.currentValue = {};
52
	$scope.currentNode = null;
53

    
54
	$scope.currentLog = [];
55
	$scope.currentSimpleLog = [];
56
	$scope.currentAdvancedLog = [];
57
	$scope.currentStartWf = '-';
58
	$scope.currentEndWf = '-';
59

    
60
	$scope.gridCurrentLogDetails = {
61
		data: 'currentLog',
62
		enableCellSelection: false,
63
		enableRowSelection: false,
64
		enableColumnResize: true,
65
		enableCellEditOnFocus: false,
66
		enablePaging: false,
67
		enableHighlighting: true,
68
		sortInfo: {fields: ['name'], directions: ['asc']},
69
		columnDefs: [
70
			{
71
				field: 'name',
72
				displayName: 'Key',
73
				width: '25%',
74
				cellTemplate: '<div class="ngCellText" ng-class="col.colIndex()"><span ng-cell-text><a href="javascript:void(0)" ng-click="setCurrentValue(row.entity)">{{row.getProperty(col.field).replace(\"mainlog:\", \"\")}}</a></span></div>'
75
			},
76
			{field: 'value', displayName: 'Value'}
77
		],
78
		filterOptions: {filterText: '', useExternalFilter: false},
79
		showFilter: true
80
	};
81

    
82
	$scope.gridCurrentProcNodeEnvParams = {
83
		data: 'currentProcNode.params',
84
		enableCellSelection: false,
85
		enableRowSelection: false,
86
		enableCellEditOnFocus: false,
87
		enablePaging: false,
88
		enableHighlighting: true,
89
		sortInfo: {fields: ['name'], directions: ['asc']},
90
		columnDefs: [
91
			{
92
				field: 'name',
93
				displayName: 'Env Parameter Name',
94
				width: '25%',
95
				cellTemplate: '<div class="ngCellText" ng-class="col.colIndex()"><span ng-cell-text><a href="javascript:void(0)" ng-click="setCurrentValue(row.entity)">{{row.getProperty(col.field)}}</a></span></div>'
96
			},
97
			{field: 'value', displayName: 'Env Parameter Value'}
98
		],
99
		filterOptions: {filterText: '', useExternalFilter: false},
100
		showFilter: true
101
	};
102

    
103
	$scope.to_trusted = function (html_code) {
104
		return $sce.trustAsHtml(html_code);
105
	}
106

    
107
	$scope.showError = function (error) {
108
		show_notification("error", error);
109
	}
110

    
111
	$scope.showNotification = function (message) {
112
		show_notification("info", message);
113
	}
114

    
115
	$scope.showSpinner = function () {
116
		showSpinner();
117
	}
118

    
119
	$scope.hideSpinner = function () {
120
		hideSpinner();
121
	}
122

    
123
	initSpinner();
124

    
125
	$scope.getNodeDetails = function (wf, node) {
126
		$scope.currentNode = null;
127
		$scope.showSpinner();
128
		$http
129
			.get('wf/workflow_node.json?wf=' + wf + '&node=' + node)
130
			.success(function (data) {
131
				$scope.currentNode = data;
132
				$scope.hideSpinner();
133
				$('#nodeEditModal').modal('show');
134
			})
135
			.error(
136
				function () {
137
					$scope.showError('Something really bad must have happened to our fellow hamster..');
138
					$scope.hideSpinner();
139
				});
140
	}
141

    
142
	$scope.setCurrentValue = function (row) {
143
		$scope.currentValue = row;
144
	}
145
	
146
	$scope.showSpinner();
147
}
148

    
149
function wf_init($scope, $http, $sce) {
150

    
151
	$scope.currentWorkflowId = '';
152
	$scope.currentUserParams = {};
153
	$scope.currentWorkflow = {};
154
	$scope.workflows = [];
155
	$scope.currentHistory = [];
156
	$scope.filterWfHistory = {filterText: ''};
157

    
158
	$scope.gridHistory = {
159
		data: 'currentHistory',
160
		enableCellEditOnFocus: false,
161
		enablePaging: false,
162
		enableHighlighting: true,
163
		sortInfo: {fields: ['date'], directions: ['desc']},
164
		filterOptions: $scope.filterWfHistory,
165
		columnDefs: [
166
			{
167
				field: 'procId',
168
				displayName: 'Process ID',
169
				width: '15%',
170
				cellTemplate: '<div class="ngCellText"><a href="javascript:void(0)" ng-click="showProcess(row.getProperty(col.field))">{{row.getProperty(col.field)}}</a></div>'
171
			},
172
			{field: 'name', displayName: 'Workflow name', width: '40%'},
173
			{field: 'family', displayName: 'Workflow Family', width: '15%'},
174
			{
175
				field: 'status',
176
				displayName: 'Status',
177
				width: '10%',
178
				cellTemplate: '<div class="ngCellText"><span class="label label-default" ng-class="{ \'label-success\': row.getProperty(col.field) == \'SUCCESS\', \'label-danger\': row.getProperty(col.field) == \'FAILURE\', \'label-info\': row.getProperty(col.field) == \'EXECUTING\'}">{{row.getProperty(col.field)}}</span></div>'
179
			},
180
			{
181
				field: 'date',
182
				displayName: 'Last activity',
183
				cellTemplate: '<div class="ngCellText">{{ (row.getProperty("date") > 0 && row.getProperty("date") < 9999999999999) ? (row.getProperty("date") | date:"yyyy-MM-dd HH:mm:ss") : "not yet started" }}</div>'
184
			}
185
		]
186
	};
187

    
188

    
189
	$scope.prepareWfEdit = function () {
190
		$scope.tempWorkflow = angular.copy($scope.currentWorkflow);
191
	};
192

    
193

    
194
	$scope.updateHistory = function (ids) {
195
		$scope.currentHistory = [];
196
		$scope.showSpinner();
197
		$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
198
		$http.post('wf/journal.find', $.param({
199
			'wfs': JSON.stringify(ids)
200
		})).success(function (data) {
201
			$scope.hideSpinner();
202
			$scope.currentHistory = data;
203
			$('#monitorWfModal').modal('show')
204
		}).error(function (err) {
205
			$scope.hideSpinner();
206
			$scope.showError(err.message);
207
		});
208
	};
209
}
(16-16/39)