[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
This commit is contained in:
k.triantafyllou 2019-04-13 18:21:51 +00:00
parent d95cf337dc
commit ac51658415
2 changed files with 73 additions and 76 deletions

View File

@ -125,21 +125,8 @@ export class ContactComponent implements OnInit {
this.showLoading = false; this.showLoading = false;
} }
getProductionPrefix():string{
return (this.properties.environment == "beta")?"beta.":""
}
isProduction():boolean{
return this.properties.environment!="development";
}
public goToHome(data: any) { public goToHome(data: any) {
if(this.isProduction()) { this._router.navigate(['/']);
window.location.hostname = 'https://'+ this.getProductionPrefix() + 'connect.openaire.eu';
} else {
this._router.navigate(['/']);
}
} }
} }

View File

@ -35,7 +35,8 @@ export class SearchCommunitiesComponent {
public piwiksub: any; public piwiksub: any;
private errorCodes: ErrorCodes; private errorCodes: ErrorCodes;
private errorMessages: ErrorMessagesComponent; private errorMessages: ErrorMessagesComponent;
public results: SearchResult[] = []; public results: CommunityInfo[] = [];
public totalResults: CommunityInfo[] = [];
public sub: any; public subResults: any; public sub: any; public subResults: any;
public filters = []; public filters = [];
public searchFields:SearchFields = new SearchFields(); public searchFields:SearchFields = new SearchFields();
@ -80,7 +81,8 @@ export class SearchCommunitiesComponent {
this.searchPage.refineFields = this.refineFields; this.searchPage.refineFields = this.refineFields;
let queryParams = this.searchPage.getQueryParamsFromUrl(params); let queryParams = this.searchPage.getQueryParamsFromUrl(params);
this.filters = this.createFilters(); 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. * Initialize communities from Communities APIs
*/
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.
* *
* @param params * @param params
* @private
*/ */
private _getResults(params: Map<string, string>){ private initCommunities(params: Map<string, string>) {
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( this.subResults = this._communitiesService.getCommunities(this.properties, this.properties.communitiesAPI).subscribe(
data => { data => {
let observables: Observable<boolean>[] = []; let observables: Observable<boolean>[] = [];
for(let i = 0; i < data.length; i++) { for(let i = 0; i < data.length; i++) {
this.results[i] = new SearchResult(); this.totalResults[i] = data[i];
this.results[i].community = data[i];
// For Test do not delete them. // 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].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())); //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.results[i].community.communityId, Session.getUserEmail(), this.properties["adminToolsAPIURL"])); observables.push(this._subscribeService.isSubscribedToCommunity(this.totalResults[i].communityId, Session.getUserEmail(), this.properties["adminToolsAPIURL"]));
this.results[i].isManager = this.isCommunityManager(this.results[i].community); this.totalResults[i].isManager = this.isCommunityManager(this.results[i]);
} }
Observable.forkJoin(observables).subscribe( Observable.forkJoin(observables).subscribe(
res => { res => {
for(let i = 0; i < res.length; i++) { 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 => { err => {
this.handleError('Error getting if user is subscribed', 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<string, string>, 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, * Apply permission access validator,
* keyword searching, filter, paging and sorting. * keyword searching, filter, paging and sorting.
@ -211,12 +221,12 @@ export class SearchCommunitiesComponent {
* one of the given words. * one of the given words.
*/ */
private searchForKeywords() { private searchForKeywords() {
let ret: SearchResult[] = []; let ret: CommunityInfo[] = [];
let keywords: string[] = this.searchUtils.keyword.split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,-1); let keywords: string[] = this.searchUtils.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) {
if (keyword != '' && (this.results[i].community.title.includes(keyword) || this.results[i].community.shortTitle.includes(keyword) || if (keyword != '' && (this.results[i].title.includes(keyword) || this.results[i].shortTitle.includes(keyword) ||
this.results[i].community.communityId.includes(keyword) || this.results[i].community.description.includes(keyword))) { this.results[i].communityId.includes(keyword) || this.results[i].description.includes(keyword))) {
ret.push(this.results[i]); ret.push(this.results[i]);
break; break;
} }
@ -232,9 +242,9 @@ export class SearchCommunitiesComponent {
* @param params * @param params
*/ */
private checkFilters(params: Map<string, string>) { private checkFilters(params: Map<string, string>) {
let typeResults: SearchResult[] = this.applyFilter('type', params); let typeResults: CommunityInfo[] = this.applyFilter('type', params);
let statusResults: SearchResult[] = this.applyFilter('status' , params); let statusResults: CommunityInfo[] = this.applyFilter('status' , params);
let roleResults: SearchResult[] = this.applyFilter('role', params); let roleResults: CommunityInfo[] = this.applyFilter('role', params);
this.resetFilterNumbers('status'); this.resetFilterNumbers('status');
this.updateFilterNumbers(typeResults.filter(value => { this.updateFilterNumbers(typeResults.filter(value => {
return roleResults.includes(value); return roleResults.includes(value);
@ -261,8 +271,8 @@ export class SearchCommunitiesComponent {
* @param filterId * @param filterId
* @param params * @param params
*/ */
private applyFilter(filterId: string, params: Map<string, string>): SearchResult[] { private applyFilter(filterId: string, params: Map<string, string>): CommunityInfo[] {
let results:SearchResult[] = []; let results:CommunityInfo[] = [];
let values: string[] = []; let values: string[] = [];
if(params.get(filterId) != undefined) { if(params.get(filterId) != undefined) {
values = (StringUtils.URIDecode(params.get(filterId))).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,-1); values = (StringUtils.URIDecode(params.get(filterId))).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,-1);
@ -273,7 +283,7 @@ export class SearchCommunitiesComponent {
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].community.type == value.replace(/["']/g, "")) { if (this.results[i].type == value.replace(/["']/g, "")) {
results.push(this.results[i]); results.push(this.results[i]);
break; break;
} }
@ -344,13 +354,13 @@ export class SearchCommunitiesComponent {
* @param results * @param results
* @param filterId * @param filterId
*/ */
private updateFilterNumbers(results: SearchResult[], filterId: string) { private updateFilterNumbers(results: CommunityInfo[], 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].community.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++;
} }
} }
@ -379,9 +389,9 @@ export class SearchCommunitiesComponent {
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.community.title > right.community.title) { if (left.title > right.title) {
return 1; return 1;
} else if (left.community.title < right.community.title) { } else if (left.title < right.title) {
return -1; return -1;
} else { } else {
return 0; return 0;
@ -389,9 +399,9 @@ export class SearchCommunitiesComponent {
}) })
} 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.community.date || left.community.date > right.community.date) { if (!right.date || left.date > right.date) {
return -1; return -1;
} else if (!left.community.date || left.community.date < right.community.date) { } else if (!left.date || left.date < right.date) {
return 1; return 1;
} else { } else {
return 0; return 0;
@ -399,9 +409,9 @@ export class SearchCommunitiesComponent {
}) })
} 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.community.date || left.community.date > right.community.date) { if (!right.date || left.date > right.date) {
return 1; return 1;
} else if (!left.community.date || left.community.date < right.community.date) { } else if (!left.date || left.date < right.date) {
return -1; return -1;
} else { } else {
return 0; return 0;
@ -416,7 +426,7 @@ export class SearchCommunitiesComponent {
} }
public queryChanged($event) { public queryChanged($event) {
this._getResults($event.params); this._getResults($event.params, this.errorCodes.DONE);
} }
/** /**