[Trunk|Connect]: Search Communities: failed at subscription service, fetch the results

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-connect-portal/trunk@55324 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2019-04-12 14:16:08 +00:00
parent 752228d106
commit 47c003bb04
1 changed files with 45 additions and 32 deletions

View File

@ -21,7 +21,7 @@ import {PiwikService} from "../../openaireLibrary/utils/piwik/piwik.service";
template: `
<search-page pageTitle="OpenAIRE Connect|Search Communities"
formPlaceholderText="Search for Research Communities and Initiatives"
type="results" entityType="community" [filters]="filters"
type="communities" entityType="community" [filters]="filters"
[results]="results" [searchUtils]="searchUtils"
[showResultCount]=true [baseUrl]="baseUrl"
(queryChange)="queryChanged($event)"
@ -120,7 +120,7 @@ export class SearchCommunitiesComponent {
/**
* Get all communities from Communities API and apply permission access validator,
* if a keyword is included, filter, paging and sorting.
* keyword searching, filter, paging and sorting.
*
* @param params
* @private
@ -147,39 +147,11 @@ export class SearchCommunitiesComponent {
for(let i = 0; i < res.length; i++) {
this.results[i].isSubscribed = res[i];
}
this.showCommunities();
if(this.searchUtils.keyword && this.searchUtils.keyword != '') {
this.searchForKeywords();
}
this.checkFilters(params);
this.sort();
this.searchUtils.totalResults = this.results.length;
this.searchPage.checkSelectedFilters(this.filters);
this.searchPage.updateBaseUrlWithParameters(this.filters);
this.results = this.results.slice((this.searchUtils.page-1)*this.searchUtils.size, (this.searchUtils.page*this.searchUtils.size));
this.searchUtils.status = this.errorCodes.DONE;
if(this.searchUtils.totalResults == 0 ){
this.searchUtils.status = this.errorCodes.NONE;
}
this.disableForms = false;
if(this.searchUtils.status == this.errorCodes.DONE) {
// Page out of limit!!!
let totalPages:any = this.searchUtils.totalResults/(this.searchUtils.size);
if(!(Number.isInteger(totalPages))) {
totalPages = (parseInt(totalPages, 10) + 1);
}
if(totalPages < this.searchUtils.page) {
this.searchUtils.totalResults = 0;
this.searchUtils.status = this.errorCodes.OUT_OF_BOUND;
}
}
this.scroll();
this.applyParams(params, this.errorCodes.DONE);
},
err => {
this.handleError('Error getting if user is subscribed', err);
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
this.disableForms = false;
this.scroll();
this.applyParams(params, this.errorCodes.MISSING_CONTENT);
}
);
},
@ -193,6 +165,47 @@ export class SearchCommunitiesComponent {
);
}
/**
* Apply permission access validator,
* keyword searching, filter, paging and sorting.
*
* @param params
* @param status
*/
public applyParams(params: Map<string, string>, status: number) {
this.showCommunities();
if(this.searchUtils.keyword && this.searchUtils.keyword != '') {
this.searchForKeywords();
}
this.checkFilters(params);
this.sort();
this.searchUtils.totalResults = this.results.length;
this.searchPage.checkSelectedFilters(this.filters);
this.searchPage.updateBaseUrlWithParameters(this.filters);
this.results = this.results.slice((this.searchUtils.page-1)*this.searchUtils.size, (this.searchUtils.page*this.searchUtils.size));
this.searchUtils.status = status;
if(this.searchUtils.totalResults == 0 ){
this.searchUtils.status = this.errorCodes.NONE;
}
else if(this.searchUtils.totalResults == 1 ){
this.searchPage.type = this.searchPage.entityType;
}
this.disableForms = false;
if(this.searchUtils.status == status) {
// Page out of limit!!!
let totalPages:any = this.searchUtils.totalResults/(this.searchUtils.size);
if(!(Number.isInteger(totalPages))) {
totalPages = (parseInt(totalPages, 10) + 1);
}
if(totalPages < this.searchUtils.page) {
this.searchUtils.totalResults = 0;
this.searchUtils.status = this.errorCodes.OUT_OF_BOUND;
}
}
this.scroll();
}
/**
* Parse the given keywords into array and check if any of the requirements field of a community includes
* one of the given words.