diff --git a/misc/config_tools/configurator/src/pages/Config/CreateNewOrImportAnExistingScenario/CreateNewOrImportAnExistingScenario.jsx b/misc/config_tools/configurator/src/pages/Config/CreateNewOrImportAnExistingScenario/CreateNewOrImportAnExistingScenario.jsx index 5698f939b..997b94929 100644 --- a/misc/config_tools/configurator/src/pages/Config/CreateNewOrImportAnExistingScenario/CreateNewOrImportAnExistingScenario.jsx +++ b/misc/config_tools/configurator/src/pages/Config/CreateNewOrImportAnExistingScenario/CreateNewOrImportAnExistingScenario.jsx @@ -2,9 +2,10 @@ import React, {Component} from "react"; import {Accordion, Button, Col, Form, Row} from "react-bootstrap"; import CreateScenarioModal from "./CreateScenarioModal/CreateScenarioModal"; -import Banner from "../../../components/Banner"; import {dialog} from "@tauri-apps/api"; import {ACRNContext} from "../../../ACRNContext"; +import {invoke} from "@tauri-apps/api/tauri"; +import _ from "lodash/fp"; export default class CreateNewOrImportAnExistingScenario extends Component { constructor(props) { @@ -21,7 +22,22 @@ export default class CreateNewOrImportAnExistingScenario extends Component { } componentDidMount() { + let {configurator} = this.context this.scenarioHistoryUpdate() + invoke('fs_read_dir', { + path: configurator.WorkingFolder, + recursive: false + }).then((files) => { + for (let i = 0; i < files.length; i++) { + let isScenario = _.endsWith("/scenario.xml", files[i].path.replace(/\\/g, '/')); + console.log("files", isScenario, files[i].path) + if (isScenario) { + this.scenarioChange(files[i].path).then(() => { + this.importScenario() + }) + } + } + }) } scenarioHistoryUpdate() { @@ -39,7 +55,7 @@ export default class CreateNewOrImportAnExistingScenario extends Component { scenarioChange = (filepath) => { console.log(filepath) let {configurator} = this.context - configurator.addHistory('scenario', filepath).then(() => { + return configurator.addHistory('scenario', filepath).then(() => { this.scenarioHistoryUpdate().then(() => { this.scenarioXMLSelect.current.value = filepath }) @@ -48,9 +64,17 @@ export default class CreateNewOrImportAnExistingScenario extends Component { importScenario = () => { let {configurator} = this.context - configurator.programLayer.loadScenario(this.scenarioXMLSelect.current.value) + return configurator.programLayer.loadScenario(this.scenarioXMLSelect.current.value) .then(() => { - this.setState({selected: configurator.WorkingFolder + '/scenario.xml'}) + let printPath = configurator.WorkingFolder; + if (_.endsWith(configurator.WorkingFolder, "/") || _.endsWith(configurator.WorkingFolder, "\\")) { + printPath = printPath + 'scenario.xml' + } else { + printPath = printPath + (configurator.WorkingFolder[1] === ":" ? "\\" : '/') + 'scenario.xml' + } + this.setState({selected: printPath}) + }).then(() => { + document.querySelectorAll(".accordion-button")[2].click() }) .catch((reason) => { console.log(reason) diff --git a/misc/config_tools/configurator/src/pages/Config/ImportABoardConfigurationFile/ImportABoardConfigurationFile.jsx b/misc/config_tools/configurator/src/pages/Config/ImportABoardConfigurationFile/ImportABoardConfigurationFile.jsx index 27f45d9bd..5548f63f8 100644 --- a/misc/config_tools/configurator/src/pages/Config/ImportABoardConfigurationFile/ImportABoardConfigurationFile.jsx +++ b/misc/config_tools/configurator/src/pages/Config/ImportABoardConfigurationFile/ImportABoardConfigurationFile.jsx @@ -1,8 +1,9 @@ import React, {Component} from "react"; import {Accordion, Button, Col, Form, Row} from "react-bootstrap"; -import Banner from "../../../components/Banner"; import {dialog} from "@tauri-apps/api"; import {ACRNContext} from "../../../ACRNContext"; +import {invoke} from "@tauri-apps/api/tauri"; +import _ from "lodash/fp"; export default class ImportABoardConfigurationFile extends Component { constructor(props) { @@ -19,12 +20,25 @@ export default class ImportABoardConfigurationFile extends Component { } } - componentDidMount() { + componentDidMount = () => { let {configurator} = this.context configurator.getHistory('board').then((boardFiles) => { let disableImport = boardFiles.length === 0 this.setState({boardFiles, disableImport}) }) + invoke('fs_read_dir', { + path: configurator.WorkingFolder, + recursive: false + }).then((files) => { + for (let i = 0; i < files.length; i++) { + console.log("files", files[i].path) + if (_.endsWith(".board.xml", files[i].path)) { + this.boardChange(files[i].path).then(() => { + this.importBoard() + }) + } + } + }) } @@ -37,7 +51,7 @@ export default class ImportABoardConfigurationFile extends Component { boardChange = (filepath) => { let {configurator} = this.context - configurator.addHistory('board', filepath).then(() => { + return configurator.addHistory('board', filepath).then(() => { return configurator.getHistory('board') }).then((boardFiles) => { console.log(boardFiles)