From a8a00b386e2281a48a8274947f0911dcec693c5f Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Fri, 12 Apr 2019 09:50:10 +0000 Subject: [PATCH] [Trunk|Connect]: 1. Add Piwiki on search Communities page and change the title of the page. 2. Add apply filter method on search Communities page git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-connect-portal/trunk@55295 d315682c-612b-4755-9ff5-7f18f6832af3 --- .../searchCommunities.component.ts | 184 +++++++++--------- .../communities/searchCommunities.module.ts | 3 +- 2 files changed, 99 insertions(+), 88 deletions(-) diff --git a/src/app/searchPages/communities/searchCommunities.component.ts b/src/app/searchPages/communities/searchCommunities.component.ts index 7de1f5d..ee72df9 100644 --- a/src/app/searchPages/communities/searchCommunities.component.ts +++ b/src/app/searchPages/communities/searchCommunities.component.ts @@ -14,11 +14,12 @@ import {SearchResult} from "../../openaireLibrary/utils/entities/searchResult"; import {SubscribeService} from "../../openaireLibrary/utils/subscribe/subscribe.service"; import {Observable} from "rxjs"; import {StringUtils} from "../../openaireLibrary/utils/string-utils.class"; +import {PiwikService} from "../../openaireLibrary/utils/piwik/piwik.service"; @Component({ selector: 'search-communities', template: ` - { this.properties = data.envSpecific; this.baseUrl = data.envSpecific.searchLinkToCommunities; + if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){ + this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE Connect|Search Communities", this.properties.piwikSiteId).subscribe(); + } }); this.sub = this.route.queryParams.subscribe(params => { this.searchPage.resultsPerPage = 5; @@ -88,9 +94,9 @@ export class SearchCommunitiesComponent { } - /** - * Return the communities in which user has permission to view or manage. - */ + /** + * Return the communities in which user has permission to view or manage. + */ private showCommunities() { let ret: SearchResult[] = []; for(let result of this.results) { @@ -112,13 +118,13 @@ export class SearchCommunitiesComponent { this.results = ret; } - /** - * Get all communities from Communities API and apply permission access validator, - * if a keyword is included, filter, paging and sorting. - * - * @param params - * @private - */ + /** + * Get all communities from Communities API and apply permission access validator, + * if a keyword is included, filter, paging and sorting. + * + * @param params + * @private + */ private _getResults(params: Map){ this.searchUtils.status = this.errorCodes.LOADING; this.disableForms = true; @@ -187,10 +193,10 @@ export class SearchCommunitiesComponent { ); } - /** - * Parse the given keywords into array and check if any of the requirements field of a community includes - * one of the given words. - */ + /** + * Parse the given keywords into array and check if any of the requirements field of a community includes + * one of the given words. + */ private searchForKeywords() { let ret: SearchResult[] = []; let keywords: string[] = this.searchUtils.keyword.split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,-1); @@ -206,78 +212,16 @@ export class SearchCommunitiesComponent { this.results = ret; } - /** - * Check the current results if they satisfy the values of each filter category and - * update the number of possible results in each value. - * - * @param params - */ + /** + * Check the current results if they satisfy the values of each filter category and + * update the number of possible results in each value. + * + * @param params + */ private checkFilters(params: Map) { - let typeResults: SearchResult[] = []; - let statusResults: SearchResult[] = []; - let roleResults: SearchResult[] = []; - let types: string[] = []; - let statuses: string[] = []; - let roles: string[] = []; - if(params.get('type') != undefined) { - types = (StringUtils.URIDecode(params.get('type'))).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,-1); - } - if(params.get('status') != undefined) { - statuses = (StringUtils.URIDecode(params.get('status'))).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,-1); - } - if(params.get('role') != undefined) { - roles = (StringUtils.URIDecode(params.get('role'))).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,-1); - } - for(let i = 0; i < this.results.length; i++) { - if (types.length == 0) { - typeResults.push(this.results[i]); - } else { - for (let type of types) { - if (this.results[i].community.type == type.replace(/["']/g, "")) { - typeResults.push(this.results[i]); - break; - } - } - } - } - for(let i = 0; i < this.results.length; i++) { - if( statuses.length == 0) { - statusResults.push(this.results[i]); - } else { - for (let status of statuses) { - if(status.replace(/["']/g, "") == 'subscribed') { - if(this.results[i].isSubscribed) { - statusResults.push(this.results[i]); - break; - } - } else if(status.replace(/["']/g, "") == 'nonsubscribed') { - if(!this.results[i].isSubscribed) { - statusResults.push(this.results[i]); - break; - } - } else if(status.replace(/["']/g, "") == 'managing') { - if (this.results[i].isManager) { - statusResults.push(this.results[i]); - break; - } - } - } - } - } - for(let i = 0; i < this.results.length; i++) { - if (roles.length == 0) { - roleResults.push(this.results[i]); - } else { - for (let role of roles) { - if(role.replace(/["']/g, "") == 'manager') { - if (this.results[i].isManager) { - roleResults.push(this.results[i]); - break; - } - } - } - } - } + let typeResults: SearchResult[] = this.applyFilter('type', params); + let statusResults: SearchResult[] = this.applyFilter('status' , params); + let roleResults: SearchResult[] = this.applyFilter('role', params); this.resetFilterNumbers('status'); this.updateFilterNumbers(typeResults.filter(value => { return roleResults.includes(value); @@ -298,6 +242,72 @@ export class SearchCommunitiesComponent { }); } + /** + * Apply filter with filterId and return the results + * + * @param filterId + * @param params + */ + private applyFilter(filterId: string, params: Map): SearchResult[] { + let results:SearchResult[] = []; + let values: string[] = []; + if(params.get(filterId) != undefined) { + values = (StringUtils.URIDecode(params.get(filterId))).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,-1); + } + if(filterId == 'type') { + for (let i = 0; i < this.results.length; i++) { + if (values.length == 0) { + results.push(this.results[i]); + } else { + for (let value of values) { + if (this.results[i].community.type == value.replace(/["']/g, "")) { + results.push(this.results[i]); + break; + } + } + } + } + } + else if(filterId == 'status') { + for (let i = 0; i < this.results.length; i++) { + if (values.length == 0) { + results.push(this.results[i]); + } else { + for (let value of values) { + if (value.replace(/["']/g, "") == 'subscribed') { + if (this.results[i].isSubscribed) { + results.push(this.results[i]); + break; + } + } else if (value.replace(/["']/g, "") == 'nonsubscribed') { + if (!this.results[i].isSubscribed) { + results.push(this.results[i]); + break; + } + } + } + } + } + } + else if(filterId == 'role') { + for (let i = 0; i < this.results.length; i++) { + if (values.length == 0) { + results.push(this.results[i]); + } else { + for (let value of values) { + if (value.replace(/["']/g, "") == 'manager') { + if (this.results[i].isManager) { + results.push(this.results[i]); + break; + } + } + } + } + } + } + return results; + } + /** * Reset the values of filter with id filterId with zero. * diff --git a/src/app/searchPages/communities/searchCommunities.module.ts b/src/app/searchPages/communities/searchCommunities.module.ts index 54281ff..279d90c 100644 --- a/src/app/searchPages/communities/searchCommunities.module.ts +++ b/src/app/searchPages/communities/searchCommunities.module.ts @@ -8,6 +8,7 @@ import {CommunitiesService} from "../../openaireLibrary/connect/communities/comm import {SearchCommunitiesRoutingModule} from "./searchCommunities-routing.module"; import {PreviousRouteRecorder} from "../../openaireLibrary/utils/piwik/previousRouteRecorder.guard"; import {SubscribeService} from "../../openaireLibrary/utils/subscribe/subscribe.service"; +import {PiwikService} from "../../openaireLibrary/utils/piwik/piwik.service"; @NgModule({ imports: [ @@ -18,7 +19,7 @@ import {SubscribeService} from "../../openaireLibrary/utils/subscribe/subscribe. declarations: [ SearchCommunitiesComponent ], - providers:[CommunitiesService, SubscribeService, PreviousRouteRecorder], + providers:[CommunitiesService, SubscribeService, PreviousRouteRecorder, PiwikService], exports: [ SearchCommunitiesComponent ]