Commit 33cc47c1 authored by Laura Fuentes Grau's avatar Laura Fuentes Grau

fixed version bugs

parent 3b3448e1
......@@ -87,6 +87,7 @@ class Dashboard extends React.Component {
console.log(rawWidgets);
dashboard = dashboard.set('widgets', rawWidgets);
console.log("")
/* for(let widget of dashboard.get('widgets')){
......@@ -99,12 +100,9 @@ class Dashboard extends React.Component {
});
}
*/
let widgets = {};
for (let widget of dashboard.get('widgets')) {
widgets[this.lastWidgetKey] = widget;
this.lastWidgetKey++;
}
//ist das überhaupt nötiG??
/* if (this.state.dashboard.has('id') === false) {
AppDispatcher.dispatch({
......@@ -113,9 +111,13 @@ class Dashboard extends React.Component {
token: this.state.sessionToken
});
}
*/
// this.computeHeightWithWidgets(widgets);
/*if(Object.keys(widgets).length !== 0 ){
this.computeHeightWithWidgets(widgets);
}
let selectedDashboards = dashboard;
......@@ -128,8 +130,23 @@ class Dashboard extends React.Component {
});
*/
}
let widgets = {};
for (let widget of dashboard.get('widgets')) {
widgets[Dashboard.lastWidgetKey] = widget;
console.log(" the last widgetKey: " + Dashboard.lastWidgetKey);
Dashboard.lastWidgetKey++;
}
let maxHeight = Object.keys(widgets).reduce( (maxHeightSoFar, widgetKey) => {
console.log("!! the widget key: "+ widgetKey);
let thisWidget = widgets[widgetKey];
let thisWidgetHeight = thisWidget.y + thisWidget.height;
return thisWidgetHeight > maxHeightSoFar? thisWidgetHeight : maxHeightSoFar;
}, 0);
console.log("now the object keys: ");
console.log(Object.keys(widgets));
let simulationModels = [];
//if (prevState.simulation != null) {
// simulationModels = SimulationModelStore.getState().filter(m => prevState.simulation.models.includes(m._id));
......@@ -138,6 +155,7 @@ class Dashboard extends React.Component {
return {
rawDashboard,
dashboard,
widgets,
sessionToken: sessionToken,
projects: null, //ProjectStore.getState(),
......@@ -154,8 +172,8 @@ class Dashboard extends React.Component {
modalData: prevState.modalData || null,
modalIndex: prevState.modalIndex || null,
maxWidgetHeight: prevState.maxWidgetHeight || 0,
dropZoneHeight: prevState.dropZoneHeight || 0,
maxWidgetHeight: maxHeight,
dropZoneHeight: maxHeight +80,
};
}
......@@ -180,6 +198,7 @@ class Dashboard extends React.Component {
}
}
componentWillUnmount() {
//document.removeEventListener('keydown', this.handleKeydown.bind(this));
......@@ -321,7 +340,7 @@ class Dashboard extends React.Component {
/*
* Set the initial height state based on the existing widgets
*/
computeHeightWithWidgets(widgets) {
computeHeightWithWidgets(widgets) {
// Compute max height from widgets
let maxHeight = Object.keys(widgets).reduce( (maxHeightSoFar, widgetKey) => {
let thisWidget = widgets[widgetKey];
......@@ -414,7 +433,10 @@ class Dashboard extends React.Component {
render() {
const widgets = this.state.dashboard.get('widgets');
console.log("the widgets in render: ");
console.log(widgets);
const grid = this.state.dashboard.get('grid');
console.log("the grid in render: "+ grid);
const boxClasses = classNames('section', 'box', { 'fullscreen-padding': this.props.isFullscreen });
......@@ -459,7 +481,7 @@ class Dashboard extends React.Component {
{/* TODO: Create only one context menu for all widgets */}
{widgets != null && Object.keys(widgets).map(widgetKey => (
<WidgetContextMenu key={widgetKey} index={widgetKey} widget={widgets[widgetKey]} onEdit={this.editWidget} onDelete={this.deleteWidget} onChange={this.widgetChange} />
<WidgetContextMenu key={widgetKey} index={parseInt(widgetKey,10)} widget={widgets[widgetKey]} onEdit={this.editWidget} onDelete={this.deleteWidget} onChange={this.widgetChange} />
))}
......
......@@ -67,7 +67,7 @@ WidgetArea.propTypes = {
editing: PropTypes.bool,
grid: PropTypes.number,
defaultSimulationModel: PropTypes.string,
widgets: PropTypes.object,
widgets: PropTypes.array,
onWidgetAdded: PropTypes.func
};
......
......@@ -21,7 +21,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { contextMenu, Item, Separator } from 'react-contexify';
import { Menu, Item, Separator } from 'react-contexify';
class WidgetContextMenu extends React.Component {
editWidget = event => {
......@@ -93,7 +93,7 @@ class WidgetContextMenu extends React.Component {
render() {
const isLocked = this.props.widget.locked;
return <contextMenu id={'widgetMenu'+ this.props.index}>
return <Menu id={'widgetMenu'+ this.props.index}>
<Item disabled={isLocked} onClick={this.editWidget}>Edit</Item>
<Item disabled={isLocked} onClick={this.deleteWidget}>Delete</Item>
......@@ -108,7 +108,7 @@ class WidgetContextMenu extends React.Component {
<Item disabled={isLocked} onClick={this.lockWidget}>Lock</Item>
<Item disabled={isLocked === false} onClick={this.unlockWidget}>Unlock</Item>
</contextMenu>;
</Menu>;
}
}
......
......@@ -63,6 +63,9 @@ class UserStore extends ReduceStore {
// // save logged-in user
return Object.assign({}, state, { currentUser: action.user});
case 'users/reload-current-user':
return state;
case 'users/current-user-error':
// discard user token
return Object.assign({}, state, { currentUser: null, token: null });
......
......@@ -38,7 +38,7 @@ class User extends Component {
}
static calculateState(prevState, props) {
//prevState = prevState || {};
prevState = prevState || {};
let sessionToken = UserStore.getState().token;
let user = UserStore.getState().currentUser;
......@@ -67,6 +67,18 @@ class User extends Component {
};
}
update(){
let tokenState = UserStore.getState().token;
setTimeout(function() {
AppDispatcher.dispatch({
type: 'users/start-load',
data: UserStore.getState().userid,
token: tokenState
});
}.bind(this), 1000)
}
closeEditModal(data) {
......@@ -91,6 +103,7 @@ class User extends Component {
});
}
}
this.update();
}
......
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