Minor UI fixes for dialogues and Tosca upload feature
[clamp.git] / ui-react / src / components / dialogs / Loop / OpenLoopModal.js
index fbfc727..c048834 100644 (file)
@@ -37,6 +37,21 @@ const ModalStyled = styled(Modal)`
 const CheckBoxStyled = styled(FormCheck.Input)`
        margin-left:3rem;
 `
+const LoopViewSvgDivStyled = styled.svg`
+       overflow-x: scroll;
+       display: flex;
+       flex-direction: row;
+       background-color: ${props => (props.theme.loopViewerBackgroundColor)};
+       border-color: ${props => (props.theme.loopViewerHeaderColor)};
+       margin-top: 2em;
+       margin-left: auto;
+       margin-right:auto;
+       margin-bottom: -3em;
+       text-align: center;
+       align-items: center;
+       height: 100%;
+       width: 100%;
+`
 
 export default class OpenLoopModal extends React.Component {
        constructor(props, context) {
@@ -46,10 +61,12 @@ export default class OpenLoopModal extends React.Component {
                this.handleOpen = this.handleOpen.bind(this);
                this.handleClose = this.handleClose.bind(this);
                this.handleDropdownListChange = this.handleDropdownListChange.bind(this);
+               this.showReadOnly = props.showReadOnly ? props.showReadOnly : true;
                this.state = {
                        show: true,
                        chosenLoopName: '',
-                       loopNames: []
+                       loopNames: [],
+                       content:''
                };
        }
 
@@ -64,41 +81,62 @@ export default class OpenLoopModal extends React.Component {
 
        handleDropdownListChange(e) {
                this.setState({ chosenLoopName: e.value });
+               LoopService.getSvg(e.value).then(svgXml => {
+                       if (svgXml.length !== 0) {
+                               this.setState({ content: svgXml })
+                       } else {
+                               this.setState({ content: 'Error1' })
+                       }
+               });
        }
 
        getLoopNames() {
                LoopService.getLoopNames().then(loopNames => {
-                       const loopOptions = loopNames.map((loopName) => { return { label: loopName, value: loopName } });
-                       this.setState({ loopNames: loopOptions })
+                   if (Object.entries(loopNames).length !== 0) {
+                       const loopOptions = loopNames.filter(loopName => loopName!=='undefined').map((loopName) => { return { label: loopName, value: loopName } });
+               this.setState({ loopNames: loopOptions })
+
+                   }
+
                });
        }
 
        handleOpen() {
                console.info("Loop " + this.state.chosenLoopName + " is chosen");
-               this.setState({ show: false });
-               this.props.history.push('/');
+        this.handleClose();
                this.props.loadLoopFunction(this.state.chosenLoopName);
        }
 
        render() {
                return (
-                       <ModalStyled size="lg" show={this.state.show} onHide={this.handleClose}>
+                       <ModalStyled size="xl" show={this.state.show} onHide={this.handleClose} backdrop="static" keyboard={false} >
                                <Modal.Header closeButton>
                                        <Modal.Title>Open Model</Modal.Title>
                                </Modal.Header>
                                <Modal.Body>
                                        <Form.Group as={Row} controlId="formPlaintextEmail">
-                                               <Form.Label column sm="2">Model Name</Form.Label>
+                                               <Form.Label column sm="2">Model Name:</Form.Label>
                                                <Col sm="10">
-                                                       <Select onChange={this.handleDropdownListChange} options={this.state.loopNames} />
+                                                       <Select onChange={this.handleDropdownListChange}
+                                                       options={this.state.loopNames} />
                                                </Col>
                                        </Form.Group>
-                                       <Form.Group controlId="formBasicChecbox">
-                                               <Form.Check>
-                                                       <FormCheck.Label>Read Only</FormCheck.Label>
-                                                       <CheckBoxStyled type="checkbox" />
-                                               </Form.Check>
+                                       <Form.Group as={Row} style={{alignItems: 'center'}} controlId="formSvgPreview">
+                                               <Form.Label column sm="2">Model Preview:</Form.Label>
+                                               <Col sm="10">
+                                                       <LoopViewSvgDivStyled dangerouslySetInnerHTML={{ __html: this.state.content }}
+                                                               value={this.state.content} >
+                                                       </LoopViewSvgDivStyled>
+                                               </Col>
                                        </Form.Group>
+                                       {this.showReadOnly === true ?
+                                               <Form.Group as={Row} controlId="formBasicChecbox">
+                                                       <Form.Check>
+                                                               <FormCheck.Label>Read Only Mode:</FormCheck.Label>
+                                                               <CheckBoxStyled style={{marginLeft: '3.5em'}} type="checkbox" />
+                                                       </Form.Check>
+                                               </Form.Group>
+                                       : null}
                                </Modal.Body>
                                <Modal.Footer>
                                        <Button variant="secondary" type="null" onClick={this.handleClose}>Cancel</Button>