diff --git a/connect/community/communityInfo.ts b/connect/community/communityInfo.ts index dd60656d..065572ec 100644 --- a/connect/community/communityInfo.ts +++ b/connect/community/communityInfo.ts @@ -7,6 +7,7 @@ export class CommunityInfo { communityId: string; queryId: string; type: string; + /** @warning Use pipe in HTML or StringUtils.getLogoUrl in components */ logoUrl: string; description: string; managers: string[]; @@ -18,10 +19,6 @@ export class CommunityInfo { isSubscribed: boolean; isManager: boolean; - getLogoUrl() { - return (this.isUpload?(properties.utilsService + '/download/' + this.logoUrl):this.logoUrl); - } - public static checkIsUpload(response: CommunityInfo | CommunityInfo[]): any | any[] { if (Array.isArray(response)) { response.forEach(value => { diff --git a/landingPages/landing-utils/relatedTo.component.ts b/landingPages/landing-utils/relatedTo.component.ts index a00c80ff..2a0cd56f 100644 --- a/landingPages/landing-utils/relatedTo.component.ts +++ b/landingPages/landing-utils/relatedTo.component.ts @@ -7,6 +7,7 @@ import {CommunityService} from '../../connect/community/community.service'; import {ConnectHelper} from '../../connect/connectHelper'; import {UserManagementService} from '../../services/user-management.service'; import {HelperFunctions} from "../../utils/HelperFunctions.class"; +import {StringUtils} from "../../utils/string-utils.class"; @Component({ selector: 'relatedTo', @@ -147,7 +148,7 @@ export class RelatedToComponent implements OnInit { context.link = url; // grabbing the logoUrl for the gateway links if(community.logoUrl) { - context.logo = community.getLogoUrl(); + context.logo = StringUtils.getLogoUrl(community); } for(let gateway of this.gateways) { if(gateway.link == context.link) { diff --git a/monitor/entities/stakeholder.ts b/monitor/entities/stakeholder.ts index 74393327..60a52bdb 100644 --- a/monitor/entities/stakeholder.ts +++ b/monitor/entities/stakeholder.ts @@ -25,6 +25,7 @@ export class Stakeholder { visibility: Visibility; creationDate: Date = null; updateDate: Date; + /** @warning Use pipe in HTML or StringUtils.getLogoUrl in components */ logoUrl: string; isUpload: boolean = false; description: string; @@ -43,10 +44,6 @@ export class Stakeholder { this.description = description; this.topics = []; } - - getLogoUrl() { - return (this.isUpload?(properties.utilsService + '/download/' + this.logoUrl):this.logoUrl); - } } export class StakeholderInfo extends Stakeholder { diff --git a/searchPages/searchUtils/portal-search-result.component.html b/searchPages/searchUtils/portal-search-result.component.html index 83d48f32..fee46508 100644 --- a/searchPages/searchUtils/portal-search-result.component.html +++ b/searchPages/searchUtils/portal-search-result.component.html @@ -106,7 +106,7 @@
{{(result.title)?result.title:result.shortTitle}} logo this.filterAll(row, query)); - counter.count = result.length; - return result; - } - return array; - } - - filterAll(row: any, query: string) { - if(row.userMail.indexOf(query) > -1) { - return true; - } - if(row.targetType != 'project' && row.target.title.indexOf(query) > -1) { - return true; - } - if(row.sourceType != 'project' && row.source.title.indexOf(query) > -1) { - return true; - } - if(row.date.indexOf(query) > -1) { - return true; - } - - if(row.curatedBy != null && row.curatedBy.indexOf(query) > -1) { - return true; - } - - if(row.curationDate != null && row.curationDate.indexOf(query) > -1) { - return true; - } - - return false; - } -} -*/ diff --git a/utils/pipes/contentProvidersDatatable.pipe.ts b/utils/pipes/contentProvidersDatatable.pipe.ts deleted file mode 100644 index 27308757..00000000 --- a/utils/pipes/contentProvidersDatatable.pipe.ts +++ /dev/null @@ -1,113 +0,0 @@ -// import { Pipe, PipeTransform} from '@angular/core'; -// import { Filter, Value} from '../../searchPages/searchUtils/searchHelperClasses.class'; -// import { SearchUtilsClass } from '../../searchPages/searchUtils/searchUtils.class'; -// import { ErrorCodes} from '../properties/openaireProperties'; -// -// @Pipe({ -// name: 'contentProvidersDatatable' -// }) -// export class ContentProvidersDatatablePipe implements PipeTransform { -// -// transform(array: any[], args: any[]): any { -// if(array.length > 0) { -// let searchUtils: SearchUtilsClass = args[0]; -// let filters:Filter[] = args[1]; -// -// -// var errorCodes:ErrorCodes = new ErrorCodes(); -// searchUtils.status = errorCodes.LOADING; -// -// var result = array.filter(row=>this.filterAll(row, searchUtils.keyword.toLowerCase(), filters)); -// -// let oldTotal = searchUtils.totalResults; -// -// searchUtils.totalResults = result.length; -// -// var errorCodes:ErrorCodes = new ErrorCodes(); -// searchUtils.status = errorCodes.DONE; -// if(searchUtils.totalResults == 0 ){ -// searchUtils.status = errorCodes.NONE; -// } -// -// if(oldTotal != searchUtils.totalResults) { -// args[3].detectChanges(); -// } -// return result; -// } -// return []; -// } -// -// filterAll(row: any, query: string, filters:Filter[]) { -// let returnValue: boolean = false; -// -// if(query) { -// if(row.title.name.toLowerCase().indexOf(query) > -1) { -// returnValue = true; -// } -// -// if(row.type.toLowerCase().indexOf(query) > -1) { -// returnValue = true; -// } -// -// if(row.countries && row.countries.length > 0) { -// for(let country of row.countries) { -// if(country.toLowerCase().indexOf(query) > -1) { -// returnValue = true; -// break; -// } -// } -// } -// -// if(row.compatibility && row.compatibility.toLowerCase().indexOf(query) > -1) { -// returnValue = true; -// } -// -// if(row.organizations && row.organizations.length > 0) { -// for(let organization of row.organizations) { -// if(organization.name.toLowerCase().indexOf(query) > -1) { -// returnValue = true; -// break; -// } -// } -// } -// -// if(!returnValue) { -// return false; -// } -// } -// -// for (let filter of filters){ -// if(filter.countSelectedValues > 0){ -// for (let value of filter.values){ -// if(value.selected == true){ -// -// // make it generic in future commit -// let field:string = ""; -// if(filter.title == "Type") { -// field = "type"; -// } else if(filter.title == "Compatibility Level") { -// field = "compatibility"; -// } -// -// if(row[field] == value.name) { -// returnValue = true; -// if(filter.filterOperator == "or") { -// break; -// } -// } else { -// if(filter.filterOperator == "and") { -// return false; -// } -// returnValue = false; -// } -// } -// } -// if(!returnValue) { -// return false; -// } -// } -// } -// -// return true; -// } -// } diff --git a/utils/pipes/logoUrl.pipe.ts b/utils/pipes/logoUrl.pipe.ts new file mode 100644 index 00000000..a2a9291c --- /dev/null +++ b/utils/pipes/logoUrl.pipe.ts @@ -0,0 +1,14 @@ +import {Pipe, PipeTransform} from '@angular/core' +import {Stakeholder} from "../../monitor/entities/stakeholder"; +import {CommunityInfo} from "../../connect/community/communityInfo"; +import {StringUtils} from "../string-utils.class"; + +@Pipe({ name: 'logoUrl'}) +export class LogoUrlPipe implements PipeTransform { + + constructor() {} + + transform(value: Stakeholder | CommunityInfo): string { + return StringUtils.getLogoUrl(value); + } +} diff --git a/utils/pipes/logoUrlPipe.module.ts b/utils/pipes/logoUrlPipe.module.ts new file mode 100644 index 00000000..4a2e658f --- /dev/null +++ b/utils/pipes/logoUrlPipe.module.ts @@ -0,0 +1,16 @@ +import {NgModule} from '@angular/core'; +import {LogoUrlPipe} from "./logoUrl.pipe"; + +@NgModule({ + imports: [], + declarations: [ + LogoUrlPipe + ], + providers: [], + exports: [ + LogoUrlPipe + ] +}) +export class LogoUrlPipeModule { + +} diff --git a/utils/string-utils.class.ts b/utils/string-utils.class.ts index 7a072771..441ea639 100644 --- a/utils/string-utils.class.ts +++ b/utils/string-utils.class.ts @@ -1,5 +1,8 @@ import {UrlSegment} from '@angular/router'; import {AbstractControl, ValidatorFn, Validators} from "@angular/forms"; +import {Stakeholder} from "../monitor/entities/stakeholder"; +import {CommunityInfo} from "../connect/community/communityInfo"; +import {properties} from "../../../environments/environment"; export class Dates { public static yearMin = 1800; @@ -13,9 +16,7 @@ export class Dates { var year = parseInt(yearString, 10); // Check the ranges of month and year - if (year < yearMin || year > yearMax) - return false; - return true; + return !(year < yearMin || year > yearMax); } //format YYYY-MM-DD @@ -289,6 +290,10 @@ export class StringUtils { return !!email.match("^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$"); } + public static getLogoUrl(result: Stakeholder | CommunityInfo): string { + return (result.isUpload && result.logoUrl)?(properties.utilsService + '/download/' + result.logoUrl):result.logoUrl; + } + public static isValidUrl(url: string): boolean { return new RegExp(this.urlRegex).test(url); }