[Trunk|Connect]: 1. Create searchCommunities. 2. Add searchLinkToCommunities property. 3. create route /search/find/communities for the communities search page.

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-connect-portal/trunk@55210 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2019-04-05 17:29:28 +00:00
parent f8ff5d1c3d
commit 28549d5973
6 changed files with 346 additions and 25 deletions

View File

@ -27,6 +27,7 @@ const routes: Routes = [
{ path: 'participate/deposit-publications-result', loadChildren: './deposit/publications/depositPublicationsResults.module#LibDepositPublicationsResultsModule', resolve: { envSpecific: EnvironmentSpecificResolver }},
{ path: 'participate/share-zenodo', loadChildren: './deposit/zenodo/shareInZenodo.module#ShareInZenodoModule', resolve: { envSpecific: EnvironmentSpecificResolver }},
{ path: 'search/find', loadChildren: './searchPages/find/libSearch.module#LibMainSearchModule', resolve: { envSpecific: EnvironmentSpecificResolver }},
{ path: 'search/find/communities', loadChildren: './searchPages/communities/searchCommunities.module#SearchCommunitiesModule', resolve: { envSpecific: EnvironmentSpecificResolver }},
{ path: 'search/find/publications', loadChildren: './searchPages/simple/searchPublications.module#LibSearchPublicationsModule', resolve: { envSpecific: EnvironmentSpecificResolver }},
{ path: 'search/find/datasets', loadChildren: './searchPages/simple/searchDatasets.module#LibSearchDatasetsModule', resolve: { envSpecific: EnvironmentSpecificResolver }},
{ path: 'search/find/software', loadChildren: './searchPages/simple/searchSoftware.module#LibSearchSoftwareModule', resolve: { envSpecific: EnvironmentSpecificResolver }},

View File

@ -1,15 +1,14 @@
import {Component, Input, Output, EventEmitter, ViewChild, ChangeDetectionStrategy, ViewEncapsulation} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {Component} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {ConnectHelper} from '..//openaireLibrary/connect/connectHelper';
@Component({
selector: 'community-wrapper',
template:`
<community *ngIf="dashboard && communityId" [communityId]=communityId></community>
<communities *ngIf="dashboard!=null && !dashboard" ></communities>
`
selector: 'community-wrapper',
template:`
<community *ngIf="dashboard && communityId" [communityId]=communityId></community>
<communities *ngIf="dashboard!=null && !dashboard" ></communities>
`
})
export class CommunityWrapperComponent {
@ -20,25 +19,25 @@ export class CommunityWrapperComponent {
private route: ActivatedRoute,
private _router: Router
) {
this.route.data
.subscribe((data: { envSpecific: any }) => {
this.route.queryParams.subscribe(
communityId => {
this.communityId = communityId['communityId'];
if(!this.communityId){
this.communityId = ConnectHelper.getCommunityFromDomain(data.envSpecific.domain);
}
if(this.communityId){
this.dashboard = true;
}else{
this.dashboard = false;
}
) {
this.route.data
.subscribe((data: { envSpecific: any }) => {
this.route.queryParams.subscribe(
communityId => {
this.communityId = communityId['communityId'];
if(!this.communityId){
this.communityId = ConnectHelper.getCommunityFromDomain(data.envSpecific.domain);
}
if(this.communityId){
this.dashboard = true;
}else{
this.dashboard = false;
}
});
});
}
});
});
}
public ngOnInit() {
}

View File

@ -0,0 +1,14 @@
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import {PreviousRouteRecorder} from '../../openaireLibrary/utils/piwik/previousRouteRecorder.guard';
import {SearchCommunitiesComponent} from "./searchCommunities.component";
@NgModule({
imports: [
RouterModule.forChild([
{ path: '', component: SearchCommunitiesComponent, canDeactivate: [PreviousRouteRecorder] }
])
]
})
export class SearchCommunitiesRoutingModule { }

View File

@ -0,0 +1,280 @@
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 {SearchPageComponent} from "../../openaireLibrary/searchPages/searchUtils/searchPage.component";
import {ActivatedRoute} from "@angular/router";
import {Filter, Value} from "../../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class";
import {SearchFields} from "../../openaireLibrary/utils/properties/searchFields";
import {CommunitiesService} from "../../openaireLibrary/connect/communities/communities.service";
import {Session} from "../../openaireLibrary/login/utils/helper.class";
import {CommunityInfo} from "../../openaireLibrary/connect/community/communityInfo";
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";
@Component({
selector: 'search-communities',
template: `
<search-page pageTitle="Research Communities and Initiatives"
formPlaceholderText="Search for Research Communities and Initiatives"
type="results" entityType="community" [filters]="filters"
[results]="results" [searchUtils]="searchUtils"
[showResultCount]=true [baseUrl]="baseUrl"
(queryChange)="queryChanged($event)"
[disableForms]="disableForms"
[lastIndex]=false [sort]=true
searchFormClass="communitiesSearchForm">
</search-page>
`
})
export class SearchCommunitiesComponent {
private errorCodes: ErrorCodes;
private errorMessages: ErrorMessagesComponent;
public results: SearchResult[] = [];
public sub: any; public subResults: any;
public filters = [];
public searchFields:SearchFields = new SearchFields();
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
public disableForms: boolean = false;
public baseUrl: string = null;
public refineFields: string[] = this.searchFields.COMMUNITIES_SEARCH_FIELDS;
properties:EnvProperties;
@ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
constructor (private route: ActivatedRoute, private _communitiesService: CommunitiesService, private _subscribeService: SubscribeService) {
this.errorCodes = new ErrorCodes();
this.errorMessages = new ErrorMessagesComponent();
this.searchUtils.status = this.errorCodes.LOADING;
}
public ngOnInit() {
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific;
this.baseUrl = data.envSpecific.searchLinkToCommunities;
});
this.sub = this.route.queryParams.subscribe(params => {
this.searchUtils.keyword = (params['keyword']?params['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.searchPage.refineFields = this.refineFields;
this.searchPage.resultsPerPage = 5;
let queryParams = this.searchPage.getQueryParamsFromUrl(params);
this.filters = this.createFilters();
this._getResults(queryParams, this.searchUtils.page, this.searchUtils.size);
});
}
public ngOnDestroy() {
if(this.sub){
this.sub.unsubscribe();
}
if(this.subResults){
this.subResults.unsubscribe();
}
}
private showCommunities(): SearchResult[]{
let ret: SearchResult[] = [];
for(let result of this.results) {
if (result.community.status == 'hidden') {
continue;
} else if (result.community.status == "manager") {
let mail = Session.getUserEmail();
if (mail == null) { // no user
continue;
} else if (Session.isCommunityCurator() || Session.isPortalAdministrator()) {
ret.push(result);
} else if (result.community.managers.indexOf(mail) != -1) {
ret.push(result);
}
continue;
}
ret.push(result);
}
return ret;
}
private _getResults(params: Map<string, string>, page: number, size: number){
this.searchUtils.status = this.errorCodes.LOADING;
this.disableForms = true;
this.results = [];
this.searchUtils.totalResults = 0;
this.subResults = this._communitiesService.getCommunities(this.properties, this.properties.communitiesAPI).subscribe(
data => {
let observables: Observable<boolean>[] = [];
for(let i = 0; i < data.length; i++) {
this.results[i] = new SearchResult();
this.results[i].community = data[i];
observables.push(this._subscribeService.isSubscribedToCommunity(this.results[i].community.communityId, Session.getUserEmail(), this.properties["adminToolsAPIURL"]));
this.results[i].isManager = this.isCommunityManager(this.results[i].community);
}
Observable.forkJoin(observables).subscribe(
res => {
for(let i = 0; i < res.length; i++) {
this.results[i].isSubscribed = res[i];
}
this.results = this.showCommunities();
this.results = this.checkFilters(params);
this.updateFilterNumbers(this.results);
this.searchUtils.totalResults = this.results.length;
this.searchPage.checkSelectedFilters(this.filters);
this.searchPage.updateBaseUrlWithParameters(this.filters);
this.results = this.results.slice((page-1)*size, (page*size));
this.searchUtils.status = this.errorCodes.DONE;
if(this.searchUtils.totalResults == 0 ){
this.searchUtils.status = this.errorCodes.NONE;
}
this.disableForms = false;
},
err => {
this.handleError('Error getting if user is subscribed', err);
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
this.disableForms = false;
}
);
},
err => {
//console.log(err);
this.handleError('Error getting communities', err);
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
this.disableForms = false;
}
);
}
private checkFilters(params: Map<string, string>) {
let ret: SearchResult[] = [];
let types: string[] = [];
let statuses: 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);
}
for(let i = 0; i < this.results.length; i++) {
if (types.length == 0) {
ret.push(this.results[i]);
} else {
for (let type of types) {
if (this.results[i].community.type == type.replace(/["']/g, "")) {
ret.push(this.results[i]);
}
}
}
}
if(ret.length > 0) {
this.results = ret;
ret = [];
}
for(let i = 0; i < this.results.length; i++) {
if( statuses.length == 0) {
ret.push(this.results[i]);
} else {
for (let status of statuses) {
if(status.replace(/["']/g, "") == 'subscribed') {
if(this.results[i].isSubscribed) {
ret.push(this.results[i]);
}
break;
} else if(status.replace(/["']/g, "") == 'nonsubscribed') {
if(!this.results[i].isSubscribed) {
ret.push(this.results[i]);
}
break;
} else if(status.replace(/["']/g, "") == 'managing') {
if (this.results[i].isManager) {
ret.push(this.results[i]);
}
break;
}
}
}
}
return ret;
}
private updateFilterNumbers(results: SearchResult[]) {
for (let i = 0; i < this.filters.length; i++) {
let filter: Filter = this.filters[i];
for (let j = 0; j < filter.values.length; j++) {
let value: Value = filter.values[j];
value.number = 0;
}
}
for(let k = 0; k < results.length; k++) {
let community: CommunityInfo = results[k].community;
for (let i = 0; i < this.filters.length; i++) {
let filter: Filter = this.filters[i];
for (let j = 0; j < filter.values.length; j++) {
let value: Value = filter.values[j];
if(filter.filterId == 'type') {
if(community.type == value.id) {
value.number++;
}
}
}
if(filter.filterId == 'status') {
if(results[k].isSubscribed){
filter.values[0].number++;
}
else {
filter.values[1].number++;
}
if(results[k].isManager) {
filter.values[2].number++;
}
}
}
}
}
private isCommunityManager(community: CommunityInfo): boolean {
return Session.isCommunityCurator() || community.managers.indexOf(Session.getUserEmail()) != -1;
}
public queryChanged($event) {
this._getResults($event.params, this.searchUtils.page, this.searchUtils.size);
}
private createFilters(): Filter[] {
let filter_names=["Type"];
let filter_ids=["type"];
let searchFields = new SearchFields();
let filter_original_ids = searchFields.COMMUNITIES_SEARCH_FIELDS;
let value_names = [
[ "Research Communities", "Research Initiatives" ]
];
let value_original_ids=[
["community","ri"]
];
if(Session.isLoggedIn()) {
filter_names[1] = "Status";
filter_ids[1] = "status";
value_names[1] = [ "Subscribed", "Non-subscribed", "Managing" ];
value_original_ids[1] = ["subscribed", "nonsubscribed", "managing"];
}
let filters: Filter[] = [];
for(let i =0 ; i < filter_names.length; i++){
let values: Value[] = [];
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:j, selected:false};
values.push(value);
}
let filter: Filter = {title: filter_names[i], filterId: filter_ids[i], originalFilterId: filter_original_ids[i], values : values, countSelectedValues:0, "filterOperator": 'or', valueIsExact: true };
filters.push(filter);
}
return filters;
}
private handleError(message: string, error) {
console.error('Communities Search Page: ' + message, error);
}
}

View File

@ -0,0 +1,26 @@
import {NgModule} from "@angular/core";
import {CommonModule} from "@angular/common";
import {FormsModule} from "@angular/forms";
import {SearchCommunitiesComponent} from "./searchCommunities.component";
import {SearchPageModule} from "../../openaireLibrary/searchPages/searchUtils/searchPage.module";
import {SearchFormModule} from "../../openaireLibrary/searchPages/searchUtils/searchForm.module";
import {CommunitiesService} from "../../openaireLibrary/connect/communities/communities.service";
import {SearchCommunitiesRoutingModule} from "./searchCommunities-routing.module";
import {PreviousRouteRecorder} from "../../openaireLibrary/utils/piwik/previousRouteRecorder.guard";
import {SubscribeService} from "../../openaireLibrary/utils/subscribe/subscribe.service";
@NgModule({
imports: [
CommonModule, FormsModule,
SearchFormModule, SearchPageModule,
SearchCommunitiesRoutingModule
],
declarations: [
SearchCommunitiesComponent
],
providers:[CommunitiesService, SubscribeService, PreviousRouteRecorder],
exports: [
SearchCommunitiesComponent
]
})
export class SearchCommunitiesModule { }

View File

@ -73,6 +73,7 @@
"searchLinkToOrganization" : "/search/organization?organizationId=",
"searchLinkToOrp" : "/search/other?orpId=",
"searchLinkToCommunities" : "/search/find/communities",
"searchLinkToPublications" : "/search/find/publications",
"searchLinkToDataProviders" : "/search/find/dataproviders",
"searchLinkToProjects" : "/search/find/projects",