diff --git a/src/app.js b/src/app.js
index aa9ce6a..cddc5de 100644
--- a/src/app.js
+++ b/src/app.js
@@ -87,8 +87,13 @@ class App extends React.Component {
};
render() {
- if (this.state.token == null) {
- return ();
+
+ let token = localStorage.getItem("token");
+ let currentUser = JSON.parse(localStorage.getItem("currentUser"));
+
+ if (token == null || currentUser == null) {
+ console.log("APP redirecting to logout/ login")
+ return ();
}
return (
@@ -99,7 +104,7 @@ class App extends React.Component {
*/}
-
+
@@ -110,17 +115,17 @@ class App extends React.Component {
})
@@ -47,7 +55,7 @@ class Home extends React.Component {
VILLASweb is a frontend for distributed real-time simulation hosted by
{config.admin.name}.
- You are logged in as user {this.state.currentUser.username} with ID {this.state.currentUser.id} and role {this.state.currentUser.role}.
+ You are logged in as user {currentUser.username} with ID {currentUser.id} and role {currentUser.role}.
Data Model
diff --git a/src/common/menu-sidebar.js b/src/common/menu-sidebar.js
index 59874ed..06d1342 100644
--- a/src/common/menu-sidebar.js
+++ b/src/common/menu-sidebar.js
@@ -31,7 +31,7 @@ class SidebarMenu extends React.Component {
{ this.props.currentRole === 'Admin' ?
User Management : ''
}
-
Account
+
Account
Logout
diff --git a/src/dashboard/dashboard.js b/src/dashboard/dashboard.js
index 584a4f2..0611196 100644
--- a/src/dashboard/dashboard.js
+++ b/src/dashboard/dashboard.js
@@ -28,7 +28,6 @@ import WidgetToolbox from '../widget/widget-toolbox';
import WidgetArea from '../widget/widget-area';
import DashboardButtonGroup from './dashboard-button-group';
-import LoginStore from '../user/login-store';
import DashboardStore from './dashboard-store';
import SignalStore from '../signal/signal-store'
import FileStore from '../file/file-store';
@@ -43,7 +42,7 @@ class Dashboard extends Component {
static lastWidgetKey = 0;
static getStores() {
- return [ DashboardStore, LoginStore,FileStore, WidgetStore, SignalStore, ConfigStore, ICStore];
+ return [ DashboardStore, FileStore, WidgetStore, SignalStore, ConfigStore, ICStore];
}
static calculateState(prevState, props) {
@@ -51,7 +50,7 @@ class Dashboard extends Component {
prevState = {};
}
- const sessionToken = LoginStore.getState().token;
+ const sessionToken = localStorage.getItem("token");
let dashboard = DashboardStore.getState().find(d => d.id === parseInt(props.match.params.dashboard, 10));
if (dashboard == null){
@@ -73,20 +72,22 @@ class Dashboard extends Component {
return thisWidgetHeight > maxHeightSoFar? thisWidgetHeight : maxHeightSoFar;
}, 0);
- if(dashboard.height === 0){
- dashboard.height = 400;
- }
- else if(maxHeight + 80 > dashboard.height)
- {
- dashboard.height = maxHeight + 80;
- }
+
// filter component configurations to the ones that belong to this scenario
let configs = []
let files = []
- if (dashboard !== null) {
+ if (dashboard !== undefined) {
configs = ConfigStore.getState().filter(config => config.scenarioID === dashboard.scenarioID);
files = FileStore.getState().filter(file => file.scenarioID === dashboard.scenarioID);
+
+ if(dashboard.height === 0){
+ dashboard.height = 400;
+ }
+ else if(maxHeight + 80 > dashboard.height)
+ {
+ dashboard.height = maxHeight + 80;
+ }
}
// filter signals to the ones belonging to the scenario at hand
@@ -154,10 +155,11 @@ class Dashboard extends Component {
AppDispatcher.dispatch({
type: 'widgets/start-load',
token: this.state.sessionToken,
- param: '?dashboardID=' + this.state.dashboard.id
+ param: '?dashboardID=' + parseInt(this.props.match.params.dashboard, 10),
});
// open web sockets if ICs are already known
+ // TODO opening websockets has to be moved to componentDidUpdate and should be done as soon as ICs are loaded!
if(this.state.ics.length > 0){
console.log("Starting to open IC websockets:", this.state.ics);
AppDispatcher.dispatch({
@@ -398,6 +400,10 @@ class Dashboard extends Component {
render() {
+ if (this.state.dashboard === undefined){
+ return
Add, edit or delete files of scenario } >
diff --git a/src/scenario/scenarios.js b/src/scenario/scenarios.js
index 63432ce..f093d7a 100644
--- a/src/scenario/scenarios.js
+++ b/src/scenario/scenarios.js
@@ -22,7 +22,6 @@ import FileSaver from 'file-saver';
import AppDispatcher from '../common/app-dispatcher';
import ScenarioStore from './scenario-store';
-import LoginStore from '../user/login-store';
import DashboardStore from '../dashboard/dashboard-store';
import WidgetStore from "../widget/widget-store";
import ConfigStore from '../componentconfig/config-store';
@@ -41,7 +40,7 @@ import DeleteDialog from '../common/dialogs/delete-dialog';
class Scenarios extends Component {
static getStores() {
- return [ScenarioStore, LoginStore, DashboardStore, WidgetStore, ConfigStore, SignalStore];
+ return [ScenarioStore, DashboardStore, WidgetStore, ConfigStore, SignalStore];
}
static calculateState() {
@@ -50,7 +49,7 @@ class Scenarios extends Component {
scenarios: ScenarioStore.getState(),
dashboards: DashboardStore.getState(),
configs: ConfigStore.getState(),
- sessionToken: LoginStore.getState().token,
+ sessionToken: localStorage.getItem("token"),
newModal: false,
deleteModal: false,
diff --git a/src/user/login.js b/src/user/login.js
index ee78945..c2791da 100644
--- a/src/user/login.js
+++ b/src/user/login.js
@@ -73,7 +73,7 @@ class Login extends Component {
render() {
if (this.state.currentUser != null) {
- return ();
+ return ();
}
return (
diff --git a/src/user/user.js b/src/user/user.js
index 6ab4b82..6c7e0df 100644
--- a/src/user/user.js
+++ b/src/user/user.js
@@ -20,10 +20,8 @@ import { Container } from 'flux/utils';
import {Button, Col, Row} from 'react-bootstrap';
import AppDispatcher from '../common/app-dispatcher';
-import LoginStore from './login-store';
import UsersStore from './users-store';
-
import Icon from '../common/icon';
import EditOwnUserDialog from './edit-own-user'
import NotificationsDataManager from "../common/data-managers/notifications-data-manager"
@@ -31,17 +29,15 @@ import NotificationsDataManager from "../common/data-managers/notifications-data
class User extends Component {
static getStores() {
- return [ LoginStore, UsersStore ];
+ return [ UsersStore ];
}
static calculateState(prevState, props) {
prevState = prevState || {};
- let user = LoginStore.getState().currentUser;
-
return {
- currentUser: user,
- token: LoginStore.getState().token,
+ currentUser: JSON.parse(localStorage.getItem("currentUser")),
+ token: localStorage.getItem("token"),
editModal: false,
};
}
diff --git a/src/user/users.js b/src/user/users.js
index d97c539..f6f03df 100644
--- a/src/user/users.js
+++ b/src/user/users.js
@@ -20,7 +20,6 @@ import { Container } from 'flux/utils';
import { Button } from 'react-bootstrap';
import AppDispatcher from '../common/app-dispatcher';
-import LoginStore from './login-store';
import UsersStore from './users-store';
import Icon from '../common/icon';
@@ -34,23 +33,23 @@ import NotificationsDataManager from "../common/data-managers/notifications-data
class Users extends Component {
static getStores() {
- return [ LoginStore, UsersStore ];
+ return [ UsersStore ];
}
static calculateState(prevState, props) {
- let tokenState = LoginStore.getState().token;
+ let token = localStorage.getItem("token");
// If there is a token available and this method was called as a result of loading users
- if (!prevState && tokenState) {
+ if (!prevState && token) {
AppDispatcher.dispatch({
type: 'users/start-load',
- token: tokenState
+ token: token
});
}
return {
- token: tokenState,
+ token: token,
users: UsersStore.getState(),
newModal: false,