[Connect|Trunk]

Search communities: use newsearchpage component


git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-connect-portal/trunk@58567 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
argiro.kokogiannaki 2020-04-28 08:05:03 +00:00
parent b83ec64b45
commit 0858643a4a
2 changed files with 36 additions and 17 deletions

View File

@ -5,7 +5,7 @@ import {ErrorCodes} from "../../openaireLibrary/utils/properties/errorCodes";
import {EnvProperties} from "../../openaireLibrary/utils/properties/env-properties";
import {SearchPageComponent} from "../../openaireLibrary/searchPages/searchUtils/searchPage.component";
import {ActivatedRoute} from "@angular/router";
import {Filter, Value} from "../../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class";
import {AdvancedField, Filter, Value} from "../../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class";
import {SearchFields} from "../../openaireLibrary/utils/properties/searchFields";
import {CommunitiesService} from "../../openaireLibrary/connect/communities/communities.service";
import {Session, User} from "../../openaireLibrary/login/utils/helper.class";
@ -15,22 +15,28 @@ import {StringUtils} from "../../openaireLibrary/utils/string-utils.class";
import {HelperFunctions} from "../../openaireLibrary/utils/HelperFunctions.class";
import {UserManagementService} from "../../openaireLibrary/services/user-management.service";
import {Breadcrumb} from "../../openaireLibrary/utils/breadcrumbs/breadcrumbs.component";
import {NewSearchPageComponent} from "../../openaireLibrary/searchPages/searchUtils/newSearchPage.component";
@Component({
selector: 'search-communities',
template: `
<search-page pageTitle="OpenAIRE-Connect | Search Communities"
<new-search-page pageTitle="OpenAIRE-Connect | Search Communities"
[hasPrefix]=false [piwikSiteId]="piwikSiteId"
searchFormClass="communitiesSearchForm"
[formPlaceholderText]="'Search for Research Gateways…'"
type="communities" entityType="community" [filters]="filters"
[results]="results" [searchUtils]="searchUtils"
[showResultCount]=true [baseUrl]="baseUrl"
[showResultCount]=true
[disableForms]="disableForms"
[lastIndex]=false [sort]=true
[breadcrumbs]="breadcrumbs"
[showType]="showType">
</search-page>
[lastIndex]=false [sort]=true
[simpleView]="true"
[fieldIds]="fieldIds" [fieldIdsMap]="fieldIdsMap" [selectedFields]="selectedFields"
[simpleSearchLink]="searchLink" [entitiesSelection]="false" [showBreadcrumb]="true"
>
</new-search-page>
<!-- [baseUrl]="baseUrl"-->
<!-- [breadcrumbs]="breadcrumbs"
[showType]="showType"-->
`
})
export class SearchCommunitiesComponent {
@ -45,11 +51,15 @@ export class SearchCommunitiesComponent {
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
public disableForms: boolean = false;
public baseUrl: string = null;
public fieldIds: string[] = ["q"];
public refineFields: string[] = this.searchFields.COMMUNITIES_SEARCH_FIELDS;
public fieldIdsMap = {["q"]:{name:"All fields", type:"keyword", param:"q", operator: "op", equalityOperator: "=", filterType: null}};
public selectedFields: AdvancedField[] = [new AdvancedField(this.fieldIds[0], "", this.fieldIdsMap[this.fieldIds[0]].name, this.fieldIdsMap[this.fieldIds[0]].type,"", "and")];
public searchLink;
public showType = false;
public breadcrumbs: Breadcrumb[] = [{name: 'home', route: '/'}, {name: 'communities'}];
properties:EnvProperties;
@ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
@ViewChild (NewSearchPageComponent) searchPage : NewSearchPageComponent ;
private user: User;
constructor (private route: ActivatedRoute,
@ -70,10 +80,11 @@ export class SearchCommunitiesComponent {
});
this.sub = this.route.queryParams.subscribe(params => {
this.searchPage.resultsPerPage = 10;
this.searchUtils.keyword = (params['keyword']?params['keyword']:'');
this.searchUtils.keyword = (params['fv0']?params['fv0']:'');
this.searchUtils.page = (params['page'] === undefined) ? 1: + params['page'];
this.searchUtils.sortBy = (params['sortBy'] === undefined)? '' : params['sortBy'];
this.searchUtils.size = (params['size'] === undefined) ? this.searchPage.resultsPerPage: +params['size'];
this.searchUtils.baseUrl = this.baseUrl;
this.searchPage.searchUtils = this.searchUtils;
if(this.searchUtils.size != 5 && this.searchUtils.size != 10 && this.searchUtils.size != 20 && this.searchUtils.size != 50) {
this.searchUtils.size = this.searchPage.resultsPerPage;
@ -82,7 +93,11 @@ export class SearchCommunitiesComponent {
this.searchUtils.sortBy = "";
}
this.searchPage.refineFields = this.refineFields;
let queryParams = this.searchPage.getQueryParamsFromUrl(params);
this.searchLink = this.properties.searchLinkToCommunities;
this.selectedFields[0] = new AdvancedField(this.fieldIds[0], "", this.fieldIdsMap[this.fieldIds[0]].name, this.fieldIdsMap[this.fieldIds[0]].type,this.searchUtils.keyword, "and");
this.searchPage.prepareSearchPage(this.fieldIds, this.selectedFields, this.refineFields,[], this.fieldIdsMap,null,params, "community", null);
let queryParams = params;//this.searchPage.getQueryParamsFromUrl(params);
if(typeof document !== 'undefined') {
this.userManagementService.getUserInfo().subscribe(user => {
this.user = user;
@ -108,7 +123,7 @@ export class SearchCommunitiesComponent {
*
* @param params
*/
private initCommunities(params: Map<string, string>) {
private initCommunities(params) {
this.subResults = this._communitiesService.getCommunitiesState().subscribe(
data => {
if(!data){
@ -203,8 +218,11 @@ export class SearchCommunitiesComponent {
this.checkFilters(params);
this.sort();
this.searchUtils.totalResults = this.results.length;
this.searchPage.checkSelectedFilters(this.filters);
this.searchPage.updateBaseUrlWithParameters(this.filters);
// this.searchPage.checkSelectedFilters(this.filters);
// this.searchPage.updateBaseUrlWithParameters(this.filters);
// this.searchPage.buildPageURLParameters(this.filters, [], false);
this.filters = this.searchPage.prepareFiltersToShow(this.filters,this.searchUtils.totalResults);
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 ){
@ -286,11 +304,11 @@ export class SearchCommunitiesComponent {
* @param filterId
* @param params
*/
private applyFilter(filterId: string, params: Map<string, string>): CommunityInfo[] {
private applyFilter(filterId: string, params): CommunityInfo[] {
let results:CommunityInfo[] = [];
let values: string[] = [];
if(params.get(filterId) != undefined) {
values = (StringUtils.URIDecode(params.get(filterId))).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,-1);
if(params[filterId] != undefined) {
values = (StringUtils.URIDecode(params[filterId])).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,-1);
}
if(filterId == 'type') {
for (let i = 0; i < this.results.length; i++) {

View File

@ -6,12 +6,13 @@ import {SearchPageModule} from "../../openaireLibrary/searchPages/searchUtils/se
import {SearchFormModule} from "../../openaireLibrary/searchPages/searchUtils/searchForm.module";
import {SearchCommunitiesRoutingModule} from "./searchCommunities-routing.module";
import {PreviousRouteRecorder} from "../../openaireLibrary/utils/piwik/previousRouteRecorder.guard";
import {NewSearchPageModule} from "../../openaireLibrary/searchPages/searchUtils/newSearchPage.module";
@NgModule({
imports: [
CommonModule, FormsModule,
SearchFormModule, SearchPageModule,
SearchCommunitiesRoutingModule
SearchCommunitiesRoutingModule, NewSearchPageModule
],
declarations: [
SearchCommunitiesComponent