Project

General

Profile

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

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

    
8
	$scope.journal = [];
9
	
10
	$scope.currentId = '';
11
	$scope.showModal = false;
12
	
13
	$scope.family = getFamily();
14
	$scope.filterJournal = {filterText: ''};
15

    
16
	$scope.endDate = new Date();
17
	$scope.startDate = new Date();
18

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

    
22
	// Grid configuration
23
	$scope.gridWfJournal = {
24
		data: 'journal',
25
		enableCellSelection: false,
26
		enableRowSelection: false,
27
		enableCellEditOnFocus: false,
28
		enablePaging: false,
29
		enableHighlighting: true,
30
		sortInfo: {fields: ['date'], directions: ['desc']},
31
		filterOptions: $scope.filterJournal,
32
		columnDefs: [
33
			{
34
				field: 'procId',
35
				displayName: 'Process ID',
36
				width: '15%',
37
				cellTemplate: '<div class="ngCellText"><a href="javascript:void(0)" ng-click="showProcess(row.getProperty(col.field))">{{row.getProperty(col.field)}}</a></div>'
38
			},
39
			{field: 'name', displayName: 'Workflow name', width: '20%'},
40
			{field: 'family', displayName: 'Workflow family', width: '15%'},
41
			{field: 'datasource', displayName: 'Datasource'},
42
			{
43
				field: 'status',
44
				displayName: 'Status',
45
				width: '10%',
46
				headerClass: 'text-center',
47
				cellTemplate: '<div class="ngCellText text-center"><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>'
48
			},
49
			{
50
				field: 'date',
51
				displayName: 'Date',
52
				width: '10%',
53
				headerClass: 'text-right',
54
				cellTemplate: '<div class="ngCellText text-right">{{ (row.getProperty("date") > 0 && row.getProperty("date") < 9999999999999) ? (row.getProperty("date") | date:"yyyy-MM-dd HH:mm:ss") : "not yet started" }}</div>'
55
			}
56
		]
57
	};
58
		
59
	$scope.popupFrom = { opened: false };	
60
	$scope.popupTo   = { opened: false };	
61
	$scope.openPopupFrom = function() { $scope.popupFrom.opened = true; };
62
	$scope.openPopupTo   = function() { $scope.popupTo.opened = true; };
63
		
64
	$scope.dateOptions = {
65
		maxDate     : new Date(),
66
		minDate     : new Date(2014, 1, 1),
67
		startingDay : 1
68
	};
69
		
70
	$scope.showProcess = function(procId) {
71
		$scope.currentId =  procId;
72
		$scope.showModal = true;
73
	}
74

    
75
	$scope.formatDate = function (date) {
76
		if (date) {
77
			var year = date.getFullYear();
78
			var month = ("00" + (date.getMonth() + 1)).slice(-2);
79
			var day = ("00" + date.getDate()).slice(-2);
80
			return year + '-' + month + '-' + day;
81
		} else {
82
			return '';
83
		}
84
	}
85
	
86
	$scope.isValidRange = function() {
87
		return ($scope.startDate && $scope.endDate && $scope.startDate.getTime() <= $scope.endDate.getTime());
88
	};
89

    
90
	$scope.refresh = function () {
91
		if (!$scope.isValidRange()) {
92
			$scope.journal = [];
93
			return;
94
		}
95
		showSpinner();
96
		$scope.current = {};
97
		$scope.currentParam = {};
98
		var url = '';
99

    
100
		if ($scope.family) {
101
			url = 'wf/journal_byFamily.find?family=' + $scope.family;
102
		} else {
103
			url = 'wf/journal.range?start=' + $scope.formatDate($scope.startDate) + '&end=' + $scope.formatDate($scope.endDate);
104
		}
105
		$http.get(url).success(
106
			function (data) {
107
				$scope.journal = data;
108
				hideSpinner();
109
			}
110
		).error(
111
			function () {
112
				showError('Something really bad must have happened to our fellow hamster..');
113
				hideSpinner();
114
			}
115
		);
116
	}
117
	
118
	$scope.resizeMainElement = function (elem) {
119
		var height = 0;
120
		var body = window.document.body;
121
		if (window.innerHeight) {
122
			height = window.innerHeight;
123
		} else if (body.parentElement.clientHeight) {
124
			height = body.parentElement.clientHeight;
125
		} else if (body && body.clientHeight) {
126
			height = body.clientHeight;
127
		}
128
		elem.style.height = ((height - elem.offsetTop - 280) + "px");
129
	}
130

    
131
	$scope.refresh();
132
	$scope.resizeMainElement(document.getElementById('wfJournalTable'));
133

    
134
	if (initProcId()) {
135
		$scope.showProcess(initProcId());
136
	}
137
});
138

    
139
window.onresize = function () {
140
	var elem = document.getElementById('wfJournalTable');
141
	angular.element(elem).scope().resizeMainElement(elem);
142
};
(6-6/8)