750 lines
25 KiB
JavaScript
750 lines
25 KiB
JavaScript
var orgsModule = angular.module('orgs', ['ngRoute', 'checklist-model']);
|
|
|
|
orgsModule.service('vocabulariesService', function($http) {
|
|
this.vocs = {};
|
|
this.getVocs = function(f) {
|
|
if (Object.keys(this.vocs).length === 0) {
|
|
$http.get('api/vocabularies').then(function successCallback(res) {
|
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
this.vocs = res.data;
|
|
f(angular.copy(this.vocs));
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
} else {
|
|
f(this.vocs);
|
|
}
|
|
};
|
|
});
|
|
|
|
orgsModule.factory('suggestionInfo', function($http) {
|
|
var info = { data : {} };
|
|
|
|
var getInfo = function() { return info; };
|
|
|
|
var updateInfo = function(callback) {
|
|
$http.get('api/organizations/suggestionsInfo').then(function successCallback(res) {
|
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
info.data = res.data;
|
|
if (callback) { callback(info); }
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
};
|
|
|
|
|
|
return {
|
|
getInfo: getInfo,
|
|
updateInfo: updateInfo
|
|
};
|
|
|
|
});
|
|
|
|
orgsModule.controller('menuCtrl', function ($scope, suggestionInfo) {
|
|
$scope.info = suggestionInfo.getInfo();
|
|
suggestionInfo.updateInfo(null);
|
|
});
|
|
|
|
orgsModule.directive('selectOrgModal', function($http) {
|
|
return {
|
|
restrict: 'E',
|
|
scope: {
|
|
'modalId' : '@',
|
|
'selectedOrg' : '='
|
|
},
|
|
templateUrl: 'resources/html/modals/select_org.html',
|
|
link: function(scope, element, attrs, ctrl) {
|
|
scope.searchOrgs = {};
|
|
scope.searchValue = '';
|
|
|
|
scope.search = function(text, page, size) {
|
|
scope.searchOrgs = {};
|
|
|
|
$http.get('api/organizations/search/' + page + '/' + size + '?q=' + text).then(function successCallback(res) {
|
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
scope.searchValue = text;
|
|
scope.searchOrgs = res.data;
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
orgsModule.directive('resolveConflictsModal', function($http, $route) {
|
|
return {
|
|
restrict: 'E',
|
|
scope: {
|
|
'modalId' : '@',
|
|
'orgs' : '=',
|
|
'selectedOrgs' : '='
|
|
},
|
|
templateUrl: 'resources/html/modals/resolve_conflicts.html',
|
|
link: function(scope, element, attrs, ctrl) {
|
|
scope.selectOrg = function(org) {
|
|
var sel = angular.copy(org);
|
|
if (scope.selectedOrgs.length == 0) { sel.show = 'success'; }
|
|
else { sel.show = 'info'; }
|
|
scope.selectedOrgs.push(sel);
|
|
org.show = 'hidden';
|
|
}
|
|
|
|
scope.reset = function() {
|
|
scope.selectedOrgs = [];
|
|
angular.forEach(scope.orgs, function(org) { org.show = 'secondary'; });
|
|
}
|
|
|
|
scope.createGroup = function() {
|
|
var masterId = '';
|
|
var otherIds = [];
|
|
angular.forEach(scope.selectedOrgs, function(o, pos) {
|
|
if (pos == 0) { masterId = o.id; }
|
|
else { otherIds.push(o.id); }
|
|
});
|
|
if (masterId && otherIds.length > 0) {
|
|
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
|
|
$http.post('api/organizations/conflicts/fix/' + masterId, otherIds).then(function successCallback(res) {
|
|
if ((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
$('#' + scope.modalId).modal('hide');
|
|
$('#' + scope.modalId).on('hidden.bs.modal', function (e) {
|
|
$route.reload();
|
|
});
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
orgsModule.directive('orgFormMetadata', function($http, $location, $route, $routeParams) {
|
|
return {
|
|
restrict: 'E',
|
|
scope: {
|
|
'org' : '=',
|
|
'vocabularies' : '=',
|
|
'mode' : '@', // insert_full, insert_pending, update_simple, update_full, approve, readonly, not_authorized
|
|
'infoMethod' : '&'
|
|
},
|
|
templateUrl: 'resources/html/parts/org_metadata.form.html',
|
|
link: function(scope, element, attrs, ctrl) {
|
|
scope.newRelation = {};
|
|
scope.newRelType = '';
|
|
|
|
scope.resetSelectedRelation = function() {
|
|
scope.newRelation = {};
|
|
}
|
|
|
|
scope.addNewRelation = function(r) {
|
|
scope.org.relations.push({
|
|
'relatedOrgId' : scope.newRelation.id,
|
|
'relatedOrgName' : scope.newRelation.name,
|
|
'type' : scope.newRelType
|
|
});
|
|
scope.newRelation = {};
|
|
scope.newRelType = '';
|
|
}
|
|
|
|
scope.save = function() {
|
|
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
|
|
$http.post('api/organizations/save', scope.org).then(function successCallback(res) {
|
|
if ((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
else if (scope.mode == 'insert') { $location.url('/edit/1/' + res.data[0]); }
|
|
else if (scope.mode == 'approve') { $location.url('/edit/3/' + res.data[0]); }
|
|
else if ($routeParams.msg == 2) { $route.reload(); }
|
|
else { $location.url('/edit/2/' + res.data[0]); }
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
}
|
|
|
|
scope.deleteOrg = function() {
|
|
if (confirm("Are you sure?")) {
|
|
$http.get('api/organizations/delete?id=' + scope.org.id).then(function successCallback(res) {
|
|
if ((typeof res.data) == 'string') {
|
|
alert("Session expired !");
|
|
location.reload(true);
|
|
} else {
|
|
alert("Organization marked as deleted !!!");
|
|
$route.reload();
|
|
}
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
}
|
|
};
|
|
scope.saveAsDiscarded = function() {
|
|
if (confirm("Are you sure?")) {
|
|
$http.get('api/organizations/discard?id=' + scope.org.id).then(function successCallback(res) {
|
|
if ((typeof res.data) == 'string') {
|
|
alert("Session expired !");
|
|
location.reload(true);
|
|
} else {
|
|
alert("Organization marked as discarded !!!");
|
|
$route.reload();
|
|
}
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
}
|
|
};
|
|
}
|
|
}
|
|
});
|
|
|
|
orgsModule.directive('orgDetails', function($http, $location, $route) {
|
|
return {
|
|
restrict: 'E',
|
|
scope: {
|
|
'org' : '=',
|
|
'orgTitle' : '@',
|
|
'show' : '@'
|
|
},
|
|
templateUrl: 'resources/html/parts/org_details.html',
|
|
link: function(scope, element, attrs, ctrl) {}
|
|
}
|
|
});
|
|
|
|
orgsModule.directive('orgResultsPage', function($http, $location, $route) {
|
|
return {
|
|
restrict: 'E',
|
|
scope: {
|
|
'searchMessage' : '@',
|
|
'orgs' : '=',
|
|
'nextFunction' : '&',
|
|
'prevFunction' : '&',
|
|
'selectedOrg' : '=',
|
|
'mode' : '@'
|
|
},
|
|
templateUrl: 'resources/html/parts/org_results_page.html',
|
|
link: function(scope, element, attrs, ctrl) {
|
|
scope.selectOrg = function(o) {
|
|
scope.selectedOrg.id = o.id;
|
|
scope.selectedOrg.name = o.name;
|
|
scope.selectedOrg.type = o.name;
|
|
scope.selectedOrg.city = o.name;
|
|
scope.selectedOrg.country = o.name;
|
|
scope.selectedOrg.acronyms = o.name;
|
|
scope.selectedOrg.approved = o.name;
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
orgsModule.directive('orgDuplicates', function($http, $location, $route) {
|
|
return {
|
|
restrict: 'E',
|
|
scope: {
|
|
'duplicates' : '=',
|
|
'showSaveButton' : '@',
|
|
'saveFunction' : '&'
|
|
},
|
|
templateUrl: 'resources/html/parts/org_duplicates.html',
|
|
link: function(scope, element, attrs, ctrl) {}
|
|
}
|
|
});
|
|
|
|
orgsModule.directive('orgConflicts', function($http, $location, $route, $q) {
|
|
return {
|
|
restrict: 'E',
|
|
scope: {
|
|
'org' : '=',
|
|
'conflicts' : '=',
|
|
'showSaveButton' : '@',
|
|
'saveFunction' : '&'
|
|
},
|
|
templateUrl: 'resources/html/parts/org_conflicts.html',
|
|
link: function(scope, element, attrs, ctrl) {
|
|
scope.candidateConflicts = [];
|
|
scope.selectedConflicts = [];
|
|
|
|
scope.prepareConflictsModal = function() {
|
|
scope.candidateConflicts = [];
|
|
scope.selectedConflicts = [];
|
|
|
|
var gets = [ $http.get('api/organizations/get?id=' + scope.org.id) ];
|
|
angular.forEach(scope.conflicts, function(c) { gets.push($http.get('api/organizations/get?id=' + c.id)); });
|
|
|
|
$q.all(gets).then(function(responses) {
|
|
scope.candidateConflicts = responses.map((resp) => resp.data);
|
|
angular.forEach(scope.candidateConflicts, function(org) { org.show = 'secondary'; });
|
|
});
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
orgsModule.config(function($routeProvider) {
|
|
$routeProvider
|
|
.when('/search', { templateUrl: 'resources/html/pages/search/search.html', controller: 'searchCtrl' })
|
|
.when('/searchResults/:page/:size/:text*', { templateUrl: 'resources/html/pages/search/searchResults.html', controller: 'searchResultsCtrl' })
|
|
.when('/countries', { templateUrl: 'resources/html/pages/search/browse.html', controller: 'countriesCtrl' })
|
|
.when('/byCountry/:page/:size/:status/:code*', { templateUrl: 'resources/html/pages/search/resultsByCountry.html', controller: 'byCountryCtrl' })
|
|
.when('/types', { templateUrl: 'resources/html/pages/search/browse.html', controller: 'typesCtrl' })
|
|
.when('/byType/:page/:size/:status/:type*', { templateUrl: 'resources/html/pages/search/resultsByType.html', controller: 'byTypeCtrl' })
|
|
.when('/edit/:msg/:id', { templateUrl: 'resources/html/pages/edit/edit.html', controller: 'showEditCtrl' })
|
|
.when('/new', { templateUrl: 'resources/html/pages/advanced/new.html', controller: 'newOrgCtrl' })
|
|
.when('/pendings/:country', { templateUrl: 'resources/html/pages/advanced/pendingOrgs.html', controller: 'pendingOrgsCtrl' })
|
|
.when('/duplicates/:country', { templateUrl: 'resources/html/pages/advanced/duplicates.html', controller: 'duplicatesCtrl' })
|
|
.when('/conflicts/:country', { templateUrl: 'resources/html/pages/advanced/conflicts.html', controller: 'conflictsCtrl' })
|
|
.when('/users', { templateUrl: 'resources/html/pages/admin/users.html', controller: 'usersCtrl' })
|
|
.otherwise({ redirectTo: '/search' });
|
|
});
|
|
|
|
orgsModule.filter('escape', function() {
|
|
return function(input) {
|
|
return encodeURIComponent(encodeURIComponent(input));
|
|
};
|
|
});
|
|
|
|
orgsModule.filter('unescape', function() {
|
|
return function(input) {
|
|
return decodeURIComponent(input);
|
|
};
|
|
});
|
|
|
|
orgsModule.controller('newOrgCtrl', function ($scope, $http, $routeParams, $location, vocabulariesService) {
|
|
$scope.org = {
|
|
"id": "",
|
|
"name": "",
|
|
"type": null,
|
|
"lat": 0.0,
|
|
"lng": 0.0,
|
|
"city": "",
|
|
"country": "",
|
|
"source": "user",
|
|
"otherIdentifiers": [],
|
|
"otherNames": [],
|
|
"relations": [],
|
|
"acronyms": [],
|
|
"urls": [],
|
|
"relations": []
|
|
};
|
|
$scope.adminMode = adminMode();
|
|
$scope.vocabularies = {};
|
|
vocabulariesService.getVocs(function(vocs) { $scope.vocabularies = vocs; });
|
|
});
|
|
|
|
orgsModule.controller('searchCtrl', function ($scope, $location) {
|
|
$scope.searchText = '';
|
|
$scope.search = function() {
|
|
if ($scope.searchText) {
|
|
$location.url('/searchResults/0/50/' + encodeURIComponent(encodeURIComponent($scope.searchText)));
|
|
} else {
|
|
$location.url('/searchResults/0/50/_');
|
|
}
|
|
}
|
|
});
|
|
|
|
orgsModule.controller('searchResultsCtrl', function ($scope, $http, $routeParams, $location) {
|
|
$scope.searchText = '';
|
|
if ($routeParams.text != '_') {
|
|
$scope.searchText = decodeURIComponent($routeParams.text);
|
|
}
|
|
$scope.orgs = {};
|
|
|
|
$http.get('api/organizations/search/' + $routeParams.page + '/' + $routeParams.size + '?q=' + $scope.searchText).then(function successCallback(res) {
|
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
$scope.orgs = res.data;
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
|
|
$scope.prev = function() {
|
|
if ($scope.searchText) {
|
|
$location.url('/searchResults/' + ($scope.orgs.number - 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.searchText));
|
|
} else {
|
|
$location.url('/searchResults/' + ($scope.orgs.number - 1) + '/' + $scope.orgs.size + '/_');
|
|
}
|
|
}
|
|
|
|
$scope.next = function() {
|
|
if ($scope.searchText) {
|
|
$location.url('/searchResults/' + ($scope.orgs.number + 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.searchText));
|
|
} else {
|
|
$location.url('/searchResults/' + ($scope.orgs.number + 1) + '/' + $scope.orgs.size + '/_');
|
|
}
|
|
}
|
|
});
|
|
|
|
orgsModule.controller('countriesCtrl', function ($scope, $http, $routeParams) {
|
|
|
|
$scope.title = 'Countries';
|
|
$scope.field = 'Country';
|
|
$scope.resultsBasePath = '/byCountry'
|
|
$scope.entries = [];
|
|
|
|
$http.get('api/organizations/browse/countries').then(function successCallback(res) {
|
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
$scope.entries = res.data;
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
|
|
});
|
|
|
|
orgsModule.controller('byCountryCtrl', function ($scope, $http, $routeParams, $location) {
|
|
$scope.fieldValue = decodeURIComponent($routeParams.code);
|
|
$scope.orgs = {};
|
|
|
|
$http.get('api/organizations/byCountry/' + $routeParams.status + '/' + $routeParams.code + '/' + $routeParams.page + '/' + $routeParams.size).then(function successCallback(res) {
|
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
$scope.orgs = res.data;
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
|
|
$scope.prev = function() {
|
|
$location.url('/byCountry/' + ($scope.orgs.number - 1) + '/' + $scope.orgs.size + '/' + $routeParams.status + '/' + encodeURIComponent($scope.fieldValue));
|
|
}
|
|
|
|
$scope.next = function() {
|
|
$location.url('/byCountry/' + ($scope.orgs.number + 1) + '/' + $scope.orgs.size + '/' + $routeParams.status + '/' + encodeURIComponent($scope.fieldValue));
|
|
}
|
|
|
|
});
|
|
|
|
orgsModule.controller('typesCtrl', function ($scope, $http, $routeParams) {
|
|
$scope.title = 'Organization types';
|
|
$scope.field = 'Organization type';
|
|
$scope.resultsBasePath = '/byType'
|
|
$scope.entries = [];
|
|
|
|
$http.get('api/organizations/browse/types').then(function successCallback(res) {
|
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
$scope.entries = res.data;
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
|
|
});
|
|
|
|
orgsModule.controller('byTypeCtrl', function ($scope, $http, $routeParams, $location) {
|
|
|
|
$scope.fieldValue = $routeParams.type;
|
|
|
|
$scope.orgs = {};
|
|
|
|
$http.get('api/organizations/byType/' + $routeParams.status + '/' + $routeParams.type + '/' + $routeParams.page + '/' + $routeParams.size).then(function successCallback(res) {
|
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
$scope.orgs = res.data;
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
|
|
$scope.prev = function() {
|
|
$location.url('/byType/' + ($scope.orgs.number - 1) + '/' + $scope.orgs.size + '/' + $routeParams.status + '/' + encodeURIComponent($scope.fieldValue));
|
|
}
|
|
|
|
$scope.next = function() {
|
|
$location.url('/byType/' + ($scope.orgs.number + 1) + '/' + $scope.orgs.size + '/' + $routeParams.status + '/' + encodeURIComponent($scope.fieldValue));
|
|
}
|
|
});
|
|
|
|
|
|
orgsModule.controller('showEditCtrl', function ($scope, $http, $routeParams, $route, $location, $timeout, $window, vocabulariesService) {
|
|
$scope.orgId = $routeParams.id;
|
|
$scope.org = {};
|
|
$scope.duplicates = [];
|
|
$scope.conflicts = [];
|
|
$scope.info = {};
|
|
$scope.currentTab = 1
|
|
$scope.vocabularies = {};
|
|
$scope.adminMode = adminMode();
|
|
|
|
$scope.getInfo = function() {
|
|
$http.get('api/organizations/info?id=' + $scope.orgId).then(function successCallback(res) {
|
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
$scope.info = res.data;
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
};
|
|
|
|
$scope.gotoTab = function(tab) {
|
|
$scope.org = {};
|
|
$http.get('api/organizations/get?id=' + $scope.orgId).then(function successCallback(res) {
|
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
$scope.org = res.data;
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
|
|
if (tab == 2) {
|
|
$scope.duplicates = [];
|
|
$http.get('api/organizations/duplicates?id=' + $scope.orgId).then(function successCallback(res) {
|
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
$scope.duplicates = res.data;
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
} else if (tab == 3) {
|
|
$scope.conflicts = [];
|
|
$http.get('api/organizations/conflicts?id=' + $scope.orgId).then(function successCallback(res) {
|
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
$scope.conflicts = res.data;
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
}
|
|
$scope.currentTab = tab;
|
|
}
|
|
|
|
|
|
|
|
|
|
$scope.saveDuplicates = function() {
|
|
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
|
|
$http.post('api/organizations/duplicates', $scope.duplicates).then(function successCallback(res) {
|
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
$scope.getInfo();
|
|
alert('Events updated !!!');
|
|
$scope.duplicates = res.data;
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
}
|
|
|
|
$scope.saveConflicts = function() {
|
|
alert('todo');
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vocabulariesService.getVocs(function(vocs) { $scope.vocabularies = vocs; });
|
|
$scope.getInfo();
|
|
$scope.gotoTab(1);
|
|
|
|
if ($routeParams.msg == 1) { $scope.message = 'New organization registered !!!'; }
|
|
else if ($routeParams.msg == 2) { $scope.message = 'Organization updated !!!'; }
|
|
else if ($routeParams.msg == 3) { $scope.message = 'Pending organization registered !!!'; }
|
|
else { $scope.message = ''; }
|
|
$window.scrollTo(0, 0);
|
|
|
|
$timeout(function() { $scope.message = ''; }, 3000)
|
|
|
|
});
|
|
|
|
orgsModule.controller('pendingOrgsCtrl', function ($scope, $http, $routeParams, $location, suggestionInfo) {
|
|
$scope.info = suggestionInfo.getInfo();
|
|
$scope.orgs = [];
|
|
$scope.country = $routeParams.country;
|
|
|
|
$scope.getInfo = function() {
|
|
suggestionInfo.updateInfo(function(info) {
|
|
if ($scope.country == '_') {
|
|
var found = '';
|
|
angular.forEach(info.data.byCountry, function(values, c) {
|
|
if (!found && values.nPendingOrgs > 0) {
|
|
found = c;
|
|
}
|
|
});
|
|
if (found) { $location.url('/pendings/' + found); }
|
|
}
|
|
});
|
|
};
|
|
|
|
$scope.refresh = function() {
|
|
$scope.orgs = [];
|
|
|
|
if ($scope.country != '_') {
|
|
$http.get('api/organizations/byCountry/suggested/' + $scope.country).then(function successCallback(res) {
|
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
$scope.orgs = res.data;
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
}
|
|
$scope.getInfo();
|
|
}
|
|
|
|
$scope.refresh();
|
|
});
|
|
|
|
orgsModule.controller('duplicatesCtrl', function ($scope, $http, $routeParams, $location, $timeout, $route, suggestionInfo) {
|
|
$scope.info = suggestionInfo.getInfo();
|
|
$scope.duplicates = [];
|
|
$scope.country = $routeParams.country;
|
|
$scope.currentOrg = {};
|
|
$scope.currentOrgDetails = {};
|
|
|
|
$scope.prepareDuplicatesModal = function(org) {
|
|
$scope.currentOrg = org;
|
|
$scope.currentOrgDetails = {};
|
|
$scope.currentDuplicates = [];
|
|
|
|
$http.get('api/organizations/get?id=' + org.id).then(function successCallback(res) {
|
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
$scope.currentOrgDetails = res.data;
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
|
|
$http.get('api/organizations/duplicates?id=' + org.id).then(function successCallback(res) {
|
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
$scope.currentDuplicates = res.data;
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
};
|
|
|
|
$scope.getInfo = function() {
|
|
suggestionInfo.updateInfo(function(info) {
|
|
if ($scope.country == '_') {
|
|
var found = '';
|
|
angular.forEach(info.data.byCountry, function(values, c) {
|
|
if (!found && values.nDuplicates > 0) {
|
|
found = c;
|
|
}
|
|
});
|
|
if (found) { $location.url('/duplicates/' + found); }
|
|
}
|
|
});
|
|
};
|
|
|
|
$scope.saveCurrentDuplicates = function() {
|
|
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
|
|
$http.post('api/organizations/duplicates', $scope.currentDuplicates).then(function successCallback(res) {
|
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
|
|
$scope.getInfo();
|
|
|
|
$scope.currentOrg.numberOfDuplicates = 0;
|
|
for (var i=0; i<res.data.length; i++) {
|
|
if (res.data[i].relType == 'suggested') {
|
|
$scope.currentOrg.numberOfDuplicates++;
|
|
}
|
|
}
|
|
$scope.currentDuplicates = [];
|
|
|
|
$timeout(function() {
|
|
if ($scope.duplicates.length > 1) {
|
|
$route.reload();
|
|
} else {
|
|
$location.url('/duplicates/_');
|
|
}
|
|
}, 600);
|
|
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
};
|
|
|
|
$scope.refresh = function() {
|
|
$scope.duplicates = [];
|
|
|
|
if ($scope.country != '_') {
|
|
$http.get('api/organizations/duplicates/byCountry/' + $scope.country).then(function successCallback(res) {
|
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
$scope.duplicates = res.data;
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
}
|
|
$scope.getInfo();
|
|
}
|
|
|
|
$scope.refresh();
|
|
});
|
|
|
|
orgsModule.controller('conflictsCtrl', function ($scope, $http, $routeParams, $location, $route, $q, suggestionInfo) {
|
|
$scope.info = suggestionInfo.getInfo();
|
|
$scope.conflicts = [];
|
|
$scope.country = $routeParams.country;
|
|
$scope.orgs = [];
|
|
|
|
$scope.prepareConflictsModal = function(list) {
|
|
$scope.orgs = [];
|
|
$scope.selectedOrgs = [];
|
|
|
|
var gets = list.map((o) => $http.get('api/organizations/get?id=' + o.id));
|
|
|
|
$q.all(gets).then(function(responses) {
|
|
$scope.orgs = responses.map((resp) => resp.data);
|
|
angular.forEach($scope.orgs, function(org) { org.show = 'secondary'; });
|
|
});
|
|
}
|
|
|
|
$scope.getInfo = function() {
|
|
suggestionInfo.updateInfo(function(info) {
|
|
if ($scope.country == '_') {
|
|
var found = '';
|
|
|
|
angular.forEach(info.data.byCountry, function(values, c) {
|
|
if (!found && values.nConflicts > 0) {
|
|
found = c;
|
|
}
|
|
});
|
|
if (found) { $location.url('/conflicts/' + found); }
|
|
}
|
|
});
|
|
};
|
|
|
|
$scope.refresh = function() {
|
|
$scope.conflicts = [];
|
|
|
|
if ($scope.country != '_') {
|
|
$http.get('api/organizations/conflicts/byCountry/' + $scope.country).then(function successCallback(res) {
|
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
$scope.conflicts = res.data;
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
}
|
|
$scope.getInfo();
|
|
}
|
|
|
|
$scope.refresh();
|
|
});
|
|
|
|
|
|
|
|
orgsModule.controller('usersCtrl', function ($scope, $http, $timeout, $route, vocabulariesService) {
|
|
$scope.users = [];
|
|
$scope.vocs = {};
|
|
$scope.currentUser = {};
|
|
$scope.superAdminMode = superAdminMode();
|
|
|
|
$scope.vocabularies = {};
|
|
vocabulariesService.getVocs(function(vocs) { $scope.vocabularies = vocs; });
|
|
|
|
$http.get('api/users').then(function successCallback(res) {
|
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
$scope.users = res.data;
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
|
|
$scope.setCurrentUser = function(user) {
|
|
angular.copy(user, $scope.currentUser);
|
|
if (!$scope.currentUser.role || $scope.currentUser.role == 'PENDING') {
|
|
$scope.currentUser.role = 'USER';
|
|
}
|
|
}
|
|
|
|
$scope.saveUser = function(user) {
|
|
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
|
|
$http.post('api/users', user).then(function successCallback(res) {
|
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
$scope.users = res.data;
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
}
|
|
|
|
$scope.deleteUser = function(email) {
|
|
if (confirm("Are you sure ?")) {
|
|
$http.delete('api/users?email=' + email).then(function successCallback(res) {
|
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
|
$scope.users = res.data;
|
|
}, function errorCallback(res) {
|
|
alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')');
|
|
});
|
|
}
|
|
}
|
|
});
|