Commit 2c5d6873 authored by Laura Fuentes Grau's avatar Laura Fuentes Grau

fix for image widget: widget knows its own file again, wip: upload image...

fix for image widget: widget knows its own file again, wip: upload image without closing edit window
parent a7e0cb27
......@@ -42,7 +42,7 @@ class Dashboard extends Component {
static lastWidgetKey = 0;
static getStores() {
return [ DashboardStore, FileStore, LoginStore, WidgetStore, SignalStore, ConfigStore, ICStore];
return [ DashboardStore, LoginStore, WidgetStore, SignalStore, ConfigStore, ICStore];
}
static calculateState(prevState, props) {
......@@ -272,6 +272,17 @@ class Dashboard extends Component {
this.setState({ editModal: true, modalData: widget, modalIndex: index });
};
uploadFile(data,widget){
console.log("tschuuuu tschuuuu");
AppDispatcher.dispatch({
type: 'files/start-upload',
data: data,
token: this.state.sessionToken,
objectType: "widget",
objectID: widget.id,
});
}
closeEdit(data){
......@@ -469,6 +480,7 @@ class Dashboard extends Component {
sessionToken={this.state.sessionToken}
show={this.state.editModal}
onClose={this.closeEdit.bind(this)}
onUpload = {this.uploadFile.bind(this)}
widget={this.state.modalData}
signals={this.state.signals}
files={this.state.files}
......
......@@ -33,7 +33,7 @@ import EditWidgetMinMaxControl from './edit-widget-min-max-control';
import EditWidgetHTMLContent from './edit-widget-html-content';
import EditWidgetParametersControl from './edit-widget-parameters-control';
export default function CreateControls(widgetType = null, widget = null, sessionToken = null, files = null, signals, handleChange) {
export default function CreateControls(widgetType = null, widget = null, sessionToken = null, files = null, signals, handleChange, onUpload) {
// Use a list to concatenate the controls according to the widget type
var DialogControls = [];
......@@ -84,7 +84,7 @@ export default function CreateControls(widgetType = null, widget = null, session
// Restrict to only image file types (MIME)
//let imageControlFiles = files == null? [] : files.filter(file => file.type.includes('image'));
DialogControls.push(
<EditImageWidgetControl key={0} widget={widget} controlId={"customProperties.file"} sessionToken={sessionToken} files={files} handleChange={(e) => handleChange(e)} />,
<EditImageWidgetControl key={0} widget={widget} controlId={"customProperties.file"} sessionToken={sessionToken} files={files} handleChange={(e) => handleChange(e)} onUpload={(f,i) => onUpload(f,i)} />,
<EditWidgetAspectControl key={1} widget={widget} controlId={"customProperties.lockAspect"} handleChange={e => handleChange(e)} />
);
break;
......
......@@ -18,7 +18,7 @@
import React from 'react';
import {FormGroup, FormControl, FormLabel, Button, ProgressBar} from 'react-bootstrap';
import AppDispatcher from '../../common/app-dispatcher';
//import AppDispatcher from '../../common/app-dispatcher';
class EditImageWidgetControl extends React.Component {
......@@ -47,9 +47,11 @@ class EditImageWidgetControl extends React.Component {
formData.append("file", this.state.fileList[key]);
}
}
this.props.onUpload(formData,this.props.widget);
// upload files
AppDispatcher.dispatch({
/* AppDispatcher.dispatch({
type: 'files/start-upload',
data: formData,
token: this.props.sessionToken,
......@@ -57,7 +59,7 @@ class EditImageWidgetControl extends React.Component {
finishedCallback: this.clearProgress,
objectType: "widget",
objectID: this.props.widget.id,
});
});*/
}
uploadProgress = (e) => {
......
......@@ -122,7 +122,7 @@ class EditWidgetDialog extends React.Component {
customProperty ? changeObject[parts[0]][parts[1]] = e.target.value : changeObject[e.target.id] = e.target.value;
// get file and update size (if it's an image)
// get file and update size (if it's an image)
if ('lockAspect' in this.state.temporal && this.state.temporal.lockAspect) {
// TODO this if condition requires changes to work!!!
changeObject = this.assignAspectRatio(changeObject, e.target.value);
......@@ -179,7 +179,8 @@ class EditWidgetDialog extends React.Component {
this.props.sessionToken,
this.props.files,
this.props.signals,
(e) => this.handleChange(e));
(e) => this.handleChange(e),
(f,i) => this.props.onUpload(f,i));
}
return (
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment