2019-12-03 12:10:05 +01:00
|
|
|
import {Component, ViewChild} from "@angular/core";
|
|
|
|
import {SearchUtilsClass} from "../openaireLibrary/searchPages/searchUtils/searchUtils.class";
|
|
|
|
import {ErrorMessagesComponent} from "../openaireLibrary/utils/errorMessages.component";
|
|
|
|
import {ErrorCodes} from "../openaireLibrary/utils/properties/errorCodes";
|
|
|
|
import {EnvProperties} from "../openaireLibrary/utils/properties/env-properties";
|
|
|
|
import {ActivatedRoute} from "@angular/router";
|
2020-06-05 14:59:28 +02:00
|
|
|
import {AdvancedField, Filter, Value} from "../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class";
|
2019-12-03 12:10:05 +01:00
|
|
|
import {SearchFields} from "../openaireLibrary/utils/properties/searchFields";
|
|
|
|
import {Session, User} from "../openaireLibrary/login/utils/helper.class";
|
|
|
|
import {StringUtils} from "../openaireLibrary/utils/string-utils.class";
|
|
|
|
import {HelperFunctions} from "../openaireLibrary/utils/HelperFunctions.class";
|
|
|
|
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
|
2020-06-03 23:55:32 +02:00
|
|
|
import {StakeholderService} from "../openaireLibrary/monitor/services/stakeholder.service";
|
2020-06-05 14:59:28 +02:00
|
|
|
import {NewSearchPageComponent} from "../openaireLibrary/searchPages/searchUtils/newSearchPage.component";
|
|
|
|
import {StakeholderInfo} from "../openaireLibrary/monitor/entities/stakeholder";
|
2019-12-03 12:10:05 +01:00
|
|
|
|
|
|
|
@Component({
|
2020-06-05 14:59:28 +02:00
|
|
|
selector: 'search-stakeholders',
|
2019-12-03 12:10:05 +01:00
|
|
|
template: `
|
2020-06-05 14:59:28 +02:00
|
|
|
<new-search-page pageTitle="OpenAIRE-Monitor | Search Stakeholders"
|
|
|
|
[hasPrefix]=false [piwikSiteId]="piwikSiteId"
|
|
|
|
[formPlaceholderText]="'Search for Stakeholders…'"
|
|
|
|
type="stakeholders" entityType="stakeholder"
|
|
|
|
[results]="results" [searchUtils]="searchUtils"
|
|
|
|
[showResultCount]=true
|
|
|
|
[disableForms]="disableForms"
|
|
|
|
[lastIndex]=false
|
|
|
|
[simpleView]="true"
|
|
|
|
[fieldIds]="fieldIds" [fieldIdsMap]="fieldIdsMap" [selectedFields]="selectedFields"
|
|
|
|
[simpleSearchLink]="searchLink" [entitiesSelection]="false">
|
|
|
|
</new-search-page>
|
2019-12-03 12:10:05 +01:00
|
|
|
`
|
|
|
|
})
|
2020-06-03 23:55:32 +02:00
|
|
|
export class SearchStakeholdersComponent {
|
2019-12-03 12:10:05 +01:00
|
|
|
public piwikSiteId = null;
|
|
|
|
private errorCodes: ErrorCodes;
|
|
|
|
private errorMessages: ErrorMessagesComponent;
|
2020-06-05 14:59:28 +02:00
|
|
|
public results: StakeholderInfo[] = [];
|
|
|
|
public totalResults: StakeholderInfo[] = [];
|
|
|
|
public sub: any;
|
|
|
|
public subResults: any;
|
2019-12-03 12:10:05 +01:00
|
|
|
public filters = [];
|
2020-06-05 14:59:28 +02:00
|
|
|
public searchFields: SearchFields = new SearchFields();
|
|
|
|
public searchUtils: SearchUtilsClass = new SearchUtilsClass();
|
|
|
|
public selectedFields: AdvancedField[] = [];
|
2019-12-03 12:10:05 +01:00
|
|
|
public disableForms: boolean = false;
|
|
|
|
public baseUrl: string = null;
|
2020-06-05 14:59:28 +02:00
|
|
|
public fieldIds: string[] = ["q"];
|
|
|
|
public refineFields: string[] = this.searchFields.STAKEHOLDER_SEARCH_FIELDS;
|
|
|
|
public fieldIdsMap = {
|
|
|
|
["q"]: {
|
|
|
|
name: "All fields",
|
|
|
|
type: "keyword",
|
|
|
|
param: "q",
|
|
|
|
operator: "op",
|
|
|
|
equalityOperator: "=",
|
|
|
|
filterType: null
|
|
|
|
}
|
|
|
|
};
|
|
|
|
public keyword = "";
|
|
|
|
public searchLink;
|
|
|
|
properties: EnvProperties;
|
|
|
|
@ViewChild(NewSearchPageComponent) searchPage: NewSearchPageComponent;
|
2019-12-03 12:10:05 +01:00
|
|
|
private user: User;
|
2020-06-05 14:59:28 +02:00
|
|
|
private userFilterLoaded: boolean = false;
|
|
|
|
|
|
|
|
constructor(private route: ActivatedRoute,
|
|
|
|
private _stakeholderService: StakeholderService,
|
|
|
|
private userManagementService: UserManagementService) {
|
2019-12-03 12:10:05 +01:00
|
|
|
this.errorCodes = new ErrorCodes();
|
|
|
|
this.errorMessages = new ErrorMessagesComponent();
|
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
|
2019-12-03 12:10:05 +01:00
|
|
|
public ngOnInit() {
|
|
|
|
this.route.data
|
2020-06-05 14:59:28 +02:00
|
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
|
|
this.properties = data.envSpecific;
|
|
|
|
this.piwikSiteId = this.properties.piwikSiteId;
|
|
|
|
this.baseUrl = "/search/find/stakeholders";
|
|
|
|
});
|
|
|
|
this.sub = this.route.queryParams.subscribe(params => {
|
2019-12-03 12:10:05 +01:00
|
|
|
this.searchPage.resultsPerPage = 10;
|
2020-06-05 14:59:28 +02:00
|
|
|
this.keyword = (params['fv0'] ? params['fv0'] : '');
|
|
|
|
this.keyword = StringUtils.URIDecode(this.keyword);
|
|
|
|
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;
|
2019-12-03 12:10:05 +01:00
|
|
|
this.searchPage.searchUtils = this.searchUtils;
|
2020-06-05 14:59:28 +02:00
|
|
|
if (this.searchUtils.size != 5 && this.searchUtils.size != 10 && this.searchUtils.size != 20 && this.searchUtils.size != 50) {
|
2019-12-03 12:10:05 +01:00
|
|
|
this.searchUtils.size = this.searchPage.resultsPerPage;
|
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
if (this.searchUtils.sortBy && this.searchUtils.sortBy != "creationdate,descending" && this.searchUtils.sortBy != "creationdate,ascending") {
|
2019-12-03 12:10:05 +01:00
|
|
|
this.searchUtils.sortBy = "";
|
|
|
|
}
|
|
|
|
this.searchPage.refineFields = this.refineFields;
|
2020-06-05 14:59:28 +02:00
|
|
|
this.searchLink = this.properties.searchLinkToCommunities;
|
|
|
|
this.selectedFields = [];
|
|
|
|
this.searchPage.prepareSearchPage(this.fieldIds, this.selectedFields, this.refineFields, [], this.fieldIdsMap, null, params, "stakeholder", null);
|
|
|
|
|
|
|
|
let queryParams = params;//this.searchPage.getQueryParamsFromUrl(params);
|
|
|
|
if (typeof document !== 'undefined') {
|
2019-12-23 17:01:48 +01:00
|
|
|
this.userManagementService.getUserInfo().subscribe(user => {
|
2019-12-03 12:10:05 +01:00
|
|
|
this.user = user;
|
|
|
|
this.initFunders(queryParams);
|
|
|
|
});
|
2020-06-05 14:59:28 +02:00
|
|
|
} else {
|
2019-12-03 12:10:05 +01:00
|
|
|
this.initFunders(queryParams);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
|
2019-12-03 12:10:05 +01:00
|
|
|
public ngOnDestroy() {
|
2020-06-05 14:59:28 +02:00
|
|
|
if (this.sub) {
|
2019-12-03 12:10:05 +01:00
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
if (this.subResults) {
|
2019-12-03 12:10:05 +01:00
|
|
|
this.subResults.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
|
2019-12-03 12:10:05 +01:00
|
|
|
/**
|
2020-06-03 23:55:32 +02:00
|
|
|
* Initialize stakeholders from Communities APIs
|
2019-12-03 12:10:05 +01:00
|
|
|
*
|
|
|
|
* @param params
|
|
|
|
*/
|
2020-06-05 14:59:28 +02:00
|
|
|
private initFunders(params) {
|
2020-06-03 23:55:32 +02:00
|
|
|
this.subResults = this._stakeholderService.getStakeholders(this.properties.monitorServiceAPIURL).subscribe(
|
2020-06-05 14:59:28 +02:00
|
|
|
data => {
|
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
this.totalResults[i] = data[i];
|
|
|
|
this.totalResults[i].isManager = this.isStakeholderManager();
|
2019-12-03 12:10:05 +01:00
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
this._getResults(params);
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
this.handleError('Error getting stakeholders', err);
|
|
|
|
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
|
|
|
|
this.disableForms = false;
|
|
|
|
HelperFunctions.scroll();
|
|
|
|
}
|
|
|
|
);
|
2019-12-03 12:10:05 +01:00
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
|
|
|
|
|
2019-12-03 12:10:05 +01:00
|
|
|
/**
|
2020-06-03 23:55:32 +02:00
|
|
|
* Get all stakeholders from mock API and apply permission access validator,
|
2019-12-03 12:10:05 +01:00
|
|
|
* keyword searching, filter, paging and sorting.
|
|
|
|
*
|
|
|
|
* @param params, status
|
|
|
|
* @private
|
|
|
|
*/
|
2020-06-05 14:59:28 +02:00
|
|
|
private _getResults(params) {
|
2019-12-03 12:10:05 +01:00
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
this.disableForms = true;
|
|
|
|
this.results = this.totalResults;
|
2020-06-05 14:59:28 +02:00
|
|
|
if (this.filters.length == 0 || (this.user && !this.userFilterLoaded)) {
|
2019-12-03 12:10:05 +01:00
|
|
|
this.filters = this.createFilters();
|
|
|
|
}
|
|
|
|
this.searchUtils.totalResults = 0;
|
|
|
|
this.applyParams(params);
|
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
|
2019-12-03 12:10:05 +01:00
|
|
|
/**
|
2020-06-03 23:55:32 +02:00
|
|
|
* Return the stakeholders in which user has permission to view or manage.
|
2019-12-03 12:10:05 +01:00
|
|
|
*/
|
|
|
|
private showFunders() {
|
|
|
|
let ret = [];
|
2020-06-05 14:59:28 +02:00
|
|
|
for (let result of this.results) {
|
|
|
|
if (!result.isPublic && !this.isStakeholderManager()) {
|
2019-12-03 12:10:05 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ret.push(result);
|
|
|
|
}
|
|
|
|
this.results = ret;
|
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
|
2019-12-03 12:10:05 +01:00
|
|
|
/**
|
|
|
|
* Apply permission access validator,
|
|
|
|
* keyword searching, filter, paging and sorting.
|
|
|
|
*
|
|
|
|
* @param params
|
|
|
|
* @param status
|
|
|
|
*/
|
2020-06-05 14:59:28 +02:00
|
|
|
public applyParams(params) {
|
2019-12-03 12:10:05 +01:00
|
|
|
this.showFunders();
|
2020-06-09 16:50:43 +02:00
|
|
|
if (this.keyword && this.keyword != '') {
|
2019-12-03 12:10:05 +01:00
|
|
|
this.searchForKeywords();
|
|
|
|
}
|
|
|
|
this.checkFilters(params);
|
|
|
|
this.sort();
|
|
|
|
this.searchUtils.totalResults = this.results.length;
|
2020-06-05 14:59:28 +02:00
|
|
|
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));
|
2019-12-03 12:10:05 +01:00
|
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
2020-06-05 14:59:28 +02:00
|
|
|
if (this.searchUtils.totalResults == 0) {
|
2019-12-03 12:10:05 +01:00
|
|
|
this.searchUtils.status = this.errorCodes.NONE;
|
|
|
|
}
|
|
|
|
this.disableForms = false;
|
2020-06-05 14:59:28 +02:00
|
|
|
if (this.searchUtils.status == this.errorCodes.DONE) {
|
2019-12-03 12:10:05 +01:00
|
|
|
// Page out of limit!!!
|
2020-06-05 14:59:28 +02:00
|
|
|
let totalPages: any = this.searchUtils.totalResults / (this.searchUtils.size);
|
|
|
|
if (!(Number.isInteger(totalPages))) {
|
2019-12-03 12:10:05 +01:00
|
|
|
totalPages = (parseInt(totalPages, 10) + 1);
|
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
if (totalPages < this.searchUtils.page) {
|
2019-12-03 12:10:05 +01:00
|
|
|
this.searchUtils.totalResults = 0;
|
|
|
|
this.searchUtils.status = this.errorCodes.OUT_OF_BOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
|
|
|
|
|
2019-12-03 12:10:05 +01:00
|
|
|
/**
|
|
|
|
* Parse the given keywords into array and check if any of the requirements field of a funder includes
|
|
|
|
* one of the given words.
|
|
|
|
*/
|
|
|
|
private searchForKeywords() {
|
2020-06-05 14:59:28 +02:00
|
|
|
let ret = [];
|
2020-06-09 16:50:43 +02:00
|
|
|
let keywords: string[] = this.keyword.split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
|
2020-06-05 14:59:28 +02:00
|
|
|
for (let i = 0; i < this.results.length; i++) {
|
|
|
|
for (let keyword of keywords) {
|
|
|
|
keyword = keyword.toLowerCase();
|
|
|
|
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))) {
|
|
|
|
ret.push(this.results[i]);
|
|
|
|
break;
|
|
|
|
}
|
2019-12-03 12:10:05 +01:00
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
}
|
|
|
|
this.results = ret;
|
2019-12-03 12:10:05 +01:00
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
|
2019-12-03 12:10:05 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2020-06-05 14:59:28 +02:00
|
|
|
private checkFilters(params) {
|
|
|
|
let typeResults: StakeholderInfo[] = this.applyFilter('type', params);
|
|
|
|
let accessResults: StakeholderInfo[] = this.results;
|
|
|
|
let roleResults: StakeholderInfo[] = this.results;
|
|
|
|
if (this.user) {
|
|
|
|
accessResults = this.applyFilter('access', params);
|
|
|
|
roleResults = this.applyFilter('role', params);
|
|
|
|
this.resetFilterNumbers('access');
|
|
|
|
this.updateFilterNumbers(typeResults.filter(value => {
|
|
|
|
return roleResults.includes(value);
|
|
|
|
}), 'access');
|
|
|
|
this.resetFilterNumbers('role');
|
|
|
|
this.updateFilterNumbers(accessResults.filter(value => {
|
|
|
|
return typeResults.includes(value);
|
|
|
|
}), 'role');
|
|
|
|
}
|
|
|
|
this.resetFilterNumbers('type');
|
|
|
|
this.updateFilterNumbers(accessResults.filter(value => {
|
|
|
|
return roleResults.includes(value);
|
|
|
|
}), 'type');
|
|
|
|
this.results = accessResults.filter(value => {
|
|
|
|
return typeResults.includes(value);
|
|
|
|
})
|
2019-12-03 12:10:05 +01:00
|
|
|
this.results = this.results.filter(value => {
|
2020-06-05 14:59:28 +02:00
|
|
|
return roleResults.includes(value);
|
2019-12-03 12:10:05 +01:00
|
|
|
});
|
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
|
2019-12-03 12:10:05 +01:00
|
|
|
/**
|
|
|
|
* Apply filter with filterId and return the results
|
|
|
|
*
|
|
|
|
* @param filterId
|
|
|
|
* @param params
|
|
|
|
*/
|
2020-06-05 14:59:28 +02:00
|
|
|
private applyFilter(filterId: string, params): StakeholderInfo[] {
|
2019-12-03 12:10:05 +01:00
|
|
|
let results = [];
|
|
|
|
let values: string[] = [];
|
2020-06-05 14:59:28 +02:00
|
|
|
if (params[filterId]) {
|
|
|
|
values = (StringUtils.URIDecode(params[filterId])).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
|
2019-12-03 12:10:05 +01:00
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
if (filterId == 'type') {
|
2019-12-03 12:10:05 +01:00
|
|
|
for (let i = 0; i < this.results.length; i++) {
|
|
|
|
if (values.length == 0) {
|
|
|
|
results.push(this.results[i]);
|
|
|
|
} else {
|
|
|
|
for (let value of values) {
|
2020-06-05 14:59:28 +02:00
|
|
|
if (this.results[i].type == value.replace(/["']/g, "")) {
|
2019-12-03 12:10:05 +01:00
|
|
|
results.push(this.results[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
} else if (filterId == 'access') {
|
|
|
|
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, "") == 'public') {
|
|
|
|
if (this.results[i].isPublic) {
|
|
|
|
results.push(this.results[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (value.replace(/["']/g, "") == 'private') {
|
|
|
|
if (!this.results[i].isPublic) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-03 12:10:05 +01:00
|
|
|
}
|
|
|
|
return results;
|
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the values of filter with id filterId with zero.
|
|
|
|
*
|
|
|
|
* @param filterId
|
|
|
|
*/
|
2019-12-03 12:10:05 +01:00
|
|
|
private resetFilterNumbers(filterId: string) {
|
|
|
|
for (let i = 0; i < this.filters.length; i++) {
|
2020-06-05 14:59:28 +02:00
|
|
|
if (this.filters[i].filterId == filterId) {
|
2019-12-03 12:10:05 +01:00
|
|
|
for (let j = 0; j < this.filters[i].values.length; j++) {
|
|
|
|
this.filters[i].values[j].number = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the values of filter with id filterId based on
|
|
|
|
* results.
|
|
|
|
*
|
|
|
|
* @param results
|
|
|
|
* @param filterId
|
|
|
|
*/
|
|
|
|
private updateFilterNumbers(results: StakeholderInfo[], filterId: string) {
|
|
|
|
for (let k = 0; k < results.length; k++) {
|
2019-12-03 12:10:05 +01:00
|
|
|
for (let i = 0; i < this.filters.length; i++) {
|
2020-06-05 14:59:28 +02:00
|
|
|
if (this.filters[i].filterId == filterId) {
|
|
|
|
if (this.filters[i].filterId == 'type') {
|
|
|
|
for (let j = 0; j < this.filters[i].values.length; j++) {
|
|
|
|
if (results[k].type == this.filters[i].values[j].id) {
|
|
|
|
this.filters[i].values[j].number++;
|
|
|
|
}
|
2019-12-03 12:10:05 +01:00
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
} else if (this.filters[i].filterId == 'access') {
|
|
|
|
if (results[k].isPublic) {
|
|
|
|
this.filters[i].values[0].number++;
|
|
|
|
} else {
|
|
|
|
this.filters[i].values[1].number++;
|
|
|
|
}
|
|
|
|
} else if (this.filters[i].filterId == 'role') {
|
|
|
|
if (results[k].isManager) {
|
|
|
|
this.filters[i].values[0].number++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2019-12-03 12:10:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sorting results based on sortBy.
|
|
|
|
*/
|
2019-12-03 12:10:05 +01:00
|
|
|
private sort() {
|
2020-06-05 14:59:28 +02:00
|
|
|
if (this.searchUtils.sortBy == '') {
|
2019-12-03 12:10:05 +01:00
|
|
|
this.results.sort((left, right): number => {
|
2020-06-05 14:59:28 +02:00
|
|
|
if (left.name > right.name) {
|
2019-12-03 12:10:05 +01:00
|
|
|
return 1;
|
2020-06-05 14:59:28 +02:00
|
|
|
} else if (left.name < right.name) {
|
2019-12-03 12:10:05 +01:00
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
})
|
2020-06-05 14:59:28 +02:00
|
|
|
} else if (this.searchUtils.sortBy == 'creationdate,descending') {
|
2019-12-03 12:10:05 +01:00
|
|
|
this.results.sort((left, right): number => {
|
2020-06-05 14:59:28 +02:00
|
|
|
if (!right.creationDate || left.creationDate > right.creationDate) {
|
2019-12-03 12:10:05 +01:00
|
|
|
return -1;
|
2020-06-05 14:59:28 +02:00
|
|
|
} else if (!left.creationDate || left.creationDate < right.creationDate) {
|
2019-12-03 12:10:05 +01:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
})
|
2020-06-05 14:59:28 +02:00
|
|
|
} else if (this.searchUtils.sortBy == 'creationdate,ascending') {
|
2019-12-03 12:10:05 +01:00
|
|
|
this.results.sort((left, right): number => {
|
2020-06-05 14:59:28 +02:00
|
|
|
if (!right.creationDate || left.creationDate > right.creationDate) {
|
2019-12-03 12:10:05 +01:00
|
|
|
return 1;
|
2020-06-05 14:59:28 +02:00
|
|
|
} else if (!left.creationDate || left.creationDate < right.creationDate) {
|
2019-12-03 12:10:05 +01:00
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
|
|
|
|
private isStakeholderManager() {
|
|
|
|
return Session.isPortalAdministrator(this.user) || Session.isMonitorCurator(this.user) || Session.isCommunityCurator(this.user);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create Search Stakeholder filters.
|
|
|
|
*
|
|
|
|
*/
|
2019-12-03 12:10:05 +01:00
|
|
|
private createFilters(): Filter[] {
|
|
|
|
let filter_names = [];
|
|
|
|
let filter_ids = [];
|
|
|
|
let value_names = [];
|
2020-06-05 14:59:28 +02:00
|
|
|
let value_original_ids = [];
|
|
|
|
filter_names.push("Type");
|
|
|
|
filter_ids.push("type");
|
|
|
|
value_names.push(["Funders", "Research Initiatives", "Organizations"]);
|
|
|
|
value_original_ids.push(["funder", "ri", "organization"]);
|
|
|
|
if (this.user) {
|
|
|
|
filter_names.push("Accessibility");
|
|
|
|
filter_ids.push("access");
|
|
|
|
value_names.push(["Public", "Private"]);
|
|
|
|
value_original_ids.push(["public", "private"]);
|
|
|
|
filter_names.push("Role");
|
|
|
|
filter_ids.push("role");
|
|
|
|
value_names.push(["Manager"]);
|
|
|
|
value_original_ids.push(["manager"]);
|
|
|
|
this.userFilterLoaded = true;
|
|
|
|
}
|
2019-12-03 12:10:05 +01:00
|
|
|
let filters: Filter[] = [];
|
2020-06-05 14:59:28 +02:00
|
|
|
for (let i = 0; i < filter_names.length; i++) {
|
2019-12-03 12:10:05 +01:00
|
|
|
let values: Value[] = [];
|
2020-06-05 14:59:28 +02:00
|
|
|
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};
|
2019-12-03 12:10:05 +01:00
|
|
|
values.push(value);
|
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
let filter: Filter = {
|
|
|
|
title: filter_names[i],
|
|
|
|
filterId: filter_ids[i],
|
|
|
|
originalFilterId: this.refineFields[i],
|
|
|
|
values: values,
|
|
|
|
countSelectedValues: 0,
|
|
|
|
"filterOperator": 'or',
|
|
|
|
valueIsExact: true,
|
|
|
|
filterType: "checkbox"
|
|
|
|
};
|
2019-12-03 12:10:05 +01:00
|
|
|
filters.push(filter);
|
|
|
|
}
|
|
|
|
return filters;
|
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
|
2019-12-03 12:10:05 +01:00
|
|
|
private handleError(message: string, error) {
|
|
|
|
console.error('Communities Search Page: ' + message, error);
|
|
|
|
}
|
2020-06-05 14:59:28 +02:00
|
|
|
|
2019-12-03 12:10:05 +01:00
|
|
|
}
|