Fix a bug in filters numbers

This commit is contained in:
Konstantinos Triantafyllou 2021-11-03 21:10:56 +02:00
parent 93598f3707
commit 7a6221e568
2 changed files with 451 additions and 452 deletions

@ -1 +1 @@
Subproject commit 045665ae107501603df4ad02ed95c9842c9c8a3e Subproject commit 104c54a3e861d65817aac59c56640457664eeaab

View File

@ -1,23 +1,23 @@
import { Component, ViewChild } from "@angular/core"; import {Component, ViewChild} from "@angular/core";
import { SearchUtilsClass } from "../openaireLibrary/searchPages/searchUtils/searchUtils.class"; import {SearchUtilsClass} from "../openaireLibrary/searchPages/searchUtils/searchUtils.class";
import { ErrorMessagesComponent } from "../openaireLibrary/utils/errorMessages.component"; import {ErrorMessagesComponent} from "../openaireLibrary/utils/errorMessages.component";
import { ErrorCodes } from "../openaireLibrary/utils/properties/errorCodes"; import {ErrorCodes} from "../openaireLibrary/utils/properties/errorCodes";
import { EnvProperties } from "../openaireLibrary/utils/properties/env-properties"; import {EnvProperties} from "../openaireLibrary/utils/properties/env-properties";
import { ActivatedRoute } from "@angular/router"; import {ActivatedRoute} from "@angular/router";
import { AdvancedField, 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 {SearchFields} from "../openaireLibrary/utils/properties/searchFields";
import { Session, User } from "../openaireLibrary/login/utils/helper.class"; import {Session, User} from "../openaireLibrary/login/utils/helper.class";
import { StringUtils } from "../openaireLibrary/utils/string-utils.class"; import {StringUtils} from "../openaireLibrary/utils/string-utils.class";
import { UserManagementService } from "../openaireLibrary/services/user-management.service"; import {UserManagementService} from "../openaireLibrary/services/user-management.service";
import { StakeholderService } from "../openaireLibrary/monitor/services/stakeholder.service"; import {StakeholderService} from "../openaireLibrary/monitor/services/stakeholder.service";
import { NewSearchPageComponent } from "../openaireLibrary/searchPages/searchUtils/newSearchPage.component"; import {NewSearchPageComponent} from "../openaireLibrary/searchPages/searchUtils/newSearchPage.component";
import { StakeholderInfo } from "../openaireLibrary/monitor/entities/stakeholder"; import {StakeholderInfo} from "../openaireLibrary/monitor/entities/stakeholder";
import { properties } from "../../environments/environment"; import {properties} from "../../environments/environment";
import { Subscriber } from "rxjs"; import {Subscriber} from "rxjs";
@Component({ @Component({
selector: 'search-stakeholders', selector: 'search-stakeholders',
template: ` template: `
<new-search-page pageTitle="OpenAIRE-Monitor | Browse" <new-search-page pageTitle="OpenAIRE-Monitor | Browse"
[hasPrefix]=false [piwikSiteId]="piwikSiteId" [hasPrefix]=false [piwikSiteId]="piwikSiteId"
[formPlaceholderText]="'Search profiles'" [formPlaceholderText]="'Search profiles'"
@ -33,442 +33,441 @@ import { Subscriber } from "rxjs";
` `
}) })
export class SearchStakeholdersComponent { export class SearchStakeholdersComponent {
public piwikSiteId = null; public piwikSiteId = null;
private errorCodes: ErrorCodes; private errorCodes: ErrorCodes;
private errorMessages: ErrorMessagesComponent; private errorMessages: ErrorMessagesComponent;
public results: StakeholderInfo[] = []; public results: StakeholderInfo[] = [];
public totalResults: StakeholderInfo[] = []; public totalResults: StakeholderInfo[] = [];
public subscriptions = []; public subscriptions = [];
public filters = []; public filters = [];
public searchFields: SearchFields = new SearchFields(); public searchFields: SearchFields = new SearchFields();
public searchUtils: SearchUtilsClass = new SearchUtilsClass(); public searchUtils: SearchUtilsClass = new SearchUtilsClass();
public selectedFields: AdvancedField[] = []; public selectedFields: AdvancedField[] = [];
public disableForms: boolean = false; public disableForms: boolean = false;
public baseUrl: string = null; public baseUrl: string = null;
public fieldIds: string[] = ["q"]; public fieldIds: string[] = ["q"];
public refineFields: string[] = this.searchFields.STAKEHOLDER_SEARCH_FIELDS; public refineFields: string[] = this.searchFields.STAKEHOLDER_SEARCH_FIELDS;
public fieldIdsMap = { public fieldIdsMap = {
["q"]: { ["q"]: {
name: "All fields", name: "All fields",
type: "keyword", type: "keyword",
param: "q", param: "q",
operator: "op", operator: "op",
equalityOperator: "=", equalityOperator: "=",
filterType: null filterType: null
} }
}; };
public keyword = ""; public keyword = "";
public searchLink; public searchLink;
properties: EnvProperties = properties; properties: EnvProperties = properties;
@ViewChild(NewSearchPageComponent, { static: true }) searchPage: NewSearchPageComponent; @ViewChild(NewSearchPageComponent, {static: true}) searchPage: NewSearchPageComponent;
private user: User; private user: User;
constructor(private route: ActivatedRoute, constructor(private route: ActivatedRoute,
private _stakeholderService: StakeholderService, private _stakeholderService: StakeholderService,
private userManagementService: UserManagementService) { private userManagementService: UserManagementService) {
this.errorCodes = new ErrorCodes(); this.errorCodes = new ErrorCodes();
this.errorMessages = new ErrorMessagesComponent(); this.errorMessages = new ErrorMessagesComponent();
this.searchUtils.status = this.errorCodes.LOADING; this.searchUtils.status = this.errorCodes.LOADING;
} }
public ngOnInit() { public ngOnInit() {
this.piwikSiteId = this.properties.piwikSiteId; this.piwikSiteId = this.properties.piwikSiteId;
this.baseUrl = this.properties.searchLinkToStakeholders; this.baseUrl = this.properties.searchLinkToStakeholders;
this.subscriptions.push(this.route.queryParams.subscribe(params => { this.subscriptions.push(this.route.queryParams.subscribe(params => {
this.searchPage.resultsPerPage = 10; this.searchPage.resultsPerPage = 10;
this.keyword = (params['fv0'] ? params['fv0'] : ''); this.keyword = (params['fv0'] ? params['fv0'] : '');
this.keyword = StringUtils.URIDecode(this.keyword); this.keyword = StringUtils.URIDecode(this.keyword);
this.searchUtils.page = (params['page'] === undefined) ? 1 : +params['page']; this.searchUtils.page = (params['page'] === undefined) ? 1 : +params['page'];
this.searchUtils.sortBy = (params['sortBy'] === undefined) ? '' : params['sortBy']; this.searchUtils.sortBy = (params['sortBy'] === undefined) ? '' : params['sortBy'];
this.searchUtils.validateSize(params['size']); this.searchUtils.validateSize(params['size']);
this.searchUtils.baseUrl = this.baseUrl; this.searchUtils.baseUrl = this.baseUrl;
this.searchPage.searchUtils = this.searchUtils; this.searchPage.searchUtils = this.searchUtils;
if (this.searchUtils.sortBy && this.searchUtils.sortBy != "creationdate,descending" && this.searchUtils.sortBy != "creationdate,ascending") { if (this.searchUtils.sortBy && this.searchUtils.sortBy != "creationdate,descending" && this.searchUtils.sortBy != "creationdate,ascending") {
this.searchUtils.sortBy = ""; this.searchUtils.sortBy = "";
} }
this.searchPage.refineFields = this.refineFields; this.searchPage.refineFields = this.refineFields;
this.searchLink = this.properties.searchLinkToStakeholders; this.searchLink = this.properties.searchLinkToStakeholders;
this.selectedFields = []; this.selectedFields = [];
this.searchPage.prepareSearchPage(this.fieldIds, this.selectedFields, this.refineFields, [], this.fieldIdsMap, null, params, "stakeholder", null); this.searchPage.prepareSearchPage(this.fieldIds, this.selectedFields, this.refineFields, [], this.fieldIdsMap, null, params, "stakeholder", null);
let queryParams = params; let queryParams = params;
if (typeof document !== 'undefined') { if (typeof document !== 'undefined') {
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => { this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
this.user = user; this.user = user;
this.initFunders(queryParams); this.initFunders(queryParams);
})); }));
} else { } else {
this.initFunders(queryParams); this.initFunders(queryParams);
} }
})); }));
} }
ngOnDestroy() { ngOnDestroy() {
this.subscriptions.forEach(subscription => { this.subscriptions.forEach(subscription => {
if (subscription instanceof Subscriber) { if (subscription instanceof Subscriber) {
subscription.unsubscribe(); subscription.unsubscribe();
} }
}); });
} }
/** /**
* Initialize stakeholders from Communities APIs * Initialize stakeholders from Communities APIs
* *
* @param params * @param params
*/ */
private initFunders(params) { private initFunders(params) {
this.subscriptions.push(this._stakeholderService.getStakeholders(this.properties.monitorServiceAPIURL).subscribe( this.subscriptions.push(this._stakeholderService.getStakeholders(this.properties.monitorServiceAPIURL).subscribe(
data => { data => {
if (!data) { if (!data) {
return; return;
} }
for (let i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
this.totalResults[i] = data[i]; this.totalResults[i] = data[i];
this.totalResults[i].isManager = this.isManager(data[i]); this.totalResults[i].isManager = this.isManager(data[i]);
this.totalResults[i].isMember = this.isMember(data[i]); this.totalResults[i].isMember = this.isMember(data[i]);
} }
this._getResults(params); this._getResults(params);
}, },
err => { err => {
this.handleError('Error getting stakeholders', err); this.handleError('Error getting stakeholders', err);
this.searchUtils.status = this.errorMessages.getErrorCode(err.status); this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
this.disableForms = false; this.disableForms = false;
} }
)); ));
} }
/** /**
* Get all stakeholders from mock API and apply permission access validator, * Get all stakeholders from mock API and apply permission access validator,
* keyword searching, filter, paging and sorting. * keyword searching, filter, paging and sorting.
* *
* @param params, status * @param params, status
* @private * @private
*/ */
private _getResults(params) { private _getResults(params) {
this.searchUtils.status = this.errorCodes.LOADING; this.searchUtils.status = this.errorCodes.LOADING;
this.disableForms = true; this.disableForms = true;
this.results = this.totalResults; this.results = this.totalResults;
this.filters = this.createFilters(); this.filters = this.createFilters();
this.searchUtils.totalResults = 0; this.searchUtils.totalResults = 0;
this.applyParams(params); this.applyParams(params);
} }
/** /**
* Apply permission access validator, * Apply permission access validator,
* keyword searching, filter, paging and sorting. * keyword searching, filter, paging and sorting.
* *
* @param params * @param params
* @param status * @param status
*/ */
public applyParams(params) { public applyParams(params) {
if (this.keyword && this.keyword != '') { if (this.keyword && this.keyword != '') {
this.searchForKeywords(); this.searchForKeywords();
} }
this.checkFilters(params); this.checkFilters(params);
this.sort(); this.sort();
this.searchUtils.totalResults = this.results.length; this.searchUtils.totalResults = this.results.length;
this.filters = this.searchPage.prepareFiltersToShow(this.filters, this.searchUtils.totalResults); 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.results = this.results.slice((this.searchUtils.page - 1) * this.searchUtils.size, (this.searchUtils.page * this.searchUtils.size));
this.searchUtils.status = this.errorCodes.DONE; this.searchUtils.status = this.errorCodes.DONE;
if (this.searchUtils.totalResults == 0) { if (this.searchUtils.totalResults == 0) {
this.searchUtils.status = this.errorCodes.NONE; this.searchUtils.status = this.errorCodes.NONE;
} }
this.disableForms = false; this.disableForms = false;
if (this.searchUtils.status == this.errorCodes.DONE) { if (this.searchUtils.status == this.errorCodes.DONE) {
// Page out of limit!!! // Page out of limit!!!
let totalPages: any = this.searchUtils.totalResults / (this.searchUtils.size); let totalPages: any = this.searchUtils.totalResults / (this.searchUtils.size);
if (!(Number.isInteger(totalPages))) { if (!(Number.isInteger(totalPages))) {
totalPages = (parseInt(totalPages, 10) + 1); totalPages = (parseInt(totalPages, 10) + 1);
} }
if (totalPages < this.searchUtils.page) { if (totalPages < this.searchUtils.page) {
this.searchUtils.totalResults = 0; this.searchUtils.totalResults = 0;
this.searchUtils.status = this.errorCodes.OUT_OF_BOUND; this.searchUtils.status = this.errorCodes.OUT_OF_BOUND;
} }
} }
} }
/** /**
* Parse the given keywords into array and check if any of the requirements field of a funder includes * Parse the given keywords into array and check if any of the requirements field of a funder includes
* one of the given words. * one of the given words.
*/ */
private searchForKeywords() { private searchForKeywords() {
let ret = []; let ret = [];
let keywords: string[] = this.keyword.split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1); let keywords: string[] = this.keyword.split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
for (let i = 0; i < this.results.length; i++) { for (let i = 0; i < this.results.length; i++) {
for (let keyword of keywords) { for (let keyword of keywords) {
keyword = keyword.toLowerCase(); keyword = keyword.toLowerCase();
if (keyword != '' && (StringUtils.containsWord(this.results[i].name, keyword) || StringUtils.containsWord(this.results[i].index_shortName, keyword) || if (keyword != '' && (StringUtils.containsWord(this.results[i].name, keyword) || StringUtils.containsWord(this.results[i].index_shortName, keyword) ||
StringUtils.containsWord(this.results[i].alias, keyword) || StringUtils.containsWord(this.results[i].description, keyword))) { StringUtils.containsWord(this.results[i].alias, keyword) || StringUtils.containsWord(this.results[i].description, keyword))) {
ret.push(this.results[i]); ret.push(this.results[i]);
break; break;
} }
} }
} }
this.results = ret; this.results = ret;
} }
/** /**
* Check the current results if they satisfy the values of each filter category and * Check the current results if they satisfy the values of each filter category and
* update the number of possible results in each value. * update the number of possible results in each value.
* *
* @param params * @param params
*/ */
private checkFilters(params) { private checkFilters(params) {
let typeResults: StakeholderInfo[] = this.applyFilter('type', params); let typeResults: StakeholderInfo[] = this.applyFilter('type', params);
let accessResults: StakeholderInfo[] = this.results; let accessResults: StakeholderInfo[] = this.applyFilter('access', params);
let roleResults: StakeholderInfo[] = this.results; let roleResults: StakeholderInfo[] = this.results;
accessResults = this.applyFilter('access', params); if (this.user) {
roleResults = this.applyFilter('role', params); roleResults = this.applyFilter('role', params);
this.resetFilterNumbers('access'); this.resetFilterNumbers('role');
this.updateFilterNumbers(typeResults.filter(value => { this.updateFilterNumbers(accessResults.filter(value => {
return roleResults.includes(value); return typeResults.includes(value);
}), 'access'); }), 'role');
if (this.user) { }
this.resetFilterNumbers('role'); this.resetFilterNumbers('access');
this.updateFilterNumbers(accessResults.filter(value => { this.updateFilterNumbers(typeResults.filter(value => {
return typeResults.includes(value); return roleResults.includes(value);
}), 'role'); }), 'access');
} this.resetFilterNumbers('type');
this.resetFilterNumbers('type'); this.updateFilterNumbers(accessResults.filter(value => {
this.updateFilterNumbers(accessResults.filter(value => { return roleResults.includes(value);
return roleResults.includes(value); }), 'type');
}), 'type'); this.results = accessResults.filter(value => {
this.results = accessResults.filter(value => { return typeResults.includes(value);
return typeResults.includes(value); })
}) this.results = this.results.filter(value => {
this.results = this.results.filter(value => { return roleResults.includes(value);
return roleResults.includes(value); });
}); }
}
/**
/** * Apply filter with filterId and return the results
* Apply filter with filterId and return the results *
* * @param filterId
* @param filterId * @param params
* @param params */
*/ private applyFilter(filterId: string, params): StakeholderInfo[] {
private applyFilter(filterId: string, params): StakeholderInfo[] { let results = [];
let results = []; let values: string[] = [];
let values: string[] = []; if (params[filterId]) {
if (params[filterId]) { values = (StringUtils.URIDecode(params[filterId])).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
values = (StringUtils.URIDecode(params[filterId])).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1); }
} if (filterId == 'type') {
if (filterId == 'type') { for (let i = 0; i < this.results.length; i++) {
for (let i = 0; i < this.results.length; i++) { if (values.length == 0) {
if (values.length == 0) { results.push(this.results[i]);
results.push(this.results[i]); } else {
} else { for (let value of values) {
for (let value of values) { if (this.results[i].type == value.replace(/["']/g, "")) {
if (this.results[i].type == value.replace(/["']/g, "")) { results.push(this.results[i]);
results.push(this.results[i]); break;
break; }
} }
} }
} }
} } else if (filterId == 'access') {
} else if (filterId == 'access') { for (let i = 0; i < this.results.length; i++) {
for (let i = 0; i < this.results.length; i++) { if (values.length == 0) {
if (values.length == 0) { results.push(this.results[i]);
results.push(this.results[i]); } else {
} else { for (let value of values) {
for (let value of values) { if (value.replace(/["']/g, "") == 'public') {
if (value.replace(/["']/g, "") == 'public') { if (this.results[i].visibility === 'PUBLIC') {
if (this.results[i].visibility === 'PUBLIC') { results.push(this.results[i]);
results.push(this.results[i]); break;
break; }
} } else if (value.replace(/["']/g, "") == 'restricted') {
} else if (value.replace(/["']/g, "") == 'restricted') { if (this.results[i].visibility === 'RESTRICTED') {
if (this.results[i].visibility === 'RESTRICTED') { results.push(this.results[i]);
results.push(this.results[i]); break;
break; }
} } else if (value.replace(/["']/g, "") == 'private') {
} else if (value.replace(/["']/g, "") == 'private') {
if (this.results[i].visibility === 'PRIVATE') { if (this.results[i].visibility === 'PRIVATE') {
results.push(this.results[i]); results.push(this.results[i]);
break; break;
} }
} }
} }
} }
} }
} else if (filterId == 'role') { } else if (filterId == 'role') {
for (let i = 0; i < this.results.length; i++) { for (let i = 0; i < this.results.length; i++) {
if (values.length == 0) { if (values.length == 0) {
results.push(this.results[i]); results.push(this.results[i]);
} else { } else {
for (let value of values) { for (let value of values) {
if (value.replace(/["']/g, "") == 'manager') { if (value.replace(/["']/g, "") == 'manager') {
if (this.results[i].isManager) { if (this.results[i].isManager) {
results.push(this.results[i]); results.push(this.results[i]);
break; break;
} }
} }
if (value.replace(/["']/g, "") == 'member') { if (value.replace(/["']/g, "") == 'member') {
if (this.results[i].isMember) { if (this.results[i].isMember) {
results.push(this.results[i]); results.push(this.results[i]);
break; break;
} }
} }
} }
} }
} }
} }
return results; return results;
} }
/** /**
* Reset the values of filter with id filterId with zero. * Reset the values of filter with id filterId with zero.
* *
* @param filterId * @param filterId
*/ */
private resetFilterNumbers(filterId: string) { private resetFilterNumbers(filterId: string) {
for (let i = 0; i < this.filters.length; i++) { for (let i = 0; i < this.filters.length; i++) {
if (this.filters[i].filterId == filterId) { if (this.filters[i].filterId == filterId) {
for (let j = 0; j < this.filters[i].values.length; j++) { for (let j = 0; j < this.filters[i].values.length; j++) {
this.filters[i].values[j].number = 0; this.filters[i].values[j].number = 0;
} }
break; break;
} }
} }
} }
/** /**
* Update the values of filter with id filterId based on * Update the values of filter with id filterId based on
* results. * results.
* *
* @param results * @param results
* @param filterId * @param filterId
*/ */
private updateFilterNumbers(results: StakeholderInfo[], filterId: string) { private updateFilterNumbers(results: StakeholderInfo[], filterId: string) {
for (let k = 0; k < results.length; k++) { for (let k = 0; k < results.length; k++) {
for (let i = 0; i < this.filters.length; i++) { for (let i = 0; i < this.filters.length; i++) {
if (this.filters[i].filterId == filterId) { if (this.filters[i].filterId == filterId) {
if (this.filters[i].filterId == 'type') { if (this.filters[i].filterId == 'type') {
for (let j = 0; j < this.filters[i].values.length; j++) { for (let j = 0; j < this.filters[i].values.length; j++) {
if (results[k].type == this.filters[i].values[j].id) { if (results[k].type == this.filters[i].values[j].id) {
this.filters[i].values[j].number++; this.filters[i].values[j].number++;
} }
} }
} else if (this.filters[i].filterId == 'access') { } else if (this.filters[i].filterId == 'access') {
if (results[k].visibility === 'PUBLIC') { if (results[k].visibility === 'PUBLIC') {
this.filters[i].values[0].number++; this.filters[i].values[0].number++;
} else if (results[k].visibility === 'RESTRICTED') { } else if (results[k].visibility === 'RESTRICTED') {
this.filters[i].values[1].number++; this.filters[i].values[1].number++;
} else { } else if (this.user) {
this.filters[i].values[2].number++; this.filters[i].values[2].number++;
} }
} else if (this.filters[i].filterId == 'role') { } else if (this.filters[i].filterId == 'role') {
if (results[k].isManager) { if (results[k].isManager) {
this.filters[i].values[0].number++; this.filters[i].values[0].number++;
} }
if (results[k].isMember) { if (results[k].isMember) {
this.filters[i].values[1].number++; this.filters[i].values[1].number++;
} }
} }
break; break;
} }
} }
} }
} }
/** /**
* Sorting results based on sortBy. * Sorting results based on sortBy.
*/ */
private sort() { private sort() {
if (this.searchUtils.sortBy == '') { if (this.searchUtils.sortBy == '') {
this.results.sort((left, right): number => { this.results.sort((left, right): number => {
if (left.name > right.name) { if (left.name > right.name) {
return 1; return 1;
} else if (left.name < right.name) { } else if (left.name < right.name) {
return -1; return -1;
} else { } else {
return 0; return 0;
} }
}) })
} else if (this.searchUtils.sortBy == 'creationdate,descending') { } else if (this.searchUtils.sortBy == 'creationdate,descending') {
this.results.sort((left, right): number => { this.results.sort((left, right): number => {
if (!right.creationDate || left.creationDate > right.creationDate) { if (!right.creationDate || left.creationDate > right.creationDate) {
return -1; return -1;
} else if (!left.creationDate || left.creationDate < right.creationDate) { } else if (!left.creationDate || left.creationDate < right.creationDate) {
return 1; return 1;
} else { } else {
return 0; return 0;
} }
}) })
} else if (this.searchUtils.sortBy == 'creationdate,ascending') { } else if (this.searchUtils.sortBy == 'creationdate,ascending') {
this.results.sort((left, right): number => { this.results.sort((left, right): number => {
if (!right.creationDate || left.creationDate > right.creationDate) { if (!right.creationDate || left.creationDate > right.creationDate) {
return 1; return 1;
} else if (!left.creationDate || left.creationDate < right.creationDate) { } else if (!left.creationDate || left.creationDate < right.creationDate) {
return -1; return -1;
} else { } else {
return 0; return 0;
} }
}) })
} }
} }
private isManager(stakeholder) { private isManager(stakeholder) {
return Session.isPortalAdministrator(this.user) || Session.isMonitorCurator(this.user) return Session.isPortalAdministrator(this.user) || Session.isMonitorCurator(this.user)
|| Session.isCommunityCurator(this.user) || Session.isManager(stakeholder.type, stakeholder.alias, this.user); || Session.isCommunityCurator(this.user) || Session.isManager(stakeholder.type, stakeholder.alias, this.user);
} }
private isMember(stakeholder) { private isMember(stakeholder) {
return this.isManager(stakeholder) || Session.isSubscribedTo(stakeholder.type, stakeholder.alias, this.user); return this.isManager(stakeholder) || Session.isSubscribedTo(stakeholder.type, stakeholder.alias, this.user);
} }
/** /**
* Create Search Stakeholder filters. * Create Search Stakeholder filters.
* *
*/ */
private createFilters(): Filter[] { private createFilters(): Filter[] {
let filter_names = []; let filter_names = [];
let filter_ids = []; let filter_ids = [];
let value_names = []; let value_names = [];
let value_original_ids = []; let value_original_ids = [];
filter_names.push("Type"); filter_names.push("Type");
filter_ids.push("type"); filter_ids.push("type");
value_names.push(["Funders", "Research Initiatives", "Institutions"]); value_names.push(["Funders", "Research Initiatives", "Institutions"]);
value_original_ids.push(["funder", "ri", "organization"]); value_original_ids.push(["funder", "ri", "organization"]);
filter_names.push("Accessibility"); filter_names.push("Accessibility");
filter_ids.push("access"); filter_ids.push("access");
if (!this.user) { if (!this.user) {
value_names.push(["Public", "Restricted"]); value_names.push(["Public", "Restricted"]);
value_original_ids.push(["public", "restricted"]); value_original_ids.push(["public", "restricted"]);
} else { } else {
value_names.push(["Public", "Restricted", "Private"]); value_names.push(["Public", "Restricted", "Private"]);
value_original_ids.push(["public", "restricted", "private"]); value_original_ids.push(["public", "restricted", "private"]);
filter_names.push("Role"); filter_names.push("Role");
filter_ids.push("role"); filter_ids.push("role");
value_names.push(["Manager", "Member"]); value_names.push(["Manager", "Member"]);
value_original_ids.push(["manager", "member"]); value_original_ids.push(["manager", "member"]);
} }
let filters: Filter[] = []; let filters: Filter[] = [];
for (let i = 0; i < filter_names.length; i++) { for (let i = 0; i < filter_names.length; i++) {
let values: Value[] = []; let values: Value[] = [];
for (let j = 0; j < value_names[i].length; j++) { for (let j = 0; j < value_names[i].length; j++) {
let value: Value = { name: value_names[i][j], id: value_original_ids[i][j], number: 0, selected: false }; let value: Value = {name: value_names[i][j], id: value_original_ids[i][j], number: 0, selected: false};
values.push(value); values.push(value);
} }
let filter: Filter = { let filter: Filter = {
title: filter_names[i], title: filter_names[i],
filterId: filter_ids[i], filterId: filter_ids[i],
originalFilterId: this.refineFields[i], originalFilterId: this.refineFields[i],
values: values, values: values,
countSelectedValues: 0, countSelectedValues: 0,
"filterOperator": 'or', "filterOperator": 'or',
valueIsExact: true, valueIsExact: true,
filterType: "checkbox" filterType: "checkbox"
}; };
filters.push(filter); filters.push(filter);
} }
return filters; return filters;
} }
private handleError(message: string, error) { private handleError(message: string, error) {
console.error('Communities Search Page: ' + message, error); console.error('Communities Search Page: ' + message, error);
} }
} }