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],
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',
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({
selector: 'edit-stakeholder',
template: `
<form *ngIf="stakeholderFb" [formGroup]="stakeholderFb">
<div class="uk-grid uk-grid-large" uk-grid>
<div class="uk-width-1-2@m">
<div input id="name" [formInput]="stakeholderFb.get('name')"
placeholder="Name"></div>
</div>
<div class="uk-width-1-2@m">
<div input [formInput]="stakeholderFb.get('alias')"
placeholder="URL Alias"></div>
</div>
<div class="uk-width-1-3@m">
<div input [formInput]="stakeholderFb.get('index_id')"
placeholder="Index ID"></div>
</div>
<div class="uk-width-1-3@m">
<div input [formInput]="stakeholderFb.get('index_name')"
placeholder="Index Name"></div>
</div>
<div class="uk-width-1-3@m">
<div input [formInput]="stakeholderFb.get('index_shortName')"
placeholder="Index Short Name"></div>
</div>
<div class="uk-width-1-1">
<div input [type]="'textarea'" placeholder="Description"
[rows]="4" [formInput]="stakeholderFb.get('description')"></div>
</div>
<div class="uk-width-1-1">
<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 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-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"
(click)="file.click()">
<icon name="cloud_upload" [flex]="true"></icon>
<span class="uk-margin-small-left">Upload a file</span>
</button>
</div>
<div class="uk-text-center uk-text-bold uk-width-expand">
OR
</div>
<form *ngIf="stakeholderFb" [formGroup]="stakeholderFb">
<div class="uk-grid uk-grid-large" uk-grid>
<div class="uk-width-1-2@m">
<div input id="name" [formInput]="stakeholderFb.get('name')"
placeholder="Name"></div>
</div>
<div class="uk-width-1-2@m">
<div input [formInput]="stakeholderFb.get('alias')"
placeholder="URL Alias"></div>
</div>
<div class="uk-width-1-3@m">
<div input [formInput]="stakeholderFb.get('index_id')"
placeholder="Index ID"></div>
</div>
<div class="uk-width-1-3@m">
<div input [formInput]="stakeholderFb.get('index_name')"
placeholder="Index Name"></div>
</div>
<div class="uk-width-1-3@m">
<div input [formInput]="stakeholderFb.get('index_shortName')"
placeholder="Index Short Name"></div>
</div>
<div class="uk-width-1-1">
<div input [type]="'textarea'" placeholder="Description"
[rows]="4" [formInput]="stakeholderFb.get('description')"></div>
</div>
<div class="uk-width-1-1">
<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 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-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"
(click)="file.click()">
<icon name="cloud_upload" [flex]="true"></icon>
<span class="uk-margin-small-left">Upload a file</span>
</button>
</div>
<div class="uk-text-center uk-text-bold uk-width-expand">
OR
</div>
</div>
<div input class="uk-width-expand" type="logoURL" [placeholder]="'Link to the logo'" [formInput]="stakeholderFb.get('logoUrl')"></div>
</div>
<div *ngIf="stakeholderFb.get('isUpload').value" class="uk-width-1-1 uk-flex uk-flex-middle">
<div class="uk-card uk-card-default uk-text-center uk-border-circle">
<img class="uk-position-center uk-blend-multiply" [src]="photo">
</div>
<div class="uk-margin-left">
<button (click)="remove()" class="uk-button-danger uk-icon-button uk-icon-button-small">
<icon [flex]="true" ratio="0.8" name="delete"></icon>
</button>
</div>
<div class="uk-margin-small-left">
<button class="uk-button-secondary uk-icon-button uk-icon-button-small" (click)="file.click()">
<icon [flex]="true" ratio="0.8" name="edit"></icon>
</button>
</div>
</div>
<!-- Full width error message -->
<div *ngIf="uploadError" class="uk-text-danger uk-margin-small-top uk-width-1-1">{{uploadError}}</div>
</div>
<div [class]="canChooseType ? 'uk-width-1-3@m' : 'uk-width-1-2@m'">
<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 input class="uk-width-expand" type="logoURL" [placeholder]="'Link to the logo'"
[formInput]="stakeholderFb.get('logoUrl')"></div>
</div>
<div *ngIf="stakeholderFb.get('isUpload').value" class="uk-width-1-1 uk-flex uk-flex-middle">
<div class="uk-card uk-card-default uk-text-center uk-border-circle">
<img class="uk-position-center uk-blend-multiply" [src]="photo">
</div>
<div class="uk-margin-left">
<button (click)="remove()" class="uk-button-danger uk-icon-button uk-icon-button-small">
<icon [flex]="true" ratio="0.8" name="delete"></icon>
</button>
</div>
<div class="uk-margin-small-left">
<button class="uk-button-secondary uk-icon-button uk-icon-button-small" (click)="file.click()">
<icon [flex]="true" ratio="0.8" name="edit"></icon>
</button>
</div>
</div>
<!-- Full width error message -->
<div *ngIf="uploadError" class="uk-text-danger uk-margin-small-top uk-width-1-1">{{uploadError}}</div>
</div>
</form>
<div #notify [class.uk-hidden]="!stakeholderFb" notify-form class="uk-width-1-1 uk-margin-large-top uk-margin-medium-bottom"></div>
<div [class]="canChooseType ? 'uk-width-1-3@m' : 'uk-width-1-2@m'">
<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']
})
@ -312,13 +314,13 @@ export class EditStakeholderComponent implements OnDestroy {
this.notify.sendNotification(this.notification);
NotificationHandler.rise(stakeholder.name + ' has been <b>successfully created</b>');
callback(stakeholder);
this.loading = false;
this.loading = false;
}, error => {
NotificationHandler.rise('An error has occurred. Please try again later', 'danger');
if (errorCallback) {
errorCallback(error)
}
this.loading = false;
this.loading = false;
}));
} else {
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,
SubCategory,
Topic, Visibility,
StakeholderEntities
StakeholderEntities
} from "../openaireLibrary/monitor/entities/stakeholder";
import {AbstractControl, ValidatorFn, Validators} from "@angular/forms";
import {Option} from "../openaireLibrary/sharedComponents/input/input.component";
@ -34,17 +34,17 @@ export class StakeholderUtils {
{icon: 'incognito', value: "PRIVATE", label: 'Private'},
];
visibilityIcon: Map<Visibility, string> = new Map<Visibility, string> ([
visibilityIcon: Map<Visibility, string> = new Map<Visibility, string>([
["PUBLIC", 'earth'],
["PRIVATE", 'incognito'],
["RESTRICTED", 'restricted']
]);
getTypesByUserRoles(user, id:string = null):Option[]{
getTypesByUserRoles(user, id: string = null): Option[] {
let types = [];
for(let type of this.types){
if(Session.isCurator(type.value, user)|| Session.isPortalAdministrator(user)|| (id && Session.isManager(type.value, id, user))){
for (let type of this.types) {
if (Session.isCurator(type.value, user) || Session.isPortalAdministrator(user) || (id && Session.isManager(type.value, id, user))) {
types.push(type);
}
}
@ -88,10 +88,10 @@ export class StakeholderUtils {
}*/
if (key == "index_name") {
indicatorPath.parameters[key] = funder.index_name;
} else if (key == "index_id" ) {
} else if (key == "index_id") {
indicatorPath.parameters[key] = funder.index_id;
} else if (key == "index_shortName" ) {
indicatorPath.parameters[key] = funder.index_shortName.toLowerCase();
} else if (key == "index_shortName") {
indicatorPath.parameters[key] = funder.index_shortName.toLowerCase();
}
});
}
@ -103,13 +103,13 @@ export class StakeholderUtils {
section.defaultId = section._id;
section.stakeholderAlias = funder.alias;
section._id = null;
for(let indicator of section.indicators) {
for (let indicator of section.indicators) {
indicator.defaultId = indicator._id;
indicator._id = null;
for (let indicatorPath of indicator.indicatorPaths) {
/* 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_shortName", encodeURIComponent(funder.index_shortName));*/
/* 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_shortName", encodeURIComponent(funder.index_shortName));*/
// if(indicatorPath.parameters) {
// indicatorPath.parameters.forEach((value: string, key: string) => {
// if (value.indexOf("_funder_name_")!=-1) {
@ -122,7 +122,7 @@ export class StakeholderUtils {
}
}
}
}
category.subCategories = subTokeep;
}
@ -141,7 +141,7 @@ export class StakeholderUtils {
return null;
}
}
aliasValidator(elements: any[]): ValidatorFn {
return (control: AbstractControl): { [key: string]: string } | null => {
if (control.value && elements.find(element =>
@ -165,7 +165,7 @@ export class StakeholderUtils {
}
export class IndicatorUtils {
allChartTypes: Option[] = [
{value: 'pie', label: 'Pie'},
{value: 'table', label: 'Table'},
@ -174,32 +174,32 @@ export class IndicatorUtils {
{value: 'bar', label: 'Bar'},
{value: 'other', label: 'Other'}
];
basicChartTypes:IndicatorPathType[] =["pie", "line", "column", "bar"];
defaultChartType:IndicatorPathType = "other";
basicChartTypes: IndicatorPathType[] = ["pie", "line", "column", "bar"];
defaultChartType: IndicatorPathType = "other";
indicatorSizes: Option[] = [
{value: 'small', label: 'Small (Enabled only for large screens)'},
{value: 'medium', label: 'Medium'},
{value: 'large', label: 'Large'}
];
allSourceTypes: Option[] = [
allSourceTypes: Option[] = [
{value: 'search', label: 'Search'},
{value: 'statistics', label: 'Statistics'},
{value: 'stats-tool', label: 'Statistics tool'}
];
sourceTypes: Option[] = [
sourceTypes: Option[] = [
{value: 'stats-tool', label: 'Statistics tool'}
];
isPublic: Option[] = [
{icon: 'public', value: true, label: 'Public'},
{icon: 'lock', value: false, label: 'Private'},
];
isActive: Option[] = [
{icon: 'brightness_1', iconClass: '', value: true, label: 'Active'},
{icon: 'brightness_1', value: false, label: 'Inactive'},
];
chartTypesIcons: Map<string, string> = new Map([
['pie', 'pie_chart'],
['table', 'table_chart'],
@ -208,42 +208,44 @@ export class IndicatorUtils {
['bar', 'notes'],
['other', 'perm_media']
]);
getChartTypes(initialType){
let types: Option[]= [];
if(this.basicChartTypes.indexOf(initialType) != -1){
getChartTypes(initialType) {
let types: Option[] = [];
if (this.basicChartTypes.indexOf(initialType) != -1) {
(this.allChartTypes).forEach(option => {
if(this.basicChartTypes.indexOf(option.value)!=-1){
if (this.basicChartTypes.indexOf(option.value) != -1) {
types.push(option);
}
});
return types;
}else if(initialType == "table") {
} else if (initialType == "table") {
(this.allChartTypes).forEach(option => {
if (initialType == option.value) {
types.push(option);
}
});
return types;
}else {
} else {
return this.allChartTypes;
}
}
isPublicIcon: Map<boolean, string> = new Map([
[true, 'public'],
[false, 'lock']
]);
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>([
['start_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 {
let replacedUrl =indicatorPath.chartObject?indicatorPath.chartObject:indicatorPath.url;
public getFullUrl(stakeholder: Stakeholder, indicatorPath: IndicatorPath, fundingL0: string = null, startYear: string = null, endYear: string = null): string {
let replacedUrl = indicatorPath.chartObject ? indicatorPath.chartObject : indicatorPath.url;
if (indicatorPath.parameters) {
Object.keys(indicatorPath.parameters).forEach(key => {
let replacedValue = indicatorPath.parameters[key];
@ -262,14 +264,14 @@ export class IndicatorUtils {
if (key == "index_shortName") {
replacedValue = stakeholder.index_shortName.toLowerCase();
}
replacedUrl = replacedUrl.split(ChartHelper.prefix + key + ChartHelper.suffix).join(replacedValue)
});
}
if (indicatorPath.chartObject) {
if (fundingL0 && indicatorPath.filters["fundingL0"]) {
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) {
queries["query"]["filters"] = [];
}
@ -280,8 +282,8 @@ export class IndicatorUtils {
}
if (startYear && indicatorPath.filters["start_year"]) {
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) {
queries["query"]["filters"] = [];
}
@ -292,7 +294,7 @@ export class IndicatorUtils {
}
if (endYear && indicatorPath.filters["end_year"]) {
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) {
queries["query"]["filters"] = [];
}
@ -301,23 +303,24 @@ export class IndicatorUtils {
}
replacedUrl = JSON.stringify(newJsonObject);
}
}
//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))
}
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))
}
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))
}
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;
let replacedUrl = indicatorPath.chartObject?indicatorPath.chartObject:indicatorPath.url;
let replacedUrl = indicatorPath.chartObject ? indicatorPath.chartObject : indicatorPath.url;
if (indicatorPath.parameters) {
Object.keys(indicatorPath.parameters).forEach(key => {
let replacedValue = indicatorPath.parameters[key];
@ -340,39 +343,39 @@ export class IndicatorUtils {
if (key == "index_shortName") {
replacedValue = stakeholder.index_shortName.toLowerCase();
}
replacedUrl = replacedUrl.split(ChartHelper.prefix + key + ChartHelper.suffix).join(replacedValue)
});
}
if (fundingL0) {
if(indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
if (indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
let filterResults = this.addFilter(replacedUrl, 'fundingL0', fundingL0);
replacedUrl = filterResults.url;
indicatorPath.filtersApplied += filterResults.filtersApplied;
}
}
if (startYear) {
if(indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
let filterResults = this.addFilter(replacedUrl, 'start_year', startYear);
if (indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
let filterResults = this.addFilter(replacedUrl, 'start_year', startYear);
replacedUrl = filterResults.url;
indicatorPath.filtersApplied += filterResults.filtersApplied;
}
}
if (endYear ) {
if(indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
if (endYear) {
if (indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
let filterResults = this.addFilter(replacedUrl, 'end_year', endYear);
replacedUrl = filterResults.url;
indicatorPath.filtersApplied += filterResults.filtersApplied;
}
}
if (coFunded ) {
if(indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
if (coFunded) {
if (indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
let filterResults = this.addFilter(replacedUrl, 'co-funded', endYear);
replacedUrl = filterResults.url;
indicatorPath.filtersApplied += filterResults.filtersApplied;
}
}
//For numbers
if (replacedUrl.indexOf(ChartHelper.prefix + 'index_id' + ChartHelper.suffix) != -1) {
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) {
replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_shortName))
}
//Check apply enhancements return this.applySchemaEnhancements( ..);
return (indicatorPath.chartObject?indicatorPath.url + encodeURIComponent(replacedUrl):replacedUrl);
//Check apply enhancements return this.applySchemaEnhancements( ..);
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 filterApplied:boolean = false;
let filterApplied: boolean = false;
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*/
if(queries["query"]["name"] && !queries["query"]["select"]){
if(queries["query"]["name"].indexOf("monitor.")==-1 || !queries["query"]["parameters"]){
if (queries["query"]["name"] && !queries["query"]["select"]) {
if (queries["query"]["name"].indexOf("monitor.") == -1 || !queries["query"]["parameters"]) {
continue;
}
if(filterType == 'fundingL0') {
if (filterType == 'fundingL0') {
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) {
//already filtered
//TODO double check if we need to override if the fl0 is already filtered
filterPosition -=3;
/* //update the value
if(paramFields.length == queries["query"]["parameters"].length ){
//ok
queries["query"]["parameters"][filterPosition] = filterValue;
}else if((paramFields.length + 2) == queries["query"]["parameters"].length || (paramFields.length*2 + 4) == queries["query"]["parameters"].length){
queries["query"]["parameters"][filterPosition + 2]=filterValue;
filterPosition -= 3;
/* //update the value
if(paramFields.length == queries["query"]["parameters"].length ){
//ok
queries["query"]["parameters"][filterPosition] = filterValue;
}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;
}
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;
}
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){
} 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;
}
} else {
// if((paramFields.length*2) == queries["query"]["parameters"].length){
// 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"]["name"] = queries["query"]["name"] + ".fl0";
queries["query"]["parameters"].push(filterValue);
filterApplied = true;
}
}else{
} else {
let paramFields = queries["query"]["name"].split(".").slice(3);
// console.debug("Field Params length:" + paramFields.length)
// console.debug(paramFields)
// 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;
if(filterType == "start_year"){
queries["query"]["parameters"][0] = parseInt(filterValue);
}else if(filterType == "end_year"){
queries["query"]["parameters"][1] = parseInt(filterValue);
}
if (filterType == "start_year") {
queries["query"]["parameters"][0] = parseInt(filterValue);
} else if (filterType == "end_year") {
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;
if(filterType == "start_year"){
if (filterType == "start_year") {
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);
}
}
@ -466,7 +470,7 @@ export class IndicatorUtils {
/*Chart with proper json object*/
//apply the filter in any select fields
for (let select of queries["query"]["select"]) {
let filterString = IndicatorFilterUtils.getFilter(select["field"],filterType);
let filterString = IndicatorFilterUtils.getFilter(select["field"], filterType);
if (filterString) {
let filter = JSON.parse(filterString);
//check if filter already exists
@ -508,16 +512,16 @@ export class IndicatorUtils {
}
queryIndex++;
}
return { "url":JSON.stringify(newJsonObject), "filtersApplied":(filterApplied)?1:0};
return {"url": JSON.stringify(newJsonObject), "filtersApplied": (filterApplied) ? 1 : 0};
}
isComparingChart(newJsonObject, filter,){
let queriesCount = this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)].length:newJsonObject[this.getDescriptionObjectName(newJsonObject)].length;
isComparingChart(newJsonObject, filter,) {
let queriesCount = this.getQueryObjectName(newJsonObject) ? newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)].length : newJsonObject[this.getDescriptionObjectName(newJsonObject)].length;
let values = [];
if(queriesCount < 2){
if (queriesCount < 2) {
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"]);
if (filterposition) {
if (values.indexOf(queries["query"]["filters"][filterposition.filter]['groupFilters'][filterposition.groupFilter]["values"][0]) == -1) {
@ -528,13 +532,14 @@ export class IndicatorUtils {
// console.debug(values);
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,
form.width, form.height, form.visibility, indicatorPaths, form.defaultId);
indicator._id = form._id;
form.indicatorPaths.forEach((indicatorPath, index) => {
indicator.indicatorPaths[index].type = indicatorPath.type;
if(addParameters) {
if (addParameters) {
indicatorPath.parameters.forEach(parameter => {
indicator.indicatorPaths[index].parameters[parameter.key] = parameter.value;
if (parameter.key === 'type') {
@ -545,24 +550,25 @@ export class IndicatorUtils {
});
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);
if (source === 'stats-tool') {
indicatorPath.url = url.split("json=")[0] + "json=";
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);
this.parameterizeDefaultQuery(chart, indicatorPath, stakeholder);
this.extractStakeHolders(chart, indicatorPath, stakeholder);
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"];
}
// this.addResultFilters(chart, indicatorPath);
}else {
for( let service of sourceServices){
if(url.indexOf(service)!=-1){
url = url.split(service)[1] ;
} else {
for (let service of sourceServices) {
if (url.indexOf(service) != -1) {
url = url.split(service)[1];
}
}
try {
@ -582,7 +588,8 @@ export class IndicatorUtils {
}
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, []);
try {
if (source === 'stats-tool') {
@ -592,18 +599,18 @@ export class IndicatorUtils {
let chart = JSON.parse(indicatorPath.chartObject);
// console.debug(indicatorPath);
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);
} else {
indicatorPath.type = this.defaultChartType;
}
this.extractTitle(chart, indicatorPath);
this.extractSubTitle(chart, indicatorPath);
this.extractXTitle(chart, indicatorPath);
this.extractYTitle(chart, indicatorPath);
}else if(indicatorPath.url == "table?json="){
} else if (indicatorPath.url == "table?json=") {
indicatorPath.type = "table";
}
if (indicatorPath.url == "chart?json=" || indicatorPath.url == "table?json=") {
@ -628,38 +635,41 @@ export class IndicatorUtils {
indicatorPath.url = url;
indicatorPath.type = type;
}
}catch(e){
} catch (e) {
console.error(e);
indicatorPath.url = url;
indicatorPath.type = type;
}
// console.debug(indicatorPath.parameters);
// console.debug(indicatorPath.chartObject);
if(indicatorPath.type == null){
if (indicatorPath.type == null) {
indicatorPath.type = this.defaultChartType;
}
return indicatorPath;
}
private getQueryObjectName(obj){
if((obj[this.getDescriptionObjectName(obj)]).hasOwnProperty("queriesInfo")){
return "queriesInfo";
}else if((obj[this.getDescriptionObjectName(obj)]).hasOwnProperty("queries")) {
private getQueryObjectName(obj) {
if ((obj[this.getDescriptionObjectName(obj)]).hasOwnProperty("queriesInfo")) {
return "queriesInfo";
} else if ((obj[this.getDescriptionObjectName(obj)]).hasOwnProperty("queries")) {
return "queries";
}
}
private getDescriptionObjectName(obj){
if(obj.hasOwnProperty("mapDescription")){
private getDescriptionObjectName(obj) {
if (obj.hasOwnProperty("mapDescription")) {
return "mapDescription";
}else if(obj.hasOwnProperty("chartDescription")) {
} else if (obj.hasOwnProperty("chartDescription")) {
return "chartDescription";
}else if(obj.hasOwnProperty("tableDescription") ){
} else if (obj.hasOwnProperty("tableDescription")) {
return "tableDescription";
}else if(obj.hasOwnProperty("series") ){
} else if (obj.hasOwnProperty("series")) {
return "series";
}
}
}
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) {
type = this.defaultChartType;
} else {
@ -668,16 +678,18 @@ export class IndicatorUtils {
}
return type;
}
private extractStakeHolders(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) {
private extractStakeHolders(obj, indicatorPath: IndicatorPath, stakeholder: Stakeholder) {
this.extractFunder(obj, indicatorPath, stakeholder);
this.extractRI(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;
}
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"]) {
return;
}
@ -698,12 +710,12 @@ export class IndicatorUtils {
}
}
}
private extractRI(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) {
if(stakeholder.type != "ri"){
private extractRI(obj, indicatorPath: IndicatorPath, stakeholder: Stakeholder) {
if (stakeholder.type != "ri") {
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"]) {
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
// and publication.organization.name
if(stakeholder.type != "organization"){
if (stakeholder.type != "organization") {
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"]) {
return;
}
@ -744,6 +756,7 @@ export class IndicatorUtils {
}
}
}
private extractStartYear(obj, indicatorPath: IndicatorPath) {
let start_year;
for (let query of obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) {
@ -761,7 +774,7 @@ export class IndicatorUtils {
}
}
}
private extractEndYear(obj, indicatorPath: IndicatorPath) {
let end_year;
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 = "";
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}}
//parameters: stakeholderId*, type
if (query["query"]["name"]) {
name = query["query"]["name"];
let parameters = (query["query"]["parameters"])?query["query"]["parameters"]:[];
if(name.split('.')[0] == "rcd" && parameters.length > 0 && stakeholder.type=="ri") {
let parameters = (query["query"]["parameters"]) ? query["query"]["parameters"] : [];
if (name.split('.')[0] == "rcd" && parameters.length > 0 && stakeholder.type == "ri") {
//rcd.{{queryname}}
parameters[0] = ChartHelper.prefix + "index_id" + ChartHelper.suffix;
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
//monitor.{{funder_shortName}}.{{type}}.{{queryname}}
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();
}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
//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]);
for(let i of index) {
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) {
if (name.split('.').length > 3 && name.split('.')[3] == "id") {
parameters[i] = ChartHelper.prefix + "index_id" + ChartHelper.suffix;
indicatorPath.parameters["index_id"] = stakeholder.index_id;
@ -819,85 +832,87 @@ export class IndicatorUtils {
}
}
}
private extractDataTitle(obj, indicatorPath: IndicatorPath) {
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;
}
for (let query of obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) {
if (query["name"]) {
let name = query["name"];
query["name"] = ChartHelper.prefix + "data_title_"+index + ChartHelper.suffix;
indicatorPath.parameters["data_title_"+index] = name;
query["name"] = ChartHelper.prefix + "data_title_" + index + ChartHelper.suffix;
indicatorPath.parameters["data_title_" + index] = name;
}
index++;
}
}
private extractTitle(obj, indicatorPath: IndicatorPath) {
let title = "";
if (obj[this.getDescriptionObjectName(obj)]["title"]) {
title = obj[this.getDescriptionObjectName(obj)]["title"]["text"];
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"];
obj[this.getDescriptionObjectName(obj)]["options"]["title"] = ChartHelper.prefix + "title" + ChartHelper.suffix;
}
indicatorPath.parameters["title"] = title ? title : "";
}
private extractSubTitle(obj, indicatorPath: IndicatorPath) {
let subtitle = "";
if (obj[this.getDescriptionObjectName(obj)]["subtitle"]) {
subtitle = obj[this.getDescriptionObjectName(obj)]["subtitle"]["text"];
obj[this.getDescriptionObjectName(obj)]["subtitle"]["text"] = ChartHelper.prefix + "subtitle" + ChartHelper.suffix;
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"];
obj[this.getDescriptionObjectName(obj)]["title"]["subtext"] = ChartHelper.prefix + "subtitle" + ChartHelper.suffix;
indicatorPath.parameters["subtitle"] = subtitle ? subtitle : "";
}
}
private extractXTitle(obj, indicatorPath: IndicatorPath) {
let title = "";
if (obj[this.getDescriptionObjectName(obj)]["xAxis"] && obj[this.getDescriptionObjectName(obj)]["xAxis"]["title"]) {
title = obj[this.getDescriptionObjectName(obj)]["xAxis"]["title"]["text"];
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"];
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"];
obj[this.getDescriptionObjectName(obj)]["xAxis"]["name"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
}
indicatorPath.parameters["xAxisTitle"] = title ? title : "";
}
private extractYTitle(obj, indicatorPath: IndicatorPath) {
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"];
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"];
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"];
obj[this.getDescriptionObjectName(obj)]["yAxis"]["name"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
}
indicatorPath.parameters["yAxisTitle"] = title ? title : "";
}
private extractOldToolTitle(obj, indicatorPath: IndicatorPath) {
let title = "";
if (obj["title"]) {
title = obj["title"];
obj["title"] = ChartHelper.prefix + "title" + ChartHelper.suffix;
indicatorPath.parameters["title"] = title;
}
}
private extractOldToolXTitle(obj, indicatorPath: IndicatorPath) {
let title = "";
if (obj["xaxistitle"]) {
@ -906,7 +921,7 @@ export class IndicatorUtils {
indicatorPath.parameters["xAxisTitle"] = title;
}
}
private extractOldToolYTitle(obj, indicatorPath: IndicatorPath) {
let title = "";
if (obj["fieldsheaders"]) {
@ -919,18 +934,19 @@ export class IndicatorUtils {
indicatorPath.parameters["yAxisTitle"] = title;
}
}
public checkForSchemaEnhancements(url:string):boolean{
return url !=this.applySchemaEnhancements(url);
public checkForSchemaEnhancements(url: string): boolean {
return url != this.applySchemaEnhancements(url);
}
public applySchemaEnhancements(url:string):string{
public applySchemaEnhancements(url: string): string {
let resultEnhancements = [
[".project.acronym",".project acronym"],
[".project.title",".project title"],
[".project.funder",".project funder"],
[".project.funding level 0",".project funding level 0"],
[".datasource.name",".HostedBy datasource"],
[".datasource.type",".HostedBy datasource type"]
[".project.acronym", ".project acronym"],
[".project.title", ".project title"],
[".project.funder", ".project funder"],
[".project.funding level 0", ".project funding level 0"],
[".datasource.name", ".HostedBy datasource"],
[".datasource.type", ".HostedBy datasource type"]
];
let changes = "";
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]));
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') {
changes += (query["query"]["profile"] ? ( "Changed profile \"" + query["query"]["profile"] + "\" to " ):"Added profile ") + " \"monitor\"";
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') {
changes += (query["query"]["profile"] ? ("Changed profile \"" + query["query"]["profile"] + "\" to ") : "Added profile ") + " \"monitor\"";
query["query"]["profile"] = 'monitor';
}
}