1
|
var orgsModule = angular.module('orgs', ['ngRoute', 'checklist-model']);
|
2
|
|
3
|
|
4
|
orgsModule.service('orgInfoService', function($http) {
|
5
|
this.info = {};
|
6
|
this.count = 0;
|
7
|
this.getInfo = function(id, f) {
|
8
|
|
9
|
if (id) {
|
10
|
if (this.info.id == id) {
|
11
|
f(this.info);
|
12
|
} else {
|
13
|
$http.get('api/organizations/info?id=' + id).then(function successCallback(res) {
|
14
|
this.info = res.data;
|
15
|
f(angular.copy(this.info));
|
16
|
}, function errorCallback(res) {
|
17
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
18
|
});
|
19
|
}
|
20
|
} else {
|
21
|
f({});
|
22
|
}
|
23
|
};
|
24
|
});
|
25
|
|
26
|
orgsModule.directive('organizationInfo', function() {
|
27
|
return {
|
28
|
restrict: 'E',
|
29
|
scope: {
|
30
|
info : '='
|
31
|
},
|
32
|
templateUrl: 'resources/html/part/org_info.html'
|
33
|
}
|
34
|
});
|
35
|
|
36
|
|
37
|
orgsModule.directive('orgTabsMenu', function($http, orgInfoService) {
|
38
|
return {
|
39
|
restrict: 'E',
|
40
|
scope: {
|
41
|
'info' : '=',
|
42
|
'selected': '@',
|
43
|
'orgId' : '@'
|
44
|
|
45
|
},
|
46
|
templateUrl: 'resources/html/part/org_tabs_menu.html'
|
47
|
}
|
48
|
});
|
49
|
|
50
|
|
51
|
orgsModule.config(function($routeProvider) {
|
52
|
$routeProvider
|
53
|
.when('/new', { templateUrl: 'resources/html/edit.html', controller: 'newOrgCtrl' })
|
54
|
.when('/search', { templateUrl: 'resources/html/search.html', controller: 'searchCtrl' })
|
55
|
.when('/searchResults/:page/:size/:text*', { templateUrl: 'resources/html/list.html', controller: 'searchResultsCtrl' })
|
56
|
.when('/countries', { templateUrl: 'resources/html/browse.html', controller: 'countriesCtrl' })
|
57
|
.when('/byCountry/:page/:size/:code*', { templateUrl: 'resources/html/list.html', controller: 'byCountryCtrl' })
|
58
|
.when('/types', { templateUrl: 'resources/html/browse.html', controller: 'typesCtrl' })
|
59
|
.when('/byType/:page/:size/:type*', { templateUrl: 'resources/html/list.html', controller: 'byTypeCtrl' })
|
60
|
.when('/metadata/:msg/:id', { templateUrl: 'resources/html/edit.html', controller: 'showMetadataCtrl' })
|
61
|
.when('/relations/:id', { templateUrl: 'resources/html/relations.html', controller: 'showRelationsCtrl' })
|
62
|
.when('/enrichments/:id', { templateUrl: 'resources/html/enrichments.html', controller: 'showEnrichmentsCtrl' })
|
63
|
.when('/conflicts/:id', { templateUrl: 'resources/html/conflicts.html', controller: 'showConflictsCtrl' })
|
64
|
.when('/allConflicts', { templateUrl: 'resources/html/allConflicts.html', controller: 'showAllConflictsCtrl' })
|
65
|
.when('/users', { templateUrl: 'resources/html/users.html', controller: 'usersCtrl' })
|
66
|
.otherwise({ redirectTo: '/search' });
|
67
|
});
|
68
|
|
69
|
orgsModule.filter('escape', function() {
|
70
|
return function(input) {
|
71
|
return encodeURIComponent(encodeURIComponent(input));
|
72
|
};
|
73
|
});
|
74
|
|
75
|
orgsModule.filter('unescape', function() {
|
76
|
return function(input) {
|
77
|
return decodeURIComponent(input);
|
78
|
};
|
79
|
});
|
80
|
|
81
|
orgsModule.controller('newOrgCtrl', function ($scope, $http, $routeParams, $location) {
|
82
|
$scope.org = {
|
83
|
"id": "",
|
84
|
"name": "",
|
85
|
"type": null,
|
86
|
"lat": 0.0,
|
87
|
"lng": 0.0,
|
88
|
"city": "",
|
89
|
"country": "",
|
90
|
"source": "user",
|
91
|
"otherIdentifiers": [],
|
92
|
"otherNames": [],
|
93
|
"relations": [],
|
94
|
"acronyms": [],
|
95
|
"urls": []
|
96
|
};
|
97
|
$scope.vocabularies = {};
|
98
|
|
99
|
$http.get('api/vocabularies').then(function successCallback(res) {
|
100
|
$scope.vocabularies = res.data;
|
101
|
}, function errorCallback(res) {
|
102
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
103
|
});
|
104
|
|
105
|
$scope.save = function() {
|
106
|
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
|
107
|
$http.post('api/organizations/save', $scope.org).then(function successCallback(res) {
|
108
|
// alert('Organization saved !!!');
|
109
|
$location.url('/metadata/1/' + res.data[0]);
|
110
|
}, function errorCallback(res) {
|
111
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
112
|
});
|
113
|
}
|
114
|
|
115
|
});
|
116
|
|
117
|
orgsModule.controller('searchCtrl', function ($scope, $location) {
|
118
|
$scope.textSearch = '';
|
119
|
$scope.search = function() {
|
120
|
$location.url('/searchResults/0/50/' + encodeURIComponent(encodeURIComponent($scope.textSearch)));
|
121
|
}
|
122
|
});
|
123
|
|
124
|
orgsModule.controller('searchResultsCtrl', function ($scope, $http, $routeParams) {
|
125
|
$scope.basepath = '/searchResults';
|
126
|
$scope.fieldValue = decodeURIComponent($routeParams.text);
|
127
|
|
128
|
$scope.orgs = {};
|
129
|
|
130
|
$http.get('api/organizations/search/' + $routeParams.page + '/' + $routeParams.size + '?q=' + $scope.fieldValue).then(function successCallback(res) {
|
131
|
$scope.orgs = res.data;
|
132
|
}, function errorCallback(res) {
|
133
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
134
|
});
|
135
|
});
|
136
|
|
137
|
orgsModule.controller('countriesCtrl', function ($scope, $http, $routeParams) {
|
138
|
$scope.field = 'Country';
|
139
|
$scope.resultsBasePath = '/byCountry'
|
140
|
$scope.entries = [];
|
141
|
|
142
|
$http.get('api/organizations/browse/countries').then(function successCallback(res) {
|
143
|
$scope.entries = res.data;
|
144
|
}, function errorCallback(res) {
|
145
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
146
|
});
|
147
|
|
148
|
});
|
149
|
|
150
|
orgsModule.controller('byCountryCtrl', function ($scope, $http, $routeParams) {
|
151
|
$scope.basepath = '/byCountry';
|
152
|
$scope.fieldValue = $routeParams.code;
|
153
|
|
154
|
$scope.orgs = [];
|
155
|
|
156
|
$http.get('api/organizations/byCountry/' + $routeParams.code + '/' + $routeParams.page + '/' + $routeParams.size).then(function successCallback(res) {
|
157
|
$scope.orgs = res.data;
|
158
|
}, function errorCallback(res) {
|
159
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
160
|
});
|
161
|
});
|
162
|
|
163
|
orgsModule.controller('typesCtrl', function ($scope, $http, $routeParams) {
|
164
|
$scope.field = 'Organization type';
|
165
|
$scope.resultsBasePath = '/byType'
|
166
|
$scope.entries = [];
|
167
|
|
168
|
$http.get('api/organizations/browse/types').then(function successCallback(res) {
|
169
|
$scope.entries = res.data;
|
170
|
}, function errorCallback(res) {
|
171
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
172
|
});
|
173
|
|
174
|
});
|
175
|
|
176
|
orgsModule.controller('byTypeCtrl', function ($scope, $http, $routeParams) {
|
177
|
$scope.basepath = '/byType';
|
178
|
$scope.fieldValue = $routeParams.type;
|
179
|
|
180
|
$scope.orgs = [];
|
181
|
|
182
|
$http.get('api/organizations/byType/' + $routeParams.type + '/' + $routeParams.page + '/' + $routeParams.size).then(function successCallback(res) {
|
183
|
$scope.orgs = res.data;
|
184
|
}, function errorCallback(res) {
|
185
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
186
|
});
|
187
|
});
|
188
|
|
189
|
|
190
|
orgsModule.controller('showMetadataCtrl', function ($scope, $http, $routeParams, $route, $location, $timeout, orgInfoService) {
|
191
|
$scope.orgId = $routeParams.id;
|
192
|
$scope.org = {};
|
193
|
$scope.vocabularies = {};
|
194
|
$scope.info = {};
|
195
|
|
196
|
orgInfoService.getInfo($scope.orgId, function(info) { $scope.info = info; });
|
197
|
|
198
|
if ($routeParams.msg == 1) {
|
199
|
$scope.message = 'New organization registered !!!';
|
200
|
} else if ($routeParams.msg == 2) {
|
201
|
$scope.message = 'Organization updated !!!';
|
202
|
} else {
|
203
|
$scope.message = '';
|
204
|
}
|
205
|
|
206
|
$timeout(function() { $scope.message = ''; }, 3000)
|
207
|
|
208
|
$http.get('api/vocabularies').then(function successCallback(res) {
|
209
|
$scope.vocabularies = res.data;
|
210
|
|
211
|
$http.get('api/organizations/get?id=' + $routeParams.id).then(function successCallback(res) {
|
212
|
$scope.org = res.data;
|
213
|
}, function errorCallback(res) {
|
214
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
215
|
});
|
216
|
}, function errorCallback(res) {
|
217
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
218
|
});
|
219
|
|
220
|
$scope.save = function() {
|
221
|
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
|
222
|
$http.post('api/organizations/save', $scope.org).then(function successCallback(res) {
|
223
|
if ($routeParams.msg == 2) { $route.reload(); }
|
224
|
else { $location.url('/metadata/2/' + res.data[0]); }
|
225
|
}, function errorCallback(res) {
|
226
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
227
|
});
|
228
|
}
|
229
|
|
230
|
});
|
231
|
|
232
|
|
233
|
orgsModule.controller('showRelationsCtrl', function ($scope, $http, $routeParams, orgInfoService) {
|
234
|
$scope.orgId = $routeParams.id;
|
235
|
$scope.rels = [];
|
236
|
$scope.vocabularies = {};
|
237
|
|
238
|
$scope.searchValue = '';
|
239
|
$scope.searchOrgs = [];
|
240
|
$scope.newRelType='';
|
241
|
$scope.newRelation = {};
|
242
|
$scope.info = {};
|
243
|
|
244
|
orgInfoService.getInfo($scope.orgId, function(info) { $scope.info = info; });
|
245
|
|
246
|
$http.get('api/vocabularies').then(function successCallback(res) {
|
247
|
$scope.vocabularies = res.data;
|
248
|
|
249
|
$http.get('api/organizations/relations?id=' + $routeParams.id).then(function successCallback(res) {
|
250
|
$scope.rels = res.data;
|
251
|
}, function errorCallback(res) {
|
252
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
253
|
});
|
254
|
}, function errorCallback(res) {
|
255
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
256
|
});
|
257
|
|
258
|
$scope.prepareNewRelation = function(o) {
|
259
|
$scope.newRelation = o;
|
260
|
}
|
261
|
|
262
|
$scope.addRelation = function() {
|
263
|
$http.put('api/organizations/relations', null, {
|
264
|
'params': { 'from': $scope.orgId, 'to': $scope.newRelation.id, 'type': $scope.newRelType }
|
265
|
}).then(function successCallback(res) {
|
266
|
$scope.rels = res.data;
|
267
|
$scope.newRelType = '';
|
268
|
$scope.newRelation = {};
|
269
|
// alert("Relation added !!!")
|
270
|
}, function errorCallback(res) {
|
271
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
272
|
});
|
273
|
}
|
274
|
|
275
|
$scope.deleteRelation = function(to, type) {
|
276
|
$http.delete('api/organizations/relations', {
|
277
|
'params': { 'from': $scope.orgId, 'to': to, 'type': type }
|
278
|
}).then(function successCallback(res) {
|
279
|
$scope.rels = res.data;
|
280
|
// alert("Relation deleted !!!")
|
281
|
}, function errorCallback(res) {
|
282
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
283
|
});
|
284
|
}
|
285
|
|
286
|
$scope.search = function(text, page, size) {
|
287
|
$scope.orgs = [];
|
288
|
$http.get('api/organizations/search/' + page + '/' + size + '?q=' + text).then(function successCallback(res) {
|
289
|
$scope.searchValue = text;
|
290
|
$scope.searchOrgs = res.data;
|
291
|
}, function errorCallback(res) {
|
292
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
293
|
});
|
294
|
}
|
295
|
|
296
|
});
|
297
|
|
298
|
orgsModule.controller('showEnrichmentsCtrl', function ($scope, $http, $routeParams, orgInfoService) {
|
299
|
$scope.orgId = $routeParams.id;
|
300
|
$scope.enrichments = [];
|
301
|
$scope.vocabularies = {};
|
302
|
$scope.info = {};
|
303
|
|
304
|
orgInfoService.getInfo($scope.orgId, function(info) { $scope.info = info; });
|
305
|
|
306
|
$http.get('api/vocabularies').then(function successCallback(res) {
|
307
|
$scope.vocabularies = res.data;
|
308
|
|
309
|
$http.get('api/organizations/enrichments?id=' + $routeParams.id).then(function successCallback(res) {
|
310
|
$scope.enrichments = res.data;
|
311
|
}, function errorCallback(res) {
|
312
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
313
|
});
|
314
|
}, function errorCallback(res) {
|
315
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
316
|
});
|
317
|
|
318
|
|
319
|
$scope.saveEnrichments = function() {
|
320
|
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
|
321
|
$http.post('api/organizations/enrichments', $scope.enrichments).then(function successCallback(res) {
|
322
|
alert('Enrichments updated !!!');
|
323
|
$scope.enrichments = res.data;
|
324
|
}, function errorCallback(res) {
|
325
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
326
|
});
|
327
|
}
|
328
|
});
|
329
|
|
330
|
orgsModule.controller('showConflictsCtrl', function ($scope, $http, $routeParams, orgInfoService) {
|
331
|
$scope.orgId = $routeParams.id;
|
332
|
$scope.conflicts = [];
|
333
|
$scope.vocabularies = {};
|
334
|
$scope.info = {};
|
335
|
|
336
|
orgInfoService.getInfo($scope.orgId, function(info) { $scope.info = info; });
|
337
|
|
338
|
$http.get('api/vocabularies').then(function successCallback(res) {
|
339
|
$scope.vocabularies = res.data;
|
340
|
|
341
|
$http.get('api/organizations/conflicts?id=' + $routeParams.id).then(function successCallback(res) {
|
342
|
$scope.conflicts = res.data;
|
343
|
}, function errorCallback(res) {
|
344
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
345
|
});
|
346
|
}, function errorCallback(res) {
|
347
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
348
|
});
|
349
|
});
|
350
|
|
351
|
orgsModule.controller('showAllConflictsCtrl', function ($scope, $http) {
|
352
|
$scope.conflicts = [];
|
353
|
$http.get('api/organizations/conflicts/all').then(function successCallback(res) {
|
354
|
$scope.conflicts = res.data;
|
355
|
}, function errorCallback(res) {
|
356
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
357
|
});
|
358
|
});
|
359
|
|
360
|
orgsModule.controller('usersCtrl', function ($scope, $http, $timeout, $route) {
|
361
|
$scope.users = [];
|
362
|
$scope.vocs = {};
|
363
|
$scope.currentUser = {};
|
364
|
$scope.superAdminMode = superAdminMode();
|
365
|
|
366
|
$http.get('api/vocabularies').then(function successCallback(res) {
|
367
|
$scope.vocs = res.data;
|
368
|
|
369
|
$http.get('api/users').then(function successCallback(res) {
|
370
|
$scope.users = res.data;
|
371
|
}, function errorCallback(res) {
|
372
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
373
|
});
|
374
|
}, function errorCallback(res) {
|
375
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
376
|
});
|
377
|
|
378
|
$scope.setCurrentUser = function(user) {
|
379
|
angular.copy(user, $scope.currentUser);
|
380
|
$scope.currentUser.role = 'USER';
|
381
|
}
|
382
|
|
383
|
$scope.saveUser = function(user) {
|
384
|
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
|
385
|
$http.post('api/users', user).then(function successCallback(res) {
|
386
|
$scope.users = res.data;
|
387
|
}, function errorCallback(res) {
|
388
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
389
|
});
|
390
|
}
|
391
|
|
392
|
$scope.deleteUser = function(email) {
|
393
|
if (confirm("Are you sure ?")) {
|
394
|
$http.delete('api/users?email=' + email).then(function successCallback(res) {
|
395
|
$scope.users = res.data;
|
396
|
}, function errorCallback(res) {
|
397
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
398
|
});
|
399
|
}
|
400
|
}
|
401
|
});
|