simple search filtered using status field
This commit is contained in:
parent
035fa98228
commit
d76b9c97b5
|
@ -236,10 +236,12 @@ public class OrganizationController {
|
||||||
public Page<OrganizationSimpleView> search(@PathVariable final int page,
|
public Page<OrganizationSimpleView> search(@PathVariable final int page,
|
||||||
@PathVariable final int size,
|
@PathVariable final int size,
|
||||||
@RequestParam final String q,
|
@RequestParam final String q,
|
||||||
|
@RequestParam(required = false, defaultValue = "suggested,approved") final String status,
|
||||||
final Authentication authentication) {
|
final Authentication authentication) {
|
||||||
|
|
||||||
return UserInfo.isSuperAdmin(authentication)
|
return UserInfo.isSuperAdmin(authentication)
|
||||||
? organizationSimpleViewRepository.search(q, PageRequest.of(page, size))
|
? organizationSimpleViewRepository.search(q, Arrays.asList(status.split(",")), PageRequest.of(page, size))
|
||||||
: organizationSimpleViewRepository.searchForUser(q, authentication.getName(), PageRequest.of(page, size));
|
: organizationSimpleViewRepository.searchForUser(q, authentication.getName(), Arrays.asList(status.split(",")), PageRequest.of(page, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/byCountry/{status}/{code}/{page}/{size}")
|
@GetMapping("/byCountry/{status}/{code}/{page}/{size}")
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package eu.dnetlib.organizations.repository.readonly;
|
package eu.dnetlib.organizations.repository.readonly;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
@ -12,12 +14,15 @@ import eu.dnetlib.organizations.model.view.OrganizationSimpleView;
|
||||||
public interface OrganizationSimpleViewRepository extends ReadOnlyRepository<OrganizationSimpleView, String> {
|
public interface OrganizationSimpleViewRepository extends ReadOnlyRepository<OrganizationSimpleView, String> {
|
||||||
|
|
||||||
// SEARCH
|
// SEARCH
|
||||||
@Query(value = "select o.* from organizations_simple_view o left outer join org_index_search idx on (idx.id = o.id) where idx.txt @@ plainto_tsquery(:text) order by o.name", nativeQuery = true)
|
@Query(value = "select o.* from organizations_simple_view o left outer join org_index_search idx on (idx.id = o.id) where idx.txt @@ plainto_tsquery(:text) and o.status in :statuses order by o.name", nativeQuery = true)
|
||||||
Page<OrganizationSimpleView> search(@Param("text") String text, Pageable pageable);
|
Page<OrganizationSimpleView> search(@Param("text") String text, @Param("statuses") List<String> statuses, Pageable pageable);
|
||||||
|
|
||||||
// SEARCH FOR USER
|
// SEARCH FOR USER
|
||||||
@Query(value = "select o.* from organizations_simple_view o left outer join org_index_search idx on (idx.id = o.id) left outer join user_countries uc on (uc.country = o.country) where idx.txt @@ plainto_tsquery(:text) and uc.email = :email order by o.name", nativeQuery = true)
|
@Query(value = "select o.* from organizations_simple_view o left outer join org_index_search idx on (idx.id = o.id) left outer join user_countries uc on (uc.country = o.country) where idx.txt @@ plainto_tsquery(:text) and uc.email = :email and o.status in :statuses order by o.name", nativeQuery = true)
|
||||||
Page<OrganizationSimpleView> searchForUser(@Param("text") String text, @Param("email") String email, Pageable pageable);
|
Page<OrganizationSimpleView> searchForUser(@Param("text") String text,
|
||||||
|
@Param("email") String email,
|
||||||
|
@Param("statuses") List<String> statuses,
|
||||||
|
Pageable pageable);
|
||||||
|
|
||||||
Page<OrganizationSimpleView> findByCountryOrderByName(String country, Pageable pageable);
|
Page<OrganizationSimpleView> findByCountryOrderByName(String country, Pageable pageable);
|
||||||
|
|
||||||
|
|
|
@ -309,4 +309,4 @@
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
||||||
<select-org-modal modal-id="selectRelatedOrgModal" selected-org="newRelation"></select-org-modal>
|
<select-org-modal modal-id="selectRelatedOrgModal" selected-org="newRelation" filter-status="approved"></select-org-modal>
|
||||||
|
|
|
@ -50,6 +50,7 @@ orgsModule.directive('selectOrgModal', function($http) {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
scope: {
|
scope: {
|
||||||
'modalId' : '@',
|
'modalId' : '@',
|
||||||
|
'filterStatus' : '@',
|
||||||
'selectedOrg' : '='
|
'selectedOrg' : '='
|
||||||
},
|
},
|
||||||
templateUrl: 'resources/html/modals/select_org.html',
|
templateUrl: 'resources/html/modals/select_org.html',
|
||||||
|
@ -60,7 +61,7 @@ orgsModule.directive('selectOrgModal', function($http) {
|
||||||
scope.search = function(text, page, size) {
|
scope.search = function(text, page, size) {
|
||||||
scope.searchOrgs = {};
|
scope.searchOrgs = {};
|
||||||
|
|
||||||
$http.get('api/organizations/search/' + page + '/' + size + '?q=' + text).then(function successCallback(res) {
|
$http.get('api/organizations/search/' + page + '/' + size + '?status='+ scope.filterStatus + '&q=' + text).then(function successCallback(res) {
|
||||||
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
if((typeof res.data) == 'string') { alert("Session expired !"); location.reload(true); }
|
||||||
scope.searchValue = text;
|
scope.searchValue = text;
|
||||||
scope.searchOrgs = res.data;
|
scope.searchOrgs = res.data;
|
||||||
|
|
Loading…
Reference in New Issue