2019-04-24 14:02:11 +02:00
|
|
|
import {Component, ViewChild} from "@angular/core";
|
2019-04-05 19:29:28 +02:00
|
|
|
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-04-28 10:05:03 +02:00
|
|
|
import {AdvancedField, Filter, Value} from "../../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class";
|
2019-04-05 19:29:28 +02:00
|
|
|
import {SearchFields} from "../../openaireLibrary/utils/properties/searchFields";
|
|
|
|
import {CommunitiesService} from "../../openaireLibrary/connect/communities/communities.service";
|
2019-09-13 09:47:29 +02:00
|
|
|
import {Session, User} from "../../openaireLibrary/login/utils/helper.class";
|
2019-04-05 19:29:28 +02:00
|
|
|
import {CommunityInfo} from "../../openaireLibrary/connect/community/communityInfo";
|
|
|
|
import {StringUtils} from "../../openaireLibrary/utils/string-utils.class";
|
2019-09-13 09:47:29 +02:00
|
|
|
import {UserManagementService} from "../../openaireLibrary/services/user-management.service";
|
2020-04-24 18:33:03 +02:00
|
|
|
import {Breadcrumb} from "../../openaireLibrary/utils/breadcrumbs/breadcrumbs.component";
|
2020-04-28 10:05:03 +02:00
|
|
|
import {NewSearchPageComponent} from "../../openaireLibrary/searchPages/searchUtils/newSearchPage.component";
|
2020-11-12 16:59:26 +01:00
|
|
|
import {properties} from "../../../environments/environment";
|
|
|
|
import {Subscriber} from "rxjs";
|
2019-04-05 19:29:28 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'search-communities',
|
|
|
|
template: `
|
2022-01-21 09:21:19 +01:00
|
|
|
<new-search-page pageTitle="Communities"
|
2021-05-12 09:31:21 +02:00
|
|
|
[hasPrefix]=true prefix="OpenAIRE Connect | " [piwikSiteId]="piwikSiteId"
|
2022-01-21 09:21:19 +01:00
|
|
|
[formPlaceholderText]="'Search OpenAIRE Communities'"
|
2021-11-05 12:38:48 +01:00
|
|
|
[type]="(results.length > 1)?'communities':'community'" entityType="community"
|
2020-06-04 13:38:43 +02:00
|
|
|
[results]="results" [searchUtils]="searchUtils"
|
|
|
|
[showResultCount]=true
|
|
|
|
[disableForms]="disableForms"
|
2021-03-08 16:40:49 +01:00
|
|
|
[showIndexInfo]=false
|
2020-06-04 13:38:43 +02:00
|
|
|
[simpleView]="true"
|
|
|
|
[fieldIds]="fieldIds" [fieldIdsMap]="fieldIdsMap" [selectedFields]="selectedFields"
|
2022-02-11 15:05:38 +01:00
|
|
|
[simpleSearchLink]="searchLink" [entitiesSelection]="false" [showBreadcrumb]="true" [breadcrumbs]="breadcrumbs"
|
2021-11-03 20:08:51 +01:00
|
|
|
[basicMetaDescription]="['Research communities', 'Discover OpenAIRE research gateways for research communities.']">
|
2020-06-04 13:38:43 +02:00
|
|
|
</new-search-page>
|
2019-04-05 19:29:28 +02:00
|
|
|
`
|
|
|
|
})
|
|
|
|
export class SearchCommunitiesComponent {
|
2019-08-02 16:56:03 +02:00
|
|
|
public piwikSiteId = null;
|
2019-04-05 19:29:28 +02:00
|
|
|
private errorCodes: ErrorCodes;
|
|
|
|
private errorMessages: ErrorMessagesComponent;
|
2019-04-13 20:21:51 +02:00
|
|
|
public results: CommunityInfo[] = [];
|
2021-11-05 12:38:48 +01:00
|
|
|
public totalResults: CommunityInfo[];
|
2020-11-12 16:59:26 +01:00
|
|
|
public subscriptions = [];
|
2019-04-05 19:29:28 +02:00
|
|
|
public filters = [];
|
2020-06-04 13:38:43 +02:00
|
|
|
public searchFields: SearchFields = new SearchFields();
|
|
|
|
public searchUtils: SearchUtilsClass = new SearchUtilsClass();
|
|
|
|
public selectedFields: AdvancedField[] = [];
|
2019-04-05 19:29:28 +02:00
|
|
|
public disableForms: boolean = false;
|
|
|
|
public baseUrl: string = null;
|
2020-04-28 10:05:03 +02:00
|
|
|
public fieldIds: string[] = ["q"];
|
2020-06-04 13:38:43 +02:00
|
|
|
public refineFields: string[] = this.searchFields.COMMUNITIES_SEARCH_FIELDS;
|
|
|
|
public fieldIdsMap = {
|
|
|
|
["q"]: {
|
|
|
|
name: "All fields",
|
|
|
|
type: "keyword",
|
|
|
|
param: "q",
|
|
|
|
operator: "op",
|
|
|
|
equalityOperator: "=",
|
|
|
|
filterType: null
|
|
|
|
}
|
|
|
|
};
|
2020-04-29 09:53:37 +02:00
|
|
|
public keyword = "";
|
2020-04-28 10:05:03 +02:00
|
|
|
public searchLink;
|
2019-08-05 12:31:12 +02:00
|
|
|
public showType = false;
|
2022-02-11 15:05:38 +01:00
|
|
|
public breadcrumbs: Breadcrumb[] = [{name: 'home', route: '/'}, {name: 'Communities'}];
|
2020-06-04 13:38:43 +02:00
|
|
|
properties: EnvProperties;
|
2021-11-03 20:08:51 +01:00
|
|
|
@ViewChild(NewSearchPageComponent, {static: true}) searchPage: NewSearchPageComponent;
|
2019-09-13 09:47:29 +02:00
|
|
|
private user: User;
|
2021-11-03 20:08:51 +01:00
|
|
|
|
2020-06-04 13:38:43 +02:00
|
|
|
constructor(private route: ActivatedRoute,
|
|
|
|
private _communitiesService: CommunitiesService,
|
|
|
|
private userManagementService: UserManagementService) {
|
2019-04-05 19:29:28 +02:00
|
|
|
this.errorCodes = new ErrorCodes();
|
|
|
|
this.errorMessages = new ErrorMessagesComponent();
|
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
}
|
2021-11-03 20:08:51 +01:00
|
|
|
|
2019-04-05 19:29:28 +02:00
|
|
|
public ngOnInit() {
|
2020-11-12 16:59:26 +01:00
|
|
|
this.properties = properties;
|
|
|
|
this.piwikSiteId = this.properties.piwikSiteId;
|
|
|
|
this.baseUrl = this.properties.searchLinkToCommunities;
|
|
|
|
this.subscriptions.push(this.route.queryParams.subscribe(params => {
|
2019-07-03 15:32:59 +02:00
|
|
|
this.searchPage.resultsPerPage = 10;
|
2020-06-04 13:38:43 +02:00
|
|
|
this.keyword = (params['fv0'] ? params['fv0'] : '');
|
2020-04-29 09:53:37 +02:00
|
|
|
this.keyword = StringUtils.URIDecode(this.keyword);
|
2020-06-04 13:38:43 +02:00
|
|
|
this.searchUtils.page = (params['page'] === undefined) ? 1 : +params['page'];
|
|
|
|
this.searchUtils.sortBy = (params['sortBy'] === undefined) ? '' : params['sortBy'];
|
2021-08-13 14:48:41 +02:00
|
|
|
this.searchUtils.validateSize(params['size']);
|
2020-04-28 10:05:03 +02:00
|
|
|
this.searchUtils.baseUrl = this.baseUrl;
|
2019-05-03 11:37:58 +02:00
|
|
|
this.searchPage.searchUtils = this.searchUtils;
|
2020-06-04 13:38:43 +02:00
|
|
|
if (this.searchUtils.sortBy && this.searchUtils.sortBy != "creationdate,descending" && this.searchUtils.sortBy != "creationdate,ascending") {
|
2019-04-07 18:08:10 +02:00
|
|
|
this.searchUtils.sortBy = "";
|
|
|
|
}
|
2019-04-05 19:29:28 +02:00
|
|
|
this.searchPage.refineFields = this.refineFields;
|
2020-04-28 10:05:03 +02:00
|
|
|
this.searchLink = this.properties.searchLinkToCommunities;
|
2020-04-29 09:53:37 +02:00
|
|
|
this.selectedFields = [];
|
2020-06-04 13:38:43 +02:00
|
|
|
this.searchPage.prepareSearchPage(this.fieldIds, this.selectedFields, this.refineFields, [], this.fieldIdsMap, null, params, "community", null);
|
2021-11-03 20:08:51 +01:00
|
|
|
|
2021-11-03 17:12:14 +01:00
|
|
|
let queryParams = params;
|
2020-06-04 13:38:43 +02:00
|
|
|
if (typeof document !== 'undefined') {
|
2020-11-12 16:59:26 +01:00
|
|
|
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
|
2019-11-08 12:04:10 +01:00
|
|
|
this.user = user;
|
|
|
|
this.initCommunities(queryParams);
|
2020-11-12 16:59:26 +01:00
|
|
|
}));
|
2020-06-04 13:38:43 +02:00
|
|
|
} else {
|
2019-09-13 09:47:29 +02:00
|
|
|
this.initCommunities(queryParams);
|
2019-11-08 12:04:10 +01:00
|
|
|
}
|
2020-11-12 16:59:26 +01:00
|
|
|
}));
|
2019-04-05 19:29:28 +02:00
|
|
|
}
|
2021-11-03 20:08:51 +01:00
|
|
|
|
2020-11-12 16:59:26 +01:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscriber) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
2019-04-05 19:29:28 +02:00
|
|
|
}
|
2021-11-03 20:08:51 +01:00
|
|
|
|
2021-11-05 13:11:38 +01:00
|
|
|
private parseResults(data: any) {
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
this.totalResults[i] = data[i];
|
|
|
|
this.totalResults[i].isManager = this.isCommunityManager(this.totalResults[i]);
|
|
|
|
this.totalResults[i].isSubscribed = Session.isSubscribedTo('community', this.totalResults[i].communityId, this.user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-12 11:50:10 +02:00
|
|
|
/**
|
2019-04-13 20:21:51 +02:00
|
|
|
* Initialize communities from Communities APIs
|
2019-04-12 11:50:10 +02:00
|
|
|
*
|
|
|
|
* @param params
|
|
|
|
*/
|
2020-04-28 10:05:03 +02:00
|
|
|
private initCommunities(params) {
|
2021-11-05 12:38:48 +01:00
|
|
|
if(this.totalResults) {
|
2021-11-05 13:11:38 +01:00
|
|
|
this.parseResults(this.totalResults);
|
2021-11-05 12:38:48 +01:00
|
|
|
this._getResults(params);
|
|
|
|
} else {
|
|
|
|
this.subscriptions.push(this._communitiesService.getCommunitiesState().subscribe(
|
|
|
|
data => {
|
2021-11-05 13:11:38 +01:00
|
|
|
this.totalResults = [];
|
|
|
|
this.parseResults(data);
|
2021-11-05 12:38:48 +01:00
|
|
|
this._getResults(params);
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
this.handleError('Error getting communities', err);
|
|
|
|
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
|
|
|
|
this.disableForms = false;
|
2020-06-04 13:38:43 +02:00
|
|
|
}
|
2021-11-05 12:38:48 +01:00
|
|
|
));
|
|
|
|
}
|
2019-04-05 19:29:28 +02:00
|
|
|
}
|
2021-11-03 20:08:51 +01:00
|
|
|
|
|
|
|
|
2019-04-13 20:21:51 +02:00
|
|
|
/**
|
|
|
|
* Get all communities from Communities API and apply permission access validator,
|
|
|
|
* keyword searching, filter, paging and sorting.
|
|
|
|
*
|
|
|
|
* @param params, status
|
|
|
|
* @private
|
|
|
|
*/
|
2020-06-05 15:03:25 +02:00
|
|
|
private _getResults(params) {
|
2019-04-13 20:21:51 +02:00
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
this.disableForms = true;
|
|
|
|
this.results = this.totalResults;
|
2020-12-02 16:28:03 +01:00
|
|
|
this.filters = this.createFilters();
|
2019-04-13 20:21:51 +02:00
|
|
|
this.searchUtils.totalResults = 0;
|
2019-04-15 12:48:18 +02:00
|
|
|
this.applyParams(params);
|
2019-04-13 20:21:51 +02:00
|
|
|
}
|
2021-11-03 20:08:51 +01:00
|
|
|
|
2019-04-13 20:21:51 +02:00
|
|
|
/**
|
|
|
|
* Return the communities in which user has permission to view or manage.
|
|
|
|
*/
|
|
|
|
private showCommunities() {
|
|
|
|
let ret: CommunityInfo[] = [];
|
2020-06-04 13:38:43 +02:00
|
|
|
for (let result of this.results) {
|
2021-11-03 17:12:14 +01:00
|
|
|
if (result.status == 'hidden' && result.isManager) {
|
|
|
|
ret.push(result);
|
|
|
|
} else if (result.status == "manager" || result.status == "all") {
|
|
|
|
ret.push(result);
|
2019-04-13 20:21:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
this.results = ret;
|
|
|
|
}
|
2021-11-03 20:08:51 +01:00
|
|
|
|
2019-04-12 16:16:08 +02:00
|
|
|
/**
|
|
|
|
* Apply permission access validator,
|
|
|
|
* keyword searching, filter, paging and sorting.
|
|
|
|
*
|
|
|
|
* @param params
|
|
|
|
*/
|
2019-04-15 12:48:18 +02:00
|
|
|
public applyParams(params: Map<string, string>) {
|
2019-04-12 16:16:08 +02:00
|
|
|
this.showCommunities();
|
2020-06-04 13:38:43 +02:00
|
|
|
if (this.keyword && this.keyword != '') {
|
2019-04-12 16:16:08 +02:00
|
|
|
this.searchForKeywords();
|
|
|
|
}
|
|
|
|
this.checkFilters(params);
|
|
|
|
this.sort();
|
|
|
|
this.searchUtils.totalResults = this.results.length;
|
2020-12-02 16:28:03 +01:00
|
|
|
this.filters = this.searchPage.prepareFiltersToShow(this.filters, this.searchUtils.totalResults);
|
2020-06-04 13:38:43 +02:00
|
|
|
this.results = this.results.slice((this.searchUtils.page - 1) * this.searchUtils.size, (this.searchUtils.page * this.searchUtils.size));
|
2019-04-15 12:48:18 +02:00
|
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
2020-06-04 13:38:43 +02:00
|
|
|
if (this.searchUtils.totalResults == 0) {
|
2019-04-12 16:16:08 +02:00
|
|
|
this.searchUtils.status = this.errorCodes.NONE;
|
|
|
|
}
|
|
|
|
this.disableForms = false;
|
2020-06-04 13:38:43 +02:00
|
|
|
if (this.searchUtils.status == this.errorCodes.DONE) {
|
2019-04-12 16:16:08 +02:00
|
|
|
// Page out of limit!!!
|
2020-06-04 13:38:43 +02:00
|
|
|
let totalPages: any = this.searchUtils.totalResults / (this.searchUtils.size);
|
|
|
|
if (!(Number.isInteger(totalPages))) {
|
2019-04-12 16:16:08 +02:00
|
|
|
totalPages = (parseInt(totalPages, 10) + 1);
|
|
|
|
}
|
2020-06-04 13:38:43 +02:00
|
|
|
if (totalPages < this.searchUtils.page) {
|
2019-04-12 16:16:08 +02:00
|
|
|
this.searchUtils.totalResults = 0;
|
|
|
|
this.searchUtils.status = this.errorCodes.OUT_OF_BOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-03 20:08:51 +01:00
|
|
|
|
|
|
|
|
2019-04-12 11:50:10 +02:00
|
|
|
/**
|
|
|
|
* Parse the given keywords into array and check if any of the requirements field of a community includes
|
|
|
|
* one of the given words.
|
|
|
|
*/
|
2019-04-07 18:08:10 +02:00
|
|
|
private searchForKeywords() {
|
2020-06-04 13:38:43 +02:00
|
|
|
let ret: CommunityInfo[] = [];
|
|
|
|
let keywords: string[] = this.keyword.split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
|
|
|
|
for (let i = 0; i < this.results.length; i++) {
|
|
|
|
for (let keyword of keywords) {
|
|
|
|
keyword = keyword.toLowerCase();
|
2020-06-05 15:03:25 +02:00
|
|
|
if (keyword != '' && (StringUtils.containsWord(this.results[i].title, keyword) || StringUtils.containsWord(this.results[i].shortTitle, keyword) ||
|
|
|
|
StringUtils.containsWord(this.results[i].communityId, keyword) || StringUtils.containsWord(this.results[i].description, keyword))) {
|
2020-06-04 13:38:43 +02:00
|
|
|
ret.push(this.results[i]);
|
|
|
|
break;
|
|
|
|
}
|
2019-04-07 18:08:10 +02:00
|
|
|
}
|
2020-06-04 13:38:43 +02:00
|
|
|
}
|
|
|
|
this.results = ret;
|
2019-04-07 18:08:10 +02:00
|
|
|
}
|
2021-11-03 20:08:51 +01:00
|
|
|
|
2019-04-12 11:50:10 +02: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 15:03:25 +02:00
|
|
|
private checkFilters(params) {
|
2019-04-13 20:21:51 +02:00
|
|
|
let typeResults: CommunityInfo[] = this.applyFilter('type', params);
|
2021-11-03 20:08:51 +01:00
|
|
|
let accessResults: CommunityInfo[] = this.applyFilter('access', params);
|
2019-04-15 11:16:29 +02:00
|
|
|
let roleResults: CommunityInfo[] = this.results;
|
2020-06-04 13:38:43 +02:00
|
|
|
if (this.user) {
|
2019-04-15 11:16:29 +02:00
|
|
|
roleResults = this.applyFilter('role', params);
|
|
|
|
this.resetFilterNumbers('role');
|
2021-11-03 20:08:51 +01:00
|
|
|
this.updateFilterNumbers(accessResults.filter(value => {
|
2019-04-15 11:16:29 +02:00
|
|
|
return typeResults.includes(value);
|
|
|
|
}), 'role');
|
|
|
|
}
|
2021-11-03 20:08:51 +01:00
|
|
|
this.resetFilterNumbers('access');
|
|
|
|
this.updateFilterNumbers(typeResults.filter(value => {
|
|
|
|
return roleResults.includes(value);
|
|
|
|
}), 'access');
|
2019-04-07 18:08:10 +02:00
|
|
|
this.resetFilterNumbers('type');
|
2021-11-03 20:08:51 +01:00
|
|
|
this.updateFilterNumbers(accessResults.filter(value => {
|
2019-04-12 10:54:55 +02:00
|
|
|
return roleResults.includes(value);
|
|
|
|
}), 'type');
|
2021-11-03 20:08:51 +01:00
|
|
|
this.results = accessResults.filter(value => {
|
2019-04-07 18:08:10 +02:00
|
|
|
return typeResults.includes(value);
|
2019-04-12 10:54:55 +02:00
|
|
|
})
|
|
|
|
this.results = this.results.filter(value => {
|
|
|
|
return roleResults.includes(value);
|
2019-04-07 18:08:10 +02:00
|
|
|
});
|
2019-04-05 19:29:28 +02:00
|
|
|
}
|
2021-11-03 20:08:51 +01:00
|
|
|
|
2019-04-12 11:50:10 +02:00
|
|
|
/**
|
|
|
|
* Apply filter with filterId and return the results
|
|
|
|
*
|
|
|
|
* @param filterId
|
|
|
|
* @param params
|
|
|
|
*/
|
2020-04-28 10:05:03 +02:00
|
|
|
private applyFilter(filterId: string, params): CommunityInfo[] {
|
2020-06-04 13:38:43 +02:00
|
|
|
let results: CommunityInfo[] = [];
|
2019-04-12 11:50:10 +02:00
|
|
|
let values: string[] = [];
|
2020-06-05 15:03:25 +02:00
|
|
|
if (params[filterId]) {
|
2020-06-04 13:38:43 +02:00
|
|
|
values = (StringUtils.URIDecode(params[filterId])).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
|
2019-04-12 11:50:10 +02:00
|
|
|
}
|
2020-06-04 13:38:43 +02:00
|
|
|
if (filterId == 'type') {
|
2019-04-12 11:50:10 +02: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) {
|
2019-04-13 20:21:51 +02:00
|
|
|
if (this.results[i].type == value.replace(/["']/g, "")) {
|
2019-04-12 11:50:10 +02:00
|
|
|
results.push(this.results[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-03 20:08:51 +01:00
|
|
|
} else if (filterId == 'access') {
|
2019-04-12 11:50:10 +02: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) {
|
2021-11-03 20:08:51 +01:00
|
|
|
if (value.replace(/["']/g, "") == 'public') {
|
|
|
|
if (this.results[i].status === 'all') {
|
|
|
|
results.push(this.results[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (value.replace(/["']/g, "") == 'restricted') {
|
|
|
|
if (this.results[i].status === 'manager') {
|
2019-04-12 11:50:10 +02:00
|
|
|
results.push(this.results[i]);
|
|
|
|
break;
|
|
|
|
}
|
2021-11-03 20:08:51 +01:00
|
|
|
} else if (value.replace(/["']/g, "") == 'private') {
|
|
|
|
if (this.results[i].status === 'hidden') {
|
2019-04-12 11:50:10 +02:00
|
|
|
results.push(this.results[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-04 13:38:43 +02:00
|
|
|
} else if (filterId == 'role') {
|
2019-04-12 11:50:10 +02: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) {
|
|
|
|
if (value.replace(/["']/g, "") == 'manager') {
|
|
|
|
if (this.results[i].isManager) {
|
|
|
|
results.push(this.results[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-11-03 20:08:51 +01:00
|
|
|
if (value.replace(/["']/g, "") == 'subscriber') {
|
|
|
|
if (this.results[i].isSubscribed) {
|
|
|
|
results.push(this.results[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-04-12 11:50:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return results;
|
|
|
|
}
|
2021-11-03 20:08:51 +01:00
|
|
|
|
2020-06-04 13:38:43 +02:00
|
|
|
/**
|
|
|
|
* Reset the values of filter with id filterId with zero.
|
|
|
|
*
|
|
|
|
* @param filterId
|
|
|
|
*/
|
2019-04-07 18:08:10 +02:00
|
|
|
private resetFilterNumbers(filterId: string) {
|
2019-04-05 19:29:28 +02:00
|
|
|
for (let i = 0; i < this.filters.length; i++) {
|
2020-06-04 13:38:43 +02:00
|
|
|
if (this.filters[i].filterId == filterId) {
|
2019-04-07 18:08:10 +02:00
|
|
|
for (let j = 0; j < this.filters[i].values.length; j++) {
|
|
|
|
this.filters[i].values[j].number = 0;
|
|
|
|
}
|
|
|
|
break;
|
2019-04-05 19:29:28 +02:00
|
|
|
}
|
|
|
|
}
|
2019-04-07 18:08:10 +02:00
|
|
|
}
|
2021-11-03 20:08:51 +01:00
|
|
|
|
2020-06-04 13:38:43 +02:00
|
|
|
/**
|
|
|
|
* Update the values of filter with id filterId based on
|
|
|
|
* results.
|
|
|
|
*
|
|
|
|
* @param results
|
|
|
|
* @param filterId
|
|
|
|
*/
|
2019-04-13 20:21:51 +02:00
|
|
|
private updateFilterNumbers(results: CommunityInfo[], filterId: string) {
|
2020-06-04 13:38:43 +02:00
|
|
|
for (let k = 0; k < results.length; k++) {
|
2019-04-05 19:29:28 +02:00
|
|
|
for (let i = 0; i < this.filters.length; i++) {
|
2020-06-04 13:38:43 +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-04-05 19:29:28 +02:00
|
|
|
}
|
2021-11-03 20:08:51 +01:00
|
|
|
} else if (this.filters[i].filterId == 'access') {
|
|
|
|
if (results[k].status === 'all') {
|
2020-06-04 13:38:43 +02:00
|
|
|
this.filters[i].values[0].number++;
|
2021-11-03 20:08:51 +01:00
|
|
|
} else if (results[k].status === 'manager') {
|
2020-06-04 13:38:43 +02:00
|
|
|
this.filters[i].values[1].number++;
|
2021-11-03 20:08:51 +01:00
|
|
|
} else if (this.user) {
|
|
|
|
this.filters[i].values[2].number++;
|
2019-04-12 10:54:55 +02:00
|
|
|
}
|
2020-06-04 13:38:43 +02:00
|
|
|
} else if (this.filters[i].filterId == 'role') {
|
|
|
|
if (results[k].isManager) {
|
|
|
|
this.filters[i].values[0].number++;
|
2019-04-07 18:08:10 +02:00
|
|
|
}
|
2021-11-03 20:08:51 +01:00
|
|
|
if (results[k].isSubscribed) {
|
|
|
|
this.filters[i].values[1].number++;
|
|
|
|
}
|
2020-06-04 13:38:43 +02:00
|
|
|
}
|
|
|
|
break;
|
2019-04-05 19:29:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-03 20:08:51 +01:00
|
|
|
|
2020-06-04 13:38:43 +02:00
|
|
|
/**
|
|
|
|
* Sorting results based on sortBy.
|
|
|
|
*/
|
2019-04-07 18:08:10 +02:00
|
|
|
private sort() {
|
2020-06-04 13:38:43 +02:00
|
|
|
if (this.searchUtils.sortBy == '') {
|
2019-04-07 18:08:10 +02:00
|
|
|
this.results.sort((left, right): number => {
|
2019-04-13 20:21:51 +02:00
|
|
|
if (left.title > right.title) {
|
2019-04-07 18:08:10 +02:00
|
|
|
return 1;
|
2019-04-13 20:21:51 +02:00
|
|
|
} else if (left.title < right.title) {
|
2019-04-07 18:08:10 +02:00
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
})
|
2020-06-04 13:38:43 +02:00
|
|
|
} else if (this.searchUtils.sortBy == 'creationdate,descending') {
|
2019-04-07 18:08:10 +02:00
|
|
|
this.results.sort((left, right): number => {
|
2019-04-13 20:21:51 +02:00
|
|
|
if (!right.date || left.date > right.date) {
|
2019-04-07 18:08:10 +02:00
|
|
|
return -1;
|
2019-04-13 20:21:51 +02:00
|
|
|
} else if (!left.date || left.date < right.date) {
|
2019-04-07 18:08:10 +02:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
})
|
2020-06-04 13:38:43 +02:00
|
|
|
} else if (this.searchUtils.sortBy == 'creationdate,ascending') {
|
2019-04-07 18:08:10 +02:00
|
|
|
this.results.sort((left, right): number => {
|
2019-04-13 20:21:51 +02:00
|
|
|
if (!right.date || left.date > right.date) {
|
2019-04-07 18:08:10 +02:00
|
|
|
return 1;
|
2019-04-13 20:21:51 +02:00
|
|
|
} else if (!left.date || left.date < right.date) {
|
2019-04-07 18:08:10 +02:00
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2021-11-03 20:08:51 +01:00
|
|
|
|
|
|
|
|
2019-04-05 19:29:28 +02:00
|
|
|
private isCommunityManager(community: CommunityInfo): boolean {
|
2021-02-19 18:52:12 +01:00
|
|
|
return Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user) || Session.isManager('community', community.communityId, this.user);
|
2019-04-05 19:29:28 +02:00
|
|
|
}
|
2021-11-03 20:08:51 +01:00
|
|
|
|
2020-06-04 13:38:43 +02:00
|
|
|
/**
|
|
|
|
* Create Search Communities filters.
|
|
|
|
*
|
|
|
|
*/
|
2019-04-05 19:29:28 +02:00
|
|
|
private createFilters(): Filter[] {
|
2019-08-05 12:31:12 +02:00
|
|
|
let filter_names = [];
|
|
|
|
let filter_ids = [];
|
2019-04-05 19:29:28 +02:00
|
|
|
let searchFields = new SearchFields();
|
|
|
|
let filter_original_ids = searchFields.COMMUNITIES_SEARCH_FIELDS;
|
2019-08-05 12:31:12 +02:00
|
|
|
let value_names = [];
|
2020-06-04 13:38:43 +02:00
|
|
|
let value_original_ids = [];
|
2019-08-05 12:31:12 +02:00
|
|
|
this.showType = this.results.filter(community => community.type === 'ri').length > 0;
|
2020-06-04 13:38:43 +02:00
|
|
|
if (this.showType) {
|
2019-08-05 12:31:12 +02:00
|
|
|
filter_names.push("Type");
|
|
|
|
filter_ids.push("type");
|
2020-06-04 13:38:43 +02:00
|
|
|
value_names.push(["Research Communities", "Research Initiatives"]);
|
|
|
|
value_original_ids.push(["community", "ri"]);
|
2019-08-05 12:31:12 +02:00
|
|
|
} else {
|
|
|
|
filter_original_ids = searchFields.COMMUNITIES_SEARCH_FIELDS.splice(0, 1);
|
|
|
|
}
|
2021-11-03 20:08:51 +01:00
|
|
|
filter_names.push("Accessibility");
|
|
|
|
filter_ids.push("access");
|
|
|
|
if (!this.user) {
|
|
|
|
value_names.push(["Public", "Restricted"]);
|
|
|
|
value_original_ids.push(["public", "restricted"]);
|
|
|
|
} else {
|
|
|
|
value_names.push(["Public", "Restricted", "Private"]);
|
|
|
|
value_original_ids.push(["public", "restricted", "private"]);
|
2019-08-05 12:31:12 +02:00
|
|
|
filter_names.push("Role");
|
|
|
|
filter_ids.push("role");
|
2021-11-03 20:08:51 +01:00
|
|
|
value_names.push(["Manager", "Subscriber"]);
|
|
|
|
value_original_ids.push(["manager", "subscriber"]);
|
2019-04-05 19:29:28 +02:00
|
|
|
}
|
|
|
|
let filters: Filter[] = [];
|
2020-06-04 13:38:43 +02:00
|
|
|
for (let i = 0; i < filter_names.length; i++) {
|
2019-04-05 19:29:28 +02:00
|
|
|
let values: Value[] = [];
|
2020-06-04 13:38:43 +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-04-05 19:29:28 +02:00
|
|
|
values.push(value);
|
|
|
|
}
|
2020-06-04 13:38:43 +02:00
|
|
|
let filter: Filter = {
|
|
|
|
title: filter_names[i],
|
|
|
|
filterId: filter_ids[i],
|
|
|
|
originalFilterId: filter_original_ids[i],
|
|
|
|
values: values,
|
|
|
|
countSelectedValues: 0,
|
|
|
|
"filterOperator": 'or',
|
|
|
|
valueIsExact: true,
|
|
|
|
filterType: "checkbox"
|
|
|
|
};
|
2019-04-05 19:29:28 +02:00
|
|
|
filters.push(filter);
|
|
|
|
}
|
|
|
|
return filters;
|
|
|
|
}
|
2021-11-03 20:08:51 +01:00
|
|
|
|
2019-04-05 19:29:28 +02:00
|
|
|
private handleError(message: string, error) {
|
|
|
|
console.error('Communities Search Page: ' + message, error);
|
|
|
|
}
|
2021-11-03 20:08:51 +01:00
|
|
|
|
2019-04-05 19:29:28 +02:00
|
|
|
}
|