mirror of
https://git.rwth-aachen.de/acs/public/villas/web/
synced 2025-03-09 00:00:01 +01:00
Add simulation model import & export
This commit is contained in:
parent
e27824f851
commit
02dcf185a3
2 changed files with 43 additions and 4 deletions
|
@ -186,4 +186,4 @@ class ImportSimulationModelDialog extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
export default ImportSimulationModelDialog;
|
||||
export default ImportSimulationModelDialog;
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
|
||||
import React from 'react';
|
||||
import { Container } from 'flux/utils';
|
||||
import { Button, Modal, Glyphicon } from 'react-bootstrap';
|
||||
import { Button, Modal, Glyphicon, FormControl, FormGroup, Form } from 'react-bootstrap';
|
||||
import FileSaver from 'file-saver';
|
||||
|
||||
import SimulationStore from '../stores/simulation-store';
|
||||
import NodeStore from '../stores/node-store';
|
||||
|
@ -32,6 +33,7 @@ import Table from '../components/table';
|
|||
import TableColumn from '../components/table-column';
|
||||
import NewSimulationModelDialog from '../components/dialog/new-simulation-model';
|
||||
import EditSimulationModelDialog from '../components/dialog/edit-simulation-model';
|
||||
import ImportSimulationModelDialog from '../components/dialog/import-simulation-model';
|
||||
|
||||
class Simulation extends React.Component {
|
||||
static getStores() {
|
||||
|
@ -47,6 +49,7 @@ class Simulation extends React.Component {
|
|||
newModal: false,
|
||||
deleteModal: false,
|
||||
editModal: false,
|
||||
importModal: false,
|
||||
modalData: {},
|
||||
modalIndex: null,
|
||||
|
||||
|
@ -146,6 +149,42 @@ class Simulation extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
exportSimulationModel(data) {
|
||||
// filter properties
|
||||
var model = Object.assign({}, data);
|
||||
|
||||
// get simulator name
|
||||
this.state.simulators.forEach(simulator => {
|
||||
if (simulator._id === model.simulator) {
|
||||
model.simulator = simulator.name;
|
||||
}
|
||||
});
|
||||
|
||||
// show save dialog
|
||||
const blob = new Blob([JSON.stringify(model, null, 2)], { type: 'application/json' });
|
||||
FileSaver.saveAs(blob, model.name + '.json');
|
||||
}
|
||||
|
||||
loadFile(fileList) {
|
||||
// get file
|
||||
const file = fileList[0];
|
||||
if (!file.type.match('application/json')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// create file reader
|
||||
var reader = new FileReader();
|
||||
var self = this;
|
||||
|
||||
reader.onload = function(event) {
|
||||
// read simulation model
|
||||
const simulationModel = JSON.parse(event.target.result);
|
||||
self.setState({ importModal: true, modalData: simulationModel });
|
||||
};
|
||||
|
||||
reader.readAsText(file);
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className='section'>
|
||||
|
@ -155,10 +194,10 @@ class Simulation extends React.Component {
|
|||
<TableColumn title='Name' dataKey='name' />
|
||||
<TableColumn title='Simulator' dataKey='simulator' width='180' modifier={(simulator) => this.getSimulatorName(simulator)} />
|
||||
<TableColumn title='Length' dataKey='length' width='100' />
|
||||
<TableColumn title='' width='70' editButton deleteButton onEdit={(index) => this.setState({ editModal: true, modalData: this.state.simulation.models[index], modalIndex: index })} onDelete={(index) => this.setState({ deleteModal: true, modalData: this.state.simulation.models[index], modalIndex: index })} />
|
||||
<TableColumn title='' width='100' editButton deleteButton exportButton onEdit={(index) => this.setState({ editModal: true, modalData: this.state.simulation.models[index], modalIndex: index })} onDelete={(index) => this.setState({ deleteModal: true, modalData: this.state.simulation.models[index], modalIndex: index })} onExport={(index) => this.exportSimulationModel(this.state.simulation.models[index])} />
|
||||
</Table>
|
||||
|
||||
<Button onClick={() => this.setState({ newModal: true })}><Glyphicon glyph="plus" /> Simulation Model</Button>
|
||||
<Button onClick={() => this.setState({ newModal: true })}><Glyphicon glyph="plus" /> Add Simulation Model</Button>
|
||||
|
||||
<NewSimulationModelDialog show={this.state.newModal} onClose={(data) => this.closeNewModal(data)} nodes={this.state.nodes} />
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue