page and sorting
This commit is contained in:
parent
6d491345fe
commit
d36c9b7a5e
|
@ -234,10 +234,12 @@ public class OrganizationController extends AbstractDnetController {
|
|||
@RequestParam(required = false, defaultValue = "false") final boolean reverse,
|
||||
final Authentication authentication) {
|
||||
|
||||
final PageRequest pageRequest = PageRequest.of(page, size, Sort.by(reverse ? Order.desc(orderBy) : Order.asc(orderBy)));
|
||||
|
||||
if (SPECIAL_STATUS_FOR_CANDIDATE_DUP.equals(status)) {
|
||||
return UserInfo.isSuperAdmin(authentication)
|
||||
? organizationSimpleViewRepository.searchCandidateDuplicates(q, PageRequest.of(page, size))
|
||||
: organizationSimpleViewRepository.searchCandidateDuplicatesForUser(q, UserInfo.getEmail(authentication), PageRequest.of(page, size));
|
||||
? organizationSimpleViewRepository.searchCandidateDuplicates(q, pageRequest)
|
||||
: organizationSimpleViewRepository.searchCandidateDuplicatesForUser(q, UserInfo.getEmail(authentication), pageRequest);
|
||||
}
|
||||
final List<String> statuses;
|
||||
if (StringUtils.isNotBlank(status)) {
|
||||
|
@ -248,8 +250,6 @@ public class OrganizationController extends AbstractDnetController {
|
|||
statuses = Arrays.asList(OrganizationStatus.approved.toString(), OrganizationStatus.suggested.toString());
|
||||
}
|
||||
|
||||
final PageRequest pageRequest = PageRequest.of(page, size, Sort.by(reverse ? Order.desc(orderBy) : Order.asc(orderBy)));
|
||||
|
||||
return UserInfo.isSuperAdmin(authentication)
|
||||
? organizationSimpleViewRepository.search(q, statuses, pageRequest)
|
||||
: organizationSimpleViewRepository.searchForUser(q, UserInfo.getEmail(authentication), statuses, pageRequest);
|
||||
|
|
|
@ -77,12 +77,12 @@ public interface OrganizationSimpleViewRepository extends ReadOnlyRepository<Org
|
|||
|
||||
// SEARCH FOR VALID DUPLICATE CANDIDATES
|
||||
@Query(value = "SELECT\n"
|
||||
+ " org.id,\n"
|
||||
+ " org.name,\n"
|
||||
+ " org.type,\n"
|
||||
+ " org.city,\n"
|
||||
+ " org.country,\n"
|
||||
+ " org.status,\n"
|
||||
+ " org.id AS id,\n"
|
||||
+ " org.name AS name,\n"
|
||||
+ " org.type AS type,\n"
|
||||
+ " org.city AS city,\n"
|
||||
+ " org.country AS country,\n"
|
||||
+ " org.status AS status,\n"
|
||||
+ " array_remove(array_agg(DISTINCT a.acronym), NULL) AS acronyms,\n"
|
||||
+ " array_remove(array_agg(DISTINCT u.url), NULL) AS urls,\n"
|
||||
+ " NULL AS n_similar_dups,\n"
|
||||
|
@ -95,18 +95,17 @@ public interface OrganizationSimpleViewRepository extends ReadOnlyRepository<Org
|
|||
+ " LEFT OUTER JOIN oa_duplicates d2 ON (org.id = d2.oa_original_id)\n"
|
||||
+ "WHERE org.status = 'raw' AND (org.name ilike '%'||:text||'%' OR idx.txt @@ plainto_tsquery(:text))\n"
|
||||
+ "GROUP BY org.id, org.name, org.type, org.city, org.country, org.status\n"
|
||||
+ "HAVING not('is_similar' = ANY(array_agg(d2.reltype)))\n"
|
||||
+ "ORDER BY org.name", nativeQuery = true)
|
||||
+ "HAVING not('is_similar' = ANY(array_agg(d2.reltype)))", nativeQuery = true)
|
||||
Page<OrganizationSimpleView> searchCandidateDuplicates(@Param("text") String text, Pageable pageable);
|
||||
|
||||
// SEARCH FOR VALID DUPLICATE CANDIDATES FOR USER
|
||||
@Query(value = "SELECT\n"
|
||||
+ " org.id,\n"
|
||||
+ " org.name,\n"
|
||||
+ " org.type,\n"
|
||||
+ " org.city,\n"
|
||||
+ " org.country,\n"
|
||||
+ " org.status,\n"
|
||||
+ " org.id AS id,\n"
|
||||
+ " org.name AS name,\n"
|
||||
+ " org.type AS type,\n"
|
||||
+ " org.city AS city,\n"
|
||||
+ " org.country AS country,\n"
|
||||
+ " org.status AS status,\n"
|
||||
+ " array_remove(array_agg(DISTINCT a.acronym), NULL) AS acronyms,\n"
|
||||
+ " array_remove(array_agg(DISTINCT u.url), NULL) AS urls,\n"
|
||||
+ " NULL AS n_similar_dups,\n"
|
||||
|
@ -120,8 +119,7 @@ public interface OrganizationSimpleViewRepository extends ReadOnlyRepository<Org
|
|||
+ " LEFT OUTER JOIN user_countries uc ON (uc.country = org.country)\n"
|
||||
+ "WHERE org.status = 'raw' AND uc.email = :email AND (org.name ilike '%'||:text||'%' OR idx.txt @@ plainto_tsquery(:text))\n"
|
||||
+ "GROUP BY org.id, org.name, org.type, org.city, org.country, org.status\n"
|
||||
+ "HAVING not('is_similar' = ANY(array_agg(d2.reltype)))\n"
|
||||
+ "ORDER BY org.name", nativeQuery = true)
|
||||
+ "HAVING not('is_similar' = ANY(array_agg(d2.reltype)))", nativeQuery = true)
|
||||
Page<OrganizationSimpleView> searchCandidateDuplicatesForUser(@Param("text") String text, @Param("email") String email, Pageable pageable);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<org-results-page search-message="Searching for type: {{fieldValue}}"
|
||||
orgs="orgs"
|
||||
page-function="pageByType(page, size)"
|
||||
page-function="pageByType()"
|
||||
show-status="1"
|
||||
show-n-dups="1"></org-results-page>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
{{searchMessage}}
|
||||
</span>
|
||||
<span ng-if="!(orgs.totalElements || orgs.totalElements === 0)">
|
||||
Total elements:<br />
|
||||
Total elements:<br />fr
|
||||
{{searchMessage}}
|
||||
</span>
|
||||
</p>
|
||||
|
@ -21,29 +21,41 @@
|
|||
<h4 ng-if="orgs.totalElements == 0" class="text-center">No results</h4>
|
||||
|
||||
<div ng-if="orgs.totalElements > 0">
|
||||
<div class="mb-2">
|
||||
<div class="dropdown float-left">
|
||||
<button class="btn btn-sm btn-outline-primary dropdown-toggle" type="button" data-toggle="dropdown">Sort by</button>
|
||||
<div class="dropdown-menu">
|
||||
<small>
|
||||
<h6 class="dropdown-header">Ascending</h6>
|
||||
<a class="dropdown-item ml-2" href="javascript:void(0)" ng-click="changeSort('name', 'asc')"><b>name</b></a>
|
||||
<a class="dropdown-item ml-2" href="javascript:void(0)" ng-click="changeSort('country', 'asc')"><b>country</b></a>
|
||||
<a class="dropdown-item ml-2" href="javascript:void(0)" ng-click="changeSort('type', 'asc')"><b>type</b></a>
|
||||
<a class="dropdown-item ml-2" href="javascript:void(0)" ng-click="changeSort('status', 'asc')"><b>status</b></a>
|
||||
<h6 class="dropdown-header">Descending</h6>
|
||||
<a class="dropdown-item ml-2" href="javascript:void(0)" ng-click="changeSort('name', 'desc')"><b>name</b></a>
|
||||
<a class="dropdown-item ml-2" href="javascript:void(0)" ng-click="changeSort('country', 'desc')"><b>country</b></a>
|
||||
<a class="dropdown-item ml-2" href="javascript:void(0)" ng-click="changeSort('type', 'desc')"><b>type</b></a>
|
||||
<a class="dropdown-item ml-2" href="javascript:void(0)" ng-click="changeSort('status', 'desc')"><b>status</b></a>
|
||||
<a class="dropdown-item ml-2" href="javascript:void(0)" ng-click="changeSort('n_similar_dups', 'desc')"><b># accepted dups</b></a>
|
||||
<a class="dropdown-item ml-2" href="javascript:void(0)" ng-click="changeSort('n_suggested_dups', 'desc')"><b># suggested dups</b></a>
|
||||
<a class="dropdown-item ml-2" href="javascript:void(0)" ng-click="changeSort('n_different_dups', 'desc')"><b># rejected dups</b></a>
|
||||
</small>
|
||||
<div class="row mb-4">
|
||||
<div class="col-sm">
|
||||
<div class="input-group input-group-sm">
|
||||
<div class="input-group-prepend">
|
||||
<button class="btn btn-sm btn-outline-primary dropdown-toggle" type="button" data-toggle="dropdown">
|
||||
Sort by
|
||||
<i ng-if="orderBy == 'name'">Name</i>
|
||||
<i ng-if="orderBy == 'country'">Country</i>
|
||||
<i ng-if="orderBy == 'type'">Type</i>
|
||||
<i ng-if="orderBy == 'status'">Status</i>
|
||||
<i ng-if="orderBy == 'n_similar_dups'"># accepted dups</i>
|
||||
<i ng-if="orderBy == 'n_suggested_dups'"># suggested dups</i>
|
||||
<i ng-if="orderBy == 'n_different_dups'"># rejected dups</i>
|
||||
</button>
|
||||
<div class="dropdown-menu">
|
||||
<small>
|
||||
<a class="dropdown-item" href="javascript:void(0)" ng-click="changeSortField('name')" ng-class="{'disabled': orderBy == 'name'}"><b>name</b></a>
|
||||
<a class="dropdown-item" href="javascript:void(0)" ng-click="changeSortField('country')" ng-class="{'disabled': orderBy == 'country'}"><b>country</b></a>
|
||||
<a class="dropdown-item" href="javascript:void(0)" ng-click="changeSortField('type')" ng-class="{'disabled': orderBy == 'type'}"><b>type</b></a>
|
||||
<a class="dropdown-item" href="javascript:void(0)" ng-click="changeSortField('status')" ng-class="{'disabled': orderBy == 'status'}" ng-if="show-status == 1"><b>status</b></a>
|
||||
<a class="dropdown-item" href="javascript:void(0)" ng-click="changeSortField('n_similar_dups')" ng-class="{'disabled': orderBy == 'n_similar_dups'}" ng-if="show-n-dups == 1"><b># accepted dups</b></a>
|
||||
<a class="dropdown-item" href="javascript:void(0)" ng-click="changeSortField('n_suggested_dups')" ng-class="{'disabled': orderBy == 'n_suggested_dups'}" ng-if="show-n-dups == 1"><b># suggested dups</b></a>
|
||||
<a class="dropdown-item" href="javascript:void(0)" ng-click="changeSortField('n_different_dups')" ng-class="{'disabled': orderBy == 'n_different_dups'}" ng-if="show-n-dups == 1"><b># rejected dups</b></a>
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="input-group-append">
|
||||
<div class="input-group-text">
|
||||
<input class="input-sm mr-2" type="checkbox" ng-click="changeSortOrder()" ng-checked="orderType == 'desc'" /> reverse
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text-center">
|
||||
<div class="col-sm text-center">
|
||||
<div class="btn-group">
|
||||
<button class="btn btn-sm btn-outline-primary" ng-click="gotoPage(orgs.number - 1, orgs.size)" ng-disabled="orgs.first">« Previous</button>
|
||||
<div class="dropdown">
|
||||
|
@ -67,7 +79,9 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<input type="text" class="form-control mt-2" ng-model="orgsFilter" placeholder="Filter in current page..." />
|
||||
<div class="col-sm">
|
||||
<input type="text" class="form-control float-right" style="max-width: 250px;" ng-model="orgsFilter" placeholder="Filter in current page..." />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p ng-if="mode == 'select-modal'">Click the <b>organization name</b> to select the organization</p>
|
||||
|
@ -95,7 +109,6 @@
|
|||
|
||||
<a ng-if="mode != 'select-modal' && mode != 'multi-select-modal'" href="#!/edit/0/{{o.id}}" title="{{o.id}}">{{o.name}}</a>
|
||||
|
||||
|
||||
<span ng-if="mode == 'select-modal' || mode == 'multi-select-modal'" class="small" ng-repeat="ourl in o.urls"><br /><b>URL: </b><a href="{{ourl}}" target="_blank" ng-if="ourl">{{ourl}}</a></span>
|
||||
</td>
|
||||
<td ng-class="{'col-3' : showNDups, 'col-4' : !showNDups }"><img ng-src="resources/images/flags/{{o.country}}.gif" /> {{o.city || '-'}}, {{o.country}}</td>
|
||||
|
|
|
@ -62,8 +62,10 @@ orgsModule.directive('selectOrgModal', function($http) {
|
|||
|
||||
scope.search = function(text) {
|
||||
scope.searchOrgs = {};
|
||||
|
||||
call_http_get($http, 'api/organizations/search/0/25?status='+ scope.filterStatus + '&q=' + text, function(res) {
|
||||
|
||||
var url = 'api/organizations/search/0/50?orderBy=name&status='+ scope.filterStatus + '&q=' + text;
|
||||
|
||||
call_http_get($http, url, function(res) {
|
||||
scope.searchValue = text;
|
||||
scope.searchOrgs = res.data;
|
||||
});
|
||||
|
@ -227,6 +229,11 @@ orgsModule.directive('orgResultsPage', function($http, $location, $route, $route
|
|||
},
|
||||
templateUrl: 'resources/html/parts/org_results_page.html',
|
||||
link: function(scope, element, attrs, ctrl) {
|
||||
|
||||
scope.orderBy = $routeParams.orderBy ? $routeParams.orderBy : 'name';
|
||||
scope.orderType = $routeParams.orderType ? $routeParams.orderType : 'asc';
|
||||
scope.size = $routeParams.size ? $routeParams.size : 50;
|
||||
|
||||
scope.selectOrg = function(o) {
|
||||
o.selected = true;
|
||||
|
||||
|
@ -251,29 +258,38 @@ orgsModule.directive('orgResultsPage', function($http, $location, $route, $route
|
|||
return input;
|
||||
}
|
||||
|
||||
scope.gotoPageAndSort = function(page, pageSize, orderBy, orderType) {
|
||||
scope.gotoPage = function(page, pageSize) {
|
||||
var url = scope.pageFunction()
|
||||
.replace(/__PAGE__/, page)
|
||||
.replace(/__SIZE__/, pageSize)
|
||||
.replace(/__ORDER_BY__/, orderBy)
|
||||
.replace(/__ORDER_TYPE__/, orderType);
|
||||
.replace(/__ORDER_BY__/, scope.orderBy)
|
||||
.replace(/__ORDER_TYPE__/, scope.orderType);
|
||||
|
||||
if (scope.mode == 'select-modal' || scope.mode == 'multi-select-modal') {
|
||||
url += '&orderBy=' + scope.orderBy;
|
||||
if (scope.orderType == 'desc') {
|
||||
url += '&reverse=true';
|
||||
}
|
||||
|
||||
scope.orgs = {};
|
||||
call_http_get($http, url, function(res) {
|
||||
scope.orgs = res.data;
|
||||
scope.size = res.data.size;
|
||||
});
|
||||
} else {
|
||||
$location.url(url);
|
||||
}
|
||||
}
|
||||
|
||||
scope.changeSort = function(orderBy, orderType) {
|
||||
scope.gotoPageAndSort(0, $routeParams.size, orderBy, orderType);
|
||||
scope.changeSortField = function(orderBy) {
|
||||
scope.orderBy = orderBy;
|
||||
scope.gotoPage(0, scope.size);
|
||||
}
|
||||
|
||||
scope.gotoPage = function(page, pageSize) {
|
||||
scope.gotoPageAndSort(page, pageSize, $routeParams.orderBy, $routeParams.orderType);
|
||||
scope.changeSortOrder = function() {
|
||||
if (scope.orderType == 'desc') { scope.orderType = 'asc'; }
|
||||
else { scope.orderType = 'desc'; }
|
||||
scope.gotoPage(0, scope.size);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue