1
|
var orgsModule = angular.module('orgs', ['ngRoute', 'checklist-model']);
|
2
|
|
3
|
orgsModule.config(function($routeProvider) {
|
4
|
$routeProvider
|
5
|
.when('/new', { templateUrl: 'resources/html/edit.html', controller: 'newOrgCtrl' })
|
6
|
.when('/search', { templateUrl: 'resources/html/search.html', controller: 'searchCtrl' })
|
7
|
.when('/searchResults/:page/:size/:text*', { templateUrl: 'resources/html/list.html', controller: 'searchResultsCtrl' })
|
8
|
.when('/countries', { templateUrl: 'resources/html/browse.html', controller: 'countriesCtrl' })
|
9
|
.when('/byCountry/:page/:size/:code*', { templateUrl: 'resources/html/list.html', controller: 'byCountryCtrl' })
|
10
|
.when('/types', { templateUrl: 'resources/html/browse.html', controller: 'typesCtrl' })
|
11
|
.when('/byType/:page/:size/:type*', { templateUrl: 'resources/html/list.html', controller: 'byTypeCtrl' })
|
12
|
.when('/metadata/:msg/:id', { templateUrl: 'resources/html/edit.html', controller: 'showMetadataCtrl' })
|
13
|
.when('/relations/:id', { templateUrl: 'resources/html/relations.html', controller: 'showRelationsCtrl' })
|
14
|
.when('/similarities/:id', { templateUrl: 'resources/html/similarities.html', controller: 'showSimilaritiesCtrl' })
|
15
|
.when('/warnings', { templateUrl: 'resources/html/warnings.html', controller: 'showWarningsCtrl' })
|
16
|
.when('/users', { templateUrl: 'resources/html/users.html', controller: 'usersCtrl' })
|
17
|
.otherwise({ redirectTo: '/search' });
|
18
|
});
|
19
|
|
20
|
orgsModule.filter('escape', function() {
|
21
|
return function(input) {
|
22
|
return encodeURIComponent(encodeURIComponent(input));
|
23
|
};
|
24
|
});
|
25
|
|
26
|
orgsModule.filter('unescape', function() {
|
27
|
return function(input) {
|
28
|
return decodeURIComponent(input);
|
29
|
};
|
30
|
});
|
31
|
|
32
|
orgsModule.controller('newOrgCtrl', function ($scope, $http, $routeParams, $location) {
|
33
|
$scope.org = {
|
34
|
"id": "",
|
35
|
"name": "",
|
36
|
"type": null,
|
37
|
"lat": 0.0,
|
38
|
"lng": 0.0,
|
39
|
"city": "",
|
40
|
"country": "",
|
41
|
"source": "user",
|
42
|
"otherIdentifiers": [],
|
43
|
"otherNames": [],
|
44
|
"relations": [],
|
45
|
"acronyms": [],
|
46
|
"urls": []
|
47
|
};
|
48
|
$scope.vocabularies = {};
|
49
|
|
50
|
$http.get('api/vocabularies').then(function successCallback(res) {
|
51
|
$scope.vocabularies = res.data;
|
52
|
}, function errorCallback(res) {
|
53
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
54
|
});
|
55
|
|
56
|
$scope.save = function() {
|
57
|
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
|
58
|
$http.post('api/organizations/save', $scope.org).then(function successCallback(res) {
|
59
|
// alert('Organization saved !!!');
|
60
|
$location.url('/metadata/1/' + res.data[0]);
|
61
|
}, function errorCallback(res) {
|
62
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
63
|
});
|
64
|
}
|
65
|
|
66
|
});
|
67
|
|
68
|
orgsModule.controller('searchCtrl', function ($scope, $http, $routeParams) {
|
69
|
$scope.textSearch = '';
|
70
|
});
|
71
|
|
72
|
|
73
|
orgsModule.controller('searchResultsCtrl', function ($scope, $http, $routeParams) {
|
74
|
$scope.basepath = '/searchResults';
|
75
|
$scope.fieldValue = decodeURIComponent($routeParams.text);
|
76
|
|
77
|
$scope.orgs = {};
|
78
|
|
79
|
$http.get('api/organizations/search/' + $routeParams.page + '/' + $routeParams.size + '?q=' + $scope.fieldValue).then(function successCallback(res) {
|
80
|
$scope.orgs = res.data;
|
81
|
}, function errorCallback(res) {
|
82
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
83
|
});
|
84
|
});
|
85
|
|
86
|
orgsModule.controller('countriesCtrl', function ($scope, $http, $routeParams) {
|
87
|
$scope.field = 'Country';
|
88
|
$scope.resultsBasePath = '/byCountry'
|
89
|
$scope.entries = [];
|
90
|
|
91
|
$http.get('api/organizations/browse/countries').then(function successCallback(res) {
|
92
|
$scope.entries = res.data;
|
93
|
}, function errorCallback(res) {
|
94
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
95
|
});
|
96
|
|
97
|
});
|
98
|
|
99
|
orgsModule.controller('byCountryCtrl', function ($scope, $http, $routeParams) {
|
100
|
$scope.basepath = '/byCountry';
|
101
|
$scope.fieldValue = $routeParams.code;
|
102
|
|
103
|
$scope.orgs = [];
|
104
|
|
105
|
$http.get('api/organizations/byCountry/' + $routeParams.code + '/' + $routeParams.page + '/' + $routeParams.size).then(function successCallback(res) {
|
106
|
$scope.orgs = res.data;
|
107
|
}, function errorCallback(res) {
|
108
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
109
|
});
|
110
|
});
|
111
|
|
112
|
orgsModule.controller('typesCtrl', function ($scope, $http, $routeParams) {
|
113
|
$scope.field = 'Organization type';
|
114
|
$scope.resultsBasePath = '/byType'
|
115
|
$scope.entries = [];
|
116
|
|
117
|
$http.get('api/organizations/browse/types').then(function successCallback(res) {
|
118
|
$scope.entries = res.data;
|
119
|
}, function errorCallback(res) {
|
120
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
121
|
});
|
122
|
|
123
|
});
|
124
|
|
125
|
orgsModule.controller('byTypeCtrl', function ($scope, $http, $routeParams) {
|
126
|
$scope.basepath = '/byType';
|
127
|
$scope.fieldValue = $routeParams.type;
|
128
|
|
129
|
$scope.orgs = [];
|
130
|
|
131
|
$http.get('api/organizations/byType/' + $routeParams.type + '/' + $routeParams.page + '/' + $routeParams.size).then(function successCallback(res) {
|
132
|
$scope.orgs = res.data;
|
133
|
}, function errorCallback(res) {
|
134
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
135
|
});
|
136
|
});
|
137
|
|
138
|
|
139
|
orgsModule.controller('showMetadataCtrl', function ($scope, $http, $routeParams, $route, $location, $timeout) {
|
140
|
$scope.orgId = $routeParams.id;
|
141
|
$scope.org = {};
|
142
|
$scope.vocabularies = {};
|
143
|
|
144
|
if ($routeParams.msg == 1) {
|
145
|
$scope.message = 'New organization registered !!!';
|
146
|
} else if ($routeParams.msg == 2) {
|
147
|
$scope.message = 'Organization updated !!!';
|
148
|
} else {
|
149
|
$scope.message = '';
|
150
|
}
|
151
|
|
152
|
$timeout(function() { $scope.message = ''; }, 3000)
|
153
|
|
154
|
$http.get('api/vocabularies').then(function successCallback(res) {
|
155
|
$scope.vocabularies = res.data;
|
156
|
|
157
|
$http.get('api/organizations/get?id=' + $routeParams.id).then(function successCallback(res) {
|
158
|
$scope.org = res.data;
|
159
|
}, function errorCallback(res) {
|
160
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
161
|
});
|
162
|
}, function errorCallback(res) {
|
163
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
164
|
});
|
165
|
|
166
|
$scope.save = function() {
|
167
|
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
|
168
|
$http.post('api/organizations/save', $scope.org).then(function successCallback(res) {
|
169
|
if ($routeParams.msg == 2) { $route.reload(); }
|
170
|
else { $location.url('/metadata/2/' + res.data[0]); }
|
171
|
}, function errorCallback(res) {
|
172
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
173
|
});
|
174
|
}
|
175
|
|
176
|
});
|
177
|
|
178
|
|
179
|
orgsModule.controller('showRelationsCtrl', function ($scope, $http, $routeParams) {
|
180
|
$scope.orgId = $routeParams.id;
|
181
|
$scope.rels = [];
|
182
|
$scope.vocabularies = {};
|
183
|
|
184
|
$scope.searchValue = '';
|
185
|
$scope.searchOrgs = [];
|
186
|
$scope.newRelType='';
|
187
|
$scope.newRelation = {};
|
188
|
|
189
|
$http.get('api/vocabularies').then(function successCallback(res) {
|
190
|
$scope.vocabularies = res.data;
|
191
|
|
192
|
$http.get('api/organizations/relations?id=' + $routeParams.id).then(function successCallback(res) {
|
193
|
$scope.rels = res.data;
|
194
|
}, function errorCallback(res) {
|
195
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
196
|
});
|
197
|
}, function errorCallback(res) {
|
198
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
199
|
});
|
200
|
|
201
|
$scope.prepareNewRelation = function(o) {
|
202
|
$scope.newRelation = o;
|
203
|
}
|
204
|
|
205
|
$scope.addRelation = function() {
|
206
|
$http.put('api/organizations/relations', null, {
|
207
|
'params': { 'from': $scope.orgId, 'to': $scope.newRelation.id, 'type': $scope.newRelType }
|
208
|
}).then(function successCallback(res) {
|
209
|
$scope.rels = res.data;
|
210
|
$scope.newRelType = '';
|
211
|
$scope.newRelation = {};
|
212
|
// alert("Relation added !!!")
|
213
|
}, function errorCallback(res) {
|
214
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
215
|
});
|
216
|
}
|
217
|
|
218
|
$scope.deleteRelation = function(to, type) {
|
219
|
$http.delete('api/organizations/relations', {
|
220
|
'params': { 'from': $scope.orgId, 'to': to, 'type': type }
|
221
|
}).then(function successCallback(res) {
|
222
|
$scope.rels = res.data;
|
223
|
// alert("Relation deleted !!!")
|
224
|
}, function errorCallback(res) {
|
225
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
226
|
});
|
227
|
}
|
228
|
|
229
|
$scope.search = function(text, page, size) {
|
230
|
$scope.orgs = [];
|
231
|
$http.get('api/organizations/search/' + page + '/' + size + '?q=' + text).then(function successCallback(res) {
|
232
|
$scope.searchValue = text;
|
233
|
$scope.searchOrgs = res.data;
|
234
|
}, function errorCallback(res) {
|
235
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
236
|
});
|
237
|
}
|
238
|
|
239
|
});
|
240
|
|
241
|
orgsModule.controller('showSimilaritiesCtrl', function ($scope, $http, $routeParams) {
|
242
|
$scope.orgId = $routeParams.id;
|
243
|
$scope.similarities = [];
|
244
|
$scope.vocabularies = {};
|
245
|
|
246
|
$http.get('api/vocabularies').then(function successCallback(res) {
|
247
|
$scope.vocabularies = res.data;
|
248
|
|
249
|
$http.get('api/organizations/similarities?id=' + $routeParams.id).then(function successCallback(res) {
|
250
|
$scope.similarities = 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
|
|
259
|
$scope.saveSimilarities = function() {
|
260
|
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
|
261
|
$http.post('api/organizations/similarities', $scope.similarities).then(function successCallback(res) {
|
262
|
alert('Similarities updated !!!');
|
263
|
$scope.similarities = res.data;
|
264
|
}, function errorCallback(res) {
|
265
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
266
|
});
|
267
|
}
|
268
|
});
|
269
|
|
270
|
|
271
|
orgsModule.controller('showWarningsCtrl', function ($scope, $http, $routeParams) {
|
272
|
$scope.orgId = $routeParams.id;
|
273
|
$scope.warnings = [];
|
274
|
|
275
|
$http.get('api/organizations/warnings?id=' + $routeParams.id).then(function successCallback(res) {
|
276
|
$scope.warnings = res.data;
|
277
|
}, function errorCallback(res) {
|
278
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
279
|
});
|
280
|
|
281
|
});
|
282
|
|
283
|
|
284
|
orgsModule.controller('usersCtrl', function ($scope, $http, $timeout, $route) {
|
285
|
$scope.users = [];
|
286
|
$scope.vocs = {};
|
287
|
$scope.currentUser = {};
|
288
|
|
289
|
$http.get('api/vocabularies').then(function successCallback(res) {
|
290
|
$scope.vocs = res.data;
|
291
|
|
292
|
$http.get('api/users').then(function successCallback(res) {
|
293
|
$scope.users = res.data;
|
294
|
}, function errorCallback(res) {
|
295
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
296
|
});
|
297
|
}, function errorCallback(res) {
|
298
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
299
|
});
|
300
|
|
301
|
$scope.setCurrentUser = function(user) {
|
302
|
angular.copy(user, $scope.currentUser);
|
303
|
}
|
304
|
|
305
|
$scope.saveUser = function(user) {
|
306
|
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
|
307
|
$http.post('api/users', user).then(function successCallback(res) {
|
308
|
$scope.users = res.data;
|
309
|
}, function errorCallback(res) {
|
310
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
311
|
});
|
312
|
}
|
313
|
|
314
|
$scope.deleteUser = function(email) {
|
315
|
if (confirm("Are you sure ?")) {
|
316
|
$http.delete('api/users?email=' + email).then(function successCallback(res) {
|
317
|
$scope.users = res.data;
|
318
|
}, function errorCallback(res) {
|
319
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
320
|
});
|
321
|
}
|
322
|
}
|
323
|
});
|