/
rule-ctrl.js
176 lines (154 loc) · 6.57 KB
/
rule-ctrl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
define(['./module'], function (controllers) {
'use strict';
controllers.controller('RuleCtrl', ['$scope', '$http', '$config', '$location', '$timeout', '$route', 'toaster', '$filter', function ($scope, $http, $config, $location, $timeout, $route, toaster, $filter) {
console.log('rule controller');
$scope.statusList = $filter('strarr')('modelstatus');
$scope.systemList = $filter('strarr')('modelsystem');
$scope.typeList = $filter('strarr')('modeltype');
var allModels = $config.uri.allModels;
var ts = null;
var start = 0;
var number = 10;
var originalRowCollection = undefined;
$scope.paging = function(tableState){
console.log(tableState);
ts = tableState;
// tableState.pagination.numberOfPages = $scope.rowCollection.length/10 + 1;
start = tableState.pagination.start || 0;
number = tableState.pagination.number || 10;
if(start == 0 && !$scope.rowCollection){
$http.get(allModels).then(function successCallback(data) {
// data.data.sort(function(a,b){
// return -(a.createDate - b.createDate);
// });
data.data.reverse();
originalRowCollection = angular.copy(data.data);
$scope.rowCollection = angular.copy(data.data);
$scope.displayed = $scope.rowCollection.slice(start, start+number);
tableState.pagination.numberOfPages = Math.ceil($scope.rowCollection.length/number);
});
}else{
$scope.displayed = $scope.rowCollection.slice(start, start+number);
}
};
var include = function(keyword, str) {
if(keyword == undefined || keyword == null){
return true;
} else if(str == undefined || str == null){
return false;
} else{
var value = keyword.trim().toLowerCase();
return str.trim().toLowerCase().includes(value);
}
};
var findValue = function(keyword, assetItem) {
var date = $filter('date')(assetItem.createDate, 'M/d/yy h:mm a')
return include(keyword, assetItem.name)
|| include(keyword, assetItem.description)
|| include(keyword, assetItem.owner)
|| include(keyword, $filter('strmap')(assetItem.system, $scope.systemList))
|| include(keyword, $filter('strmap')(assetItem.status, $scope.statusList))
|| include(keyword, $filter('strmap')(assetItem.type, $scope.typeList))
|| include(keyword, date);
};
$scope.$watch('keyword', function(newValue){
if(originalRowCollection){
start = 0;
if(newValue == undefined || newValue == ''){
$scope.rowCollection = angular.copy(originalRowCollection);
}else{
var result = [];
for (var i = 0; i < originalRowCollection.length; i++) {
var item = originalRowCollection[i];
if(findValue(newValue, item)){
result.push(item);
}
};
$scope.rowCollection = angular.copy(result);
}
$scope.displayed = $scope.rowCollection.slice(start, start+number);
ts.pagination.numberOfPages = Math.ceil($scope.rowCollection.length/number);
}
});
$scope.remove = function remove(row) {
var getModelUrl = $config.uri.getModel + '/' +row.id;
$http.get(getModelUrl).then(function successCallback(data){
$scope.deletedRow = data.data;
$scope.sourceTable = $scope.deletedRow.source.config["table.name"];
$scope.targetTable = $scope.deletedRow.target.config["table.name"];
});
// $scope.deletedRow = row;
$scope.deletedBriefRow = row;
$('#deleteConfirmation').modal('show');
}
$scope.confirmDelete = function(){
var row = $scope.deletedBriefRow;
var deleteModelUrl = $config.uri.deleteModel + '/' + row.id;
$http.delete(deleteModelUrl).then(function successCallback(data){
if(data.data.description=="Delete Measures By Name Succeed"){
var index = $scope.rowCollection.indexOf(row);
$scope.rowCollection.splice(index, 1);
index = $scope.displayed.indexOf(row);
$scope.displayed.splice(index, 1);
}
else {
toaster.pop('error', 'Error when deleting measure', data.data.description);
}
$('#deleteConfirmation').modal('hide');
},function errorCallback(response) {
toaster.pop('error', 'Error when deleting measure', response.message);
});
}
$scope.edit = function edit() {
}
$scope.$on('$viewContentLoaded', function() {
$scope.$emit('initReq');
});
/*
function createRowCollection(){
var data = [];
for (var j = 0; j < 22; j++) {
data.push(createRandomItem());
}
return data;
}
function createRandomItem() {
var nameList = ['ViewItem', 'Search', 'BidEvent', 'user_dna', 'LAST_ITEMS_VIEWED'],
systemList = ['Bullseye', 'PDS', 'GPS', 'IDLS', 'Hadoop'],
dateList = ['2016-03-10', '2016-03-12', '2016-03-15', '2016-03-19', '2016-03-20'],
statusList = [0, 1, 2];
var
name = nameList[Math.floor(Math.random() * 5)],
system = Math.floor(Math.random() * 7),
type = Math.floor(Math.random() * 4),
description = 'Only for demo purpose',
createDate = dateList[Math.floor(Math.random() * 5)],
status = Math.floor(Math.random() * 3);
return{
name: name,
system: system,
type: type,
description: description,
createDate: createDate,
status:status
};
}
*/
}]);
});