Project

General

Profile

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

    
3
module.controller('wfJournalCtrl', function($scope, $http, $sce) {
4
	commonInitialize($scope, $http, $sce);
5
	
6
	initSpinner();
7

    
8
	$scope.journal = [];
9
	
10
	$scope.current = {};
11
	$scope.family = getFamily();
12
	$scope.filterJournal = {filterText: ''};
13
	$scope.currentParam = {};
14
	
15
	$scope.maxDate = new Date();
16
	$scope.minDate = new Date(2014, 0, 1);
17

    
18
	$scope.endDate = new Date();
19
	$scope.startDate = new Date();
20

    
21
	$scope.updateDates = function (start, end) {
22
		$scope.startDate = start;
23
		$scope.endDate = end;
24
		$scope.$apply();
25
		$scope.refresh();
26
	}
27

    
28
	// Set date range to [7 days before today, today] inclusive
29
	$scope.startDate.setDate($scope.endDate.getDate() - 7);
30

    
31
	// Grid configuration
32
	$scope.gridWfJournal = {
33
		data: 'journal',
34
		enableCellSelection: false,
35
		enableRowSelection: false,
36
		enableCellEditOnFocus: false,
37
		enablePaging: false,
38
		enableHighlighting: true,
39
		sortInfo: {fields: ['date'], directions: ['desc']},
40
		filterOptions: $scope.filterJournal,
41
		columnDefs: [{
42
			field: 'procId',
43
			displayName: 'Process ID',
44
			width: '15%',
45
			cellTemplate: '<div class="ngCellText"><a href="javascript:void(0)" ng-click="showProcess(row.getProperty(col.field))" data-target="#currentLogDetailsModal" data-toggle="modal">{{row.getProperty(col.field)}}</a></div>'
46
		},
47
			{field: 'name', displayName: 'Workflow name', width: '20%',},
48
			{field: 'family', displayName: 'Workflow family', width: '15%'},
49
			{field: 'datasource', displayName: 'Datasource'},
50
			{
51
				field: 'status',
52
				displayName: 'Status',
53
				width: '10%',
54
				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>'
55
			},
56
			{
57
				field: 'date',
58
				displayName: 'Date',
59
				width: '10%',
60
				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>'
61
			}
62
		]
63
	};
64
	
65
	$scope.showProcess = function(procId) {
66
		$scope.current = { 'procId' : procId };
67
		$scope.currentParam = {};
68
		
69
		$scope.showSpinner();
70
		
71
		$http.get("wf/journal.get?id="+procId).success(
72
			function (data) {
73
				$scope.current = data;
74
				$scope.hideSpinner();
75
			}
76
		).error(
77
			function () {
78
				$scope.showError('Something really bad must have happened to our fellow hamster..');
79
				$scope.hideSpinner();
80
			}
81
		);
82
	}
83

    
84
	$scope.formatDate = function (date) {
85
		var year = date.getFullYear();
86
		var month = ("00" + (date.getMonth() + 1)).slice(-2);
87
		var day = ("00" + date.getDate()).slice(-2);
88
		return year + '-' + month + '-' + day;
89
	}
90

    
91
	$scope.refresh = function () {
92
		$scope.showSpinner();
93
		$scope.current = {};
94
		$scope.currentParam = {};
95
		var url = '';
96

    
97
		if ($scope.family) {
98
			url = 'wf/journal_byFamily.find?family=' + $scope.family;
99
		} else {
100
			url = 'wf/journal.range?start=' + $scope.formatDate($scope.startDate) + '&end=' + $scope.formatDate($scope.endDate);
101
		}
102
		$http.get(url).success(
103
			function (data) {
104
				$scope.journal = data;
105
				$scope.hideSpinner();
106
			}
107
		).error(
108
			function () {
109
				$scope.showError('Something really bad must have happened to our fellow hamster..');
110
				$scope.hideSpinner();
111
			}
112
		);
113
	}
114

    
115
	$scope.calculateDateDiff = function (start, end) {
116
		if (start <= 0 || end <= 0) {
117
			return '-';
118
		}
119
		var seconds = 0;
120
		var minutes = 0;
121
		var hours = 0;
122
		var days = 0;
123

    
124
		if (end > start) {
125
			seconds = Math.round((end - start) / 1000);
126

    
127
			if (seconds > 60) {
128
				minutes = Math.floor(seconds / 60);
129
				seconds = seconds % 60;
130
				if (minutes > 60) {
131
					hours = Math.floor(minutes / 60);
132
					minutes = minutes % 60;
133
					if (hours > 24) {
134
						days = Math.floor(hours / 24);
135
						hours = hours % 24;
136
					}
137
				}
138
			}
139
		}
140

    
141
		var res = '';
142
		if (days > 0) {
143
			if (res) {
144
				res += ', ';
145
			}
146
			res += days + " day(s)"
147
		}
148
		if (hours > 0) {
149
			if (res) {
150
				res += ', ';
151
			}
152
			res += hours + " hour(s)"
153
		}
154
		if (minutes > 0) {
155
			if (res) {
156
				res += ', ';
157
			}
158
			res += minutes + " minute(s)"
159
		}
160
		if (seconds > 0) {
161
			if (res) {
162
				res += ', ';
163
			}
164
			res += seconds + " second(s)"
165
		}
166

    
167
		if (!res) {
168
			res = '0 seconds';
169
		}
170

    
171
		return res;
172
	}
173
	
174
	$scope.setCurrentParam  = function (p) {
175
		$scope.currentParam = p;
176
	}
177
	
178
	$scope.resizeMainElement = function (elem) {
179
		var height = 0;
180
		var body = window.document.body;
181
		if (window.innerHeight) {
182
			height = window.innerHeight;
183
		} else if (body.parentElement.clientHeight) {
184
			height = body.parentElement.clientHeight;
185
		} else if (body && body.clientHeight) {
186
			height = body.clientHeight;
187
		}
188
		elem.style.height = ((height - elem.offsetTop - 280) + "px");
189
	}
190

    
191
	$scope.refresh();
192
	$scope.resizeMainElement(document.getElementById('wfJournalTable'));
193

    
194
	if (initProcId()) {
195
		$scope.showProcess(initProcId());
196
	}
197
});
198

    
199
window.onresize = function () {
200
	var elem = document.getElementById('wfJournalTable');
201
	angular.element(elem).scope().resizeMainElement(elem);
202
};
(14-14/39)