summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSunil Shetye2021-01-27 17:38:58 +0530
committerSunil Shetye2021-04-11 21:23:03 +0530
commit087cf39ef1baafe297072021e2926cda8ad9d586 (patch)
tree0fbe7fb5e71782bc83115b32342c1b221971f9fc
parent381c3cbd3eef00b4be509c789c74583b25aace3b (diff)
downloadCommon-Interface-Project-087cf39ef1baafe297072021e2926cda8ad9d586.tar.gz
Common-Interface-Project-087cf39ef1baafe297072021e2926cda8ad9d586.tar.bz2
Common-Interface-Project-087cf39ef1baafe297072021e2926cda8ad9d586.zip
trim early
set to empty before every search set width and height of dragged element from image
-rw-r--r--blocks/eda-frontend/src/components/SchematicEditor/ComponentSidebar.js5
-rw-r--r--blocks/eda-frontend/src/components/SchematicEditor/Helper/SideBar.js4
-rw-r--r--blocks/eda-frontend/src/components/Simulator/NetlistUpload.js155
3 files changed, 5 insertions, 159 deletions
diff --git a/blocks/eda-frontend/src/components/SchematicEditor/ComponentSidebar.js b/blocks/eda-frontend/src/components/SchematicEditor/ComponentSidebar.js
index cb1b8a00..0fdb1786 100644
--- a/blocks/eda-frontend/src/components/SchematicEditor/ComponentSidebar.js
+++ b/blocks/eda-frontend/src/components/SchematicEditor/ComponentSidebar.js
@@ -66,7 +66,7 @@ export default function ComponentSidebar ({ compRef }) {
if (searchText.length === 0) {
setSearchedComponents([])
}
- setSearchText(evt.target.value)
+ setSearchText(evt.target.value.trim())
setSearchedComponents([])
// mimic the value so we can access the latest value in our API call.
@@ -76,8 +76,9 @@ export default function ComponentSidebar ({ compRef }) {
React.useEffect(() => {
// if the user keeps typing, stop the API call!
clearTimeout(timeoutId.current)
+ setSearchedComponents([])
// don't make an API call with no data
- if (!searchText.trim()) return
+ if (searchText.length === 0) return
// capture the timeoutId so we can
// stop the call if the user keeps typing
timeoutId.current = setTimeout(() => {
diff --git a/blocks/eda-frontend/src/components/SchematicEditor/Helper/SideBar.js b/blocks/eda-frontend/src/components/SchematicEditor/Helper/SideBar.js
index 7de78c19..b359ea57 100644
--- a/blocks/eda-frontend/src/components/SchematicEditor/Helper/SideBar.js
+++ b/blocks/eda-frontend/src/components/SchematicEditor/Helper/SideBar.js
@@ -66,8 +66,8 @@ export function AddComponent (component, imgref) {
// Creates the element that is being for the actual preview.
var dragElt = document.createElement('div')
dragElt.style.border = 'dashed black 1px'
- dragElt.style.width = '120px'
- dragElt.style.height = '40px'
+ dragElt.style.width = (img.naturalWidth ? img.naturalWidth : 40) + 'px'
+ dragElt.style.height = (img.naturalHeight ? img.naturalHeight : 40) + 'px'
// Drag source is configured to use dragElt for preview and as drag icon
// if scalePreview (last) argument is true. Dx and dy are null to force
diff --git a/blocks/eda-frontend/src/components/Simulator/NetlistUpload.js b/blocks/eda-frontend/src/components/Simulator/NetlistUpload.js
deleted file mode 100644
index 55ffa958..00000000
--- a/blocks/eda-frontend/src/components/Simulator/NetlistUpload.js
+++ /dev/null
@@ -1,155 +0,0 @@
-import React, { Component } from 'react'
-import { Grid, Button, Paper } from '@material-ui/core'
-import { withStyles } from '@material-ui/core/styles'
-
-import api from '../../utils/Api'
-
-const styles = (theme) => ({
- paper: {
- padding: theme.spacing(2),
- textAlign: 'center',
- backgroundColor: '#404040',
- color: '#fff'
- },
- finlabel: {
- cursor: 'pointer',
- color: '#9feaf9',
- padding: theme.spacing(1),
- border: '2px solid #9feaf9'
- },
- finput: {
- opacity: 0,
- position: 'absolute',
- zIndex: -1
- }
-})
-
-class NetlistUpload extends Component {
- constructor (props) {
- super(props)
- this.state = {
- file: null,
- filename: 'Choose Netlist',
- x_1: [],
- y1_1: [],
- y2_1: []
- }
- this.onFormSubmit = this.onFormSubmit.bind(this)
- this.onChange = this.onChange.bind(this)
- this.netlistUpload = this.netlistUpload.bind(this)
- }
-
- onChange (e) {
- this.setState({
- file: e.target.files[0],
- filename: e.target.files[0].name
- })
- }
-
- onFormSubmit (e) {
- // Stop default form submit
- e.preventDefault()
- this.netlistUpload(this.state.file)
- .then((response) => {
- const res = response.data
- const getUrl = 'simulation/status/'.concat(res.details.task_id)
- this.simulationResult(getUrl)
- })
- .catch(function (error) {
- console.log(error)
- })
- }
-
- // Upload the nelist
- netlistUpload (file) {
- const formData = new FormData()
- formData.append('file', file)
- const config = {
- headers: {
- 'content-type': 'multipart/form-data'
- }
- }
- return api.post('simulation/upload', formData, config)
- }
-
- // Get the simulation result with task_Id
- simulationResult (url) {
- api
- .get(url)
- .then((res) => {
- if (res.data.state === 'PROGRESS' || res.data.state === 'PENDING') {
- setTimeout(this.simulationResult(url), 1000)
- } else {
- this.setState({
- x_1: res.data.details.data[0].x,
- y1_1: res.data.details.data[0].y[0],
- y2_1: res.data.details.data[0].y[1]
- })
- }
- })
- .then((res) => { })
- .catch(function (error) {
- console.log(error)
- })
- }
-
- fileData = () => {
- if (this.state.file) {
- return (
- <div>
- <h3>File Details:</h3>
- <p>File Name: {this.state.file.name}</p>
- <p>File Type: Ngspice Netlist</p>
- </div>
- )
- } else {
- return (
- <div>
- <h4>Choose Netlist before pressing UPLOAD button</h4>
- </div>
- )
- }
- };
-
- render () {
- const { classes } = this.props
- return (
- <>
- <Grid item xs={12} sm={5}>
- <Paper className={classes.paper}>
- <h2>SUBMIT NETLIST</h2>
- <form onSubmit={this.onFormSubmit} style={{ marginTop: '45px' }}>
- <label htmlFor="netlist" className={classes.finlabel}>
- {this.state.filename}
- </label>
- <input
- type="file"
- id="netlist"
- onChange={this.onChange}
- className={classes.finput}
- />
- <br />
- <Button
- type="submit"
- variant="contained"
- color="primary"
- style={{ marginTop: '30px' }}
- >
- Upload
- </Button>
- </form>
- <br />
- {this.fileData()}
- </Paper>
- </Grid>
- <Grid item xs={12} sm={7}>
- <Paper className={classes.paper}>
- <h2>GRAPH OUTPUT</h2>
- </Paper>
- </Grid>
- </>
- )
- }
-}
-
-export default withStyles(styles, { withTheme: true })(NetlistUpload)