[develop | FIXED | CHANGED]: Move formalize methods of stakehodlers in stakeholder.ts. Fix empty chart and number section in monitorbase component.
This commit is contained in:
parent
368ef1aba4
commit
35323bd744
|
@ -1,6 +1,6 @@
|
|||
import {SafeResourceUrl} from "@angular/platform-browser";
|
||||
import {properties} from "../../../../environments/environment";
|
||||
import {Session, User} from "../../login/utils/helper.class";
|
||||
import {StringUtils} from "../../utils/string-utils.class";
|
||||
|
||||
export const ChartHelper = {
|
||||
prefix: "((__",
|
||||
|
@ -52,6 +52,17 @@ export class Stakeholder {
|
|||
this.description = description;
|
||||
this.topics = [];
|
||||
}
|
||||
|
||||
static checkIsUpload(response: Stakeholder | Stakeholder[]): any | any[] {
|
||||
if (Array.isArray(response)) {
|
||||
response.forEach(value => {
|
||||
value.isUpload = value.logoUrl && !StringUtils.isValidUrl(value.logoUrl);
|
||||
});
|
||||
} else {
|
||||
response.isUpload = response.logoUrl && !StringUtils.isValidUrl(response.logoUrl);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
export class StakeholderInfo extends Stakeholder {
|
||||
|
|
|
@ -208,6 +208,8 @@ export abstract class MonitorIndicatorStakeholderBaseComponent extends Indicator
|
|||
}
|
||||
|
||||
protected setIndicators() {
|
||||
this.activeSubCategory.numbers = this.activeSubCategory.numbers.filter(section => section.indicators.length > 0);
|
||||
this.activeSubCategory.charts = this.activeSubCategory.charts.filter(section => section.indicators.length > 0);
|
||||
this.periodFilter.selectedFromAndToValues = (this.periodFilter.selectedFromValue || this.periodFilter.selectedToValue ? ((this.periodFilter.selectedFromValue && !this.periodFilter.selectedToValue ? "From " : "") + (!this.periodFilter.selectedFromValue && this.periodFilter.selectedToValue ? "Until " : "") + (this.periodFilter.selectedFromValue ? this.periodFilter.selectedFromValue : "") +
|
||||
(this.periodFilter.selectedFromValue && this.periodFilter.selectedToValue ? " - " : "") + (this.periodFilter.selectedToValue ? this.periodFilter.selectedToValue : "")) : "");
|
||||
//clear numbers when filters change
|
||||
|
|
|
@ -6,7 +6,6 @@ import {HelperFunctions} from "../../utils/HelperFunctions.class";
|
|||
import {map} from "rxjs/operators";
|
||||
import {properties} from "../../../../environments/environment";
|
||||
import {CustomOptions} from "../../services/servicesUtils/customOptions.class";
|
||||
import {StringUtils} from "../../utils/string-utils.class";
|
||||
|
||||
export interface Reorder {
|
||||
action: 'moved' | 'added' | 'removed',
|
||||
|
@ -41,7 +40,7 @@ export class StakeholderService {
|
|||
if (!this.stakeholderSubject.value || this.stakeholderSubject.value.alias !== alias || shouldUpdate) {
|
||||
this.promise = new Promise<void>((resolve, reject) => {
|
||||
this.sub = this.http.get<Stakeholder>(properties.monitorServiceAPIURL + '/stakeholder/' + encodeURIComponent(alias), CustomOptions.registryOptions()).pipe(map(stakeholder => {
|
||||
return this.formalize(this.checkIsUpload(stakeholder));
|
||||
return HelperFunctions.copy(Stakeholder.checkIsUpload(stakeholder));
|
||||
})).subscribe(stakeholder => {
|
||||
this.stakeholderSubject.next(stakeholder);
|
||||
resolve();
|
||||
|
@ -53,23 +52,24 @@ export class StakeholderService {
|
|||
}
|
||||
return from(this.getStakeholderAsync());
|
||||
}
|
||||
getResearcherStakeholder( orcid, name, results, shouldUpdate: boolean = false): Observable<Stakeholder> {
|
||||
|
||||
getResearcherStakeholder(orcid, name, results, shouldUpdate: boolean = false): Observable<Stakeholder> {
|
||||
if (!this.stakeholderSubject.value || this.stakeholderSubject.value.alias !== orcid || shouldUpdate) {
|
||||
this.promise = new Promise<void>((resolve, reject) => {
|
||||
this.sub = this.http.get<Stakeholder>(properties.monitorServiceAPIURL + '/stakeholder/' + encodeURIComponent("researcher"), CustomOptions.registryOptions()).pipe(map(stakeholder => {
|
||||
return this.formalize(this.checkIsUpload(stakeholder));
|
||||
return HelperFunctions.copy(Stakeholder.checkIsUpload(stakeholder));
|
||||
})).subscribe(stakeholder => {
|
||||
stakeholder.index_id = orcid;
|
||||
stakeholder.index_name = name;
|
||||
stakeholder.name = name;
|
||||
stakeholder.alias = orcid;
|
||||
if(results <7 && stakeholder.topics[0]?.categories[0]?.subCategories[0]){
|
||||
stakeholder.topics[0].categories[0].subCategories[0].charts=[]; // keep only numbers - charts wont show much anyway
|
||||
if (results < 7 && stakeholder.topics[0]?.categories[0]?.subCategories[0]) {
|
||||
stakeholder.topics[0].categories[0].subCategories[0].charts = []; // keep only numbers - charts wont show much anyway
|
||||
}
|
||||
this.stakeholderSubject.next(stakeholder);
|
||||
resolve();
|
||||
}, error => {
|
||||
let stakeholder = new Stakeholder(null,"researcher", orcid,name,name,orcid,"PUBLIC", null, null,"");
|
||||
let stakeholder = new Stakeholder(null, "researcher", orcid, name, name, orcid, "PUBLIC", null, null, "");
|
||||
this.stakeholderSubject.next(stakeholder);
|
||||
resolve();
|
||||
});
|
||||
|
@ -89,25 +89,25 @@ export class StakeholderService {
|
|||
|
||||
getAlias(url: string): Observable<string[]> {
|
||||
return this.http.get<Stakeholder[]>(url + '/stakeholder/alias', CustomOptions.registryOptions()).pipe(map(stakeholders => {
|
||||
return this.formalize(stakeholders);
|
||||
return HelperFunctions.copy(stakeholders);
|
||||
}));
|
||||
}
|
||||
|
||||
getStakeholders(url: string, type: string = null, defaultId: string = null): Observable<(Stakeholder & StakeholderInfo)[]> {
|
||||
return this.http.get<Stakeholder[]>(url + '/stakeholder' + ((type) ? ('?type=' + type) : '') + ((!type && defaultId) ? ('?defaultId=' + defaultId) : ''), CustomOptions.registryOptions()).pipe(map(stakeholders => {
|
||||
return this.formalize(this.checkIsUpload(stakeholders));
|
||||
return HelperFunctions.copy(Stakeholder.checkIsUpload(stakeholders));
|
||||
}));
|
||||
}
|
||||
|
||||
getMyStakeholders(url: string, type: string = null): Observable<(Stakeholder & StakeholderInfo)[]> {
|
||||
return this.http.get<Stakeholder[]>(url + '/my-stakeholder' + ((type) ? ('?type=' + type) : ''), CustomOptions.registryOptions()).pipe(map(stakeholders => {
|
||||
return this.formalize(this.checkIsUpload(stakeholders));
|
||||
return HelperFunctions.copy(Stakeholder.checkIsUpload(stakeholders));
|
||||
}));
|
||||
}
|
||||
|
||||
getDefaultStakeholders(url: string, type: string = null): Observable<Stakeholder[]> {
|
||||
return this.http.get<Stakeholder[]>(url + '/stakeholder/default' + ((type) ? ('?type=' + type) : ''), CustomOptions.registryOptions()).pipe(map(stakeholders => {
|
||||
return this.formalize(this.checkIsUpload(stakeholders));
|
||||
return HelperFunctions.copy(Stakeholder.checkIsUpload(stakeholders));
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ export class StakeholderService {
|
|||
stakeholder.alias = stakeholder.alias.slice(1);
|
||||
}
|
||||
return this.http.post<Stakeholder>(url + '/build-stakeholder', stakeholder, CustomOptions.registryOptions()).pipe(map(stakeholder => {
|
||||
return this.formalize(this.checkIsUpload(stakeholder));
|
||||
return HelperFunctions.copy(Stakeholder.checkIsUpload(stakeholder));
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -130,11 +130,11 @@ export class StakeholderService {
|
|||
}
|
||||
path = HelperFunctions.encodeArray(path);
|
||||
return this.http.post<any>(url + ((path.length > 0) ? '/' : '') + path.join('/') +
|
||||
'/save', element, CustomOptions.registryOptions()).pipe(map(element => {
|
||||
'/save', element, CustomOptions.registryOptions()).pipe(map(element => {
|
||||
if (path.length === 0) {
|
||||
return this.formalize(this.checkIsUpload(element));
|
||||
return HelperFunctions.copy(Stakeholder.checkIsUpload(element));
|
||||
} else {
|
||||
return this.formalize(element);
|
||||
return HelperFunctions.copy(element);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
@ -142,11 +142,11 @@ export class StakeholderService {
|
|||
saveBulkElements(url: string, indicators, path: string[] = []): Observable<any> {
|
||||
path = HelperFunctions.encodeArray(path);
|
||||
return this.http.post<any>(url + ((path.length > 0) ? '/' : '') + path.join('/') +
|
||||
'/save-bulk', indicators, CustomOptions.registryOptions()).pipe(map(element => {
|
||||
'/save-bulk', indicators, CustomOptions.registryOptions()).pipe(map(element => {
|
||||
if (path.length === 0) {
|
||||
return this.formalize(this.checkIsUpload(element));
|
||||
return HelperFunctions.copy(Stakeholder.checkIsUpload(element));
|
||||
} else {
|
||||
return this.formalize(element);
|
||||
return HelperFunctions.copy(element);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
@ -154,8 +154,8 @@ export class StakeholderService {
|
|||
saveSection(url: string, element: any, path: string[] = [], index: number = -1): Observable<Section> {
|
||||
path = HelperFunctions.encodeArray(path);
|
||||
return this.http.post<Section>(url + ((path.length > 0) ? '/' : '') + path.join('/') +
|
||||
'/save/' + index, element, CustomOptions.registryOptions()).pipe(map(element => {
|
||||
return this.formalize(element);
|
||||
'/save/' + index, element, CustomOptions.registryOptions()).pipe(map(element => {
|
||||
return HelperFunctions.copy(element);
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -176,7 +176,7 @@ export class StakeholderService {
|
|||
reorderIndicators(url: string, path: string[], reorder: Reorder, type: string = 'chart'): Observable<Indicator[]> {
|
||||
path = HelperFunctions.encodeArray(path);
|
||||
return this.http.post<Indicator[]>(url + '/' + path.join('/') + '/' + type + '/reorder', reorder, CustomOptions.registryOptions()).pipe(map(indicators => {
|
||||
return this.formalize(indicators);
|
||||
return HelperFunctions.copy(indicators);
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -187,19 +187,4 @@ export class StakeholderService {
|
|||
setStakeholder(stakeholder: Stakeholder) {
|
||||
this.stakeholderSubject.next(stakeholder);
|
||||
}
|
||||
|
||||
private checkIsUpload(response: Stakeholder | Stakeholder[]): any | any[] {
|
||||
if (Array.isArray(response)) {
|
||||
response.forEach(value => {
|
||||
value.isUpload = value.logoUrl && !StringUtils.isValidUrl(value.logoUrl);
|
||||
});
|
||||
} else {
|
||||
response.isUpload = response.logoUrl && !StringUtils.isValidUrl(response.logoUrl);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
private formalize(element: any) {
|
||||
return HelperFunctions.copy(element);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue