diff --git a/src/app/searchPages/communities/searchCommunities.component.ts b/src/app/searchPages/communities/searchCommunities.component.ts index 0f862eb..8bbd2ec 100644 --- a/src/app/searchPages/communities/searchCommunities.component.ts +++ b/src/app/searchPages/communities/searchCommunities.component.ts @@ -20,12 +20,13 @@ import {HelperFunctions} from "../../openaireLibrary/utils/HelperFunctions.class + [lastIndex]=false [sort]=true + [showType]="showType"> ` }) @@ -42,6 +43,7 @@ export class SearchCommunitiesComponent { public disableForms: boolean = false; public baseUrl: string = null; public refineFields: string[] = this.searchFields.COMMUNITIES_SEARCH_FIELDS; + public showType = false; properties:EnvProperties; @ViewChild (SearchPageComponent) searchPage : SearchPageComponent ; @@ -75,7 +77,6 @@ export class SearchCommunitiesComponent { } this.searchPage.refineFields = this.refineFields; let queryParams = this.searchPage.getQueryParamsFromUrl(params); - this.filters = this.createFilters(); this.initCommunities(queryParams); }); @@ -105,9 +106,6 @@ export class SearchCommunitiesComponent { this.totalResults[i] = data[i]; this.totalResults[i].isManager = false; this.totalResults[i].isSubscribed = false; - // For Test do not delete them. - //this.results[i].description = "EGI is a federated e-Infrastructure set up to provide advanced computing services for research and innovation.EGI is a federated e-Infrastructure set up to provide advanced computing services for research and innovation.EGI is a federated e-Infrastructure set up to provide advanced computing services for research and innovation." - //this.results[i].date = new Date(new Date(2012, 0, 1).getTime() + Math.random() * (new Date().getTime() - new Date(2012, 0, 1).getTime())); if(Session.isLoggedIn()) { this.totalResults[i].isManager = this.isCommunityManager(this.totalResults[i]); } @@ -147,6 +145,9 @@ export class SearchCommunitiesComponent { this.searchUtils.status = this.errorCodes.LOADING; this.disableForms = true; this.results = this.totalResults; + if(this.filters.length === 0) { + this.filters = this.createFilters(); + } this.searchUtils.totalResults = 0; this.applyParams(params); } @@ -432,25 +433,30 @@ export class SearchCommunitiesComponent { * */ private createFilters(): Filter[] { - let filter_names=["Type"]; - let filter_ids=["type"]; + let filter_names = []; + let filter_ids = []; let searchFields = new SearchFields(); let filter_original_ids = searchFields.COMMUNITIES_SEARCH_FIELDS; - let value_names = [ - [ "Research Communities", "Research Initiatives" ] - ]; - let value_original_ids=[ - ["community","ri"] - ]; + let value_names = []; + let value_original_ids=[]; + this.showType = this.results.filter(community => community.type === 'ri').length > 0; + if(this.showType) { + filter_names.push("Type"); + filter_ids.push("type"); + value_names.push([ "Research Communities", "Research Initiatives" ]); + value_original_ids.push(["community","ri"]); + } else { + filter_original_ids = searchFields.COMMUNITIES_SEARCH_FIELDS.splice(0, 1); + } if(Session.isLoggedIn()) { - filter_names[1] = "Status"; - filter_ids[1] = "status"; - value_names[1] = [ "Subscribed", "Non-subscribed"]; - value_original_ids[1] = ["subscribed", "nonsubscribed"]; - filter_names[2] = "Role"; - filter_ids[2] = "role"; - value_names[2] = [ "Manager" ]; - value_original_ids[2] = ["manager"]; + filter_names.push("Status"); + filter_ids.push("status"); + value_names.push([ "Subscribed", "Non-subscribed"]); + value_original_ids.push(["subscribed", "nonsubscribed"]); + filter_names.push("Role"); + filter_ids.push("role"); + value_names.push([ "Manager"]); + value_original_ids.push(["manager"]); } let filters: Filter[] = []; for(let i =0 ; i < filter_names.length; i++){