Revision 60326
Added by Konstantinos Triantafyllou about 3 years ago
modules/uoa-services-library/trunk/ng-openaire-library/src/app/monitor/services/stakeholder.service.ts | ||
---|---|---|
7 | 7 |
import {ActivatedRoute} from "@angular/router"; |
8 | 8 |
import {properties} from "../../../../environments/environment"; |
9 | 9 |
import {CustomOptions} from "../../services/servicesUtils/customOptions.class"; |
10 |
import {StringUtils} from "../../utils/string-utils.class"; |
|
11 |
import {el} from "@angular/platform-browser/testing/src/browser_util"; |
|
10 | 12 |
|
11 | 13 |
let maps: string[] = ['parameters', 'filters']; |
12 | 14 |
|
... | ... | |
43 | 45 |
if (!this.stakeholderSubject.value || this.stakeholderSubject.value.alias !== alias) { |
44 | 46 |
this.promise = new Promise<any>((resolve, reject) => { |
45 | 47 |
this.sub = this.http.get<Stakeholder>(properties.monitorServiceAPIURL + '/stakeholder/' + encodeURIComponent(alias), CustomOptions.registryOptions()).pipe(map(stakeholder => { |
46 |
return this.formalize(stakeholder);
|
|
48 |
return this.formalize(this.checkIsUpload(stakeholder));
|
|
47 | 49 |
})).subscribe(stakeholder => { |
48 | 50 |
this.stakeholderSubject.next(stakeholder); |
49 | 51 |
resolve(); |
... | ... | |
70 | 72 |
|
71 | 73 |
getStakeholders(url: string, type: string = null): Observable<(Stakeholder & StakeholderInfo)[]> { |
72 | 74 |
return this.http.get<Stakeholder[]>(url + '/stakeholder' + ((type) ? ('?type=' + type) : ''), CustomOptions.registryOptions()).pipe(map(stakeholders => { |
73 |
return this.formalize(stakeholders);
|
|
75 |
return this.formalize(this.checkIsUpload(stakeholders));
|
|
74 | 76 |
})); |
75 | 77 |
} |
76 | 78 |
|
77 | 79 |
getMyStakeholders(url: string, type: string = null): Observable<Stakeholder[]> { |
78 | 80 |
return this.http.get<Stakeholder[]>(url + '/my-stakeholder' + ((type) ? ('?type=' + type) : ''), CustomOptions.registryOptions()).pipe(map(stakeholders => { |
79 |
return this.formalize(stakeholders);
|
|
81 |
return this.formalize(this.checkIsUpload(stakeholders));
|
|
80 | 82 |
})); |
81 | 83 |
} |
82 | 84 |
|
83 | 85 |
getDefaultStakeholders(url: string, type: string = null): Observable<Stakeholder[]> { |
84 | 86 |
return this.http.get<Stakeholder[]>(url + '/stakeholder/default' + ((type) ? ('?type=' + type) : ''), CustomOptions.registryOptions()).pipe(map(stakeholders => { |
85 |
return this.formalize(stakeholders);
|
|
87 |
return this.formalize(this.checkIsUpload(stakeholders));
|
|
86 | 88 |
})); |
87 | 89 |
} |
88 | 90 |
|
89 | 91 |
buildStakeholder(url: string, stakeholder: Stakeholder): Observable<Stakeholder> { |
90 | 92 |
return this.http.post<Stakeholder>(url + '/build-stakeholder', stakeholder, CustomOptions.registryOptions()).pipe(map(stakeholder => { |
91 |
return this.formalize(stakeholder);
|
|
93 |
return this.formalize(this.checkIsUpload(stakeholder));
|
|
92 | 94 |
})); |
93 | 95 |
} |
94 | 96 |
|
... | ... | |
100 | 102 |
path = HelperFunctions.encodeArray(path); |
101 | 103 |
return this.http.post<any>(url + ((path.length > 0) ? '/' : '') + path.join('/') + |
102 | 104 |
'/save', element, CustomOptions.registryOptions()).pipe(map(element => { |
103 |
return this.formalize(element); |
|
105 |
if(path.length === 0) { |
|
106 |
return this.formalize(this.checkIsUpload(element)); |
|
107 |
} else { |
|
108 |
this.formalize(element); |
|
109 |
} |
|
104 | 110 |
})); |
105 | 111 |
} |
106 | 112 |
|
... | ... | |
136 | 142 |
this.stakeholderSubject.next(stakeholder); |
137 | 143 |
} |
138 | 144 |
|
145 |
private checkIsUpload(response: Stakeholder | Stakeholder[]): any | any[] { |
|
146 |
if(Array.isArray(response)) { |
|
147 |
response.forEach(value => { |
|
148 |
value.isUpload = !StringUtils.isValidUrl(value.logoUrl); |
|
149 |
}); |
|
150 |
} else { |
|
151 |
response.isUpload = !StringUtils.isValidUrl(response.logoUrl); |
|
152 |
} |
|
153 |
return response; |
|
154 |
} |
|
155 |
|
|
139 | 156 |
private formalize(element: any) { |
140 | 157 |
return HelperFunctions.copy(element); |
141 | 158 |
} |
modules/uoa-services-library/trunk/ng-openaire-library/src/app/utils/string-utils.class.ts | ||
---|---|---|
187 | 187 |
} |
188 | 188 |
|
189 | 189 |
export class StringUtils { |
190 |
|
|
191 |
public static urlRegex = 'https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.' + |
|
192 |
'[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.' + |
|
193 |
'[a-zA-Z0-9]+\.[^\s]{2,}'; |
|
194 |
|
|
190 | 195 |
public static urlPrefix(url: string): string { |
191 | 196 |
if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("//")) { |
192 | 197 |
return ""; |
... | ... | |
230 | 235 |
return !!email.match("^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$"); |
231 | 236 |
} |
232 | 237 |
|
238 |
public static isValidUrl(url: string): boolean { |
|
239 |
return new RegExp(this.urlRegex).test(url); |
|
240 |
} |
|
241 |
|
|
233 | 242 |
public static urlValidator(): ValidatorFn { |
234 |
return Validators.pattern('https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.' + |
|
235 |
'[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.' + |
|
236 |
'[a-zA-Z0-9]+\.[^\s]{2,}'); |
|
243 |
return Validators.pattern(this.urlRegex); |
|
237 | 244 |
} |
238 | 245 |
|
239 | 246 |
public static sliceString(mystr, size: number): string { |
modules/uoa-services-library/trunk/ng-openaire-library/src/app/utils/icons/icons.ts | ||
---|---|---|
62 | 62 |
data: '<svg xmlns="http://www.w3.org/2000/svg" height="20" viewBox="0 0 24 24" width="20"><path d="M0 0h24v24H0z" fill="none"/><circle cx="12" cy="12" r="10"/></svg>' |
63 | 63 |
} |
64 | 64 |
|
65 |
export const remove_circle = { |
|
66 |
name: 'remove_circle', |
|
67 |
data: '<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="20" viewBox="0 0 24 24" width="20"><g><path d="M0,0h24v24H0V0z" fill="none"/></g><g><path d="M12,2C6.47,2,2,6.47,2,12c0,5.53,4.47,10,10,10s10-4.47,10-10C22,6.47,17.53,2,12,2z M16.29,14.89 c0.39,0.39,0.39,1.02,0,1.41c-0.39,0.39-1.02,0.39-1.41,0L12,13.41l-2.89,2.89c-0.39,0.39-1.02,0.39-1.41,0 c-0.39-0.39-0.39-1.02,0-1.41L10.59,12L7.71,9.11c-0.39-0.39-0.39-1.02,0-1.41c0.39-0.39,1.02-0.39,1.41,0L12,10.59l2.89-2.89 c0.39-0.39,1.02-0.39,1.41,0c0.39,0.39,0.39,1.02,0,1.41L13.41,12L16.29,14.89z"/></g></svg>' |
|
68 |
} |
|
69 |
|
|
65 | 70 |
export const remove_circle_outline = { |
66 | 71 |
name: 'remove_circle_outline', |
67 | 72 |
data: '<svg xmlns="http://www.w3.org/2000/svg" height="20" viewBox="0 0 24 24" width="20"><path d="M0 0h24v24H0V0z" fill="none" opacity=".87"/><path d="M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm3.59-13L12 10.59 8.41 7 7 8.41 10.59 12 7 15.59 8.41 17 12 13.41 15.59 17 17 15.59 13.41 12 17 8.41z"/></svg>' |
modules/uoa-services-library/trunk/ng-openaire-library/src/app/sharedComponents/input/input.component.ts | ||
---|---|---|
72 | 72 |
<mat-form-field class="uk-width-1-1"> |
73 | 73 |
<mat-chip-list #chipList aria-label="Page selection"> |
74 | 74 |
<mat-chip *ngFor="let chip of formAsArray.controls; let i=index" |
75 |
(removed)="removed(i)" |
|
76 | 75 |
[removable]="removable"> |
77 | 76 |
{{chip.value[chipLabel]}} |
78 |
<span (click)="removed(i)" |
|
79 |
class="mat-chip-remove mat-chip-trailing-icon" uk-icon="close"></span> |
|
77 |
<icon name="remove_circle" class="mat-chip-remove" (click)="removed(i)"></icon> |
|
80 | 78 |
</mat-chip> |
81 |
<div class="uk-width-expand uk-position-relative uk-text-small"> |
|
79 |
<div class="uk-width-expand uk-position-relative uk-text-small chip-input">
|
|
82 | 80 |
<input #searchInput class="uk-width-1-1" [formControl]="searchControl" [matAutocomplete]="auto" [matChipInputFor]="chipList"> |
83 | 81 |
<div *ngIf="placeholder && !searchControl.value" class="placeholder uk-width-1-1" |
84 | 82 |
(click)="searchInput.focus()">{{placeholder}}</div> |
modules/uoa-services-library/trunk/ng-openaire-library/src/app/sharedComponents/input/input.component.css | ||
---|---|---|
32 | 32 |
font-family: "Roboto", sans-serif; |
33 | 33 |
font-size: 14px; |
34 | 34 |
} |
35 |
|
|
36 |
.chip-input { |
|
37 |
min-width: 100px; |
|
38 |
} |
modules/uoa-services-library/trunk/ng-openaire-library/src/app/sharedComponents/input/input.module.ts | ||
---|---|---|
7 | 7 |
import {MatCheckboxModule} from '@angular/material/checkbox'; |
8 | 8 |
import {IconsModule} from "../../utils/icons/icons.module"; |
9 | 9 |
import {IconsService} from "../../utils/icons/icons.service"; |
10 |
import {lock} from "../../utils/icons/icons"; |
|
10 |
import {lock, remove_circle} from "../../utils/icons/icons";
|
|
11 | 11 |
import {MatChipsModule} from "@angular/material/chips"; |
12 | 12 |
import {MatAutocompleteModule} from "@angular/material/autocomplete"; |
13 | 13 |
import {MatIconModule} from "@angular/material/icon"; |
... | ... | |
33 | 33 |
}) |
34 | 34 |
export class InputModule { |
35 | 35 |
constructor(private iconsService: IconsService) { |
36 |
this.iconsService.registerIcons([lock]); |
|
36 |
this.iconsService.registerIcons([lock, remove_circle]);
|
|
37 | 37 |
} |
38 | 38 |
} |
Also available in: Unified diff
[Library | Trunk]: 1. Fix chips css. 2. Stakeholder Service: Init is Upload after request