[Monitor Dashboard|Trunk]
Add importAndSave indicators method git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-monitor-portal/trunk/monitor_dashboard@61425 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
18a31fdf7c
commit
94fe302965
|
@ -1,11 +1,12 @@
|
|||
<div *ngIf="stakeholder && canEdit">
|
||||
<div class="uk-text-right uk-width-expand">
|
||||
<button class="uk-margin-bottom uk-margin-right uk-button uk-button-primary" (click)="export_indicators()">
|
||||
<a class="uk-margin-bottom uk-margin-right " uk-icon="icon:download" title="Export indicators (JSON file)"
|
||||
(click)="export_indicators()">
|
||||
<span class="uk-text-small">Export</span>
|
||||
</button>
|
||||
<div uk-form-custom class="js-upload">
|
||||
</a>
|
||||
<div uk-form-custom class="js-upload uk-margin-top">
|
||||
<input id="exampleInputFile" type="file" class="uk-width-medium" (change)="fileChangeEvent($event)"/>
|
||||
<button class="uk-button uk-button-primary uk-margin-bottom">Import (JSON file) </button>
|
||||
<a class=" uk-margin-bottom" uk-icon="icon:upload" title="Import indicators (JSON file)"> Import</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -566,8 +566,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
|
|||
this.numberIndicatorPaths.at(index).get('result').setValue(null);
|
||||
if (this.numberIndicatorPaths.at(index).get('url').valid) {
|
||||
let indicatorPath: IndicatorPath = this.indicatorUtils.generateIndicatorByNumberUrl(this.statisticsService.getNumberSource(value), value, this.stakeholder, this.numberIndicatorPaths.at(index).get('jsonPath').value, this.statisticsService.numberSources.get(this.statisticsService.getNumberSource(value)));
|
||||
if ((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)) {
|
||||
if (!this.isStakeholderParametersValid(indicatorPath)) {
|
||||
// default profile
|
||||
if (this.stakeholder.defaultId == null) {
|
||||
this.urlParameterizedMessage = "This indicator couldn't be generated properly. Stakeholders based on this profile may not inherit the data correctly."
|
||||
|
@ -636,7 +635,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
|
|||
this.urlSubscriptions.push(this.chartIndicatorPaths.at(index).get('url').valueChanges.subscribe(value => {
|
||||
if (this.chartIndicatorPaths.at(index).get('url').valid) {
|
||||
let indicatorPath: IndicatorPath = this.indicatorUtils.generateIndicatorByChartUrl(this.statisticsService.getChartSource(value), value, this.chartIndicatorPaths.at(index).get('type').value, this.stakeholder);
|
||||
if (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) {
|
||||
if (!this.isStakeholderParametersValid(indicatorPath)) {
|
||||
// default profile
|
||||
if (this.stakeholder.defaultId == null) {
|
||||
this.urlParameterizedMessage = "This chart couldn't be generated properly. Stakeholders based on this profile may not inherit the data correctly."
|
||||
|
@ -663,7 +662,11 @@ 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): FormArray {
|
||||
let jsonPath = this.fb.array([]);
|
||||
if (indicatorPath.jsonPath) {
|
||||
|
@ -755,7 +758,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
|
|||
}
|
||||
this.editNumberModal.open();
|
||||
}
|
||||
|
||||
|
||||
public editChartIndicatorOpen(section: Section, id = null) {
|
||||
this.urlParameterizedMessage = null;
|
||||
this.urlSubscriptions.forEach(value => {
|
||||
|
@ -892,7 +895,38 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
|
|||
this.editing = false;
|
||||
}));
|
||||
}
|
||||
|
||||
saveIndicators(indicators:Indicator[]) {
|
||||
this.editing = true;
|
||||
let path = [
|
||||
this.stakeholder._id,
|
||||
this.stakeholder.topics[this.topicIndex]._id,
|
||||
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex]._id,
|
||||
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]._id
|
||||
];
|
||||
this.subscriptions.push(this.stakeholderService.saveBulkElements(this.properties.monitorServiceAPIURL, indicators, path).subscribe(stakeholder => {
|
||||
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex].charts = stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex].charts;
|
||||
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex].numbers = stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex].numbers;
|
||||
this.buildSections();
|
||||
this.filterCharts();
|
||||
this.filterNumbers();
|
||||
this.editing = false;
|
||||
UIkit.notification("Success! Indicated were imported", {
|
||||
status: 'success',
|
||||
timeout: 6000,
|
||||
pos: 'bottom-right'
|
||||
});
|
||||
}, error => {
|
||||
this.chartIndicatorFb = null;
|
||||
UIkit.notification(error.error.message, {
|
||||
status: 'danger',
|
||||
timeout: 6000,
|
||||
pos: 'bottom-right'
|
||||
});
|
||||
this.editing = false;
|
||||
}));
|
||||
|
||||
|
||||
}
|
||||
reorderIndicators(sectionId: string, type: IndicatorType, reorder: Reorder) {
|
||||
this.editing = true;
|
||||
let path = [
|
||||
|
@ -1190,6 +1224,77 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
|
|||
//new schema
|
||||
this.showCheckForSchemaEnhancements = this.isAdministrator && url && !this.properties.useOldStatisticsSchema && this.indicatorUtils.checkForSchemaEnhancements(url);
|
||||
}
|
||||
importIndicatorsAndSave( charts:any[]){
|
||||
|
||||
let indicators:Indicator[] = [];
|
||||
// name description additionalDescription, height, width, visibility
|
||||
let noValidParams = 0;
|
||||
let duplicates = 0;
|
||||
for(let chart of charts) {
|
||||
let exists = false;
|
||||
let indicatorPath;
|
||||
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.subcategoryIndex].charts) {
|
||||
for (let chart of section.indicators) {
|
||||
if (JSON.stringify(chart.indicatorPaths[0].chartObject) == JSON.stringify(indicatorPath.chartObject)) {
|
||||
duplicates++;
|
||||
exists = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}else if (chart.type == "number") {
|
||||
indicatorPath = this.indicatorUtils.generateIndicatorByNumberUrl(this.statisticsService.getNumberSource(chart.url), chart.url, this.stakeholder,
|
||||
chart.jsonPath, this.statisticsService.numberSources.get(this.statisticsService.getNumberSource(chart.url)));
|
||||
for (let section of this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex].numbers) {
|
||||
for (let chart of section.indicators) {
|
||||
if (JSON.stringify(chart.indicatorPaths[0].chartObject) == JSON.stringify(indicatorPath.chartObject)) {
|
||||
duplicates++;
|
||||
exists = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (!this.isStakeholderParametersValid(indicatorPath)) {
|
||||
noValidParams++;
|
||||
}
|
||||
if (!exists) {
|
||||
let i: Indicator = new Indicator(chart.name, chart.description, chart.additionalDescription, chart.type, chart.width, chart.height, chart.visibility, [indicatorPath]);
|
||||
indicators.push(i);
|
||||
}
|
||||
|
||||
}
|
||||
if(duplicates > 0 ){
|
||||
UIkit.notification(duplicates + " urls already exist and will not be imported!", {
|
||||
status: 'warning',
|
||||
timeout: 6000,
|
||||
pos: 'bottom-right'
|
||||
});
|
||||
}
|
||||
if(noValidParams > 0 ){
|
||||
let noValidMesseage = "Some indicators couldn't be generated properly. Please make sure chart data is for the current stakeholder.";
|
||||
if (this.stakeholder.defaultId == null) {
|
||||
noValidMesseage = "Some indicators couldn't be generated properly. Stakeholders based on this profile may not inherit the data correctly.";
|
||||
}
|
||||
UIkit.notification(noValidMesseage, {
|
||||
status: 'danger',
|
||||
timeout: 6000,
|
||||
pos: 'bottom-right'
|
||||
});
|
||||
}else if(indicators.length > 0){
|
||||
console.log(indicators);
|
||||
this.saveIndicators(indicators)
|
||||
}
|
||||
if(indicators.length == 0){
|
||||
UIkit.notification( " No urls imported!", {
|
||||
status: 'warning',
|
||||
timeout: 6000,
|
||||
pos: 'bottom-right'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public export_indicators() {
|
||||
console.debug("Export indicators");
|
||||
|
@ -1202,7 +1307,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
|
|||
indicator.indicatorPaths.forEach(indicatorPath => {
|
||||
console.debug("export number: ", this.statisticsService.getNumberUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(this.stakeholder, indicatorPath)));
|
||||
indicators[index] = {
|
||||
"type": indicator.type, "name": indicator.name,
|
||||
"type": indicator.type, "name": indicator.name, "jsonPath":indicatorPath.jsonPath,
|
||||
"description": indicator.description, "additionalDescription": indicator.additionalDescription,
|
||||
"visibility": indicator.visibility, "width": indicator.width, "height": indicator.height,
|
||||
"url": this.statisticsService.getNumberUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(this.stakeholder, indicatorPath))};
|
||||
|
@ -1263,21 +1368,9 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
|
|||
// this.loading.open();
|
||||
|
||||
this.makeFileRequest(this.properties.utilsService + '/upload?type=json', [], this.filesToUpload).then(async (result: string) => {
|
||||
// const rows = (result as any).split('\n'); // I have used space, you can use any thing.
|
||||
let invalid_rows = 0;
|
||||
|
||||
// let chartSection = null;//this.createSection(-1, "chart");
|
||||
// let numberSection = null;//this.createSection(-1, "number");
|
||||
// await this.newSectionReady;
|
||||
|
||||
let json_result = JSON.parse(result);
|
||||
for (let i = 0; i < (json_result.length); i++) {
|
||||
if (json_result[i] && json_result[i] != null && json_result[i] != "") {
|
||||
this.processIndicatorEntry(json_result[i]);
|
||||
} else {
|
||||
invalid_rows++;
|
||||
}
|
||||
}
|
||||
this.importIndicatorsAndSave(json_result);
|
||||
this.endOfFetching();
|
||||
}, (error) => {
|
||||
this.enableUpload = true;
|
||||
|
@ -1311,15 +1404,4 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
|
|||
this.enableUpload = true;
|
||||
}
|
||||
|
||||
processIndicatorEntry(indicator) {
|
||||
if(indicator.type == "chart") {
|
||||
console.debug("TODO Create chart for url: "+indicator.url);
|
||||
//this.editChartIndicatorOpen(chartSection, null, false, indicator.url);
|
||||
} else if(indicator.type == "number") {
|
||||
console.debug("TODO Create number for url: "+indicator.url);
|
||||
//this.editNumberIndicatorOpen(numberSection);
|
||||
}
|
||||
console.debug(indicator);
|
||||
// this.saveIndicator(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -547,7 +547,9 @@ export class IndicatorUtils {
|
|||
this.parameterizeDefaultQuery(chart, indicatorPath, stakeholder);
|
||||
this.extractStakeHolders(chart, indicatorPath, stakeholder);
|
||||
indicatorPath.chartObject = JSON.stringify(chart);
|
||||
indicatorPath.jsonPath = ["data","0","0","0"];
|
||||
if(!jsonPath || jsonPath.length == 0 ) {
|
||||
indicatorPath.jsonPath = ["data", "0", "0", "0"];
|
||||
}
|
||||
// this.addResultFilters(chart, indicatorPath);
|
||||
}else {
|
||||
for( let service of sourceServices){
|
||||
|
|
Loading…
Reference in New Issue