Create stats profile admin page

This commit is contained in:
Konstantinos Triantafyllou 2023-04-11 01:29:30 +03:00
parent 0b793bba40
commit 7b59267582
7 changed files with 458 additions and 267 deletions

View File

@ -44,6 +44,12 @@ const routes: Routes = [
canActivateChild: [AdminLoginGuard], canActivateChild: [AdminLoginGuard],
data: {hasAdminMenu: true, hasSidebar: false, portal: 'monitor', monitorCurator: true, parentClass: 'monitor'} data: {hasAdminMenu: true, hasSidebar: false, portal: 'monitor', monitorCurator: true, parentClass: 'monitor'}
}, },
{
path: 'admin/monitor/admin-tools/stats-profiles',
loadChildren: () => import('./stats-profiles/stats-profiles.module').then(m => m.StatsProfilesModule),
canActivateChild: [AdminLoginGuard],
data: {hasAdminMenu: true, hasSidebar: false, portal: 'monitor', monitorCurator: true}
},
{ {
path: 'admin/:stakeholder', path: 'admin/:stakeholder',
loadChildren: () => import('./admin-stakeholder/admin-stakeholder-routing.module').then(m => m.AdminStakeholderRoutingModule), loadChildren: () => import('./admin-stakeholder/admin-stakeholder-routing.module').then(m => m.AdminStakeholderRoutingModule),

View File

@ -19,89 +19,91 @@ import {NotificationHandler} from "../../openaireLibrary/utils/notification-hand
@Component({ @Component({
selector: 'edit-stakeholder', selector: 'edit-stakeholder',
template: ` template: `
<form *ngIf="stakeholderFb" [formGroup]="stakeholderFb"> <form *ngIf="stakeholderFb" [formGroup]="stakeholderFb">
<div class="uk-grid uk-grid-large" uk-grid> <div class="uk-grid uk-grid-large" uk-grid>
<div class="uk-width-1-2@m"> <div class="uk-width-1-2@m">
<div input id="name" [formInput]="stakeholderFb.get('name')" <div input id="name" [formInput]="stakeholderFb.get('name')"
placeholder="Name"></div> placeholder="Name"></div>
</div> </div>
<div class="uk-width-1-2@m"> <div class="uk-width-1-2@m">
<div input [formInput]="stakeholderFb.get('alias')" <div input [formInput]="stakeholderFb.get('alias')"
placeholder="URL Alias"></div> placeholder="URL Alias"></div>
</div> </div>
<div class="uk-width-1-3@m"> <div class="uk-width-1-3@m">
<div input [formInput]="stakeholderFb.get('index_id')" <div input [formInput]="stakeholderFb.get('index_id')"
placeholder="Index ID"></div> placeholder="Index ID"></div>
</div> </div>
<div class="uk-width-1-3@m"> <div class="uk-width-1-3@m">
<div input [formInput]="stakeholderFb.get('index_name')" <div input [formInput]="stakeholderFb.get('index_name')"
placeholder="Index Name"></div> placeholder="Index Name"></div>
</div> </div>
<div class="uk-width-1-3@m"> <div class="uk-width-1-3@m">
<div input [formInput]="stakeholderFb.get('index_shortName')" <div input [formInput]="stakeholderFb.get('index_shortName')"
placeholder="Index Short Name"></div> placeholder="Index Short Name"></div>
</div> </div>
<div class="uk-width-1-1"> <div class="uk-width-1-1">
<div input [type]="'textarea'" placeholder="Description" <div input [type]="'textarea'" placeholder="Description"
[rows]="4" [formInput]="stakeholderFb.get('description')"></div> [rows]="4" [formInput]="stakeholderFb.get('description')"></div>
</div> </div>
<div class="uk-width-1-1"> <div class="uk-width-1-1">
<input #file id="photo" type="file" class="uk-hidden" (change)="fileChangeEvent($event)"/> <input #file id="photo" type="file" class="uk-hidden" (change)="fileChangeEvent($event)"/>
<div *ngIf="!stakeholderFb.get('isUpload').value" class="uk-grid uk-grid-column-large" uk-grid> <div *ngIf="!stakeholderFb.get('isUpload').value" class="uk-grid uk-grid-column-large" uk-grid>
<div class="uk-margin-top uk-width-auto@l uk-width-1-1"> <div class="uk-margin-top uk-width-auto@l uk-width-1-1">
<div class="uk-grid uk-grid-column-large uk-flex-middle" uk-grid> <div class="uk-grid uk-grid-column-large uk-flex-middle" uk-grid>
<div class="uk-width-auto@l uk-width-1-1 uk-flex uk-flex-center"> <div class="uk-width-auto@l uk-width-1-1 uk-flex uk-flex-center">
<button class="uk-button uk-button-primary uk-flex uk-flex-middle uk-flex-wrap" <button class="uk-button uk-button-primary uk-flex uk-flex-middle uk-flex-wrap"
(click)="file.click()"> (click)="file.click()">
<icon name="cloud_upload" [flex]="true"></icon> <icon name="cloud_upload" [flex]="true"></icon>
<span class="uk-margin-small-left">Upload a file</span> <span class="uk-margin-small-left">Upload a file</span>
</button> </button>
</div> </div>
<div class="uk-text-center uk-text-bold uk-width-expand"> <div class="uk-text-center uk-text-bold uk-width-expand">
OR OR
</div>
</div> </div>
</div> </div>
<div input class="uk-width-expand" type="logoURL" [placeholder]="'Link to the logo'" [formInput]="stakeholderFb.get('logoUrl')"></div>
</div> </div>
<div *ngIf="stakeholderFb.get('isUpload').value" class="uk-width-1-1 uk-flex uk-flex-middle"> <div input class="uk-width-expand" type="logoURL" [placeholder]="'Link to the logo'"
<div class="uk-card uk-card-default uk-text-center uk-border-circle"> [formInput]="stakeholderFb.get('logoUrl')"></div>
<img class="uk-position-center uk-blend-multiply" [src]="photo"> </div>
</div> <div *ngIf="stakeholderFb.get('isUpload').value" class="uk-width-1-1 uk-flex uk-flex-middle">
<div class="uk-margin-left"> <div class="uk-card uk-card-default uk-text-center uk-border-circle">
<button (click)="remove()" class="uk-button-danger uk-icon-button uk-icon-button-small"> <img class="uk-position-center uk-blend-multiply" [src]="photo">
<icon [flex]="true" ratio="0.8" name="delete"></icon> </div>
</button> <div class="uk-margin-left">
</div> <button (click)="remove()" class="uk-button-danger uk-icon-button uk-icon-button-small">
<div class="uk-margin-small-left"> <icon [flex]="true" ratio="0.8" name="delete"></icon>
<button class="uk-button-secondary uk-icon-button uk-icon-button-small" (click)="file.click()"> </button>
<icon [flex]="true" ratio="0.8" name="edit"></icon> </div>
</button> <div class="uk-margin-small-left">
</div> <button class="uk-button-secondary uk-icon-button uk-icon-button-small" (click)="file.click()">
</div> <icon [flex]="true" ratio="0.8" name="edit"></icon>
<!-- Full width error message --> </button>
<div *ngIf="uploadError" class="uk-text-danger uk-margin-small-top uk-width-1-1">{{uploadError}}</div> </div>
</div> </div>
<div [class]="canChooseType ? 'uk-width-1-3@m' : 'uk-width-1-2@m'"> <!-- Full width error message -->
<div input [formInput]="stakeholderFb.get('visibility')" <div *ngIf="uploadError" class="uk-text-danger uk-margin-small-top uk-width-1-1">{{uploadError}}</div>
[placeholder]="'Select a status'"
[options]="stakeholderUtils.statuses" type="select"></div>
</div>
<div [class]="canChooseType ? 'uk-width-1-3@m' : 'uk-width-1-2@m'">
<div input [formInput]="stakeholderFb.get('type')"
[placeholder]="'Select a type'"
[options]="types" type="select"></div>
</div>
<ng-container *ngIf="canChooseType">
<div class="uk-width-1-3@m">
<div [placeholder]="'Select a template'"
input [formInput]="stakeholderFb.get('defaultId')"
[options]="defaultStakeholdersOptions" type="select"></div>
</div>
</ng-container>
</div> </div>
</form> <div [class]="canChooseType ? 'uk-width-1-3@m' : 'uk-width-1-2@m'">
<div #notify [class.uk-hidden]="!stakeholderFb" notify-form class="uk-width-1-1 uk-margin-large-top uk-margin-medium-bottom"></div> <div input [formInput]="stakeholderFb.get('visibility')"
[placeholder]="'Select a status'"
[options]="stakeholderUtils.statuses" type="select"></div>
</div>
<div [class]="canChooseType ? 'uk-width-1-3@m' : 'uk-width-1-2@m'">
<div input [formInput]="stakeholderFb.get('type')"
[placeholder]="'Select a type'"
[options]="types" type="select"></div>
</div>
<ng-container *ngIf="canChooseType">
<div class="uk-width-1-3@m">
<div [placeholder]="'Select a template'"
input [formInput]="stakeholderFb.get('defaultId')"
[options]="defaultStakeholdersOptions" type="select"></div>
</div>
</ng-container>
</div>
</form>
<div #notify [class.uk-hidden]="!stakeholderFb" notify-form
class="uk-width-1-1 uk-margin-large-top uk-margin-medium-bottom"></div>
`, `,
styleUrls: ['edit-stakeholder.component.less'] styleUrls: ['edit-stakeholder.component.less']
}) })
@ -312,13 +314,13 @@ export class EditStakeholderComponent implements OnDestroy {
this.notify.sendNotification(this.notification); this.notify.sendNotification(this.notification);
NotificationHandler.rise(stakeholder.name + ' has been <b>successfully created</b>'); NotificationHandler.rise(stakeholder.name + ' has been <b>successfully created</b>');
callback(stakeholder); callback(stakeholder);
this.loading = false; this.loading = false;
}, error => { }, error => {
NotificationHandler.rise('An error has occurred. Please try again later', 'danger'); NotificationHandler.rise('An error has occurred. Please try again later', 'danger');
if (errorCallback) { if (errorCallback) {
errorCallback(error) errorCallback(error)
} }
this.loading = false; this.loading = false;
})); }));
} else { } else {
this.subscriptions.push(this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, this.stakeholderFb.getRawValue()).subscribe(stakeholder => { this.subscriptions.push(this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, this.stakeholderFb.getRawValue()).subscribe(stakeholder => {

@ -1 +1 @@
Subproject commit f49149c99e7bf08179d95b56a1aac9848a850344 Subproject commit 6a2ac8cc4e1a77c10f632eccfd73b91082fe4a4a

View File

@ -0,0 +1,125 @@
import {ChangeDetectorRef, Component, OnDestroy, OnInit} from "@angular/core";
import {StatsProfilesService} from "./stats-profiles.service";
import {StatsProfile} from "../openaireLibrary/monitor/entities/stakeholder";
import {Subscription} from "rxjs";
import {FormBuilder, UntypedFormArray, Validators} from "@angular/forms";
import {NotificationHandler} from "../openaireLibrary/utils/notification-handler";
@Component({
selector: 'stats-profiles',
template: `
<div page-content>
<div header>
<admin-tabs tab="stats-profiles" [portal]="'monitor'"></admin-tabs>
</div>
<div actions>
<div class="uk-section-xsmall uk-container uk-container-xsmall">
<div class="uk-flex uk-flex-right@m uk-flex-center uk-flex-wrap uk-flex-middle">
<button class="uk-button uk-button-default uk-margin-small-right" (click)="resetForm()"
[disabled]="loading || statsProfilesForm.pristine" [class.uk-disabled]="loading">
Reset
</button>
<button class="uk-button uk-button-primary" (click)="save()"
[disabled]="loading || statsProfilesForm.pristine || statsProfilesForm.invalid"
[class.uk-disabled]="loading || statsProfilesForm.pristine || statsProfilesForm.invalid">
Save
</button>
</div>
</div>
</div>
<div inner>
<div class="uk-section uk-container uk-container-xsmall uk-position-relative" style="min-height: 60vh">
<div *ngIf="loading" class="uk-position-center">
<loading></loading>
</div>
<div *ngIf="!loading" class="uk-grid uk-child-width-1-1" uk-grid>
<div [id]="'profile-' + i.toString()" *ngFor="let statsProfile of statsProfilesForm.controls; let i=index" class="uk-flex uk-flex-middle">
<div input placeholder="Name" class="uk-width-expand" [formInput]="statsProfile.get('name')"></div>
<button *ngIf="statsProfilesForm.controls.length > 1" class="uk-button uk-button-link uk-margin-small-left" (click)="remove(i)">
<icon name="delete" [ratio]="1.2" [flex]="true"></icon>
</button>
</div>
<div class="uk-flex uk-flex-center">
<button class="uk-button uk-button-link uk-flex uk-flex-middle" (click)="add()">
<icon name="add" [flex]="true"></icon>
<span class="uk-margin-small-left uk-text-bold uk-text-uppercase">Add profile</span>
</button>
</div>
</div>
</div>
</div>
</div>
`
})
export class StatsProfilesComponent implements OnInit, OnDestroy {
public statsProfiles: StatsProfile[] = [];
public statsProfilesForm: UntypedFormArray;
public loading: boolean = true;
private subscriptions: any[] = [];
constructor(private statsProfilesService: StatsProfilesService,
private cdr: ChangeDetectorRef,
private fb: FormBuilder) {
}
ngOnInit() {
this.subscriptions.push(this.statsProfilesService.getStatsProfile().subscribe(statsProfiles => {
this.statsProfiles = statsProfiles;
this.resetForm();
this.loading = false;
}));
}
resetForm() {
this.statsProfilesForm =this.fb.array([]);
this.statsProfiles.forEach(statsProfile => {
this.statsProfilesForm.push(this.fb.group({
_id: this.fb.control(statsProfile._id),
name: this.fb.control(statsProfile.name, Validators.required)
}));
});
if(this.statsProfilesForm.length === 0) {
this.add();
}
}
remove(index: number) {
this.statsProfilesForm.removeAt(index);
this.statsProfilesForm.markAsDirty();
this.cdr.detectChanges();
}
add() {
this.statsProfilesForm.push(this.fb.group({
_id: this.fb.control(null),
name: this.fb.control('', Validators.required)
}));
this.statsProfilesForm.markAsDirty();
this.cdr.detectChanges();
if(!this.loading) {
document.getElementById('profile-' + (this.statsProfilesForm.length - 1).toString()).scrollIntoView({behavior: 'smooth'});
}
}
ngOnDestroy() {
this.subscriptions.forEach(subscription => {
if(subscription instanceof Subscription) {
subscription.unsubscribe();
}
});
}
save() {
this.loading = true;
this.subscriptions.push(this.statsProfilesService.saveStatsProfiles(this.statsProfilesForm.getRawValue()).subscribe(statsProfiles => {
this.statsProfiles = statsProfiles;
this.resetForm();
this.loading = false;
}, error => {
NotificationHandler.rise('An error has occurred. Please try again later', 'danger');
this.loading = false;
}));
}
}

View File

@ -0,0 +1,19 @@
import {NgModule} from "@angular/core";
import {CommonModule} from "@angular/common";
import {RouterModule} from "@angular/router";
import {StatsProfilesComponent} from "./stats-profiles.component";
import {PageContentModule} from "../openaireLibrary/dashboard/sharedComponents/page-content/page-content.module";
import {AdminTabsModule} from "../openaireLibrary/dashboard/sharedComponents/admin-tabs/admin-tabs.module";
import {IconsModule} from "../openaireLibrary/utils/icons/icons.module";
import {SearchInputModule} from "../openaireLibrary/sharedComponents/search-input/search-input.module";
import {InputModule} from "../openaireLibrary/sharedComponents/input/input.module";
import {LoadingModule} from "../openaireLibrary/utils/loading/loading.module";
@NgModule({
imports: [CommonModule, RouterModule.forChild([
{path: '', component: StatsProfilesComponent}
]), PageContentModule, AdminTabsModule, IconsModule, SearchInputModule, InputModule, LoadingModule],
declarations: [StatsProfilesComponent],
exports: [StatsProfilesComponent]
})
export class StatsProfilesModule {}

View File

@ -0,0 +1,23 @@
import {Injectable} from "@angular/core";
import {HttpClient} from "@angular/common/http";
import {properties} from "../../environments/environment";
import {Observable} from "rxjs";
import {StatsProfile} from "../openaireLibrary/monitor/entities/stakeholder";
import {CustomOptions} from "../openaireLibrary/services/servicesUtils/customOptions.class";
@Injectable({
providedIn: 'root'
})
export class StatsProfilesService {
constructor(private http: HttpClient) {
}
getStatsProfile(): Observable<StatsProfile[]> {
return this.http.get<StatsProfile[]>(properties.monitorServiceAPIURL + '/stats-profiles', CustomOptions.registryOptions());
}
saveStatsProfiles(statsProfiles: StatsProfile[]): Observable<StatsProfile[]> {
return this.http.post<StatsProfile[]>(properties.monitorServiceAPIURL + '/stats-profiles/bulk', statsProfiles, CustomOptions.registryOptions());
}
}

View File

@ -6,7 +6,7 @@ import {
Stakeholder, Stakeholder,
SubCategory, SubCategory,
Topic, Visibility, Topic, Visibility,
StakeholderEntities StakeholderEntities
} from "../openaireLibrary/monitor/entities/stakeholder"; } from "../openaireLibrary/monitor/entities/stakeholder";
import {AbstractControl, ValidatorFn, Validators} from "@angular/forms"; import {AbstractControl, ValidatorFn, Validators} from "@angular/forms";
import {Option} from "../openaireLibrary/sharedComponents/input/input.component"; import {Option} from "../openaireLibrary/sharedComponents/input/input.component";
@ -34,17 +34,17 @@ export class StakeholderUtils {
{icon: 'incognito', value: "PRIVATE", label: 'Private'}, {icon: 'incognito', value: "PRIVATE", label: 'Private'},
]; ];
visibilityIcon: Map<Visibility, string> = new Map<Visibility, string> ([ visibilityIcon: Map<Visibility, string> = new Map<Visibility, string>([
["PUBLIC", 'earth'], ["PUBLIC", 'earth'],
["PRIVATE", 'incognito'], ["PRIVATE", 'incognito'],
["RESTRICTED", 'restricted'] ["RESTRICTED", 'restricted']
]); ]);
getTypesByUserRoles(user, id:string = null):Option[]{ getTypesByUserRoles(user, id: string = null): Option[] {
let types = []; let types = [];
for(let type of this.types){ for (let type of this.types) {
if(Session.isCurator(type.value, user)|| Session.isPortalAdministrator(user)|| (id && Session.isManager(type.value, id, user))){ if (Session.isCurator(type.value, user) || Session.isPortalAdministrator(user) || (id && Session.isManager(type.value, id, user))) {
types.push(type); types.push(type);
} }
} }
@ -88,10 +88,10 @@ export class StakeholderUtils {
}*/ }*/
if (key == "index_name") { if (key == "index_name") {
indicatorPath.parameters[key] = funder.index_name; indicatorPath.parameters[key] = funder.index_name;
} else if (key == "index_id" ) { } else if (key == "index_id") {
indicatorPath.parameters[key] = funder.index_id; indicatorPath.parameters[key] = funder.index_id;
} else if (key == "index_shortName" ) { } else if (key == "index_shortName") {
indicatorPath.parameters[key] = funder.index_shortName.toLowerCase(); indicatorPath.parameters[key] = funder.index_shortName.toLowerCase();
} }
}); });
} }
@ -103,13 +103,13 @@ export class StakeholderUtils {
section.defaultId = section._id; section.defaultId = section._id;
section.stakeholderAlias = funder.alias; section.stakeholderAlias = funder.alias;
section._id = null; section._id = null;
for(let indicator of section.indicators) { for (let indicator of section.indicators) {
indicator.defaultId = indicator._id; indicator.defaultId = indicator._id;
indicator._id = null; indicator._id = null;
for (let indicatorPath of indicator.indicatorPaths) { for (let indicatorPath of indicator.indicatorPaths) {
/* indicatorPath.url = indicatorPath.url.replace("index_id", encodeURIComponent(funder.index_id)); /* indicatorPath.url = indicatorPath.url.replace("index_id", encodeURIComponent(funder.index_id));
indicatorPath.url = indicatorPath.url.replace("index_name", encodeURIComponent(funder.index_name)); indicatorPath.url = indicatorPath.url.replace("index_name", encodeURIComponent(funder.index_name));
indicatorPath.url = indicatorPath.url.replace("index_shortName", encodeURIComponent(funder.index_shortName));*/ indicatorPath.url = indicatorPath.url.replace("index_shortName", encodeURIComponent(funder.index_shortName));*/
// if(indicatorPath.parameters) { // if(indicatorPath.parameters) {
// indicatorPath.parameters.forEach((value: string, key: string) => { // indicatorPath.parameters.forEach((value: string, key: string) => {
// if (value.indexOf("_funder_name_")!=-1) { // if (value.indexOf("_funder_name_")!=-1) {
@ -122,7 +122,7 @@ export class StakeholderUtils {
} }
} }
} }
} }
category.subCategories = subTokeep; category.subCategories = subTokeep;
} }
@ -141,7 +141,7 @@ export class StakeholderUtils {
return null; return null;
} }
} }
aliasValidator(elements: any[]): ValidatorFn { aliasValidator(elements: any[]): ValidatorFn {
return (control: AbstractControl): { [key: string]: string } | null => { return (control: AbstractControl): { [key: string]: string } | null => {
if (control.value && elements.find(element => if (control.value && elements.find(element =>
@ -165,7 +165,7 @@ export class StakeholderUtils {
} }
export class IndicatorUtils { export class IndicatorUtils {
allChartTypes: Option[] = [ allChartTypes: Option[] = [
{value: 'pie', label: 'Pie'}, {value: 'pie', label: 'Pie'},
{value: 'table', label: 'Table'}, {value: 'table', label: 'Table'},
@ -174,32 +174,32 @@ export class IndicatorUtils {
{value: 'bar', label: 'Bar'}, {value: 'bar', label: 'Bar'},
{value: 'other', label: 'Other'} {value: 'other', label: 'Other'}
]; ];
basicChartTypes:IndicatorPathType[] =["pie", "line", "column", "bar"]; basicChartTypes: IndicatorPathType[] = ["pie", "line", "column", "bar"];
defaultChartType:IndicatorPathType = "other"; defaultChartType: IndicatorPathType = "other";
indicatorSizes: Option[] = [ indicatorSizes: Option[] = [
{value: 'small', label: 'Small (Enabled only for large screens)'}, {value: 'small', label: 'Small (Enabled only for large screens)'},
{value: 'medium', label: 'Medium'}, {value: 'medium', label: 'Medium'},
{value: 'large', label: 'Large'} {value: 'large', label: 'Large'}
]; ];
allSourceTypes: Option[] = [ allSourceTypes: Option[] = [
{value: 'search', label: 'Search'}, {value: 'search', label: 'Search'},
{value: 'statistics', label: 'Statistics'}, {value: 'statistics', label: 'Statistics'},
{value: 'stats-tool', label: 'Statistics tool'} {value: 'stats-tool', label: 'Statistics tool'}
]; ];
sourceTypes: Option[] = [ sourceTypes: Option[] = [
{value: 'stats-tool', label: 'Statistics tool'} {value: 'stats-tool', label: 'Statistics tool'}
]; ];
isPublic: Option[] = [ isPublic: Option[] = [
{icon: 'public', value: true, label: 'Public'}, {icon: 'public', value: true, label: 'Public'},
{icon: 'lock', value: false, label: 'Private'}, {icon: 'lock', value: false, label: 'Private'},
]; ];
isActive: Option[] = [ isActive: Option[] = [
{icon: 'brightness_1', iconClass: '', value: true, label: 'Active'}, {icon: 'brightness_1', iconClass: '', value: true, label: 'Active'},
{icon: 'brightness_1', value: false, label: 'Inactive'}, {icon: 'brightness_1', value: false, label: 'Inactive'},
]; ];
chartTypesIcons: Map<string, string> = new Map([ chartTypesIcons: Map<string, string> = new Map([
['pie', 'pie_chart'], ['pie', 'pie_chart'],
['table', 'table_chart'], ['table', 'table_chart'],
@ -208,42 +208,44 @@ export class IndicatorUtils {
['bar', 'notes'], ['bar', 'notes'],
['other', 'perm_media'] ['other', 'perm_media']
]); ]);
getChartTypes(initialType){
let types: Option[]= []; getChartTypes(initialType) {
if(this.basicChartTypes.indexOf(initialType) != -1){ let types: Option[] = [];
if (this.basicChartTypes.indexOf(initialType) != -1) {
(this.allChartTypes).forEach(option => { (this.allChartTypes).forEach(option => {
if(this.basicChartTypes.indexOf(option.value)!=-1){ if (this.basicChartTypes.indexOf(option.value) != -1) {
types.push(option); types.push(option);
} }
}); });
return types; return types;
}else if(initialType == "table") { } else if (initialType == "table") {
(this.allChartTypes).forEach(option => { (this.allChartTypes).forEach(option => {
if (initialType == option.value) { if (initialType == option.value) {
types.push(option); types.push(option);
} }
}); });
return types; return types;
}else { } else {
return this.allChartTypes; return this.allChartTypes;
} }
} }
isPublicIcon: Map<boolean, string> = new Map([ isPublicIcon: Map<boolean, string> = new Map([
[true, 'public'], [true, 'public'],
[false, 'lock'] [false, 'lock']
]); ]);
isActiveIcon: string = 'brightness_1'; isActiveIcon: string = 'brightness_1';
ignoredParameters = ['index_name','index_id','index_shortName']; ignoredParameters = ['index_name', 'index_id', 'index_shortName'];
parametersValidators: Map<string, any> = new Map<string, any>([ parametersValidators: Map<string, any> = new Map<string, any>([
['start_year', [Validators.required, Validators.pattern('^\\d+$')]], ['start_year', [Validators.required, Validators.pattern('^\\d+$')]],
['end_year', [Validators.required, Validators.pattern('^\\d+$')]] ['end_year', [Validators.required, Validators.pattern('^\\d+$')]]
]); ]);
public getFullUrl(stakeholder:Stakeholder, indicatorPath: IndicatorPath, fundingL0: string = null, startYear: string = null, endYear: string = null): string { public getFullUrl(stakeholder: Stakeholder, indicatorPath: IndicatorPath, fundingL0: string = null, startYear: string = null, endYear: string = null): string {
let replacedUrl =indicatorPath.chartObject?indicatorPath.chartObject:indicatorPath.url; let replacedUrl = indicatorPath.chartObject ? indicatorPath.chartObject : indicatorPath.url;
if (indicatorPath.parameters) { if (indicatorPath.parameters) {
Object.keys(indicatorPath.parameters).forEach(key => { Object.keys(indicatorPath.parameters).forEach(key => {
let replacedValue = indicatorPath.parameters[key]; let replacedValue = indicatorPath.parameters[key];
@ -262,14 +264,14 @@ export class IndicatorUtils {
if (key == "index_shortName") { if (key == "index_shortName") {
replacedValue = stakeholder.index_shortName.toLowerCase(); replacedValue = stakeholder.index_shortName.toLowerCase();
} }
replacedUrl = replacedUrl.split(ChartHelper.prefix + key + ChartHelper.suffix).join(replacedValue) replacedUrl = replacedUrl.split(ChartHelper.prefix + key + ChartHelper.suffix).join(replacedValue)
}); });
} }
if (indicatorPath.chartObject) { if (indicatorPath.chartObject) {
if (fundingL0 && indicatorPath.filters["fundingL0"]) { if (fundingL0 && indicatorPath.filters["fundingL0"]) {
let newJsonObject = JSON.parse(replacedUrl); let newJsonObject = JSON.parse(replacedUrl);
for (let queries of this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)]:newJsonObject[this.getDescriptionObjectName(newJsonObject)]) { for (let queries of this.getQueryObjectName(newJsonObject) ? newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)] : newJsonObject[this.getDescriptionObjectName(newJsonObject)]) {
if (!queries["query"]["filters"] || queries["query"]["filters"].length == 0) { if (!queries["query"]["filters"] || queries["query"]["filters"].length == 0) {
queries["query"]["filters"] = []; queries["query"]["filters"] = [];
} }
@ -280,8 +282,8 @@ export class IndicatorUtils {
} }
if (startYear && indicatorPath.filters["start_year"]) { if (startYear && indicatorPath.filters["start_year"]) {
let newJsonObject = JSON.parse(replacedUrl); let newJsonObject = JSON.parse(replacedUrl);
for (let queries of this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)]:newJsonObject[this.getDescriptionObjectName(newJsonObject)]) { for (let queries of this.getQueryObjectName(newJsonObject) ? newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)] : newJsonObject[this.getDescriptionObjectName(newJsonObject)]) {
if (!queries["query"]["filters"] || queries["query"]["filters"].length == 0) { if (!queries["query"]["filters"] || queries["query"]["filters"].length == 0) {
queries["query"]["filters"] = []; queries["query"]["filters"] = [];
} }
@ -292,7 +294,7 @@ export class IndicatorUtils {
} }
if (endYear && indicatorPath.filters["end_year"]) { if (endYear && indicatorPath.filters["end_year"]) {
let newJsonObject = JSON.parse(replacedUrl); let newJsonObject = JSON.parse(replacedUrl);
for (let queries of this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)]:newJsonObject[this.getDescriptionObjectName(newJsonObject)]) { for (let queries of this.getQueryObjectName(newJsonObject) ? newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)] : newJsonObject[this.getDescriptionObjectName(newJsonObject)]) {
if (!queries["query"]["filters"] || queries["query"]["filters"].length == 0) { if (!queries["query"]["filters"] || queries["query"]["filters"].length == 0) {
queries["query"]["filters"] = []; queries["query"]["filters"] = [];
} }
@ -301,23 +303,24 @@ export class IndicatorUtils {
} }
replacedUrl = JSON.stringify(newJsonObject); replacedUrl = JSON.stringify(newJsonObject);
} }
} }
//For numbers (e.g from stats-api , search service, etc) //For numbers (e.g from stats-api , search service, etc)
if(indicatorPath.url.indexOf(ChartHelper.prefix + 'index_id' + ChartHelper.suffix) !=- 1){ if (indicatorPath.url.indexOf(ChartHelper.prefix + 'index_id' + ChartHelper.suffix) != -1) {
replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_id' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_id)) replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_id' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_id))
} }
if(indicatorPath.url.indexOf(ChartHelper.prefix + 'index_name' + ChartHelper.suffix) !=- 1){ if (indicatorPath.url.indexOf(ChartHelper.prefix + 'index_name' + ChartHelper.suffix) != -1) {
replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_name' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_name)) replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_name' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_name))
} }
if(indicatorPath.url.indexOf(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix) !=- 1){ if (indicatorPath.url.indexOf(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix) != -1) {
replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_shortName)) replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_shortName))
} }
return (indicatorPath.chartObject?indicatorPath.url + encodeURIComponent(replacedUrl):replacedUrl); return (indicatorPath.chartObject ? indicatorPath.url + encodeURIComponent(replacedUrl) : replacedUrl);
} }
public getFullUrlWithFilters(stakeholder:Stakeholder, indicatorPath: IndicatorPath, fundingL0: string = null, startYear: string = null, endYear: string = null, coFunded:boolean=false): string {
public getFullUrlWithFilters(stakeholder: Stakeholder, indicatorPath: IndicatorPath, fundingL0: string = null, startYear: string = null, endYear: string = null, coFunded: boolean = false): string {
indicatorPath.filtersApplied = 0; indicatorPath.filtersApplied = 0;
let replacedUrl = indicatorPath.chartObject?indicatorPath.chartObject:indicatorPath.url; let replacedUrl = indicatorPath.chartObject ? indicatorPath.chartObject : indicatorPath.url;
if (indicatorPath.parameters) { if (indicatorPath.parameters) {
Object.keys(indicatorPath.parameters).forEach(key => { Object.keys(indicatorPath.parameters).forEach(key => {
let replacedValue = indicatorPath.parameters[key]; let replacedValue = indicatorPath.parameters[key];
@ -340,39 +343,39 @@ export class IndicatorUtils {
if (key == "index_shortName") { if (key == "index_shortName") {
replacedValue = stakeholder.index_shortName.toLowerCase(); replacedValue = stakeholder.index_shortName.toLowerCase();
} }
replacedUrl = replacedUrl.split(ChartHelper.prefix + key + ChartHelper.suffix).join(replacedValue) replacedUrl = replacedUrl.split(ChartHelper.prefix + key + ChartHelper.suffix).join(replacedValue)
}); });
} }
if (fundingL0) { if (fundingL0) {
if(indicatorPath.source == "stats-tool" && indicatorPath.chartObject) { if (indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
let filterResults = this.addFilter(replacedUrl, 'fundingL0', fundingL0); let filterResults = this.addFilter(replacedUrl, 'fundingL0', fundingL0);
replacedUrl = filterResults.url; replacedUrl = filterResults.url;
indicatorPath.filtersApplied += filterResults.filtersApplied; indicatorPath.filtersApplied += filterResults.filtersApplied;
} }
} }
if (startYear) { if (startYear) {
if(indicatorPath.source == "stats-tool" && indicatorPath.chartObject) { if (indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
let filterResults = this.addFilter(replacedUrl, 'start_year', startYear); let filterResults = this.addFilter(replacedUrl, 'start_year', startYear);
replacedUrl = filterResults.url; replacedUrl = filterResults.url;
indicatorPath.filtersApplied += filterResults.filtersApplied; indicatorPath.filtersApplied += filterResults.filtersApplied;
} }
} }
if (endYear ) { if (endYear) {
if(indicatorPath.source == "stats-tool" && indicatorPath.chartObject) { if (indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
let filterResults = this.addFilter(replacedUrl, 'end_year', endYear); let filterResults = this.addFilter(replacedUrl, 'end_year', endYear);
replacedUrl = filterResults.url; replacedUrl = filterResults.url;
indicatorPath.filtersApplied += filterResults.filtersApplied; indicatorPath.filtersApplied += filterResults.filtersApplied;
} }
} }
if (coFunded ) { if (coFunded) {
if(indicatorPath.source == "stats-tool" && indicatorPath.chartObject) { if (indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
let filterResults = this.addFilter(replacedUrl, 'co-funded', endYear); let filterResults = this.addFilter(replacedUrl, 'co-funded', endYear);
replacedUrl = filterResults.url; replacedUrl = filterResults.url;
indicatorPath.filtersApplied += filterResults.filtersApplied; indicatorPath.filtersApplied += filterResults.filtersApplied;
} }
} }
//For numbers //For numbers
if (replacedUrl.indexOf(ChartHelper.prefix + 'index_id' + ChartHelper.suffix) != -1) { if (replacedUrl.indexOf(ChartHelper.prefix + 'index_id' + ChartHelper.suffix) != -1) {
replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_id' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_id)) replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_id' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_id))
@ -383,75 +386,76 @@ export class IndicatorUtils {
if (replacedUrl.indexOf(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix) != -1) { if (replacedUrl.indexOf(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix) != -1) {
replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_shortName)) replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_shortName))
} }
//Check apply enhancements return this.applySchemaEnhancements( ..); //Check apply enhancements return this.applySchemaEnhancements( ..);
return (indicatorPath.chartObject?indicatorPath.url + encodeURIComponent(replacedUrl):replacedUrl); return (indicatorPath.chartObject ? indicatorPath.url + encodeURIComponent(replacedUrl) : replacedUrl);
} }
private addFilter(replacedUrl, filterType:FilterType, filterValue){
private addFilter(replacedUrl, filterType: FilterType, filterValue) {
let newJsonObject = JSON.parse(replacedUrl); let newJsonObject = JSON.parse(replacedUrl);
let filterApplied:boolean = false; let filterApplied: boolean = false;
let queryIndex = 0; let queryIndex = 0;
for (let queries of this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)]:newJsonObject[this.getDescriptionObjectName(newJsonObject)]) { for (let queries of this.getQueryObjectName(newJsonObject) ? newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)] : newJsonObject[this.getDescriptionObjectName(newJsonObject)]) {
/*Chart with Named Queries*/ /*Chart with Named Queries*/
if(queries["query"]["name"] && !queries["query"]["select"]){ if (queries["query"]["name"] && !queries["query"]["select"]) {
if(queries["query"]["name"].indexOf("monitor.")==-1 || !queries["query"]["parameters"]){ if (queries["query"]["name"].indexOf("monitor.") == -1 || !queries["query"]["parameters"]) {
continue; continue;
} }
if(filterType == 'fundingL0') { if (filterType == 'fundingL0') {
let paramFields = queries["query"]["name"].split(".").slice(3); let paramFields = queries["query"]["name"].split(".").slice(3);
let filterPosition = queries["query"]["name"].split(".").indexOf(filterType == "fundingL0" ? 'fl0' : filterType) ; let filterPosition = queries["query"]["name"].split(".").indexOf(filterType == "fundingL0" ? 'fl0' : filterType);
if (filterPosition != -1) { if (filterPosition != -1) {
//already filtered //already filtered
//TODO double check if we need to override if the fl0 is already filtered //TODO double check if we need to override if the fl0 is already filtered
filterPosition -=3; filterPosition -= 3;
/* //update the value /* //update the value
if(paramFields.length == queries["query"]["parameters"].length ){ if(paramFields.length == queries["query"]["parameters"].length ){
//ok //ok
queries["query"]["parameters"][filterPosition] = filterValue; queries["query"]["parameters"][filterPosition] = filterValue;
}else if((paramFields.length + 2) == queries["query"]["parameters"].length || (paramFields.length*2 + 4) == queries["query"]["parameters"].length){ }else if((paramFields.length + 2) == queries["query"]["parameters"].length || (paramFields.length*2 + 4) == queries["query"]["parameters"].length){
queries["query"]["parameters"][filterPosition + 2]=filterValue; queries["query"]["parameters"][filterPosition + 2]=filterValue;
filterApplied = true;
}
if((paramFields.length*2 + 4) == queries["query"]["parameters"].length){
queries["query"]["parameters"][(2* filterPosition) + 5]=filterValue;
}*/
//if applied with the same value mark as filtered
if (paramFields.length == queries["query"]["parameters"].length && queries["query"]["parameters"][filterPosition] == filterValue) {
filterApplied = true; filterApplied = true;
} } else if ((paramFields.length + 2) == queries["query"]["parameters"].length || (paramFields.length * 2 + 4) == queries["query"]["parameters"].length && queries["query"]["parameters"][filterPosition + 2] == filterValue) {
if((paramFields.length*2 + 4) == queries["query"]["parameters"].length){
queries["query"]["parameters"][(2* filterPosition) + 5]=filterValue;
}*/
//if applied with the same value mark as filtered
if(paramFields.length == queries["query"]["parameters"].length && queries["query"]["parameters"][filterPosition] == filterValue){
filterApplied = true;
}else if((paramFields.length + 2) == queries["query"]["parameters"].length || (paramFields.length*2 + 4) == queries["query"]["parameters"].length && queries["query"]["parameters"][filterPosition + 2]==filterValue){
filterApplied = true; filterApplied = true;
} }
} else { } else {
// if((paramFields.length*2) == queries["query"]["parameters"].length){ // if((paramFields.length*2) == queries["query"]["parameters"].length){
// queries["query"]["parameters"].splice(paramFields.length, 0, filterValue); // queries["query"]["parameters"].splice(paramFields.length, 0, filterValue);
// } // }
if((paramFields.length*2 + 4) == queries["query"]["parameters"].length){ if ((paramFields.length * 2 + 4) == queries["query"]["parameters"].length) {
queries["query"]["parameters"].splice(paramFields.length + 1, 0, filterValue); queries["query"]["parameters"].splice(paramFields.length + 1, 0, filterValue);
} }
queries["query"]["name"] = queries["query"]["name"] + ".fl0"; queries["query"]["name"] = queries["query"]["name"] + ".fl0";
queries["query"]["parameters"].push(filterValue); queries["query"]["parameters"].push(filterValue);
filterApplied = true; filterApplied = true;
} }
}else{ } else {
let paramFields = queries["query"]["name"].split(".").slice(3); let paramFields = queries["query"]["name"].split(".").slice(3);
// console.debug("Field Params length:" + paramFields.length) // console.debug("Field Params length:" + paramFields.length)
// console.debug(paramFields) // console.debug(paramFields)
// console.debug("Parameters length:" + queries["query"]["parameters"].length) // console.debug("Parameters length:" + queries["query"]["parameters"].length)
if((paramFields.length + 2) == queries["query"]["parameters"].length || (paramFields.length*2 + 4) == queries["query"]["parameters"].length){ if ((paramFields.length + 2) == queries["query"]["parameters"].length || (paramFields.length * 2 + 4) == queries["query"]["parameters"].length) {
filterApplied = true; filterApplied = true;
if(filterType == "start_year"){ if (filterType == "start_year") {
queries["query"]["parameters"][0] = parseInt(filterValue); queries["query"]["parameters"][0] = parseInt(filterValue);
}else if(filterType == "end_year"){ } else if (filterType == "end_year") {
queries["query"]["parameters"][1] = parseInt(filterValue); queries["query"]["parameters"][1] = parseInt(filterValue);
} }
} }
if((paramFields.length*2 + 4) == queries["query"]["parameters"].length){ if ((paramFields.length * 2 + 4) == queries["query"]["parameters"].length) {
filterApplied = true; filterApplied = true;
if(filterType == "start_year"){ if (filterType == "start_year") {
queries["query"]["parameters"][paramFields.length + 2] = parseInt(filterValue); queries["query"]["parameters"][paramFields.length + 2] = parseInt(filterValue);
}else if(filterType == "end_year"){ } else if (filterType == "end_year") {
queries["query"]["parameters"][paramFields.length + 3] = parseInt(filterValue); queries["query"]["parameters"][paramFields.length + 3] = parseInt(filterValue);
} }
} }
@ -466,7 +470,7 @@ export class IndicatorUtils {
/*Chart with proper json object*/ /*Chart with proper json object*/
//apply the filter in any select fields //apply the filter in any select fields
for (let select of queries["query"]["select"]) { for (let select of queries["query"]["select"]) {
let filterString = IndicatorFilterUtils.getFilter(select["field"],filterType); let filterString = IndicatorFilterUtils.getFilter(select["field"], filterType);
if (filterString) { if (filterString) {
let filter = JSON.parse(filterString); let filter = JSON.parse(filterString);
//check if filter already exists //check if filter already exists
@ -508,16 +512,16 @@ export class IndicatorUtils {
} }
queryIndex++; queryIndex++;
} }
return { "url":JSON.stringify(newJsonObject), "filtersApplied":(filterApplied)?1:0}; return {"url": JSON.stringify(newJsonObject), "filtersApplied": (filterApplied) ? 1 : 0};
} }
isComparingChart(newJsonObject, filter,){ isComparingChart(newJsonObject, filter,) {
let queriesCount = this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)].length:newJsonObject[this.getDescriptionObjectName(newJsonObject)].length; let queriesCount = this.getQueryObjectName(newJsonObject) ? newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)].length : newJsonObject[this.getDescriptionObjectName(newJsonObject)].length;
let values = []; let values = [];
if(queriesCount < 2){ if (queriesCount < 2) {
return false; return false;
} }
for (let queries of this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)]:newJsonObject[this.getDescriptionObjectName(newJsonObject)]) { for (let queries of this.getQueryObjectName(newJsonObject) ? newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)] : newJsonObject[this.getDescriptionObjectName(newJsonObject)]) {
let filterposition = IndicatorFilterUtils.filterIndexOf(filter, queries["query"]["filters"]); let filterposition = IndicatorFilterUtils.filterIndexOf(filter, queries["query"]["filters"]);
if (filterposition) { if (filterposition) {
if (values.indexOf(queries["query"]["filters"][filterposition.filter]['groupFilters'][filterposition.groupFilter]["values"][0]) == -1) { if (values.indexOf(queries["query"]["filters"][filterposition.filter]['groupFilters'][filterposition.groupFilter]["values"][0]) == -1) {
@ -528,13 +532,14 @@ export class IndicatorUtils {
// console.debug(values); // console.debug(values);
return values.length > 1; return values.length > 1;
} }
generateIndicatorByForm(form: any, indicatorPaths: IndicatorPath[], type:IndicatorType, addParameters:boolean = true ): Indicator {
generateIndicatorByForm(form: any, indicatorPaths: IndicatorPath[], type: IndicatorType, addParameters: boolean = true): Indicator {
let indicator: Indicator = new Indicator(form.name, form.description, form.additionalDescription, type, let indicator: Indicator = new Indicator(form.name, form.description, form.additionalDescription, type,
form.width, form.height, form.visibility, indicatorPaths, form.defaultId); form.width, form.height, form.visibility, indicatorPaths, form.defaultId);
indicator._id = form._id; indicator._id = form._id;
form.indicatorPaths.forEach((indicatorPath, index) => { form.indicatorPaths.forEach((indicatorPath, index) => {
indicator.indicatorPaths[index].type = indicatorPath.type; indicator.indicatorPaths[index].type = indicatorPath.type;
if(addParameters) { if (addParameters) {
indicatorPath.parameters.forEach(parameter => { indicatorPath.parameters.forEach(parameter => {
indicator.indicatorPaths[index].parameters[parameter.key] = parameter.value; indicator.indicatorPaths[index].parameters[parameter.key] = parameter.value;
if (parameter.key === 'type') { if (parameter.key === 'type') {
@ -545,24 +550,25 @@ export class IndicatorUtils {
}); });
return indicator; return indicator;
} }
generateIndicatorByNumberUrl(source: SourceType, url: string, stakeholder:Stakeholder, jsonPath = [], sourceServices:string[] =[] ): IndicatorPath {
generateIndicatorByNumberUrl(source: SourceType, url: string, stakeholder: Stakeholder, jsonPath = [], sourceServices: string[] = []): IndicatorPath {
let indicatorPath = new IndicatorPath(null, source, url, null, jsonPath); let indicatorPath = new IndicatorPath(null, source, url, null, jsonPath);
if (source === 'stats-tool') { if (source === 'stats-tool') {
indicatorPath.url = url.split("json=")[0] + "json="; indicatorPath.url = url.split("json=")[0] + "json=";
indicatorPath.url = indicatorPath.url.split("/")[indicatorPath.url.split("/").length - 1]; indicatorPath.url = indicatorPath.url.split("/")[indicatorPath.url.split("/").length - 1];
indicatorPath.chartObject = decodeURIComponent(url.indexOf("json=")!=-1?url.split("json=")[1]:""); indicatorPath.chartObject = decodeURIComponent(url.indexOf("json=") != -1 ? url.split("json=")[1] : "");
let chart = JSON.parse(indicatorPath.chartObject); let chart = JSON.parse(indicatorPath.chartObject);
this.parameterizeDefaultQuery(chart, indicatorPath, stakeholder); this.parameterizeDefaultQuery(chart, indicatorPath, stakeholder);
this.extractStakeHolders(chart, indicatorPath, stakeholder); this.extractStakeHolders(chart, indicatorPath, stakeholder);
indicatorPath.chartObject = JSON.stringify(chart); indicatorPath.chartObject = JSON.stringify(chart);
if(!jsonPath || jsonPath.length == 0 || (jsonPath.length == 1 && jsonPath[0]=="")) { if (!jsonPath || jsonPath.length == 0 || (jsonPath.length == 1 && jsonPath[0] == "")) {
indicatorPath.jsonPath = ["data", "0", "0", "0"]; indicatorPath.jsonPath = ["data", "0", "0", "0"];
} }
// this.addResultFilters(chart, indicatorPath); // this.addResultFilters(chart, indicatorPath);
}else { } else {
for( let service of sourceServices){ for (let service of sourceServices) {
if(url.indexOf(service)!=-1){ if (url.indexOf(service) != -1) {
url = url.split(service)[1] ; url = url.split(service)[1];
} }
} }
try { try {
@ -582,7 +588,8 @@ export class IndicatorUtils {
} }
return indicatorPath; return indicatorPath;
} }
generateIndicatorByChartUrl(source: SourceType, url: string, type: IndicatorPathType = null, stakeholder:Stakeholder): IndicatorPath {
generateIndicatorByChartUrl(source: SourceType, url: string, type: IndicatorPathType = null, stakeholder: Stakeholder): IndicatorPath {
let indicatorPath = new IndicatorPath(type, source, null, null, []); let indicatorPath = new IndicatorPath(type, source, null, null, []);
try { try {
if (source === 'stats-tool') { if (source === 'stats-tool') {
@ -592,18 +599,18 @@ export class IndicatorUtils {
let chart = JSON.parse(indicatorPath.chartObject); let chart = JSON.parse(indicatorPath.chartObject);
// console.debug(indicatorPath); // console.debug(indicatorPath);
if (indicatorPath.url == "chart?json=") { if (indicatorPath.url == "chart?json=") {
if (chart["library"] && (chart["library"] == "HighCharts" || chart["library"] == "eCharts" || chart["library"] == "HighMaps" )) { if (chart["library"] && (chart["library"] == "HighCharts" || chart["library"] == "eCharts" || chart["library"] == "HighMaps")) {
indicatorPath.type = this.extractType(chart, indicatorPath); indicatorPath.type = this.extractType(chart, indicatorPath);
} else { } else {
indicatorPath.type = this.defaultChartType; indicatorPath.type = this.defaultChartType;
} }
this.extractTitle(chart, indicatorPath); this.extractTitle(chart, indicatorPath);
this.extractSubTitle(chart, indicatorPath); this.extractSubTitle(chart, indicatorPath);
this.extractXTitle(chart, indicatorPath); this.extractXTitle(chart, indicatorPath);
this.extractYTitle(chart, indicatorPath); this.extractYTitle(chart, indicatorPath);
}else if(indicatorPath.url == "table?json="){ } else if (indicatorPath.url == "table?json=") {
indicatorPath.type = "table"; indicatorPath.type = "table";
} }
if (indicatorPath.url == "chart?json=" || indicatorPath.url == "table?json=") { if (indicatorPath.url == "chart?json=" || indicatorPath.url == "table?json=") {
@ -628,38 +635,41 @@ export class IndicatorUtils {
indicatorPath.url = url; indicatorPath.url = url;
indicatorPath.type = type; indicatorPath.type = type;
} }
}catch(e){ } catch (e) {
console.error(e); console.error(e);
indicatorPath.url = url; indicatorPath.url = url;
indicatorPath.type = type; indicatorPath.type = type;
} }
// console.debug(indicatorPath.parameters); // console.debug(indicatorPath.parameters);
// console.debug(indicatorPath.chartObject); // console.debug(indicatorPath.chartObject);
if(indicatorPath.type == null){ if (indicatorPath.type == null) {
indicatorPath.type = this.defaultChartType; indicatorPath.type = this.defaultChartType;
} }
return indicatorPath; return indicatorPath;
} }
private getQueryObjectName(obj){
if((obj[this.getDescriptionObjectName(obj)]).hasOwnProperty("queriesInfo")){ private getQueryObjectName(obj) {
return "queriesInfo"; if ((obj[this.getDescriptionObjectName(obj)]).hasOwnProperty("queriesInfo")) {
}else if((obj[this.getDescriptionObjectName(obj)]).hasOwnProperty("queries")) { return "queriesInfo";
} else if ((obj[this.getDescriptionObjectName(obj)]).hasOwnProperty("queries")) {
return "queries"; return "queries";
} }
} }
private getDescriptionObjectName(obj){
if(obj.hasOwnProperty("mapDescription")){ private getDescriptionObjectName(obj) {
if (obj.hasOwnProperty("mapDescription")) {
return "mapDescription"; return "mapDescription";
}else if(obj.hasOwnProperty("chartDescription")) { } else if (obj.hasOwnProperty("chartDescription")) {
return "chartDescription"; return "chartDescription";
}else if(obj.hasOwnProperty("tableDescription") ){ } else if (obj.hasOwnProperty("tableDescription")) {
return "tableDescription"; return "tableDescription";
}else if(obj.hasOwnProperty("series") ){ } else if (obj.hasOwnProperty("series")) {
return "series"; return "series";
} }
} }
private extractType(obj, indicatorPath: IndicatorPath): IndicatorPathType { private extractType(obj, indicatorPath: IndicatorPath): IndicatorPathType {
let type = (obj[this.getDescriptionObjectName(obj)] && obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)][0]["type"])?obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)][0]["type"]:""; let type = (obj[this.getDescriptionObjectName(obj)] && obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)][0]["type"]) ? obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)][0]["type"] : "";
if (this.basicChartTypes.indexOf(type) == -1) { if (this.basicChartTypes.indexOf(type) == -1) {
type = this.defaultChartType; type = this.defaultChartType;
} else { } else {
@ -668,16 +678,18 @@ export class IndicatorUtils {
} }
return type; return type;
} }
private extractStakeHolders(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) {
private extractStakeHolders(obj, indicatorPath: IndicatorPath, stakeholder: Stakeholder) {
this.extractFunder(obj, indicatorPath, stakeholder); this.extractFunder(obj, indicatorPath, stakeholder);
this.extractRI(obj, indicatorPath, stakeholder); this.extractRI(obj, indicatorPath, stakeholder);
this.extractOrganization(obj, indicatorPath, stakeholder); this.extractOrganization(obj, indicatorPath, stakeholder);
} }
private extractFunder(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) {
if(stakeholder.type != "funder"){ private extractFunder(obj, indicatorPath: IndicatorPath, stakeholder: Stakeholder) {
if (stakeholder.type != "funder") {
return; return;
} }
for (let query of this.getQueryObjectName(obj)?obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]:obj[this.getDescriptionObjectName(obj)]) { for (let query of this.getQueryObjectName(obj) ? obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)] : obj[this.getDescriptionObjectName(obj)]) {
if (!query["query"]["filters"]) { if (!query["query"]["filters"]) {
return; return;
} }
@ -698,12 +710,12 @@ export class IndicatorUtils {
} }
} }
} }
private extractRI(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) { private extractRI(obj, indicatorPath: IndicatorPath, stakeholder: Stakeholder) {
if(stakeholder.type != "ri"){ if (stakeholder.type != "ri") {
return; return;
} }
for (let query of this.getQueryObjectName(obj)?obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]:obj[this.getDescriptionObjectName(obj)]) { for (let query of this.getQueryObjectName(obj) ? obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)] : obj[this.getDescriptionObjectName(obj)]) {
if (!query["query"]["filters"]) { if (!query["query"]["filters"]) {
return; return;
} }
@ -720,14 +732,14 @@ export class IndicatorUtils {
} }
} }
} }
private extractOrganization(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) { private extractOrganization(obj, indicatorPath: IndicatorPath, stakeholder: Stakeholder) {
// works for publication.project.organization.name // works for publication.project.organization.name
// and publication.organization.name // and publication.organization.name
if(stakeholder.type != "organization"){ if (stakeholder.type != "organization") {
return; return;
} }
for (let query of this.getQueryObjectName(obj)?obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]:obj[this.getDescriptionObjectName(obj)]) { for (let query of this.getQueryObjectName(obj) ? obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)] : obj[this.getDescriptionObjectName(obj)]) {
if (!query["query"]["filters"]) { if (!query["query"]["filters"]) {
return; return;
} }
@ -744,6 +756,7 @@ export class IndicatorUtils {
} }
} }
} }
private extractStartYear(obj, indicatorPath: IndicatorPath) { private extractStartYear(obj, indicatorPath: IndicatorPath) {
let start_year; let start_year;
for (let query of obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) { for (let query of obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) {
@ -761,7 +774,7 @@ export class IndicatorUtils {
} }
} }
} }
private extractEndYear(obj, indicatorPath: IndicatorPath) { private extractEndYear(obj, indicatorPath: IndicatorPath) {
let end_year; let end_year;
for (let query of obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) { for (let query of obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) {
@ -779,31 +792,31 @@ export class IndicatorUtils {
} }
} }
} }
private parameterizeDefaultQuery(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) { private parameterizeDefaultQuery(obj, indicatorPath: IndicatorPath, stakeholder: Stakeholder) {
let name = ""; let name = "";
for (let query of this.getQueryObjectName(obj)?obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]:obj[this.getDescriptionObjectName(obj)]) { for (let query of this.getQueryObjectName(obj) ? obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)] : obj[this.getDescriptionObjectName(obj)]) {
//monitor.{{stakeholderType}}.{{queryname}} //monitor.{{stakeholderType}}.{{queryname}}
//parameters: stakeholderId*, type //parameters: stakeholderId*, type
if (query["query"]["name"]) { if (query["query"]["name"]) {
name = query["query"]["name"]; name = query["query"]["name"];
let parameters = (query["query"]["parameters"])?query["query"]["parameters"]:[]; let parameters = (query["query"]["parameters"]) ? query["query"]["parameters"] : [];
if(name.split('.')[0] == "rcd" && parameters.length > 0 && stakeholder.type=="ri") { if (name.split('.')[0] == "rcd" && parameters.length > 0 && stakeholder.type == "ri") {
//rcd.{{queryname}} //rcd.{{queryname}}
parameters[0] = ChartHelper.prefix + "index_id" + ChartHelper.suffix; parameters[0] = ChartHelper.prefix + "index_id" + ChartHelper.suffix;
indicatorPath.parameters["index_id"] = stakeholder.index_id; indicatorPath.parameters["index_id"] = stakeholder.index_id;
}else if(name.split('.')[0] == "monitor" && parameters.length == 0 && stakeholder.type=="funder"){ } else if (name.split('.')[0] == "monitor" && parameters.length == 0 && stakeholder.type == "funder") {
// old saved queries without params // old saved queries without params
//monitor.{{funder_shortName}}.{{type}}.{{queryname}} //monitor.{{funder_shortName}}.{{type}}.{{queryname}}
let stakeholderSN = name.split('.')[1]; let stakeholderSN = name.split('.')[1];
query["query"]["name"] = name.split('.' + stakeholderSN + ".")[0] + "." + ChartHelper.prefix + "index_shortName" + ChartHelper.suffix +"." + name.split('.' + stakeholderSN + ".")[1]; query["query"]["name"] = name.split('.' + stakeholderSN + ".")[0] + "." + ChartHelper.prefix + "index_shortName" + ChartHelper.suffix + "." + name.split('.' + stakeholderSN + ".")[1];
indicatorPath.parameters["index_shortName"] = stakeholder.index_shortName.toLowerCase(); indicatorPath.parameters["index_shortName"] = stakeholder.index_shortName.toLowerCase();
}else if(name.split('.')[0] == "monitor" && parameters.length > 0 && name.split('.')[1] == stakeholder.type) { } else if (name.split('.')[0] == "monitor" && parameters.length > 0 && name.split('.')[1] == stakeholder.type) {
// new parameterized queries // new parameterized queries
//monitor.{{type}}.{{queryname}}.{{param1 - id }}.{{param2 result-type}}.{{fl0}} --> params [start year, end year, id, result type, fl0] //monitor.{{type}}.{{queryname}}.{{param1 - id }}.{{param2 result-type}}.{{fl0}} --> params [start year, end year, id, result type, fl0]
let index = (name.split('.').slice(3).length +2 == parameters.length)?[2]:((name.split('.').slice(3).length * 2 + 4 == parameters.length)?[2,name.split('.').slice(3).length+4]:[0]); let index = (name.split('.').slice(3).length + 2 == parameters.length) ? [2] : ((name.split('.').slice(3).length * 2 + 4 == parameters.length) ? [2, name.split('.').slice(3).length + 4] : [0]);
for(let i of index) { for (let i of index) {
if (name.split('.').length > 3 && name.split('.')[3] == "id") { if (name.split('.').length > 3 && name.split('.')[3] == "id") {
parameters[i] = ChartHelper.prefix + "index_id" + ChartHelper.suffix; parameters[i] = ChartHelper.prefix + "index_id" + ChartHelper.suffix;
indicatorPath.parameters["index_id"] = stakeholder.index_id; indicatorPath.parameters["index_id"] = stakeholder.index_id;
@ -819,85 +832,87 @@ export class IndicatorUtils {
} }
} }
} }
private extractDataTitle(obj, indicatorPath: IndicatorPath) { private extractDataTitle(obj, indicatorPath: IndicatorPath) {
let index = 0; let index = 0;
if(!obj[this.getDescriptionObjectName(obj)] || !obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]){ if (!obj[this.getDescriptionObjectName(obj)] || !obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) {
return; return;
} }
for (let query of obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) { for (let query of obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) {
if (query["name"]) { if (query["name"]) {
let name = query["name"]; let name = query["name"];
query["name"] = ChartHelper.prefix + "data_title_"+index + ChartHelper.suffix; query["name"] = ChartHelper.prefix + "data_title_" + index + ChartHelper.suffix;
indicatorPath.parameters["data_title_"+index] = name; indicatorPath.parameters["data_title_" + index] = name;
} }
index++; index++;
} }
} }
private extractTitle(obj, indicatorPath: IndicatorPath) { private extractTitle(obj, indicatorPath: IndicatorPath) {
let title = ""; let title = "";
if (obj[this.getDescriptionObjectName(obj)]["title"]) { if (obj[this.getDescriptionObjectName(obj)]["title"]) {
title = obj[this.getDescriptionObjectName(obj)]["title"]["text"]; title = obj[this.getDescriptionObjectName(obj)]["title"]["text"];
obj[this.getDescriptionObjectName(obj)]["title"]["text"] = ChartHelper.prefix + "title" + ChartHelper.suffix; obj[this.getDescriptionObjectName(obj)]["title"]["text"] = ChartHelper.prefix + "title" + ChartHelper.suffix;
}else if (obj[this.getDescriptionObjectName(obj)]["options"] && obj[this.getDescriptionObjectName(obj)]["options"]["title"]) { } else if (obj[this.getDescriptionObjectName(obj)]["options"] && obj[this.getDescriptionObjectName(obj)]["options"]["title"]) {
title = obj[this.getDescriptionObjectName(obj)]["options"]["title"]; title = obj[this.getDescriptionObjectName(obj)]["options"]["title"];
obj[this.getDescriptionObjectName(obj)]["options"]["title"] = ChartHelper.prefix + "title" + ChartHelper.suffix; obj[this.getDescriptionObjectName(obj)]["options"]["title"] = ChartHelper.prefix + "title" + ChartHelper.suffix;
} }
indicatorPath.parameters["title"] = title ? title : ""; indicatorPath.parameters["title"] = title ? title : "";
} }
private extractSubTitle(obj, indicatorPath: IndicatorPath) { private extractSubTitle(obj, indicatorPath: IndicatorPath) {
let subtitle = ""; let subtitle = "";
if (obj[this.getDescriptionObjectName(obj)]["subtitle"]) { if (obj[this.getDescriptionObjectName(obj)]["subtitle"]) {
subtitle = obj[this.getDescriptionObjectName(obj)]["subtitle"]["text"]; subtitle = obj[this.getDescriptionObjectName(obj)]["subtitle"]["text"];
obj[this.getDescriptionObjectName(obj)]["subtitle"]["text"] = ChartHelper.prefix + "subtitle" + ChartHelper.suffix; obj[this.getDescriptionObjectName(obj)]["subtitle"]["text"] = ChartHelper.prefix + "subtitle" + ChartHelper.suffix;
indicatorPath.parameters["subtitle"] = subtitle ? subtitle : ""; indicatorPath.parameters["subtitle"] = subtitle ? subtitle : "";
}else if (obj[this.getDescriptionObjectName(obj)]["title"] && obj[this.getDescriptionObjectName(obj)]["title"] && obj[this.getDescriptionObjectName(obj)]["title"]["subtext"]) { } else if (obj[this.getDescriptionObjectName(obj)]["title"] && obj[this.getDescriptionObjectName(obj)]["title"] && obj[this.getDescriptionObjectName(obj)]["title"]["subtext"]) {
subtitle = obj[this.getDescriptionObjectName(obj)]["title"]["subtext"]; subtitle = obj[this.getDescriptionObjectName(obj)]["title"]["subtext"];
obj[this.getDescriptionObjectName(obj)]["title"]["subtext"] = ChartHelper.prefix + "subtitle" + ChartHelper.suffix; obj[this.getDescriptionObjectName(obj)]["title"]["subtext"] = ChartHelper.prefix + "subtitle" + ChartHelper.suffix;
indicatorPath.parameters["subtitle"] = subtitle ? subtitle : ""; indicatorPath.parameters["subtitle"] = subtitle ? subtitle : "";
} }
} }
private extractXTitle(obj, indicatorPath: IndicatorPath) { private extractXTitle(obj, indicatorPath: IndicatorPath) {
let title = ""; let title = "";
if (obj[this.getDescriptionObjectName(obj)]["xAxis"] && obj[this.getDescriptionObjectName(obj)]["xAxis"]["title"]) { if (obj[this.getDescriptionObjectName(obj)]["xAxis"] && obj[this.getDescriptionObjectName(obj)]["xAxis"]["title"]) {
title = obj[this.getDescriptionObjectName(obj)]["xAxis"]["title"]["text"]; title = obj[this.getDescriptionObjectName(obj)]["xAxis"]["title"]["text"];
obj[this.getDescriptionObjectName(obj)]["xAxis"]["title"]["text"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix; obj[this.getDescriptionObjectName(obj)]["xAxis"]["title"]["text"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
}else if (obj[this.getDescriptionObjectName(obj)]["options"] && obj[this.getDescriptionObjectName(obj)]["options"]["hAxis"] && obj[this.getDescriptionObjectName(obj)]["options"]["hAxis"]["title"]) { } else if (obj[this.getDescriptionObjectName(obj)]["options"] && obj[this.getDescriptionObjectName(obj)]["options"]["hAxis"] && obj[this.getDescriptionObjectName(obj)]["options"]["hAxis"]["title"]) {
title = obj[this.getDescriptionObjectName(obj)]["options"]["hAxis"]["title"]; title = obj[this.getDescriptionObjectName(obj)]["options"]["hAxis"]["title"];
obj[this.getDescriptionObjectName(obj)]["options"]["hAxis"]["title"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix; obj[this.getDescriptionObjectName(obj)]["options"]["hAxis"]["title"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
}else if (obj[this.getDescriptionObjectName(obj)]["xAxis"] && obj[this.getDescriptionObjectName(obj)]["xAxis"]["name"]) { } else if (obj[this.getDescriptionObjectName(obj)]["xAxis"] && obj[this.getDescriptionObjectName(obj)]["xAxis"]["name"]) {
title = obj[this.getDescriptionObjectName(obj)]["xAxis"]["name"]; title = obj[this.getDescriptionObjectName(obj)]["xAxis"]["name"];
obj[this.getDescriptionObjectName(obj)]["xAxis"]["name"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix; obj[this.getDescriptionObjectName(obj)]["xAxis"]["name"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
} }
indicatorPath.parameters["xAxisTitle"] = title ? title : ""; indicatorPath.parameters["xAxisTitle"] = title ? title : "";
} }
private extractYTitle(obj, indicatorPath: IndicatorPath) { private extractYTitle(obj, indicatorPath: IndicatorPath) {
let title = ""; let title = "";
if (obj[this.getDescriptionObjectName(obj)]["yAxis"] && obj[this.getDescriptionObjectName(obj)]["yAxis"]["title"] ) { if (obj[this.getDescriptionObjectName(obj)]["yAxis"] && obj[this.getDescriptionObjectName(obj)]["yAxis"]["title"]) {
title = obj[this.getDescriptionObjectName(obj)]["yAxis"]["title"]["text"]; title = obj[this.getDescriptionObjectName(obj)]["yAxis"]["title"]["text"];
obj[this.getDescriptionObjectName(obj)]["yAxis"]["title"]["text"] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix; obj[this.getDescriptionObjectName(obj)]["yAxis"]["title"]["text"] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix;
}else if (obj[this.getDescriptionObjectName(obj)]["options"]&& obj[this.getDescriptionObjectName(obj)]["options"]["vAxis"] && obj[this.getDescriptionObjectName(obj)]["options"]["vAxis"]["title"]) { } else if (obj[this.getDescriptionObjectName(obj)]["options"] && obj[this.getDescriptionObjectName(obj)]["options"]["vAxis"] && obj[this.getDescriptionObjectName(obj)]["options"]["vAxis"]["title"]) {
title = obj[this.getDescriptionObjectName(obj)]["options"]["vAxis"]["title"]; title = obj[this.getDescriptionObjectName(obj)]["options"]["vAxis"]["title"];
obj[this.getDescriptionObjectName(obj)]["options"]["vAxis"]["title"] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix; obj[this.getDescriptionObjectName(obj)]["options"]["vAxis"]["title"] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix;
}else if (obj[this.getDescriptionObjectName(obj)]["yAxis"] && obj[this.getDescriptionObjectName(obj)]["yAxis"]["name"]) { } else if (obj[this.getDescriptionObjectName(obj)]["yAxis"] && obj[this.getDescriptionObjectName(obj)]["yAxis"]["name"]) {
title = obj[this.getDescriptionObjectName(obj)]["yAxis"]["name"]; title = obj[this.getDescriptionObjectName(obj)]["yAxis"]["name"];
obj[this.getDescriptionObjectName(obj)]["yAxis"]["name"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix; obj[this.getDescriptionObjectName(obj)]["yAxis"]["name"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
} }
indicatorPath.parameters["yAxisTitle"] = title ? title : ""; indicatorPath.parameters["yAxisTitle"] = title ? title : "";
} }
private extractOldToolTitle(obj, indicatorPath: IndicatorPath) { private extractOldToolTitle(obj, indicatorPath: IndicatorPath) {
let title = ""; let title = "";
if (obj["title"]) { if (obj["title"]) {
title = obj["title"]; title = obj["title"];
obj["title"] = ChartHelper.prefix + "title" + ChartHelper.suffix; obj["title"] = ChartHelper.prefix + "title" + ChartHelper.suffix;
indicatorPath.parameters["title"] = title; indicatorPath.parameters["title"] = title;
} }
} }
private extractOldToolXTitle(obj, indicatorPath: IndicatorPath) { private extractOldToolXTitle(obj, indicatorPath: IndicatorPath) {
let title = ""; let title = "";
if (obj["xaxistitle"]) { if (obj["xaxistitle"]) {
@ -906,7 +921,7 @@ export class IndicatorUtils {
indicatorPath.parameters["xAxisTitle"] = title; indicatorPath.parameters["xAxisTitle"] = title;
} }
} }
private extractOldToolYTitle(obj, indicatorPath: IndicatorPath) { private extractOldToolYTitle(obj, indicatorPath: IndicatorPath) {
let title = ""; let title = "";
if (obj["fieldsheaders"]) { if (obj["fieldsheaders"]) {
@ -919,18 +934,19 @@ export class IndicatorUtils {
indicatorPath.parameters["yAxisTitle"] = title; indicatorPath.parameters["yAxisTitle"] = title;
} }
} }
public checkForSchemaEnhancements(url:string):boolean{ public checkForSchemaEnhancements(url: string): boolean {
return url !=this.applySchemaEnhancements(url); return url != this.applySchemaEnhancements(url);
} }
public applySchemaEnhancements(url:string):string{
public applySchemaEnhancements(url: string): string {
let resultEnhancements = [ let resultEnhancements = [
[".project.acronym",".project acronym"], [".project.acronym", ".project acronym"],
[".project.title",".project title"], [".project.title", ".project title"],
[".project.funder",".project funder"], [".project.funder", ".project funder"],
[".project.funding level 0",".project funding level 0"], [".project.funding level 0", ".project funding level 0"],
[".datasource.name",".HostedBy datasource"], [".datasource.name", ".HostedBy datasource"],
[".datasource.type",".HostedBy datasource type"] [".datasource.type", ".HostedBy datasource type"]
]; ];
let changes = ""; let changes = "";
for (let field of resultEnhancements) { for (let field of resultEnhancements) {
@ -941,12 +957,12 @@ export class IndicatorUtils {
} }
} }
} }
if(url.split('json=').length > 1) { if (url.split('json=').length > 1) {
let obj = JSON.parse(decodeURIComponent(url.split('json=')[1])); let obj = JSON.parse(decodeURIComponent(url.split('json=')[1]));
for (let query of this.getQueryObjectName(obj)?obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]:obj[this.getDescriptionObjectName(obj)]) { for (let query of this.getQueryObjectName(obj) ? obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)] : obj[this.getDescriptionObjectName(obj)]) {
if (!query["query"]["profile"] || query["query"]["profile"] == 'OpenAIRE All-inclusive' || query["query"]["profile"] == 'OpenAIRE original') { if (!query["query"]["profile"] || query["query"]["profile"] == 'OpenAIRE All-inclusive' || query["query"]["profile"] == 'OpenAIRE original') {
changes += (query["query"]["profile"] ? ( "Changed profile \"" + query["query"]["profile"] + "\" to " ):"Added profile ") + " \"monitor\""; changes += (query["query"]["profile"] ? ("Changed profile \"" + query["query"]["profile"] + "\" to ") : "Added profile ") + " \"monitor\"";
query["query"]["profile"] = 'monitor'; query["query"]["profile"] = 'monitor';
} }
} }