Add format in number indicators in order to support percentages.

This commit is contained in:
Konstantinos Triantafyllou 2023-04-18 15:30:05 +03:00
parent be7fd26f7b
commit 54fa0aa7a6
5 changed files with 120 additions and 115 deletions

View File

@ -108,7 +108,7 @@
class="uk-text-small uk-text-truncate uk-margin-xsmall-bottom uk-margin-right">{{indicator.name}}</div>
<div class="number uk-text-small uk-text-bold">
<span *ngIf="numberResults.get(i + '-' + j)"
[innerHTML]="numberResults.get(i + '-' + j) | numberRound: 2:1"></span>
[innerHTML]="(indicator.indicatorPaths[0].format == 'NUMBER'?(numberResults.get(i + '-' + j) | numberRound: 2:1):(numberResults.get(i + '-' + j) | numberPercentage))"></span>
<span *ngIf="!numberResults.get(i + '-' + j)">--</span>
</div>
<div *ngIf="indicator.description || indicator.additionalDescription"
@ -159,7 +159,7 @@
class="uk-text-xsmall uk-text-truncate uk-margin-xsmall-bottom uk-margin-right">{{indicator.name}}</div>
<div class="number uk-text-small uk-text-bold">
<span *ngIf="numberResults.get(i + '-' + j)"
[innerHTML]="numberResults.get(i + '-' + j) | numberRound: 2:1"></span>
[innerHTML]="(indicator.indicatorPaths[0].format == 'NUMBER'?(numberResults.get(i + '-' + j) | numberRound: 2:1):(numberResults.get(i + '-' + j) | numberPercentage))"></span>
<span *ngIf="!numberResults.get(i + '-' + j)">--</span>
</div>
</div>

@ -1 +1 @@
Subproject commit e88bb206dcfbe6da62542c45794d4fe6e552fb09
Subproject commit a49970aca66cf98a2ee9cd767e8dc87badc0b80f

View File

@ -68,7 +68,7 @@
</div>
<div class="uk-text-small uk-text-truncate uk-margin-xsmall-bottom uk-margin-right">{{indicator.name}}</div>
<div class="number uk-text-small uk-text-bold">
<span *ngIf="numberResults.get(i + '-' + j)" [innerHTML]="numberResults.get(i + '-' + j) | numberRound: 2:1"></span>
<span *ngIf="numberResults.get(i + '-' + j)" [innerHTML]="(indicator.indicatorPaths[0].format == 'NUMBER'?(numberResults.get(i + '-' + j) | numberRound: 2:1):(numberResults.get(i + '-' + j) | numberPercentage))"></span>
<span *ngIf="!numberResults.get(i + '-' + j)">--</span>
</div>
</div>
@ -257,11 +257,16 @@
now</a>
</div>
</div>
<div class="uk-width-1-1">
<div class="uk-width-1-2@m">
<div input [formInput]="indicatorPath.get('source')" placeholder="Source"
[options]="isAdministrator?indicatorUtils.allSourceTypes:indicatorUtils.sourceTypes" type="select">
</div>
</div>
<div class="uk-width-1-2@m">
<div input [formInput]="indicatorPath.get('format')" placeholder="Format"
[options]="indicatorUtils.formats" type="select">
</div>
</div>
</div>
</div>
<div formArrayName="jsonPath" class="uk-width-1-1">
@ -297,7 +302,8 @@
<div class="uk-width-1-1 uk-flex uk-flex-center">
<div class="uk-flex uk-position-relative">
<span class="uk-padding number number-preview uk-flex uk-flex-column uk-flex-center uk-text-center">
<span *ngIf="numberIndicatorPaths.at(i).get('result').valid && numberIndicatorPaths.at(i).get('result').value !== 0">
<span *ngIf="numberIndicatorPaths.at(i).get('result').valid && numberIndicatorPaths.at(i).get('result').value !== 0"
[innerHTML]="(numberIndicatorPaths.at(i).get('format').value == 'NUMBER'?(numberIndicatorPaths.at(i).get('result').value | numberRound: 2:1):(numberIndicatorPaths.at(i).get('result').value | numberPercentage))">
{{numberIndicatorPaths.at(i).get('result').value | number}}
</span>
<span *ngIf="numberIndicatorPaths.at(i).get('result').valid && numberIndicatorPaths.at(i).get('result').value === 0">

View File

@ -11,6 +11,7 @@ import {
ViewChild
} from "@angular/core";
import {
Format,
Indicator,
IndicatorPath,
IndicatorSize,
@ -20,7 +21,14 @@ import {
Visibility
} from "../openaireLibrary/monitor/entities/stakeholder";
import {IndicatorUtils, StakeholderUtils} from "../utils/indicator-utils";
import {AbstractControl, UntypedFormArray, UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, Validators} from "@angular/forms";
import {
AbstractControl,
UntypedFormArray,
UntypedFormBuilder,
UntypedFormControl,
UntypedFormGroup,
Validators
} from "@angular/forms";
import {AlertModal} from "../openaireLibrary/utils/modal/alert";
import {StatisticsService} from "../utils/services/statistics.service";
import {HelperFunctions} from "../openaireLibrary/utils/HelperFunctions.class";
@ -96,9 +104,9 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
@ViewChild('editNumberNotify', {static: true}) editNumberNotify: NotifyFormComponent;
@ViewChild('editChartNotify', {static: true}) editChartNotify: NotifyFormComponent;
@ViewChild('deleteNotify', {static: true}) deleteNotify: NotifyFormComponent;
public isFullscreen: boolean = false;
@HostListener('fullscreenchange', ['$event'])
@HostListener('webkitfullscreenchange', ['$event'])
@HostListener('mozfullscreenchange', ['$event'])
@ -106,14 +114,14 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
screenChange(event) {
this.isFullscreen = !this.isFullscreen;
}
/**
* Subscriptions
**/
private subscriptions: any[] = [];
private urlSubscriptions: any[] = [];
private numberSubscription: any[] = [];
constructor(private layoutService: LayoutService,
private stakeholderService: StakeholderService,
private statisticsService: StatisticsService,
@ -124,7 +132,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
private sanitizer: DomSanitizer) {
this.filesToUpload = [];
}
ngOnInit(): void {
if (this.stakeholder) {
this.setCharts();
@ -136,7 +144,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.initReorder();
})
}
ngOnDestroy(): void {
this.subscriptions.forEach(value => {
if (value instanceof Subscriber) {
@ -156,11 +164,11 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
}
});
}
ngAfterViewInit(): void {
this.initReorder();
}
ngOnChanges(changes: SimpleChanges): void {
if (this.canEdit) {
if (changes.topicIndex || changes.categoryIndex || changes.subcategoryIndex) {
@ -170,7 +178,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
}
}
}
initReorder() {
this.subscriptions.forEach(value => {
if (value instanceof Function) {
@ -223,11 +231,11 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
});
}
}
hide(element: any) {
UIkit.dropdown(element).hide();
}
setCharts() {
this.chartSections = this.fb.array([]);
this.charts.forEach(section => {
@ -251,7 +259,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
})
});
}
setNumbers() {
this.numberSections = this.fb.array([]);
this.numberResults.clear();
@ -292,7 +300,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
}
});
}
private calculateResults(response: any, indexes: [number, number][]) {
indexes.forEach(([i, j]) => {
let result = JSON.parse(JSON.stringify(response));
@ -312,7 +320,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.numberResults.set(i + '-' + j, result);
});
}
get charts(): Section[] {
if (this.stakeholder.topics[this.topicIndex] &&
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex] &&
@ -322,7 +330,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
return [];
}
}
get numbers(): Section[] {
if (this.stakeholder.topics[this.topicIndex] &&
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex] &&
@ -332,30 +340,30 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
return [];
}
}
set numbers(sections: Section[]) {
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex].numbers = sections;
}
get open(): boolean {
return this.layoutService.open;
}
get canEdit() {
return this.stakeholder &&
this.stakeholder.topics[this.topicIndex] &&
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex] &&
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex];
}
public get numberIndicatorPaths(): UntypedFormArray {
return this.numberIndicatorFb.get('indicatorPaths') as UntypedFormArray;
}
public get chartIndicatorPaths(): UntypedFormArray {
return this.chartIndicatorFb.get('indicatorPaths') as UntypedFormArray;
}
public getNumberClassBySize(size: IndicatorSize) {
if (size === 'small') {
return 'uk-width-medium@m uk-width-1-1';
@ -365,7 +373,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
return 'uk-width-1-2@l uk-width-1-1@m uk-width-1-1';
}
}
public getChartClassBySize(size: IndicatorSize) {
if (size === 'small') {
return 'uk-width-1-3@xl uk-width-1-2@m uk-width-1-1';
@ -375,7 +383,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
return 'uk-width-1-1';
}
}
public addJsonPath(index: number) {
if (index == 0 && this.getJsonPath(index).getRawValue()[index].indexOf(",") != -1) {
//if in the first path there are more than one paths comma separated, split them and autogenerate the forms
@ -390,13 +398,13 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.getJsonPath(index).push(this.fb.control('', Validators.required));
}
}
public removeJsonPath(i: number, j: number) {
if (this.getJsonPath(i).enabled) {
this.getJsonPath(i).removeAt(j);
}
}
public validateJsonPath(index: number, dirty: boolean = false) {
let indicatorPath: UntypedFormGroup = <UntypedFormGroup>this.numberIndicatorPaths.at(index);
if (this.indicator.defaultId === null) {
@ -442,33 +450,33 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
}, 500);
}));
}
public getJsonPath(index: number): UntypedFormArray {
return this.numberIndicatorPaths.at(index).get('jsonPath') as UntypedFormArray;
}
public getCurrentJsonPath(index: number): string[] {
return this.section.indicators[this.index].indicatorPaths[index].jsonPath;
}
public getParameters(index: number): UntypedFormArray {
return this.chartIndicatorPaths.at(index).get('parameters') as UntypedFormArray;
}
public getParameter(index: number, key: string): UntypedFormControl {
return this.getParameters(index).controls.filter(control => control.value.key === key)[0] as UntypedFormControl;
}
private getSecureUrlByStakeHolder(indicatorPath: IndicatorPath) {
return this.sanitizer.bypassSecurityTrustResourceUrl(
this.statisticsService.getChartUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(this.stakeholder, indicatorPath)));
}
private getUrlByStakeHolder(indicatorPath: IndicatorPath) {
return this.statisticsService.getChartUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(this.stakeholder, indicatorPath));
}
public addNumberIndicatorPath(url: string = '', parameters: UntypedFormArray = new UntypedFormArray([]), source: string = 'stats-tool', jsonPath: UntypedFormArray = new UntypedFormArray([])) {
public addNumberIndicatorPath(url: string = '', parameters: UntypedFormArray = new UntypedFormArray([]), source: string = 'stats-tool', jsonPath: UntypedFormArray = new UntypedFormArray([]), format: Format = "NUMBER") {
if (jsonPath.length === 0) {
jsonPath.push(this.fb.control('', Validators.required));
}
@ -476,8 +484,8 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
url: this.fb.control(url, [Validators.required, StringUtils.urlValidator()]),
jsonPath: jsonPath,
result: this.fb.control(0, Validators.required),
// parameters: parameters,
source: this.fb.control(source, Validators.required)
source: this.fb.control(source, Validators.required),
format: this.fb.control(format, Validators.required)
}
));
let index = this.numberIndicatorPaths.length - 1;
@ -523,7 +531,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
}
})
);
this.subscriptions.push(this.numberIndicatorPaths.at(index).get('jsonPath').valueChanges.subscribe(value => {
if (this.indicator.indicatorPaths[index]) {
this.indicator.indicatorPaths[index].jsonPath = value;
@ -543,7 +551,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.numberIndicatorPaths.at(index).get('source').disable();
}
}
public addChartIndicatorPath(value: string = '', parameters: UntypedFormArray = new UntypedFormArray([]), disableUrl: boolean = false, type: string = null) {
this.chartIndicatorPaths.push(this.fb.group({
url: this.fb.control(value, [Validators.required, StringUtils.urlValidator()]),
@ -586,13 +594,13 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
}));
}
}
private isStakeholderParametersValid(indicatorPath: IndicatorPath) {
return !((indicatorPath.chartObject && Object.keys(indicatorPath.parameters).indexOf("index_id") == -1 && Object.keys(indicatorPath.parameters).indexOf("index_name") == -1 && Object.keys(indicatorPath.parameters).indexOf("index_shortName") == -1)
|| (!indicatorPath.chartObject && indicatorPath.url.indexOf("index_id") == -1 && indicatorPath.url.indexOf("index_name") == -1 && (indicatorPath.url).indexOf("index_shortName") == -1));
}
private getJsonPathAsFormArray(indicatorPath: IndicatorPath): UntypedFormArray {
let jsonPath = this.fb.array([]);
if (indicatorPath.jsonPath) {
@ -602,7 +610,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
}
return jsonPath;
}
private getParametersAsFormArray(indicatorPath: IndicatorPath): UntypedFormArray {
let parameters = this.fb.array([]);
if (indicatorPath.parameters) {
@ -624,7 +632,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
}
return parameters;
}
public editNumberIndicatorOpen(section: Section, id = null) {
this.urlParameterizedMessage = null;
this.section = section;
@ -645,7 +653,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
defaultId: this.fb.control(this.indicator.defaultId)
});
this.indicator.indicatorPaths.forEach(indicatorPath => {
this.addNumberIndicatorPath(this.statisticsService.getNumberUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(this.stakeholder, indicatorPath)), indicatorPath.parameters, indicatorPath.source, this.getJsonPathAsFormArray(indicatorPath));
this.addNumberIndicatorPath(this.statisticsService.getNumberUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(this.stakeholder, indicatorPath)), indicatorPath.parameters, indicatorPath.source, this.getJsonPathAsFormArray(indicatorPath), indicatorPath.format);
});
} else {
this.indicator = new Indicator('', '', '', 'number', 'small', 'small', "PUBLIC", []);
@ -685,7 +693,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.editNumberModal.stayOpen = true;
this.editNumberModal.open();
}
public editChartIndicatorOpen(section: Section, id = null) {
this.urlParameterizedMessage = null;
this.urlSubscriptions.forEach(value => {
@ -752,7 +760,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.editChartModal.stayOpen = true;
this.editChartModal.open();
}
saveIndicator() {
this.editing = true;
if (this.indicator.type === 'chart') {
@ -834,7 +842,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
}
}));
}
saveIndicators(sections) {
this.editing = true;
let path = [
@ -892,10 +900,10 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.editing = false;
this.importLoading = false;
}));
}
reorderIndicators(sectionId: string, type: IndicatorType, reorder: Reorder) {
this.editing = true;
let path = [
@ -916,7 +924,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.editing = false;
}));
}
hasDifference(index: number): boolean {
let hasDifference = false;
this.chartIndicatorPaths.at(index).value.parameters.forEach((parameter) => {
@ -928,22 +936,22 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
return hasDifference || this.indicator.indicatorPaths[index].safeResourceUrl.toString() !==
this.getSecureUrlByStakeHolder(this.indicator.indicatorPaths[index]).toString();
}
public get isAdministrator(): boolean {
return Session.isPortalAdministrator(this.user);
}
public get isCurator(): boolean {
return this.isAdministrator || Session.isCurator(this.stakeholder.type, this.user);
}
refreshIndicator() {
this.indicator = this.indicatorUtils.generateIndicatorByForm(this.chartIndicatorFb.value, this.indicator.indicatorPaths, 'chart', true);
this.indicator.indicatorPaths.forEach(indicatorPath => {
indicatorPath.safeResourceUrl = this.getSecureUrlByStakeHolder(indicatorPath);
});
}
deleteIndicatorOpen(section: Section, indicatorId: string, type: string, childrenAction: string = null) {
this.indicatorChildrenActionOnDelete = null;
if (childrenAction == "delete") {
@ -951,7 +959,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
} else if (childrenAction == "disconnect") {
this.indicatorChildrenActionOnDelete = childrenAction;
}
this.section = section;
if (type === 'chart') {
this.index = this.charts.find(value => value._id == section._id).indicators.findIndex(value => value._id == indicatorId);
@ -967,7 +975,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.deleteModal.stayOpen = true;
this.deleteModal.open();
}
deleteIndicator() {
this.editing = true;
let path = [
@ -1018,7 +1026,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.deleteModal.cancel();
}));
}
changeIndicatorStatus(sectionId: string, indicator: Indicator, visibility: Visibility) {
this.editing = true;
let path = [
@ -1046,7 +1054,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.editing = false;
}));
}
saveSection(focused: boolean, sectionControl: AbstractControl, index: number, type: IndicatorType = "chart") {
if (!focused && sectionControl.dirty) {
this.editing = true;
@ -1081,7 +1089,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
}));
}
}
createSection(index = -1, type: IndicatorType = 'chart') {
this.editing = true;
this.section = new Section(type, null, null, this.stakeholder.alias);
@ -1123,7 +1131,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.editing = false;
}));
}
// deleteNumberSectionOpen(section: Section, index: number) {
// this.section = section;
// this.index = index;
@ -1141,7 +1149,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
// this.deleteChartSectionModal.okButtonText = 'Yes';
// this.deleteChartSectionModal.open();
// }
deleteSectionOpen(section: Section, index: number, type: IndicatorType, childrenAction: string = null) {
if (!this.editing && !section.defaultId) {
this.sectionTypeToDelete = type;
@ -1151,7 +1159,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
} else if (childrenAction == "disconnect") {
this.sectionChildrenActionOnDelete = childrenAction;
}
this.section = section;
this.index = index;
this.deleteSectionModal.alertTitle = 'Delete Section';
@ -1161,7 +1169,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.deleteSectionModal.open();
}
}
deleteSection() {
this.editing = true;
let path = [
@ -1197,21 +1205,22 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.deleteSectionModal.cancel();
}));
}
private checkForSchemaEnhancements(url: string) {
this.showCheckForSchemaEnhancements = this.isAdministrator && url && !this.properties.useOldStatisticsSchema && this.indicatorUtils.checkForSchemaEnhancements(url);
}
migrateFromOldImportJsonFile(charts){
migrateFromOldImportJsonFile(charts) {
// first section contains numbers
// second contains charts
let hasNumbers = false;
for (let chart of charts) {
for (let chart of charts) {
if (chart['type'] == 'number') {
hasNumbers = true;
break;
}
}
let chartsSection = (hasNumbers?1:0); // no numbers: first sections contains charts
let chartsSection = (hasNumbers ? 1 : 0); // no numbers: first sections contains charts
for (let chart of charts) {
if (chart['sectionIndex'] == null) {
chart['sectionIndex'] = chart['type'] == 'chart' ? chartsSection : 0;
@ -1219,7 +1228,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
}
return charts;
}
importIndicatorsAndSave(charts: any[]) {
let sectionsToSave: Section[] = [];
let countIndicators = 0;
@ -1246,7 +1255,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
} else if (!chart.url) {
invalid_file_message = "No indicator url is specified.";
}
if (invalid_file_message) {
UIkit.notification(invalid_file_message, {
status: 'danger',
@ -1257,7 +1266,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.importLoading = false;
break;
}
if (chart.type == "chart") {
indicatorPath = this.indicatorUtils.generateIndicatorByChartUrl(this.statisticsService.getChartSource(chart.url), chart.url, chart.type, this.stakeholder);
for (let section of this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.index].charts) {
@ -1267,7 +1276,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
exists = true;
}
}
}
} else if (chart.type == "number") {
indicatorPath = this.indicatorUtils.generateIndicatorByNumberUrl(this.statisticsService.getNumberSource(chart.url), chart.url, this.stakeholder,
@ -1279,7 +1288,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
exists = true;
}
}
}
}
if (!this.isStakeholderParametersValid(indicatorPath)) {
@ -1290,9 +1299,9 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
sectionsToSave[chart['sectionIndex']].indicators.push(i);
countIndicators++;
}
}
if (duplicates > 0) {
UIkit.notification(duplicates + " urls already exist and will not be imported!", {
status: 'warning',
@ -1325,7 +1334,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.importLoading = false;
}
}
public exportIndicators(subcategoryIndex) {
this.editing = true;
let indicators = [];
@ -1348,7 +1357,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
});
index++;
});
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[subcategoryIndex].charts.forEach(section => {
section.indicators.forEach(indicator => {
indicator.indicatorPaths.forEach(indicatorPath => {
@ -1365,13 +1374,13 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
});
});
index++;
});
let topic = this.stakeholder ? this.stakeholder.topics[this.topicIndex] : null;
let category = topic ? topic.categories[this.categoryIndex] : null;
let subCategory = category ? category.subCategories[this.subcategoryIndex] : null;
var jsonFileUrl = window.URL.createObjectURL(new Blob([JSON.stringify(indicators)], {type: 'application/json'}));
var a = window.document.createElement('a');
window.document.body.appendChild(a);
@ -1381,10 +1390,10 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
a.click();
window.URL.revokeObjectURL(jsonFileUrl);
a.remove(); // remove the element
this.editing = false;
}
fileChangeEvent(fileInput: any, index) {
this.index = index;
this.editing = true;
@ -1392,7 +1401,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.filesToUpload = <Array<File>>fileInput.target.files;
this.upload();
}
upload() {
if (this.filesToUpload.length == 0) {
console.error("There is no selected file to upload.");
@ -1417,11 +1426,11 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
return;
}
}
this.makeFileRequest(this.properties.utilsService + '/upload?type=json', [], this.filesToUpload).then(async (result: string) => {
let json_result = JSON.parse(result);
// validate file
if (!json_result || json_result.length == 0) {
UIkit.notification("Importing file is empty", {
@ -1445,7 +1454,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.importLoading = false;
});
}
makeFileRequest(url: string, params: Array<string>, files: Array<File>) {
return new Promise((resolve, reject) => {
const formData: any = new FormData();
@ -1466,7 +1475,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
xhr.send(formData);
});
}
copyToClipboard(value) {
const tempBox = document.createElement('textarea');
tempBox.style.position = 'fixed';

View File

@ -39,7 +39,6 @@ export class StakeholderUtils {
{icon: 'incognito', value: "PRIVATE", label: 'Private'},
];
visibilityIcon: Map<Visibility, string> = new Map<Visibility, string>([
["PUBLIC", 'earth'],
["PRIVATE", 'incognito'],
@ -59,10 +58,8 @@ export class StakeholderUtils {
public createFunderFromDefaultProfile(funder: Stakeholder, defaultTopics: Topic[]): Stakeholder {
funder.topics = HelperFunctions.copy(defaultTopics);
for (let topic of funder.topics) {
// console.log('id:' + topic._id);
topic.defaultId = topic._id;
topic._id = null;
// console.log('defaultId:' + topic.defaultId);
for (let category of topic.categories) {
category.defaultId = category._id;
category._id = null;
@ -132,7 +129,6 @@ export class StakeholderUtils {
category.subCategories = subTokeep;
}
}
//console.log (funder);
return funder;
}
@ -192,6 +188,12 @@ export class IndicatorUtils {
{value: 'statistics', label: 'Statistics'},
{value: 'stats-tool', label: 'Statistics tool'}
];
formats: Option[] = [
{value: "NUMBER", label: "Number"},
{value: "PERCENTAGE", label: "Percentage"}
];
sourceTypes: Option[] = [
{value: 'stats-tool', label: 'Statistics tool'}
];
@ -311,7 +313,7 @@ export class IndicatorUtils {
indicatorPath.filtersApplied = 0;
let replacedUrl = indicatorPath.chartObject ? indicatorPath.chartObject : indicatorPath.url;
if (stakeholder.statsProfile) {
replacedUrl = replacedUrl.split(ChartHelper.prefix + this.statsProfileParameter + ChartHelper.suffix).join(stakeholder.statsProfile)
replacedUrl = replacedUrl.split(ChartHelper.prefix + this.statsProfileParameter + ChartHelper.suffix).join(stakeholder.statsProfile);
}
if (indicatorPath.parameters) {
Object.keys(indicatorPath.parameters).forEach(key => {
@ -379,7 +381,6 @@ export class IndicatorUtils {
replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_shortName))
}
//Check apply enhancements return this.applySchemaEnhancements( ..);
console.log(replacedUrl);
return (indicatorPath.chartObject ? indicatorPath.url + encodeURIComponent(replacedUrl) : replacedUrl);
}
@ -432,10 +433,6 @@ export class IndicatorUtils {
}
} 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) {
filterApplied = true;
if (filterType == "start_year") {
@ -453,7 +450,6 @@ export class IndicatorUtils {
}
}
}
// console.debug(queries["query"])
// it is a name query
continue;
}
@ -522,7 +518,6 @@ export class IndicatorUtils {
}
}
}
// console.debug(values);
return values.length > 1;
}
@ -532,6 +527,7 @@ export class IndicatorUtils {
indicator._id = form._id;
form.indicatorPaths.forEach((indicatorPath, index) => {
indicator.indicatorPaths[index].type = indicatorPath.type;
indicator.indicatorPaths[index].format = indicatorPath.format;
if (addParameters) {
indicatorPath.parameters.forEach(parameter => {
indicator.indicatorPaths[index].parameters[parameter.key] = parameter.value;
@ -590,7 +586,6 @@ export class IndicatorUtils {
indicatorPath.url = indicatorPath.url.split("/")[indicatorPath.url.split("/").length - 1];
indicatorPath.chartObject = decodeURIComponent(url.split("json=")[1]);
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")) {
@ -614,7 +609,6 @@ export class IndicatorUtils {
this.extractStartYear(chart, indicatorPath);
this.extractEndYear(chart, indicatorPath);
indicatorPath.chartObject = JSON.stringify(chart);
console.log(indicatorPath);
}
} else if (source === 'old') {
indicatorPath.url = url.split("data=")[0].split("/stats/")[1] + "data=";
@ -634,8 +628,6 @@ export class IndicatorUtils {
indicatorPath.url = url;
indicatorPath.type = type;
}
// console.debug(indicatorPath.parameters);
// console.debug(indicatorPath.chartObject);
if (indicatorPath.type == null) {
indicatorPath.type = this.defaultChartType;
}
@ -684,7 +676,7 @@ export class IndicatorUtils {
return;
}
for (let query of this.getQueryObjectName(obj) ? obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)] : obj[this.getDescriptionObjectName(obj)]) {
if(query["query"]["profile"]) {
if (query["query"]["profile"]) {
query["query"]["profile"] = ChartHelper.prefix + this.statsProfileParameter + ChartHelper.suffix;
}
if (!query["query"]["filters"]) {
@ -713,7 +705,7 @@ export class IndicatorUtils {
return;
}
for (let query of this.getQueryObjectName(obj) ? obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)] : obj[this.getDescriptionObjectName(obj)]) {
if(query["query"]["profile"]) {
if (query["query"]["profile"]) {
query["query"]["profile"] = ChartHelper.prefix + this.statsProfileParameter + ChartHelper.suffix;
}
if (!query["query"]["filters"]) {
@ -740,7 +732,7 @@ export class IndicatorUtils {
return;
}
for (let query of this.getQueryObjectName(obj) ? obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)] : obj[this.getDescriptionObjectName(obj)]) {
if(query["query"]["profile"]) {
if (query["query"]["profile"]) {
query["query"]["profile"] = ChartHelper.prefix + this.statsProfileParameter + ChartHelper.suffix;
}
if (!query["query"]["filters"]) {
@ -971,8 +963,6 @@ export class IndicatorUtils {
}
url = url.split('json=')[0] + "json=" + encodeURIComponent(JSON.stringify(obj));
}
console.debug(changes);
console.debug(url);
return url;
}
}