Add logoUrl function in string utils and logoUrl pipe for HTML usage

This commit is contained in:
Konstantinos Triantafyllou 2021-11-12 14:07:55 +02:00
parent b9e6894ba1
commit 7ef741c205
11 changed files with 46 additions and 178 deletions

View File

@ -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 => {

View File

@ -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) {

View File

@ -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 {

View File

@ -106,7 +106,7 @@
<ng-template #resultPreview let-result="result">
<div class="uk-flex uk-flex-center">
<img *ngIf="result.logoUrl"
[src]="result.getLogoUrl()"
[src]="result | logoUrl"
alt="{{(result.title)?result.title:result.shortTitle}} logo" loading="lazy">
<span *ngIf="!result.logoUrl" class="uk-icon">
<svg viewBox="0 0 20 20" class="uk-width-1-1" xmlns="http://www.w3.org/2000/svg" ratio="2.5"> <circle fill="none"

View File

@ -1,4 +1,4 @@
import {Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild} from '@angular/core';
import {Component, Input, OnInit, ViewChild} from '@angular/core';
import {ErrorCodes} from '../../utils/properties/errorCodes';
import {RouterHelper} from '../../utils/routerHelper.class';
import {EnvProperties} from '../../utils/properties/env-properties';

View File

@ -10,6 +10,7 @@ import {IconsModule} from "../../utils/icons/icons.module";
import {UrlPrefixModule} from "../../utils/pipes/url-prefix.module";
import {IconsService} from "../../utils/icons/icons.service";
import {group, lock} from "../../utils/icons/icons";
import {LogoUrlPipeModule} from "../../utils/pipes/logoUrlPipe.module";
// import {IconsService} from "../../utils/icons/icons.service";
// import {group, lock} from "../../utils/icons/icons";
@ -17,7 +18,7 @@ import {group, lock} from "../../utils/icons/icons";
imports: [
CommonModule, FormsModule,
RouterModule, ErrorMessagesModule,
AlertModalModule, ManageModule, IconsModule, UrlPrefixModule
AlertModalModule, ManageModule, IconsModule, UrlPrefixModule, LogoUrlPipeModule
],
declarations: [
PortalSearchResultComponent

View File

@ -1,50 +0,0 @@
/*
import { Pipe, PipeTransform} from '@angular/core'
@Pipe({
name: 'claimsDatatable'
})
export class ClaimsDatatablePipe implements PipeTransform {
transform(array: any[], args: any[]): any {
let query: string = args[0];
let counter:any = args[1];
let active: any = args[2];
active.page = 1;
if (query) {
var result = array.filter(row=>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;
}
}
*/

View File

@ -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;
// }
// }

View File

@ -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);
}
}

View File

@ -0,0 +1,16 @@
import {NgModule} from '@angular/core';
import {LogoUrlPipe} from "./logoUrl.pipe";
@NgModule({
imports: [],
declarations: [
LogoUrlPipe
],
providers: [],
exports: [
LogoUrlPipe
]
})
export class LogoUrlPipeModule {
}

View File

@ -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);
}