simple search filtered using status field

This commit is contained in:
Michele Artini 2020-10-21 15:31:31 +02:00
parent 035fa98228
commit d76b9c97b5
4 changed files with 16 additions and 8 deletions

View File

@ -236,10 +236,12 @@ public class OrganizationController {
public Page<OrganizationSimpleView> search(@PathVariable final int page,
@PathVariable final int size,
@RequestParam final String q,
@RequestParam(required = false, defaultValue = "suggested,approved") final String status,
final Authentication authentication) {
return UserInfo.isSuperAdmin(authentication)
? organizationSimpleViewRepository.search(q, PageRequest.of(page, size))
: organizationSimpleViewRepository.searchForUser(q, authentication.getName(), PageRequest.of(page, size));
? organizationSimpleViewRepository.search(q, Arrays.asList(status.split(",")), PageRequest.of(page, size))
: organizationSimpleViewRepository.searchForUser(q, authentication.getName(), Arrays.asList(status.split(",")), PageRequest.of(page, size));
}
@GetMapping("/byCountry/{status}/{code}/{page}/{size}")

View File

@ -1,5 +1,7 @@
package eu.dnetlib.organizations.repository.readonly;
import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
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> {
// 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)
Page<OrganizationSimpleView> search(@Param("text") String text, Pageable pageable);
@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, @Param("statuses") List<String> statuses, Pageable pageable);
// 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)
Page<OrganizationSimpleView> searchForUser(@Param("text") String text, @Param("email") String email, Pageable pageable);
@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,
@Param("statuses") List<String> statuses,
Pageable pageable);
Page<OrganizationSimpleView> findByCountryOrderByName(String country, Pageable pageable);

View File

@ -309,4 +309,4 @@
</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>

View File

@ -50,6 +50,7 @@ orgsModule.directive('selectOrgModal', function($http) {
restrict: 'E',
scope: {
'modalId' : '@',
'filterStatus' : '@',
'selectedOrg' : '='
},
templateUrl: 'resources/html/modals/select_org.html',
@ -60,7 +61,7 @@ orgsModule.directive('selectOrgModal', function($http) {
scope.search = function(text, page, size) {
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); }
scope.searchValue = text;
scope.searchOrgs = res.data;