national_admin_functions #1

Manually merged
michele.artini merged 75 commits from national_admin_functions into master 2020-10-26 08:32:19 +01:00
4 changed files with 16 additions and 8 deletions
Showing only changes of commit c8f1e08b57 - Show all commits

View File

@ -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}")

View File

@ -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);

View File

@ -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>

View File

@ -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;