[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 {SafeResourceUrl} from "@angular/platform-browser";
|
||||||
import {properties} from "../../../../environments/environment";
|
|
||||||
import {Session, User} from "../../login/utils/helper.class";
|
import {Session, User} from "../../login/utils/helper.class";
|
||||||
|
import {StringUtils} from "../../utils/string-utils.class";
|
||||||
|
|
||||||
export const ChartHelper = {
|
export const ChartHelper = {
|
||||||
prefix: "((__",
|
prefix: "((__",
|
||||||
|
@ -52,6 +52,17 @@ export class Stakeholder {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.topics = [];
|
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 {
|
export class StakeholderInfo extends Stakeholder {
|
||||||
|
|
|
@ -208,6 +208,8 @@ export abstract class MonitorIndicatorStakeholderBaseComponent extends Indicator
|
||||||
}
|
}
|
||||||
|
|
||||||
protected setIndicators() {
|
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.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 : "")) : "");
|
(this.periodFilter.selectedFromValue && this.periodFilter.selectedToValue ? " - " : "") + (this.periodFilter.selectedToValue ? this.periodFilter.selectedToValue : "")) : "");
|
||||||
//clear numbers when filters change
|
//clear numbers when filters change
|
||||||
|
|
|
@ -6,7 +6,6 @@ import {HelperFunctions} from "../../utils/HelperFunctions.class";
|
||||||
import {map} from "rxjs/operators";
|
import {map} from "rxjs/operators";
|
||||||
import {properties} from "../../../../environments/environment";
|
import {properties} from "../../../../environments/environment";
|
||||||
import {CustomOptions} from "../../services/servicesUtils/customOptions.class";
|
import {CustomOptions} from "../../services/servicesUtils/customOptions.class";
|
||||||
import {StringUtils} from "../../utils/string-utils.class";
|
|
||||||
|
|
||||||
export interface Reorder {
|
export interface Reorder {
|
||||||
action: 'moved' | 'added' | 'removed',
|
action: 'moved' | 'added' | 'removed',
|
||||||
|
@ -41,7 +40,7 @@ export class StakeholderService {
|
||||||
if (!this.stakeholderSubject.value || this.stakeholderSubject.value.alias !== alias || shouldUpdate) {
|
if (!this.stakeholderSubject.value || this.stakeholderSubject.value.alias !== alias || shouldUpdate) {
|
||||||
this.promise = new Promise<void>((resolve, reject) => {
|
this.promise = new Promise<void>((resolve, reject) => {
|
||||||
this.sub = this.http.get<Stakeholder>(properties.monitorServiceAPIURL + '/stakeholder/' + encodeURIComponent(alias), CustomOptions.registryOptions()).pipe(map(stakeholder => {
|
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 => {
|
})).subscribe(stakeholder => {
|
||||||
this.stakeholderSubject.next(stakeholder);
|
this.stakeholderSubject.next(stakeholder);
|
||||||
resolve();
|
resolve();
|
||||||
|
@ -53,23 +52,24 @@ export class StakeholderService {
|
||||||
}
|
}
|
||||||
return from(this.getStakeholderAsync());
|
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) {
|
if (!this.stakeholderSubject.value || this.stakeholderSubject.value.alias !== orcid || shouldUpdate) {
|
||||||
this.promise = new Promise<void>((resolve, reject) => {
|
this.promise = new Promise<void>((resolve, reject) => {
|
||||||
this.sub = this.http.get<Stakeholder>(properties.monitorServiceAPIURL + '/stakeholder/' + encodeURIComponent("researcher"), CustomOptions.registryOptions()).pipe(map(stakeholder => {
|
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 => {
|
})).subscribe(stakeholder => {
|
||||||
stakeholder.index_id = orcid;
|
stakeholder.index_id = orcid;
|
||||||
stakeholder.index_name = name;
|
stakeholder.index_name = name;
|
||||||
stakeholder.name = name;
|
stakeholder.name = name;
|
||||||
stakeholder.alias = orcid;
|
stakeholder.alias = orcid;
|
||||||
if(results <7 && stakeholder.topics[0]?.categories[0]?.subCategories[0]){
|
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
|
stakeholder.topics[0].categories[0].subCategories[0].charts = []; // keep only numbers - charts wont show much anyway
|
||||||
}
|
}
|
||||||
this.stakeholderSubject.next(stakeholder);
|
this.stakeholderSubject.next(stakeholder);
|
||||||
resolve();
|
resolve();
|
||||||
}, error => {
|
}, 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);
|
this.stakeholderSubject.next(stakeholder);
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
|
@ -89,25 +89,25 @@ export class StakeholderService {
|
||||||
|
|
||||||
getAlias(url: string): Observable<string[]> {
|
getAlias(url: string): Observable<string[]> {
|
||||||
return this.http.get<Stakeholder[]>(url + '/stakeholder/alias', CustomOptions.registryOptions()).pipe(map(stakeholders => {
|
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)[]> {
|
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.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)[]> {
|
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.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[]> {
|
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.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);
|
stakeholder.alias = stakeholder.alias.slice(1);
|
||||||
}
|
}
|
||||||
return this.http.post<Stakeholder>(url + '/build-stakeholder', stakeholder, CustomOptions.registryOptions()).pipe(map(stakeholder => {
|
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));
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,9 +132,9 @@ export class StakeholderService {
|
||||||
return this.http.post<any>(url + ((path.length > 0) ? '/' : '') + path.join('/') +
|
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) {
|
if (path.length === 0) {
|
||||||
return this.formalize(this.checkIsUpload(element));
|
return HelperFunctions.copy(Stakeholder.checkIsUpload(element));
|
||||||
} else {
|
} else {
|
||||||
return this.formalize(element);
|
return HelperFunctions.copy(element);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -144,9 +144,9 @@ export class StakeholderService {
|
||||||
return this.http.post<any>(url + ((path.length > 0) ? '/' : '') + path.join('/') +
|
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) {
|
if (path.length === 0) {
|
||||||
return this.formalize(this.checkIsUpload(element));
|
return HelperFunctions.copy(Stakeholder.checkIsUpload(element));
|
||||||
} else {
|
} else {
|
||||||
return this.formalize(element);
|
return HelperFunctions.copy(element);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ export class StakeholderService {
|
||||||
path = HelperFunctions.encodeArray(path);
|
path = HelperFunctions.encodeArray(path);
|
||||||
return this.http.post<Section>(url + ((path.length > 0) ? '/' : '') + path.join('/') +
|
return this.http.post<Section>(url + ((path.length > 0) ? '/' : '') + path.join('/') +
|
||||||
'/save/' + index, element, CustomOptions.registryOptions()).pipe(map(element => {
|
'/save/' + index, element, CustomOptions.registryOptions()).pipe(map(element => {
|
||||||
return this.formalize(element);
|
return HelperFunctions.copy(element);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ export class StakeholderService {
|
||||||
reorderIndicators(url: string, path: string[], reorder: Reorder, type: string = 'chart'): Observable<Indicator[]> {
|
reorderIndicators(url: string, path: string[], reorder: Reorder, type: string = 'chart'): Observable<Indicator[]> {
|
||||||
path = HelperFunctions.encodeArray(path);
|
path = HelperFunctions.encodeArray(path);
|
||||||
return this.http.post<Indicator[]>(url + '/' + path.join('/') + '/' + type + '/reorder', reorder, CustomOptions.registryOptions()).pipe(map(indicators => {
|
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) {
|
setStakeholder(stakeholder: Stakeholder) {
|
||||||
this.stakeholderSubject.next(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