From 33cc47c1786461bef1c84ef737133c2ba8da2da6 Mon Sep 17 00:00:00 2001 From: Laura Fuentes Grau Date: Tue, 26 Nov 2019 11:48:42 +0100 Subject: [PATCH] fixed version bugs --- src/dashboard/dashboard.js | 48 ++++++++++++++++++++-------- src/dashboard/widget-area.js | 2 +- src/dashboard/widget-context-menu.js | 6 ++-- src/user/user-store.js | 3 ++ src/user/user.js | 15 ++++++++- 5 files changed, 56 insertions(+), 18 deletions(-) diff --git a/src/dashboard/dashboard.js b/src/dashboard/dashboard.js index 7e5caff..499d620 100644 --- a/src/dashboard/dashboard.js +++ b/src/dashboard/dashboard.js @@ -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 => ( - + ))} diff --git a/src/dashboard/widget-area.js b/src/dashboard/widget-area.js index cc08afc..f3e7c0f 100644 --- a/src/dashboard/widget-area.js +++ b/src/dashboard/widget-area.js @@ -67,7 +67,7 @@ WidgetArea.propTypes = { editing: PropTypes.bool, grid: PropTypes.number, defaultSimulationModel: PropTypes.string, - widgets: PropTypes.object, + widgets: PropTypes.array, onWidgetAdded: PropTypes.func }; diff --git a/src/dashboard/widget-context-menu.js b/src/dashboard/widget-context-menu.js index 69e0683..9276d3c 100644 --- a/src/dashboard/widget-context-menu.js +++ b/src/dashboard/widget-context-menu.js @@ -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 + return Edit Delete @@ -108,7 +108,7 @@ class WidgetContextMenu extends React.Component { Lock Unlock - ; + ; } } diff --git a/src/user/user-store.js b/src/user/user-store.js index c925a35..2da3ca3 100644 --- a/src/user/user-store.js +++ b/src/user/user-store.js @@ -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 }); diff --git a/src/user/user.js b/src/user/user.js index b587637..9f888b6 100644 --- a/src/user/user.js +++ b/src/user/user.js @@ -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(); }