Add "from-String" method to plotconfigurator

This commit is contained in:
Matthias 2020-07-11 17:41:33 +02:00
parent 0a30561bed
commit bdc0673110

View File

@ -79,9 +79,26 @@
>Show</b-button >Show</b-button
> >
</div> </div>
<div class="col-mb-3 ml-2">
<b-button
variant="primary"
@click="loadConfigFromString"
size="sm"
v-if="showConfig"
title="Load configuration from text box below"
>Load from String</b-button
>
</div>
</div> </div>
<div class="col-mb-5 ml-2" v-if="showConfig"> <div class="col-mb-5 ml-2 mt-2" v-if="showConfig">
<b-textarea id="TextArea" class="textArea" v-model="plotConfigJson" size="sm"> </b-textarea> <b-textarea
id="TextArea"
class="textArea"
v-model="plotConfigJson"
size="sm"
:state="tempPlotConfigValid"
>
</b-textarea>
</div> </div>
</div> </div>
</template> </template>
@ -122,6 +139,10 @@ export default class PlotConfigurator extends Vue {
selField = ''; selField = '';
tempPlotConfig?: PlotConfig = undefined;
tempPlotConfigValid = true;
selColor = randomColor(); selColor = randomColor();
@ftbot.Mutation @ftbot.Mutation
@ -131,6 +152,16 @@ export default class PlotConfigurator extends Vue {
return JSON.stringify(this.plotConfig, null, 2); return JSON.stringify(this.plotConfig, null, 2);
} }
set plotConfigJson(newValue: string) {
try {
this.tempPlotConfig = JSON.parse(newValue);
// TODO: Should Validate schema validity (should be PlotConfig type...)
this.tempPlotConfigValid = true;
} catch (err) {
this.tempPlotConfigValid = false;
}
}
get subplots() { get subplots() {
// Subplot keys (for selection window) // Subplot keys (for selection window)
return Object.keys(this.plotConfig.subplots); return Object.keys(this.plotConfig.subplots);
@ -194,6 +225,14 @@ export default class PlotConfigurator extends Vue {
console.log('loading config'); console.log('loading config');
this.emitPlotConfig(); this.emitPlotConfig();
} }
loadConfigFromString() {
// this.plotConfig = JSON.parse();
if (this.tempPlotConfig !== undefined && this.tempPlotConfigValid) {
this.plotConfig = this.tempPlotConfig;
this.emitPlotConfig();
}
}
} }
</script> </script>