Import/ Exprort: only for curators, import: set Restricted for indicators

This commit is contained in:
argirok 2021-07-21 12:39:46 +03:00
parent 26d31191af
commit e009a7526f
2 changed files with 10 additions and 15 deletions

View File

@ -1,8 +1,8 @@
<div *ngIf="stakeholder && canEdit"> <div *ngIf="stakeholder && canEdit">
<div class="uk-text-right uk-width-expand"> <div *ngIf="isCurator" class="uk-text-right uk-width-expand">
<a class="uk-margin-bottom uk-margin-right " [attr.uk-icon]="export_loading ? null : 'icon:download'" title="Export indicators (JSON file)" <a class="uk-margin-bottom uk-margin-right " [attr.uk-icon]="export_loading ? null : 'icon:download'" title="Export indicators (JSON file)"
(click)="export_indicators()"> (click)="export_indicators()">
<span class="uk-text-small">Export</span> <span class="">Export</span>
<span *ngIf="export_loading" class="uk-margin-small-left uk-icon icon-button"><loading [top_margin]="false"></loading></span> <span *ngIf="export_loading" class="uk-margin-small-left uk-icon icon-button"><loading [top_margin]="false"></loading></span>
</a> </a>
<div uk-form-custom class="js-upload uk-margin-top"> <div uk-form-custom class="js-upload uk-margin-top">

View File

@ -1228,7 +1228,6 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.showCheckForSchemaEnhancements = this.isAdministrator && url && !this.properties.useOldStatisticsSchema && this.indicatorUtils.checkForSchemaEnhancements(url); this.showCheckForSchemaEnhancements = this.isAdministrator && url && !this.properties.useOldStatisticsSchema && this.indicatorUtils.checkForSchemaEnhancements(url);
} }
importIndicatorsAndSave( charts:any[]){ importIndicatorsAndSave( charts:any[]){
let indicators:Indicator[] = []; let indicators:Indicator[] = [];
// name description additionalDescription, height, width, visibility // name description additionalDescription, height, width, visibility
let noValidParams = 0; let noValidParams = 0;
@ -1236,12 +1235,11 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
for(let chart of charts) { for(let chart of charts) {
let exists = false; let exists = false;
let indicatorPath; let indicatorPath;
// validate indicators' schema from file // validate indicators' schema from file
let invalid_file_message = ""; let invalid_file_message = "";
if (!chart.type) { if (!chart.type) {
invalid_file_message = "No indicator type is specified. Type should be chart or number."; invalid_file_message = "No indicator type is specified. Type should be chart or number.";
} else if(chart.type != "chart" || chart.type != "number") { } else if(chart.type != "chart" && chart.type != "number") {
invalid_file_message = "Invalid indicator type. Type should be chart or number."; invalid_file_message = "Invalid indicator type. Type should be chart or number.";
} else if(chart.type == "number" && !chart.jsonPath) { } else if(chart.type == "number" && !chart.jsonPath) {
invalid_file_message = "No jsonPath is specified for number indicator." invalid_file_message = "No jsonPath is specified for number indicator."
@ -1250,7 +1248,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
} }
if(invalid_file_message) { if(invalid_file_message) {
UIkit.notification("Error on indicators' schema. Type should be chart or number, url is needed and for number indicators, jsonPath is needed as well.", { UIkit.notification(invalid_file_message, {
status: 'danger', status: 'danger',
timeout: 6000, timeout: 6000,
pos: 'bottom-right' pos: 'bottom-right'
@ -1288,7 +1286,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
noValidParams++; noValidParams++;
} }
if (!exists) { if (!exists) {
let i: Indicator = new Indicator(chart.name, chart.description, chart.additionalDescription, chart.type, chart.width, chart.height, chart.visibility, [indicatorPath]); let i: Indicator = new Indicator(chart.name, chart.description, chart.additionalDescription, chart.type, chart.width, chart.height,"RESTRICTED", [indicatorPath]);
indicators.push(i); indicators.push(i);
} }
@ -1301,11 +1299,11 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
}); });
} }
if(noValidParams > 0 ){ if(noValidParams > 0 ){
let noValidMesseage = "Some indicators couldn't be generated properly. Please make sure chart data is for the current stakeholder."; let noValidMessage = "Some indicators couldn't be generated properly. Please make sure chart data is for the current stakeholder.";
if (this.stakeholder.defaultId == null) { if (this.stakeholder.defaultId == null) {
noValidMesseage = "Some indicators couldn't be generated properly. Stakeholders based on this profile may not inherit the data correctly."; noValidMessage = "Some indicators couldn't be generated properly. Stakeholders based on this profile may not inherit the data correctly.";
} }
UIkit.notification(noValidMesseage, { UIkit.notification(noValidMessage, {
status: 'danger', status: 'danger',
timeout: 6000, timeout: 6000,
pos: 'bottom-right' pos: 'bottom-right'
@ -1328,8 +1326,6 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
} }
public export_indicators() { public export_indicators() {
console.debug("Export indicators");
this.editing = true; this.editing = true;
this.export_loading = true; this.export_loading = true;
@ -1339,7 +1335,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.displayNumbers.forEach(section => { this.displayNumbers.forEach(section => {
section.indicators.forEach(indicator => { section.indicators.forEach(indicator => {
indicator.indicatorPaths.forEach(indicatorPath => { indicator.indicatorPaths.forEach(indicatorPath => {
console.debug("export number: ", this.statisticsService.getNumberUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(this.stakeholder, indicatorPath))); // console.debug("export number: ", this.statisticsService.getNumberUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(this.stakeholder, indicatorPath)));
indicators[index] = { indicators[index] = {
"type": indicator.type, "name": indicator.name, "jsonPath": indicatorPath.jsonPath, "type": indicator.type, "name": indicator.name, "jsonPath": indicatorPath.jsonPath,
"description": indicator.description, "additionalDescription": indicator.additionalDescription, "description": indicator.description, "additionalDescription": indicator.additionalDescription,
@ -1354,7 +1350,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.displayCharts.forEach(section => { this.displayCharts.forEach(section => {
section.indicators.forEach(indicator => { section.indicators.forEach(indicator => {
indicator.indicatorPaths.forEach(indicatorPath => { indicator.indicatorPaths.forEach(indicatorPath => {
console.debug("export chart: " + this.getUrlByStakeHolder(indicatorPath)); // console.debug("export chart: " + this.getUrlByStakeHolder(indicatorPath));
indicators[index] = { indicators[index] = {
"type": indicator.type, "name": indicator.name, "type": indicator.type, "name": indicator.name,
"description": indicator.description, "additionalDescription": indicator.additionalDescription, "description": indicator.description, "additionalDescription": indicator.additionalDescription,
@ -1393,7 +1389,6 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
} }
upload() { upload() {
console.debug(this.filesToUpload);
if (this.filesToUpload.length == 0) { if (this.filesToUpload.length == 0) {
console.error("There is no selected file to upload."); console.error("There is no selected file to upload.");
UIkit.notification("There is no selected file to upload.", { UIkit.notification("There is no selected file to upload.", {