diff --git a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/OrganizationController.java b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/OrganizationController.java index 1a8aaefe..b71986b8 100644 --- a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/OrganizationController.java +++ b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/OrganizationController.java @@ -216,13 +216,18 @@ public class OrganizationController { : organizationSimpleViewRepository.searchForUser(q, authentication.getName(), PageRequest.of(page, size)); } - @GetMapping("/byCountry/{code}/{page}/{size}") - public Page findByCountry(@PathVariable final String code, + @GetMapping("/byCountry/{status}/{code}/{page}/{size}") + public Page findByCountry(@PathVariable final String status, + @PathVariable final String code, @PathVariable final int page, @PathVariable final int size, final Authentication authentication) { if (UserInfo.isSuperAdmin(authentication) || userCountryRepository.verifyAuthorizationForCountry(code, authentication.getName())) { - return organizationSimpleViewRepository.findByCountryOrderByName(code, PageRequest.of(page, size)); + if (status.equalsIgnoreCase("all")) { + return organizationSimpleViewRepository.findByCountryOrderByName(code, PageRequest.of(page, size)); + } else { + return organizationSimpleViewRepository.findByCountryAndStatusOrderByName(code, status, PageRequest.of(page, size)); + } } else { throw new RuntimeException("User not authorized"); } @@ -243,14 +248,27 @@ public class OrganizationController { } } - @GetMapping("/byType/{type}/{page}/{size}") - public Page findByType(@PathVariable final String type, + @GetMapping("/byType/{status}/{type}/{page}/{size}") + public Page findByType(@PathVariable final String status, + @PathVariable final String type, @PathVariable final int page, @PathVariable final int size, final Authentication authentication) { - return UserInfo.isSuperAdmin(authentication) - ? organizationSimpleViewRepository.findByTypeOrderByName(type, PageRequest.of(page, size)) - : organizationSimpleViewRepository.findByTypeForUser(type, authentication.getName(), PageRequest.of(page, size)); + + if (UserInfo.isSuperAdmin(authentication)) { + if (status.equalsIgnoreCase("all")) { + return organizationSimpleViewRepository.findByTypeOrderByName(type, PageRequest.of(page, size)); + } else { + return organizationSimpleViewRepository.findByTypeAndStatusOrderByName(type, status, PageRequest.of(page, size)); + } + } else { + if (status.equalsIgnoreCase("all")) { + return organizationSimpleViewRepository.findByTypeForUser(type, authentication.getName(), PageRequest.of(page, size)); + } else { + return organizationSimpleViewRepository.findByTypeAndStatusForUser(type, status, authentication.getName(), PageRequest.of(page, size)); + } + } + } @GetMapping("/browse/countries") diff --git a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/model/utils/BrowseEntry.java b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/model/utils/BrowseEntry.java index 8647374c..86a71797 100644 --- a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/model/utils/BrowseEntry.java +++ b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/model/utils/BrowseEntry.java @@ -1,6 +1,8 @@ package eu.dnetlib.organizations.model.utils; import java.io.Serializable; +import java.util.LinkedHashMap; +import java.util.Map; public class BrowseEntry implements Serializable { @@ -9,17 +11,16 @@ public class BrowseEntry implements Serializable { */ private static final long serialVersionUID = 8854955977257064470L; - private String value; + private String code; private String name; - private int approved; - private int pending; + private Map values = new LinkedHashMap<>(); - public String getValue() { - return value; + public String getCode() { + return code; } - public void setValue(final String value) { - this.value = value; + public void setCode(final String code) { + this.code = code; } public String getName() { @@ -30,20 +31,12 @@ public class BrowseEntry implements Serializable { this.name = name; } - public int getApproved() { - return approved; + public Map getValues() { + return values; } - public void setApproved(final int approved) { - this.approved = approved; - } - - public int getPending() { - return pending; - } - - public void setPending(final int pending) { - this.pending = pending; + public void setValues(final Map values) { + this.values = values; } } diff --git a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/model/utils/TempBrowseEntry.java b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/model/utils/TempBrowseEntry.java new file mode 100644 index 00000000..e9a42a2c --- /dev/null +++ b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/model/utils/TempBrowseEntry.java @@ -0,0 +1,48 @@ +package eu.dnetlib.organizations.model.utils; + +import java.io.Serializable; + +public class TempBrowseEntry implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -2233409680550512318L; + + private String code; + private String name; + private String group; + private Integer count; + + public String getCode() { + return code; + } + + public void setCode(final String code) { + this.code = code; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public String getGroup() { + return group; + } + + public void setGroup(final String group) { + this.group = group; + } + + public Integer getCount() { + return count; + } + + public void setCount(final Integer count) { + this.count = count; + } +} diff --git a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/repository/readonly/OrganizationSimpleViewRepository.java b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/repository/readonly/OrganizationSimpleViewRepository.java index 9ced1f1c..9c6b0bcd 100644 --- a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/repository/readonly/OrganizationSimpleViewRepository.java +++ b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/repository/readonly/OrganizationSimpleViewRepository.java @@ -25,9 +25,16 @@ public interface OrganizationSimpleViewRepository extends ReadOnlyRepository findByCountryAndStatusOrderByName(String code, String status); + Page findByCountryAndStatusOrderByName(String code, String status, Pageable pageable); + Page findByTypeOrderByName(String type, Pageable pageable); + Page findByTypeAndStatusOrderByName(String type, String status, Pageable pageable); + @Query(value = "select o.* from organizations_simple_view o left outer join user_countries uc on (uc.country = o.country) where uc.email = ?2 and o.type = ?1 order by o.name", nativeQuery = true) Page findByTypeForUser(String type, String name, Pageable pageable); + @Query(value = "select o.* from organizations_simple_view o left outer join user_countries uc on (uc.country = o.country) where o.type = ?1 and o.status = ?2 and uc.email = ?3 order by o.name", nativeQuery = true) + Page findByTypeAndStatusForUser(String type, String status, String name, Pageable pageable); + } diff --git a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/utils/DatabaseUtils.java b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/utils/DatabaseUtils.java index 61af9b8e..2a403305 100644 --- a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/utils/DatabaseUtils.java +++ b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/utils/DatabaseUtils.java @@ -38,6 +38,7 @@ import eu.dnetlib.organizations.model.User; import eu.dnetlib.organizations.model.UserCountry; import eu.dnetlib.organizations.model.utils.BrowseEntry; import eu.dnetlib.organizations.model.utils.OrganizationConflict; +import eu.dnetlib.organizations.model.utils.TempBrowseEntry; import eu.dnetlib.organizations.model.utils.VocabularyTerm; import eu.dnetlib.organizations.model.view.OrganizationView; import eu.dnetlib.organizations.model.view.UserView; @@ -280,36 +281,51 @@ public class DatabaseUtils { // BROWSE BY COUNTRY public List browseCountries() { final String sql = - "select o.country as value, c.name as name, sum(case when status='approved' then 1 else 0 end) as approved, sum(case when status='pending' then 1 else 0 end) as pending from organizations o left outer join countries c on (o.country = c.val) group by o.country, c.name order by approved desc"; - return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BrowseEntry.class)); + "select o.country as code, c.name as name, o.status as group, count(o.status) as count from organizations o left outer join countries c on (o.country = c.val) group by o.country, c.name, o.status"; + return listBrowseEntries(sql); } // BROWSE BY COUNTRY FOR USER public List browseCountriesForUser(final String email) { final String sql = - "select o.country as value, c.name as name, sum(case when status='approved' then 1 else 0 end) as approved, sum(case when status='pending' then 1 else 0 end) as pending from user_countries uc left outer join organizations o on (uc.country = o.country) left outer join countries c on (o.country = c.val) where uc.email=? group by o.country, c.name order by approved desc"; - return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BrowseEntry.class), email); + "select o.country as code, c.name as name, o.status as group, count(o.status) as count from user_countries uc left outer join organizations o on (uc.country = o.country) left outer join countries c on (o.country = c.val) where uc.email=? group by o.country, c.name, o.status"; + return listBrowseEntries(sql, email); } // BROWSE BY ORG TYPE public List browseTypes() { final String sql = - "select type as value, type as name, sum(case when status='approved' then 1 else 0 end) as approved, sum(case when status='pending' then 1 else 0 end) as pending from organizations group by type order by approved desc"; - return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BrowseEntry.class)); + "select type as code, type as name, status as group, count(status) as count from organizations group by type, status"; + return listBrowseEntries(sql); } // BROWSE BY ORG TYPE FOR USER public List browseTypesForUser(final String email) { - final String sql = "select o.type as value, o.type as name," - + "sum(case when status='approved' then 1 else 0 end) as approved, " - + "sum(case when status='pending' then 1 else 0 end) as pending " + final String sql = "select o.type as code, o.type as name," + + "o.status as group, count(o.status) as count " + "from organizations o " + "left outer join user_countries uc on (uc.country = o.country) " + "where uc.email=? " - + "group by o.type " - + "order by approved desc;"; - return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BrowseEntry.class), email); + + "group by o.type, o.status"; + return listBrowseEntries(sql, email); + } + private List listBrowseEntries(final String sql, final Object... params) { + final Map map = new HashMap<>(); + + for (final TempBrowseEntry t : jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(TempBrowseEntry.class), params)) { + if (StringUtils.isNotBlank(t.getCode())) { + if (!map.containsKey(t.getCode())) { + final BrowseEntry e = new BrowseEntry(); + e.setCode(t.getCode()); + e.setName(t.getName()); + map.put(t.getCode(), e); + } + map.get(t.getCode()).getValues().put(t.getGroup(), t.getCount()); + } + } + + return map.values().stream().sorted((o1, o2) -> StringUtils.compare(o1.getName(), o2.getName())).collect(Collectors.toList()); } public List listConflictsForId(final String id) { diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/browse.html b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/browse.html deleted file mode 100644 index f58a31ea..00000000 --- a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/browse.html +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - -
{{field}}# approved# pending
{{e.name}} ({{e.value}}){{e.approved}}{{e.pending}}
diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/forms/all_conflicts.html b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/forms/all_conflicts.html deleted file mode 100644 index 49f72213..00000000 --- a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/forms/all_conflicts.html +++ /dev/null @@ -1,42 +0,0 @@ -
- -
No suggestions
- -
- -
- Country: - - -
-
- -
-
Group {{$index+1}}
- - - - - - - -
#{{$index+1}}{{o.name}} {{o.city || '-'}}, {{o.country}}{{o.type}}
- -
- -
- - diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/forms/all_duplicates.html b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/forms/all_duplicates.html deleted file mode 100644 index 84754aa5..00000000 --- a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/forms/all_duplicates.html +++ /dev/null @@ -1,62 +0,0 @@ -
- -
No suggestions
- -
- -
- Country: - - -
-
- - - - - - - - - - - - - - - - -
OrganizationPlace# pending duplicates
- {{d.name}} - - {{d.city || '-'}}, {{d.country}}{{d.numberOfDuplicates}}
-
- - - diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/forms/pending_orgs.html b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/forms/pending_orgs.html deleted file mode 100644 index 69a0eaf2..00000000 --- a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/forms/pending_orgs.html +++ /dev/null @@ -1,43 +0,0 @@ -
- -
No suggestions
- -
- -
- Country: - - -
-
- - - - - - - - - - - - - - - - - - -
Organization namePlaceAcronymsType
- {{o.name}} - {{o.city || '-'}}, {{o.country}}{{o.acronyms.join()}}{{o.type}}
- -
diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/users.html b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/admin/users.html similarity index 100% rename from apps/dnet-orgs-database-application/src/main/resources/static/resources/html/users.html rename to apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/admin/users.html diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/advanced/conflicts.html b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/advanced/conflicts.html new file mode 100644 index 00000000..3a1d98f5 --- /dev/null +++ b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/advanced/conflicts.html @@ -0,0 +1,40 @@ +

Conflicts

+ +

No suggestions

+ +
+ +
+ Country: + + +
+
+ +
+
Group {{$index+1}}
+ + + + + + + +
#{{$index+1}}{{o.name}} {{o.city || '-'}}, {{o.country}}{{o.type}}
+ +
+ + diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/advanced/duplicates.html b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/advanced/duplicates.html new file mode 100644 index 00000000..6f05b3b0 --- /dev/null +++ b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/advanced/duplicates.html @@ -0,0 +1,60 @@ +

Duplicates

+ +

No duplicates

+ +
+ +
+ Country: + + +
+
+ + + + + + + + + + + + + + + + +
OrganizationPlace# pending duplicates
+ {{d.name}} + + {{d.city || '-'}}, {{d.country}}{{d.numberOfDuplicates}}
+ + diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/new.html b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/advanced/new.html similarity index 100% rename from apps/dnet-orgs-database-application/src/main/resources/static/resources/html/new.html rename to apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/advanced/new.html diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/advanced/pendingOrgs.html b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/advanced/pendingOrgs.html new file mode 100644 index 00000000..27a88f55 --- /dev/null +++ b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/advanced/pendingOrgs.html @@ -0,0 +1,42 @@ +

Pending Organizations

+ +

No pending organizations

+ +
+ +
+ Country: + + +
+
+ + + + + + + + + + + + + + + + + + +
Organization namePlaceAcronymsType
+ {{o.name}} + {{o.city || '-'}}, {{o.country}}{{o.acronyms.join()}}{{o.type}}
+ diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/edit.html b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/edit/edit.html similarity index 100% rename from apps/dnet-orgs-database-application/src/main/resources/static/resources/html/edit.html rename to apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/edit/edit.html diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/search/browse.html b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/search/browse.html new file mode 100644 index 00000000..b4382f0d --- /dev/null +++ b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/search/browse.html @@ -0,0 +1,50 @@ +

{{title}}

+ +

No entries

+ +

+ +

+ + + + + + + + + + + + + + + + + + + + + + + + +
{{field}}# approved# pending# deleted# duplicated# discarded# hidden
{{e.name}} ({{e.code}}) + {{e.values.approved}} + - + + {{e.values.pending}} + - + + {{e.values.deleted}} + - + + {{e.values.duplicate}} + - + + {{e.values.discarded}} + - + + {{e.values.hidden}} + - +
diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/resultsByCountry.html b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/search/resultsByCountry.html similarity index 100% rename from apps/dnet-orgs-database-application/src/main/resources/static/resources/html/resultsByCountry.html rename to apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/search/resultsByCountry.html diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/resultsByType.html b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/search/resultsByType.html similarity index 100% rename from apps/dnet-orgs-database-application/src/main/resources/static/resources/html/resultsByType.html rename to apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/search/resultsByType.html diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/search.html b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/search/search.html similarity index 100% rename from apps/dnet-orgs-database-application/src/main/resources/static/resources/html/search.html rename to apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/search/search.html diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/searchResults.html b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/search/searchResults.html similarity index 100% rename from apps/dnet-orgs-database-application/src/main/resources/static/resources/html/searchResults.html rename to apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/search/searchResults.html diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/suggestions.html b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/suggestions.html deleted file mode 100644 index 0d947cd0..00000000 --- a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/suggestions.html +++ /dev/null @@ -1,23 +0,0 @@ - diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/js/organizations.js b/apps/dnet-orgs-database-application/src/main/resources/static/resources/js/organizations.js index 67ea4246..f57ee40f 100644 --- a/apps/dnet-orgs-database-application/src/main/resources/static/resources/js/organizations.js +++ b/apps/dnet-orgs-database-application/src/main/resources/static/resources/js/organizations.js @@ -17,6 +17,34 @@ orgsModule.service('vocabulariesService', function($http) { }; }); +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', @@ -265,52 +293,6 @@ orgsModule.directive('orgResultsPage', function($http, $location, $route) { } }); -orgsModule.directive('allConflicts', function($http, $location, $route, $q) { - return { - restrict: 'E', - scope: { - 'conflicts' : '=', - 'country' : '@', - 'info' : '=', - 'infoMethod' : '&' - }, - templateUrl: 'resources/html/forms/all_conflicts.html', - link: function(scope, element, attrs, ctrl) { - 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'; }); - }); - } - - } - } -}); - - -orgsModule.directive('pendingOrgs', function($http, $location, $route, $q) { - return { - restrict: 'E', - scope: { - 'orgs' : '=', - 'country' : '@', - 'info' : '=', - 'infoMethod' : '&' - }, - templateUrl: 'resources/html/forms/pending_orgs.html', - link: function(scope, element, attrs, ctrl) { - - } - } -}); - orgsModule.directive('orgFormDuplicates', function($http, $location, $route) { return { restrict: 'E', @@ -354,83 +336,21 @@ orgsModule.directive('orgFormConflicts', function($http, $location, $route, $q) } }); -orgsModule.directive('allDuplicates', function($http, $location, $route, $timeout) { - return { - restrict: 'E', - scope: { - 'duplicates' : '=', - 'country' : '@', - 'info' : '=', - 'infoMethod' : '&' - }, - templateUrl: 'resources/html/forms/all_duplicates.html', - link: function(scope, element, attrs, ctrl) { - scope.currentOrg = {}; - scope.currentOrgDetails = {}; - scope.currentDuplicates = []; - - 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.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); } - if (scope.infoMethod) { scope.infoMethod(); } - scope.currentOrg.numberOfDuplicates = 0; - for (var i=0; i 1) { - $route.reload(); - } else { - $location.url('/suggestions/_/1'); - } - }, 600); - - }, function errorCallback(res) { - alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')'); - }); - }; - } - } -}); - orgsModule.config(function($routeProvider) { $routeProvider - .when('/new', { templateUrl: 'resources/html/new.html', controller: 'newOrgCtrl' }) - .when('/search', { templateUrl: 'resources/html/search.html', controller: 'searchCtrl' }) - .when('/searchResults/:page/:size/:text*', { templateUrl: 'resources/html/searchResults.html', controller: 'searchResultsCtrl' }) - .when('/countries', { templateUrl: 'resources/html/browse.html', controller: 'countriesCtrl' }) - .when('/byCountry/:page/:size/:code*', { templateUrl: 'resources/html/resultsByCountry.html', controller: 'byCountryCtrl' }) - .when('/types', { templateUrl: 'resources/html/browse.html', controller: 'typesCtrl' }) - .when('/byType/:page/:size/:type*', { templateUrl: 'resources/html/resultsByType.html', controller: 'byTypeCtrl' }) - .when('/edit/:msg/:id', { templateUrl: 'resources/html/edit.html', controller: 'showEditCtrl' }) - .when('/suggestions/:country/:tab', { templateUrl: 'resources/html/suggestions.html', controller: 'showSuggestionsCtrl' }) - .when('/users', { templateUrl: 'resources/html/users.html', controller: 'usersCtrl' }) - .otherwise({ redirectTo: '/suggestions/_/0' }); + .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() { @@ -511,6 +431,8 @@ orgsModule.controller('searchResultsCtrl', function ($scope, $http, $routeParams }); orgsModule.controller('countriesCtrl', function ($scope, $http, $routeParams) { + + $scope.title = 'Countries'; $scope.field = 'Country'; $scope.resultsBasePath = '/byCountry' $scope.entries = []; @@ -528,7 +450,7 @@ orgsModule.controller('byCountryCtrl', function ($scope, $http, $routeParams, $l $scope.fieldValue = decodeURIComponent($routeParams.code); $scope.orgs = {}; - $http.get('api/organizations/byCountry/' + $routeParams.code + '/' + $routeParams.page + '/' + $routeParams.size).then(function successCallback(res) { + $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) { @@ -536,16 +458,17 @@ orgsModule.controller('byCountryCtrl', function ($scope, $http, $routeParams, $l }); $scope.prev = function() { - $location.url('/byCountry/' + ($scope.orgs.number - 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.fieldValue)); + $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 + '/' + encodeURIComponent($scope.fieldValue)); + $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 = []; @@ -565,7 +488,7 @@ orgsModule.controller('byTypeCtrl', function ($scope, $http, $routeParams, $loca $scope.orgs = {}; - $http.get('api/organizations/byType/' + $routeParams.type + '/' + $routeParams.page + '/' + $routeParams.size).then(function successCallback(res) { + $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) { @@ -573,11 +496,11 @@ orgsModule.controller('byTypeCtrl', function ($scope, $http, $routeParams, $loca }); $scope.prev = function() { - $location.url('/byType/' + ($scope.orgs.number - 1) + '/' + $scope.orgs.size + '/' + encodeURIComponent($scope.fieldValue)); + $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 + '/' + encodeURIComponent($scope.fieldValue)); + $location.url('/byType/' + ($scope.orgs.number + 1) + '/' + $scope.orgs.size + '/' + $routeParams.status + '/' + encodeURIComponent($scope.fieldValue)); } }); @@ -612,62 +535,35 @@ orgsModule.controller('showEditCtrl', function ($scope, $http, $routeParams, $ro }); -orgsModule.controller('showSuggestionsCtrl', function ($scope, $http, $routeParams, $location) { - $scope.info = {}; - $scope.pendingOrgs = []; - $scope.duplicates = []; - $scope.conflicts = []; - $scope.currentTab = $routeParams.tab; +orgsModule.controller('pendingOrgsCtrl', function ($scope, $http, $routeParams, $location, suggestionInfo) { + $scope.info = suggestionInfo.getInfo(); + $scope.orgs = []; $scope.country = $routeParams.country; $scope.getInfo = function() { - $http.get('api/organizations/suggestionsInfo').then(function successCallback(res) { - if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); } - $scope.info = res.data; - if ($scope.country == '_') { - var found = ''; - - angular.forEach($scope.info.byCountry, function(values, c) { - if (!found && (($scope.currentTab == 0 && values.nPendingOrgs > 0) || ($scope.currentTab == 1 && values.nDuplicates > 0) || ($scope.currentTab == 2 && values.nConflicts > 0))) { - found = c; - } - }); - if (found) { $location.url('/suggestions/' + found + '/' + $scope.currentTab); } - } - }, function errorCallback(res) { - alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')'); + 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.pendingOrgs = []; - $scope.duplicates = []; - $scope.conflicts = []; + $scope.orgs = []; if ($scope.country != '_') { - if ($scope.currentTab == 0) { - $http.get('api/organizations/byCountry/pending/' + $scope.country).then(function successCallback(res) { - if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); } - $scope.pendingOrgs = res.data; - }, function errorCallback(res) { - alert('ERROR: ' + res.data.error + ' (' + res.data.message + ')'); - }); - } else if ($scope.currentTab == 1) { - $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 + ')'); - }); - } else if ($scope.currentTab == 2) { - $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 + ')'); - }); - } else { } + $http.get('api/organizations/byCountry/pending/' + $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(); } @@ -675,6 +571,143 @@ orgsModule.controller('showSuggestionsCtrl', function ($scope, $http, $routePara $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 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 = []; diff --git a/apps/dnet-orgs-database-application/src/main/resources/templates/home.html b/apps/dnet-orgs-database-application/src/main/resources/templates/home.html index f7a6a0de..e6a6d090 100644 --- a/apps/dnet-orgs-database-application/src/main/resources/templates/home.html +++ b/apps/dnet-orgs-database-application/src/main/resources/templates/home.html @@ -15,16 +15,9 @@ @@ -33,7 +26,7 @@ fieldset > legend { -