[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
This commit is contained in:
parent
18cef75b2e
commit
a8a00b386e
|
@ -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: `
|
||||
<search-page pageTitle="Research Communities and Initiatives"
|
||||
<search-page pageTitle="OpenAIRE Connect|Search Communities"
|
||||
formPlaceholderText="Search for Research Communities and Initiatives"
|
||||
type="results" entityType="community" [filters]="filters"
|
||||
[results]="results" [searchUtils]="searchUtils"
|
||||
|
@ -31,6 +32,7 @@ import {StringUtils} from "../../openaireLibrary/utils/string-utils.class";
|
|||
`
|
||||
})
|
||||
export class SearchCommunitiesComponent {
|
||||
public piwiksub: any;
|
||||
private errorCodes: ErrorCodes;
|
||||
private errorMessages: ErrorMessagesComponent;
|
||||
public results: SearchResult[] = [];
|
||||
|
@ -47,7 +49,8 @@ export class SearchCommunitiesComponent {
|
|||
constructor (private route: ActivatedRoute,
|
||||
private _communitiesService: CommunitiesService,
|
||||
private _subscribeService: SubscribeService,
|
||||
private element: ElementRef) {
|
||||
private element: ElementRef,
|
||||
private _piwikService:PiwikService) {
|
||||
this.errorCodes = new ErrorCodes();
|
||||
this.errorMessages = new ErrorMessagesComponent();
|
||||
this.searchUtils.status = this.errorCodes.LOADING;
|
||||
|
@ -58,6 +61,9 @@ export class SearchCommunitiesComponent {
|
|||
.subscribe((data: { envSpecific: EnvProperties }) => {
|
||||
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<string, string>){
|
||||
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<string, string>) {
|
||||
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<string, string>): 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.
|
||||
*
|
||||
|
|
|
@ -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
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue