1
|
var dedupInspectorControllers = angular.module('dedupInspectorControllers', []);
|
2
|
|
3
|
function common_init($scope, $http, $sce, $location) {
|
4
|
initSpinner();
|
5
|
$scope.showError = function(error) { show_notification("error", error); }
|
6
|
$scope.showNotification = function(message) { show_notification("info", message); }
|
7
|
$scope.showSpinner = function() { showSpinner(); }
|
8
|
$scope.hideSpinner = function() { hideSpinner(); }
|
9
|
$scope.to_trusted = function(html) { return $sce.trustAsHtml(html); }
|
10
|
$scope.go = function(path) { document.location.href='#'+path; }
|
11
|
$scope.encodeValue = function(val) { return val; }
|
12
|
|
13
|
|
14
|
$scope.encodeDateParam = function(date) {
|
15
|
var year = date.getFullYear();
|
16
|
var month = ("00" + (date.getMonth() + 1)).slice(-2);
|
17
|
var day = ("00" + date.getDate()).slice(-2);
|
18
|
return year + month + day;
|
19
|
}
|
20
|
|
21
|
$scope.decodeDateParam = function(s) {
|
22
|
var year = s.substring(0,4);
|
23
|
var month = s.substring(4,6);
|
24
|
var day = s.substring(6,8);
|
25
|
|
26
|
return new Date(year,month-1,day);
|
27
|
}
|
28
|
}
|
29
|
|
30
|
dedupInspectorControllers.controller('addSimRelsCtrl', [
|
31
|
'$scope', '$http', '$sce', '$location', '$routeParams',
|
32
|
function ($scope, $http, $sce, $location, $routeParams) {
|
33
|
|
34
|
common_init($scope, $http, $sce, $location);
|
35
|
|
36
|
$scope.validEntityTypes = {
|
37
|
'result' : {id:'50', type:'result', label:'Publication'},
|
38
|
'organization' : {id:'20', type:'organization', label:'Organization'}
|
39
|
};
|
40
|
$scope.group = {
|
41
|
group : [],
|
42
|
entitytype : $scope.validEntityTypes[$routeParams.entitytype]
|
43
|
};
|
44
|
|
45
|
$scope.groupIdDetails = {};
|
46
|
|
47
|
if($routeParams.query && $routeParams.query.length > 0) {
|
48
|
$scope.query = $routeParams.query;
|
49
|
}
|
50
|
if($routeParams.start) {
|
51
|
$scope.start = parseInt($routeParams.start);
|
52
|
} else {
|
53
|
$scope.start = 0;
|
54
|
}
|
55
|
$scope.rows = 20;
|
56
|
|
57
|
$scope.search = function() {
|
58
|
$scope.showSpinner();
|
59
|
var q = '';
|
60
|
if($scope.query.match('^[0-9][0-9]\|.{12}::[a-zA-Z0-9]{32}$')) {
|
61
|
q = 'objidentifier exact "' + $scope.query + '"';
|
62
|
} else {
|
63
|
q = $scope.query;
|
64
|
}
|
65
|
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
|
66
|
$http.post('dedup/search.do', $.param({
|
67
|
'entitytype' : $scope.group.entitytype.type,
|
68
|
'query' : q,
|
69
|
'start' : $scope.start,
|
70
|
'rows' : $scope.rows
|
71
|
})).success(function(res) {
|
72
|
if(res) {
|
73
|
$scope.results = res;
|
74
|
$scope.hideSpinner();
|
75
|
} else {
|
76
|
$scope.hideSpinner();
|
77
|
$scope.showError('Registration failed');
|
78
|
}
|
79
|
}).error(function(err) {
|
80
|
$scope.hideSpinner();
|
81
|
$scope.showError('Registration failed: ' + err.message);
|
82
|
});
|
83
|
}
|
84
|
|
85
|
if($scope.query) {
|
86
|
$scope.search();
|
87
|
}
|
88
|
|
89
|
$scope.resetForm = function() {
|
90
|
if (confirm('Reset group?')) {
|
91
|
$scope.group.group = [];
|
92
|
$scope.groupIdDetails = {};
|
93
|
}
|
94
|
}
|
95
|
|
96
|
$scope.registerSimilarities = function() {
|
97
|
if (confirm('Add new similarity group?')) {
|
98
|
$scope.showSpinner();
|
99
|
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
|
100
|
$http.post('dedup/addSimRels.do', $.param($scope.group)).success(function(res) {
|
101
|
if(res) {
|
102
|
$scope.showNotification('The Similarities has been registered');
|
103
|
$scope.hideSpinner();
|
104
|
$scope.resetForm();
|
105
|
} else {
|
106
|
$scope.hideSpinner();
|
107
|
$scope.showError('Registration failed');
|
108
|
}
|
109
|
}).error(function(err) {
|
110
|
$scope.hideSpinner();
|
111
|
$scope.showError('Registration failed: ' + err.message);
|
112
|
});
|
113
|
}
|
114
|
}
|
115
|
|
116
|
$scope.updateSimilarities = function() {
|
117
|
if (confirm('Update similarity group?')) {
|
118
|
$scope.showSpinner();
|
119
|
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
|
120
|
$http.post('dedup/updateSimRels.do', $.param({
|
121
|
'groupid' : $scope.group.id,
|
122
|
'entityType' : $scope.group.entitytype.id,
|
123
|
'idsCsv' : $scope.group.group.join()
|
124
|
})).success(function(res) {
|
125
|
if(res) {
|
126
|
$scope.showNotification('The Similarities has been updated');
|
127
|
$scope.hideSpinner();
|
128
|
$scope.resetForm();
|
129
|
$scope.go('/edit/' + $scope.groupid);
|
130
|
} else {
|
131
|
$scope.hideSpinner();
|
132
|
$scope.showError('Registration failed');
|
133
|
}
|
134
|
}).error(function(err) {
|
135
|
$scope.hideSpinner();
|
136
|
$scope.showError('Registration failed: ' + err.message);
|
137
|
});
|
138
|
}
|
139
|
}
|
140
|
|
141
|
|
142
|
|
143
|
$scope.searchById = function(objidentifier, entitytype) {
|
144
|
if(!$scope.groupIdDetails[objidentifier]) {
|
145
|
$http.post('dedup/searchById.do', $.param({
|
146
|
'entitytype' : entitytype,
|
147
|
'objidentifier' : objidentifier
|
148
|
})).success(function(res) {
|
149
|
if(res) {
|
150
|
$scope.groupIdDetails[objidentifier] = res;
|
151
|
$scope.hideSpinner();
|
152
|
} else {
|
153
|
$scope.hideSpinner();
|
154
|
$scope.showError('Registration failed');
|
155
|
}
|
156
|
}).error(function(err) {
|
157
|
$scope.hideSpinner();
|
158
|
$scope.showError('Registration failed: ' + err.message);
|
159
|
});
|
160
|
}
|
161
|
}
|
162
|
|
163
|
$scope.add = function(idCsv) {
|
164
|
var size = $scope.group.group.length;
|
165
|
angular.forEach(idCsv.split(","), function(id) {
|
166
|
if(jQuery.grep($scope.group.group, function(val, i) {
|
167
|
return val == id;
|
168
|
}).length == 0) {
|
169
|
$scope.group.group.push(id);
|
170
|
} else {
|
171
|
$scope.showError('id already selected');
|
172
|
};
|
173
|
});
|
174
|
var newSize = $scope.group.group.length - size;
|
175
|
if (newSize > 0) {
|
176
|
$scope.showNotification('added ' + newSize + ' element(s)');
|
177
|
}
|
178
|
}
|
179
|
|
180
|
$scope.remove = function(idCsv) {
|
181
|
var tmpGroup = [];
|
182
|
var toRemove = idCsv.split(",");
|
183
|
var size = $scope.group.group.length;
|
184
|
angular.forEach($scope.group.group, function(id) {
|
185
|
if(jQuery.grep(toRemove, function(val, i) {
|
186
|
return val == id;
|
187
|
}).length == 0) {
|
188
|
tmpGroup.push(id);
|
189
|
};
|
190
|
});
|
191
|
$scope.group.group = tmpGroup;
|
192
|
var newSize = size - tmpGroup.length;
|
193
|
if (newSize > 0) {
|
194
|
$scope.showNotification('removed ' + newSize + ' element(s)');
|
195
|
}
|
196
|
}
|
197
|
|
198
|
$scope.isSelected = function(idCsv) {
|
199
|
var res = true;
|
200
|
angular.forEach(idCsv.split(","), function(id) {
|
201
|
if(jQuery.grep($scope.group.group, function(val, i) {
|
202
|
return val == id;
|
203
|
}).length == 0) {
|
204
|
res = false;
|
205
|
return;
|
206
|
};
|
207
|
});
|
208
|
return res;
|
209
|
}
|
210
|
|
211
|
}
|
212
|
]);
|
213
|
|
214
|
dedupInspectorControllers.controller('manageSimRelsCtrl', [
|
215
|
'$scope', '$http', '$sce', '$location', '$routeParams',
|
216
|
function ($scope, $http, $sce, $location, $routeParams) {
|
217
|
|
218
|
common_init($scope, $http, $sce, $location);
|
219
|
|
220
|
$scope.validEntityTypes = [ {id:'result' , name: 'Publications'}, {id:'organization' , name: 'Organizations'}, {id:'all', name:'All'} ];
|
221
|
|
222
|
$scope.groups = [];
|
223
|
|
224
|
if($routeParams.type) {
|
225
|
$scope.type = $routeParams.type;
|
226
|
} else {
|
227
|
$scope.type = 'all';
|
228
|
}
|
229
|
if($routeParams.offset) {
|
230
|
$scope.offset = parseInt($routeParams.offset);
|
231
|
} else {
|
232
|
$scope.offset = 0;
|
233
|
}
|
234
|
if($routeParams.limit) {
|
235
|
$scope.limit = parseInt($routeParams.limit);
|
236
|
} else {
|
237
|
$scope.limit = 0;
|
238
|
}
|
239
|
|
240
|
$scope.refresh = function() {
|
241
|
$scope.showSpinner();
|
242
|
$http.get('dedup/listSimRels.do?entitytype=' + $scope.type + '&offset=' + $scope.offset + '&limit=' + $scope.limit).success(
|
243
|
function(res) {
|
244
|
$scope.groups = res;
|
245
|
$scope.hideSpinner();
|
246
|
}).error(function(err) {
|
247
|
$scope.hideSpinner();
|
248
|
$scope.showError('Unable to list groups');
|
249
|
});
|
250
|
}
|
251
|
$scope.showgroup = function(g) {
|
252
|
$scope.go('/edit/' + g.id);
|
253
|
}
|
254
|
$scope.refresh();
|
255
|
}
|
256
|
]);
|
257
|
|
258
|
dedupInspectorControllers.controller('editSimRelsCtrl', [
|
259
|
'$scope', '$http', '$sce', '$location', '$routeParams',
|
260
|
function ($scope, $http, $sce, $location, $routeParams) {
|
261
|
|
262
|
common_init($scope, $http, $sce, $location);
|
263
|
|
264
|
$scope.group = {};
|
265
|
|
266
|
$scope.refresh = function() {
|
267
|
$scope.showSpinner();
|
268
|
$http.get('dedup/getExtGroup.do?groupid=' + $routeParams.groupid).success(
|
269
|
function(res) {
|
270
|
$scope.group = res;
|
271
|
$scope.hideSpinner();
|
272
|
}).error(function(err) {
|
273
|
$scope.hideSpinner();
|
274
|
$scope.showError('Unable to get group');
|
275
|
});
|
276
|
}
|
277
|
$scope.editSimilarity = function(g) {
|
278
|
$scope.go('/add/' + g.id);
|
279
|
}
|
280
|
|
281
|
$scope.refresh();
|
282
|
}
|
283
|
]);
|
284
|
|
285
|
|