Commit 42ffff2d authored by Sonja Happ's avatar Sonja Happ

Merge branch 'example-dashboard' into develop

# Conflicts:
#	src/dashboard/dashboard.js
parents 5ad2c987 6fa61d07
...@@ -54,6 +54,7 @@ class Dashboard extends Component { ...@@ -54,6 +54,7 @@ class Dashboard extends Component {
if (prevState == null) { if (prevState == null) {
prevState = {}; prevState = {};
} }
const sessionToken = LoginStore.getState().token; const sessionToken = LoginStore.getState().token;
let dashboard = DashboardStore.getState().find(d => d.id === parseInt(props.match.params.dashboard, 10)); let dashboard = DashboardStore.getState().find(d => d.id === parseInt(props.match.params.dashboard, 10));
...@@ -96,7 +97,7 @@ class Dashboard extends Component { ...@@ -96,7 +97,7 @@ class Dashboard extends Component {
modalData: null, modalData: null,
modalIndex: null, modalIndex: null,
widgetChangeData: [], widgetChangeData: [],
widgetAddData:[], widgetAddData:prevState.widgetAddData || [],
maxWidgetHeight: maxHeight || null, maxWidgetHeight: maxHeight || null,
dropZoneHeight: maxHeight +80 || null, dropZoneHeight: maxHeight +80 || null,
...@@ -167,6 +168,10 @@ class Dashboard extends Component { ...@@ -167,6 +168,10 @@ class Dashboard extends Component {
handleDrop(widget) { handleDrop(widget) {
widget.dashboardID = this.state.dashboard.id; widget.dashboardID = this.state.dashboard.id;
let tempChanges = this.state.widgetAddData;
tempChanges.push(widget);
this.setState({ widgetAddData: tempChanges})
AppDispatcher.dispatch({ AppDispatcher.dispatch({
type: 'widgets/start-add', type: 'widgets/start-add',
...@@ -174,10 +179,7 @@ class Dashboard extends Component { ...@@ -174,10 +179,7 @@ class Dashboard extends Component {
data: widget data: widget
}); });
let tempChanges = this.state.widgetAddData;
tempChanges.push(widget);
this.setState({ widgetAddData: tempChanges})
/*let widgets = []; /*let widgets = [];
widgets = this.state.dashboard.get('widgets'); widgets = this.state.dashboard.get('widgets');
...@@ -297,15 +299,17 @@ class Dashboard extends Component { ...@@ -297,15 +299,17 @@ class Dashboard extends Component {
} }
cancelEditing() { cancelEditing() {
console.log("cancelEditing the add data: "); //raw widget has no id -> cannot be deleted in its original form
console.log(this.state.widgetAddData); /*
this.state.widgetAddData.forEach( widget => { this.state.widgetAddData.forEach( widget => {
AppDispatcher.dispatch({ AppDispatcher.dispatch({
type: 'widgets/start-remove', type: 'widgets/start-remove',
data: widget, data: widget,
token: this.state.sessionToken token: this.state.sessionToken
}); });
}); }); */
AppDispatcher.dispatch({ AppDispatcher.dispatch({
type: 'widgets/start-load', type: 'widgets/start-load',
token: this.state.sessionToken, token: this.state.sessionToken,
......
...@@ -113,7 +113,7 @@ class WidgetContextMenu extends React.Component { ...@@ -113,7 +113,7 @@ class WidgetContextMenu extends React.Component {
); );
return <div> return <div>
<MenuProvider id={'widgetMenu'+ this.props.index} style={{ border: '1px solid purple', display: 'inline-block' }}> <MenuProvider id={'widgetMenu'+ this.props.index}>
<Widget <Widget
data={this.props.widget} data={this.props.widget}
onWidgetChange={this.props.onWidgetChange} onWidgetChange={this.props.onWidgetChange}
......
...@@ -44,7 +44,7 @@ class EditWidgetColorControl extends Component { ...@@ -44,7 +44,7 @@ class EditWidgetColorControl extends Component {
this.state = { this.state = {
widget: { widget: {
customProperties:{}
} }
}; };
} }
......
...@@ -77,7 +77,7 @@ class EditImageWidgetControl extends React.Component { ...@@ -77,7 +77,7 @@ class EditImageWidgetControl extends React.Component {
return <div> return <div>
<FormGroup controlId="file"> <FormGroup controlId="file">
<FormLabel>Image</FormLabel> <FormLabel>Image</FormLabel>
<FormControl componentClass="select" value={this.state.widget.customProperties.file} onChange={(e) => this.props.handleChange(e)}> <FormControl className="select" value={this.state.widget.customProperties.file} onChange={(e) => this.props.handleChange(e)}>
{this.props.files.length === 0 ? ( {this.props.files.length === 0 ? (
<option disabled value style={{ display: 'none' }}>No images found, please upload one first.</option> <option disabled value style={{ display: 'none' }}>No images found, please upload one first.</option>
) : ( ) : (
...@@ -96,8 +96,8 @@ class EditImageWidgetControl extends React.Component { ...@@ -96,8 +96,8 @@ class EditImageWidgetControl extends React.Component {
<FormControl type="file" onChange={(e) => this.setState({ fileList: e.target.files }) } /> <FormControl type="file" onChange={(e) => this.setState({ fileList: e.target.files }) } />
</FormGroup> </FormGroup>
<ProgressBar striped active now={this.state.progress} label={`${this.state.progress}%`} /> <ProgressBar striped active={'true'} now={this.state.progress} label={`${this.state.progress}%`} />
<Button bsSize="small" onClick={this.startFileUpload}>Upload</Button> <Button size='sm' onClick={this.startFileUpload}>Upload</Button>
</div>; </div>;
} }
} }
......
...@@ -28,22 +28,23 @@ import CreateControls from './edit-widget-control-creator'; ...@@ -28,22 +28,23 @@ import CreateControls from './edit-widget-control-creator';
class EditWidgetDialog extends React.Component { class EditWidgetDialog extends React.Component {
valid = true; valid = true;
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
temporal: { temporal: {},
name: '', };
simulationModel: '', }
signal: 0
static getDerivedStateFromProps(props, state){
} return {
temporal: props.widget
}; };
} }
onClose(canceled) { onClose(canceled) {
if (canceled === false) { if (canceled === false) {
...@@ -67,7 +68,7 @@ class EditWidgetDialog extends React.Component { ...@@ -67,7 +68,7 @@ class EditWidgetDialog extends React.Component {
} }
handleChange(e) { handleChange(e) {
// TODO: check what we really need in this function. Can we reduce its complexity?
if (e.constructor === Array) { if (e.constructor === Array) {
// Every property in the array will be updated // Every property in the array will be updated
let changes = e.reduce( (changesObject, event) => { let changes = e.reduce( (changesObject, event) => {
...@@ -78,7 +79,7 @@ class EditWidgetDialog extends React.Component { ...@@ -78,7 +79,7 @@ class EditWidgetDialog extends React.Component {
this.setState({ temporal: Object.assign({}, this.state.temporal, changes ) }); this.setState({ temporal: Object.assign({}, this.state.temporal, changes ) });
} }
if(e.target.type !== 'text'){ if(e.target.type !== 'text'){
let changeObject = {}; let changeObject = {};
if (e.target.id === 'lockAspect') { if (e.target.id === 'lockAspect') {
...@@ -100,28 +101,25 @@ class EditWidgetDialog extends React.Component { ...@@ -100,28 +101,25 @@ class EditWidgetDialog extends React.Component {
} else if (e.target.type === 'number') { } else if (e.target.type === 'number') {
changeObject[e.target.id] = Number(e.target.value); changeObject[e.target.id] = Number(e.target.value);
} }
else { else {
changeObject[e.target.id] = e.target.value; changeObject[e.target.id] = e.target.value;
} }
let finalChange = this.state.temporal; let finalChange = this.state.temporal;
finalChange.customProperties[e.target.id] = changeObject[e.target.id]; finalChange.customProperties[e.target.id] = changeObject[e.target.id];
this.setState({ temporal: finalChange}); this.setState({ temporal: finalChange});
} }
else{ else{
if(this.state.temporal[e.target.id]){ if(this.state.temporal[e.target.id]){
let finalChange = this.state.temporal; let finalChange = this.state.temporal;
finalChange[e.target.id] = e.target.value; finalChange[e.target.id] = e.target.value;
this.setState({ temporal: finalChange}); this.setState({ temporal: finalChange});
} }
} }
} }
resetState() { resetState() {
......
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