-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drawing upload and visualization. Small improvements also to the drop…
…zone (#2)
- Loading branch information
Showing
20 changed files
with
388 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
|
||
const api_url = "http://localhost:5000/api"; | ||
|
||
const static_url = "http://localhost:5000/static"; | ||
|
||
export {api_url, static_url}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import './DrawingCard.scss'; | ||
|
||
import React, { Component } from 'react'; | ||
import { Card, Modal } from 'react-bootstrap'; | ||
|
||
import {static_url} from '../../../project_defaults'; | ||
|
||
class DrawingCard extends Component{ | ||
constructor(props){ | ||
super(props); | ||
this.state = {show_details: false}; | ||
} | ||
|
||
getImgUrl(){ | ||
return static_url + "/Drawings/" + this.props.element.id + "/" + this.props.element.id + ".jpg"; | ||
} | ||
|
||
render(){ | ||
return <div> | ||
<Card className="p-2 hover-zoom" onClick={()=>this.setState({show_details: true})}> | ||
<div className="border-0 bg-black rounded text-dark clickable center p-0"> | ||
<img className="card-img-top rounded" src={this.getImgUrl()} alt="Not available"/> | ||
<div className="card-img-overlay h-100 d-flex flex-column justify-content-end p-2"> | ||
<div className="card-text text-center text-dark p-1 fade-top"></div> | ||
<div className="card-text text-center text-dark pb-1 bg-primary rounded-bottom"> | ||
{this.props.element.filename} | ||
</div> | ||
</div> | ||
</div> | ||
</Card> | ||
<Modal show={this.state.show_details} | ||
onHide={() => this.setState({show_details: false})} | ||
size="lg" | ||
centered> | ||
<Modal.Header closeButton> | ||
<Modal.Title >{this.props.element.filename}</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<div className="center pb-3"> | ||
<button>Draw it now</button> | ||
<button>+ Add to playlist</button> | ||
</div> | ||
<div className="center mb-5"> | ||
<img className="modal-drawing-preview" src={this.getImgUrl()} alt="Not available"/> | ||
</div> | ||
</Modal.Body> | ||
</Modal> | ||
</div> | ||
} | ||
} | ||
|
||
export default DrawingCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
.modal-drawing-preview{ | ||
width: 80%; | ||
} |
21 changes: 21 additions & 0 deletions
21
frontend/src/structure/tabs/drawings/DrawingDataDownloader.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {api_url} from "../../../project_defaults"; | ||
|
||
class DrawingDataDownloader{ | ||
// need to pass a callback as argument that will be called when the data is ready | ||
constructor(data_callback){ | ||
this.cb = data_callback; | ||
} | ||
|
||
requestDrawings(){ | ||
fetch(api_url+"/drawings/") | ||
.then(response => response.json()) | ||
.then(data => { | ||
this.cb(data); | ||
}).catch(error => { | ||
console.log("There was an error"); | ||
console.log(error); | ||
}) | ||
} | ||
} | ||
|
||
export default DrawingDataDownloader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { Component } from 'react'; | ||
import { Container, Row, Col } from 'react-bootstrap'; | ||
import Section from '../../../components/Section'; | ||
import DrawingDataDownloader from './DrawingDataDownloader'; | ||
import UploadDrawingsModal from './UploadDrawing'; | ||
import DrawingCard from './DrawingCard'; | ||
|
||
class Drawings extends Component{ | ||
constructor(props){ | ||
super(props); | ||
this.state = {show_upload: false, loaded: false, drawings: []} | ||
this.dhandler = new DrawingDataDownloader(this.addElements.bind(this)); | ||
} | ||
|
||
componentDidMount(){ | ||
this.dhandler.requestDrawings(); | ||
} | ||
|
||
addElements(data){ | ||
this.setState({drawings: data, loaded: true}); | ||
} | ||
|
||
handleFileUploaded(){ | ||
this.dhandler.requestDrawings(); | ||
} | ||
|
||
renderDrawings(drawings){ | ||
return drawings.map((d, index)=>{ | ||
return <Col key={index} sm={4}> | ||
<DrawingCard element={d}/> | ||
</Col> | ||
}); | ||
} | ||
// todo load more on page scroll | ||
|
||
render(){ | ||
return <Section sectionTitle="Drawings" | ||
sectionButton="+ Upload new drawing" | ||
sectionButtonHandler={()=>this.setState({show_upload: true})}> | ||
|
||
<div className={(this.state.loaded ? " d-none" : "")}> | ||
<div className="w-100 pt-5 center"> | ||
<h1>Loading...</h1> | ||
</div> | ||
</div> | ||
|
||
<Container> | ||
<Row> | ||
{this.renderDrawings(this.state.drawings)} | ||
</Row> | ||
</Container> | ||
|
||
<UploadDrawingsModal key={2} | ||
show={this.state.show_upload} | ||
handleClose={()=>{this.setState({show_upload: false})}} | ||
handleFileUploaded={this.handleFileUploaded.bind(this)}/> | ||
</Section> | ||
} | ||
} | ||
|
||
export default Drawings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import "./UploadDrawing.scss"; | ||
|
||
import React, { Component } from 'react'; | ||
|
||
import {api_url} from "../../../project_defaults"; | ||
|
||
import Dropzone from 'react-dropzone'; | ||
import Modal from 'react-bootstrap/Modal'; | ||
|
||
class UploadDrawingsModal extends Component{ | ||
|
||
static defaultProps = { | ||
playlist: 0, | ||
show: false | ||
} | ||
|
||
handleClose(){ | ||
this.props.handleClose(); | ||
} | ||
|
||
handleFiles(files){ | ||
let promises = files.map(f => { | ||
let data = new FormData(); | ||
data.append("file", f); | ||
data.append("filename", f.name); | ||
return fetch(api_url + "/upload/" + this.props.playlist, { | ||
method: "POST", | ||
body: data | ||
}).then((response => { | ||
if (response.status === 200){ | ||
window.show_toast("Drawing \""+f.name+"\" uploaded successfully"); | ||
}else{ | ||
window.show_toast("There was a problem when uploading \""+f.name+"\""); | ||
} | ||
})); | ||
}); | ||
// wait until all file have been laoaded to refresh the list | ||
Promise.all(promises) | ||
.then(()=>{this.props.handleFileUploaded()}); | ||
|
||
this.handleClose(); | ||
} | ||
|
||
render(){ | ||
return <Modal show={this.props.show} onHide={this.handleClose.bind(this)} size="lg" centered> | ||
<Modal.Header closeButton> | ||
<Modal.Title >Upload new drawing</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<Dropzone | ||
onDrop={this.handleFiles.bind(this)} | ||
accept={".gcode"} | ||
noKeyboard> | ||
{({getRootProps, getInputProps, isDragActive}) => (<div {...getRootProps()} className={"animated-background m-2 p-5 mh-100 d-flex justify-content-center align-items-center" + (isDragActive ? " drag-active" : "")}> | ||
<input {...getInputProps()}/> | ||
<div className="d-block text-center">Drag and drop the .gcode/.nc file here <br/>or click to open the file explorer | ||
</div> | ||
</div>)} | ||
</Dropzone> | ||
</Modal.Body> | ||
</Modal> | ||
} | ||
} | ||
|
||
export default UploadDrawingsModal; |
Oops, something went wrong.