From ac516584151ecaf342f4a88f312e1e506a26ae1e Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Sat, 13 Apr 2019 18:21:51 +0000 Subject: [PATCH] [Trunk|Connect]: 1. Change search Communities to initialize with one call to the APIs ngOnInit. 2. Contact: Redirect from modal is the same in production and dev git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-connect-portal/trunk@55338 d315682c-612b-4755-9ff5-7f18f6832af3 --- src/app/contact/contact.component.ts | 15 +- .../searchCommunities.component.ts | 134 ++++++++++-------- 2 files changed, 73 insertions(+), 76 deletions(-) diff --git a/src/app/contact/contact.component.ts b/src/app/contact/contact.component.ts index 3840dad..d0507a6 100644 --- a/src/app/contact/contact.component.ts +++ b/src/app/contact/contact.component.ts @@ -125,21 +125,8 @@ export class ContactComponent implements OnInit { this.showLoading = false; } - getProductionPrefix():string{ - return (this.properties.environment == "beta")?"beta.":"" - } - - isProduction():boolean{ - return this.properties.environment!="development"; - - } - public goToHome(data: any) { - if(this.isProduction()) { - window.location.hostname = 'https://'+ this.getProductionPrefix() + 'connect.openaire.eu'; - } else { - this._router.navigate(['/']); - } + this._router.navigate(['/']); } } diff --git a/src/app/searchPages/communities/searchCommunities.component.ts b/src/app/searchPages/communities/searchCommunities.component.ts index e130d42..70f72bc 100644 --- a/src/app/searchPages/communities/searchCommunities.component.ts +++ b/src/app/searchPages/communities/searchCommunities.component.ts @@ -35,7 +35,8 @@ export class SearchCommunitiesComponent { public piwiksub: any; private errorCodes: ErrorCodes; private errorMessages: ErrorMessagesComponent; - public results: SearchResult[] = []; + public results: CommunityInfo[] = []; + public totalResults: CommunityInfo[] = []; public sub: any; public subResults: any; public filters = []; public searchFields:SearchFields = new SearchFields(); @@ -80,7 +81,8 @@ export class SearchCommunitiesComponent { this.searchPage.refineFields = this.refineFields; let queryParams = this.searchPage.getQueryParamsFromUrl(params); this.filters = this.createFilters(); - this._getResults(queryParams); + + this.initCommunities(queryParams); }); } @@ -93,65 +95,33 @@ export class SearchCommunitiesComponent { } } - /** - * Return the communities in which user has permission to view or manage. - */ - private showCommunities() { - 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); - } - this.results = ret; - } - - /** - * Get all communities from Communities API and apply permission access validator, - * keyword searching, filter, paging and sorting. + * Initialize communities from Communities APIs * * @param params - * @private */ - private _getResults(params: Map){ - this.searchUtils.status = this.errorCodes.LOADING; - this.disableForms = true; - this.results = []; - this.searchUtils.totalResults = 0; + private initCommunities(params: Map) { this.subResults = this._communitiesService.getCommunities(this.properties, this.properties.communitiesAPI).subscribe( data => { let observables: Observable[] = []; for(let i = 0; i < data.length; i++) { - this.results[i] = new SearchResult(); - this.results[i].community = data[i]; + this.totalResults[i] = data[i]; // For Test do not delete them. - //this.results[i].community.description = "EGI is a federated e-Infrastructure set up to provide advanced computing services for research and innovation.EGI is a federated e-Infrastructure set up to provide advanced computing services for research and innovation.EGI is a federated e-Infrastructure set up to provide advanced computing services for research and innovation." - //this.results[i].community.date = new Date(new Date(2012, 0, 1).getTime() + Math.random() * (new Date().getTime() - new Date(2012, 0, 1).getTime())); - 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); + //this.results[i].description = "EGI is a federated e-Infrastructure set up to provide advanced computing services for research and innovation.EGI is a federated e-Infrastructure set up to provide advanced computing services for research and innovation.EGI is a federated e-Infrastructure set up to provide advanced computing services for research and innovation." + //this.results[i].date = new Date(new Date(2012, 0, 1).getTime() + Math.random() * (new Date().getTime() - new Date(2012, 0, 1).getTime())); + observables.push(this._subscribeService.isSubscribedToCommunity(this.totalResults[i].communityId, Session.getUserEmail(), this.properties["adminToolsAPIURL"])); + this.totalResults[i].isManager = this.isCommunityManager(this.results[i]); } Observable.forkJoin(observables).subscribe( res => { for(let i = 0; i < res.length; i++) { - this.results[i].isSubscribed = res[i]; + this.totalResults[i].isSubscribed = res[i]; } - this.applyParams(params, this.errorCodes.DONE); + this._getResults(params, this.errorCodes.DONE); }, err => { this.handleError('Error getting if user is subscribed', err); - this.applyParams(params, this.errorCodes.MISSING_CONTENT); + this._getResults(params, this.errorCodes.MISSING_CONTENT); } ); }, @@ -165,6 +135,46 @@ export class SearchCommunitiesComponent { ); } + + /** + * Get all communities from Communities API and apply permission access validator, + * keyword searching, filter, paging and sorting. + * + * @param params, status + * @private + */ + private _getResults(params: Map, status: number){ + this.searchUtils.status = this.errorCodes.LOADING; + this.disableForms = true; + this.results = this.totalResults; + this.searchUtils.totalResults = 0; + this.applyParams(params, status); + } + + /** + * Return the communities in which user has permission to view or manage. + */ + private showCommunities() { + let ret: CommunityInfo[] = []; + for(let result of this.results) { + if (result.status == 'hidden') { + continue; + } else if (result.status == "manager") { + let mail = Session.getUserEmail(); + if (mail == null) { // no user + continue; + } else if (Session.isCommunityCurator() || Session.isPortalAdministrator()) { + ret.push(result); + } else if (result.managers.indexOf(mail) != -1) { + ret.push(result); + } + continue; + } + ret.push(result); + } + this.results = ret; + } + /** * Apply permission access validator, * keyword searching, filter, paging and sorting. @@ -211,12 +221,12 @@ export class SearchCommunitiesComponent { * one of the given words. */ private searchForKeywords() { - let ret: SearchResult[] = []; + let ret: CommunityInfo[] = []; let keywords: string[] = this.searchUtils.keyword.split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,-1); for(let i = 0; i < this.results.length; i++) { for(let keyword of keywords) { - if (keyword != '' && (this.results[i].community.title.includes(keyword) || this.results[i].community.shortTitle.includes(keyword) || - this.results[i].community.communityId.includes(keyword) || this.results[i].community.description.includes(keyword))) { + if (keyword != '' && (this.results[i].title.includes(keyword) || this.results[i].shortTitle.includes(keyword) || + this.results[i].communityId.includes(keyword) || this.results[i].description.includes(keyword))) { ret.push(this.results[i]); break; } @@ -232,9 +242,9 @@ export class SearchCommunitiesComponent { * @param params */ private checkFilters(params: Map) { - let typeResults: SearchResult[] = this.applyFilter('type', params); - let statusResults: SearchResult[] = this.applyFilter('status' , params); - let roleResults: SearchResult[] = this.applyFilter('role', params); + let typeResults: CommunityInfo[] = this.applyFilter('type', params); + let statusResults: CommunityInfo[] = this.applyFilter('status' , params); + let roleResults: CommunityInfo[] = this.applyFilter('role', params); this.resetFilterNumbers('status'); this.updateFilterNumbers(typeResults.filter(value => { return roleResults.includes(value); @@ -261,8 +271,8 @@ export class SearchCommunitiesComponent { * @param filterId * @param params */ - private applyFilter(filterId: string, params: Map): SearchResult[] { - let results:SearchResult[] = []; + private applyFilter(filterId: string, params: Map): CommunityInfo[] { + let results:CommunityInfo[] = []; let values: string[] = []; if(params.get(filterId) != undefined) { values = (StringUtils.URIDecode(params.get(filterId))).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,-1); @@ -273,7 +283,7 @@ export class SearchCommunitiesComponent { results.push(this.results[i]); } else { for (let value of values) { - if (this.results[i].community.type == value.replace(/["']/g, "")) { + if (this.results[i].type == value.replace(/["']/g, "")) { results.push(this.results[i]); break; } @@ -344,13 +354,13 @@ export class SearchCommunitiesComponent { * @param results * @param filterId */ - private updateFilterNumbers(results: SearchResult[], filterId: string) { + private updateFilterNumbers(results: CommunityInfo[], filterId: string) { for(let k = 0; k < results.length; k++) { for (let i = 0; i < this.filters.length; i++) { 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].community.type == this.filters[i].values[j].id) { + if (results[k].type == this.filters[i].values[j].id) { this.filters[i].values[j].number++; } } @@ -379,9 +389,9 @@ export class SearchCommunitiesComponent { private sort() { if(this.searchUtils.sortBy == '') { this.results.sort((left, right): number => { - if (left.community.title > right.community.title) { + if (left.title > right.title) { return 1; - } else if (left.community.title < right.community.title) { + } else if (left.title < right.title) { return -1; } else { return 0; @@ -389,9 +399,9 @@ export class SearchCommunitiesComponent { }) } else if(this.searchUtils.sortBy == 'creationdate,descending') { this.results.sort((left, right): number => { - if (!right.community.date || left.community.date > right.community.date) { + if (!right.date || left.date > right.date) { return -1; - } else if (!left.community.date || left.community.date < right.community.date) { + } else if (!left.date || left.date < right.date) { return 1; } else { return 0; @@ -399,9 +409,9 @@ export class SearchCommunitiesComponent { }) } else if(this.searchUtils.sortBy == 'creationdate,ascending') { this.results.sort((left, right): number => { - if (!right.community.date || left.community.date > right.community.date) { + if (!right.date || left.date > right.date) { return 1; - } else if (!left.community.date || left.community.date < right.community.date) { + } else if (!left.date || left.date < right.date) { return -1; } else { return 0; @@ -416,7 +426,7 @@ export class SearchCommunitiesComponent { } public queryChanged($event) { - this._getResults($event.params); + this._getResults($event.params, this.errorCodes.DONE); } /**