aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/odlux/framework/src/actions
diff options
context:
space:
mode:
Diffstat (limited to 'sdnr/wt/odlux/framework/src/actions')
-rw-r--r--sdnr/wt/odlux/framework/src/actions/authentication.ts38
-rw-r--r--sdnr/wt/odlux/framework/src/actions/settingsAction.ts86
2 files changed, 100 insertions, 24 deletions
diff --git a/sdnr/wt/odlux/framework/src/actions/authentication.ts b/sdnr/wt/odlux/framework/src/actions/authentication.ts
index 20a248dc1..f1d11de37 100644
--- a/sdnr/wt/odlux/framework/src/actions/authentication.ts
+++ b/sdnr/wt/odlux/framework/src/actions/authentication.ts
@@ -18,9 +18,11 @@
import { Dispatch } from '../flux/store';
import { Action } from '../flux/action';
import { AuthPolicy, User } from '../models/authentication';
-import { GeneralSettings } from '../models/settings';
-import { SetGeneralSettingsAction, setGeneralSettingsAction } from './settingsAction';
+import { GeneralSettings, Settings } from '../models/settings';
+import { saveInitialSettings, SetGeneralSettingsAction, setGeneralSettingsAction } from './settingsAction';
import { endWebsocketSession } from '../services/notificationService';
+import { endUserSession, startUserSession } from '../services/userSessionService';
+import { IApplicationStoreState } from '../store/applicationStore';
export class UpdateUser extends Action {
@@ -40,16 +42,30 @@ export class UpdatePolicies extends Action {
export const loginUserAction = (user?: User) => (dispatcher: Dispatch) =>{
dispatcher(new UpdateUser(user));
- loadUserSettings(user, dispatcher);
-
-
+ if(user){
+ startUserSession(user);
+ loadUserSettings(user, dispatcher);
+ localStorage.setItem("userToken", user.toString());
+ }
}
-export const logoutUser = () => (dispatcher: Dispatch) =>{
+export const logoutUser = () => (dispatcher: Dispatch, getState: () => IApplicationStoreState) =>{
+
+ const {framework:{applicationState:{ authentication }, authenticationState: {user}}} = getState();
dispatcher(new UpdateUser(undefined));
dispatcher(new SetGeneralSettingsAction(null));
endWebsocketSession();
+ endUserSession();
+ localStorage.removeItem("userToken");
+
+
+ //only call if a user is currently logged in
+ if (authentication === "oauth" && user) {
+
+ const url = window.location.origin;
+ window.location.href=`${url}/oauth/logout`;
+ }
}
const loadUserSettings = (user: User | undefined, dispatcher: Dispatch) =>{
@@ -74,14 +90,8 @@ const loadUserSettings = (user: User | undefined, dispatcher: Dispatch) =>{
}else{
return null;
}
- }).then((result:GeneralSettings)=>{
- if(result?.general){
- //will start websocket session if applicable
- dispatcher(setGeneralSettingsAction(result.general.areNotificationsEnabled!));
-
- }else{
- dispatcher(setGeneralSettingsAction(false));
- }
+ }).then((result:Settings)=>{
+ dispatcher(saveInitialSettings(result));
})
}
} \ No newline at end of file
diff --git a/sdnr/wt/odlux/framework/src/actions/settingsAction.ts b/sdnr/wt/odlux/framework/src/actions/settingsAction.ts
index ffcdfc26a..1c18ddc8e 100644
--- a/sdnr/wt/odlux/framework/src/actions/settingsAction.ts
+++ b/sdnr/wt/odlux/framework/src/actions/settingsAction.ts
@@ -18,47 +18,113 @@
import { Dispatch } from "../flux/store";
import { Action } from "../flux/action";
-import { GeneralSettings } from "../models/settings";
+import { GeneralSettings, Settings, TableSettings, TableSettingsColumn } from "../models/settings";
import { getSettings, putSettings } from "../services/settingsService";
import { startWebsocketSession, suspendWebsocketSession } from "../services/notificationService";
+import { IApplicationStoreState } from "../store/applicationStore";
-export class SetGeneralSettingsAction extends Action{
+export class SetGeneralSettingsAction extends Action {
/**
*
*/
- constructor(public areNoticationsActive: boolean|null) {
+ constructor(public areNoticationsActive: boolean | null) {
super();
-
}
}
-export const setGeneralSettingsAction = (value: boolean) => (dispatcher: Dispatch) =>{
+export class SetTableSettings extends Action {
+
+ constructor(public tableName: string, public updatedColumns: TableSettingsColumn[]) {
+ super();
+ }
+}
+
+export class LoadSettingsAction extends Action {
+
+ constructor(public settings: Settings & { isInitialLoadDone: true }) {
+ super();
+ }
+
+}
+
+export class SettingsDoneLoadingAction extends Action {
+
+}
+
+export const setGeneralSettingsAction = (value: boolean) => (dispatcher: Dispatch) => {
dispatcher(new SetGeneralSettingsAction(value));
- if(value){
+ if (value) {
startWebsocketSession();
- }else{
+ } else {
suspendWebsocketSession();
}
}
-export const updateGeneralSettingsAction = (activateNotifications: boolean) => async (dispatcher: Dispatch) =>{
+export const updateGeneralSettingsAction = (activateNotifications: boolean) => async (dispatcher: Dispatch) => {
- const value: GeneralSettings = {general:{areNotificationsEnabled: activateNotifications}};
+ const value: GeneralSettings = { general: { areNotificationsEnabled: activateNotifications } };
const result = await putSettings("/general", JSON.stringify(value.general));
dispatcher(setGeneralSettingsAction(activateNotifications));
}
+export const updateTableSettings = (tableName: string, columns: TableSettingsColumn[]) => async (dispatcher: Dispatch, getState: () => IApplicationStoreState) => {
+
+
+ //TODO: ask micha how to handle object with variable properties!
+ //fix for now: just safe everything!
+
+ let {framework:{applicationState:{settings:{tables}}}} = getState();
+
+ tables[tableName] = { columns: columns };
+ const json=JSON.stringify(tables);
+
+ // would only save latest entry
+ //const json = JSON.stringify({ [tableName]: { columns: columns } });
+
+ const result = await putSettings("/tables", json);
+
+ dispatcher(new SetTableSettings(tableName, columns));
+}
+
export const getGeneralSettingsAction = () => async (dispatcher: Dispatch) => {
const result = await getSettings<GeneralSettings>();
- if(result && result.general){
+ if (result && result.general) {
dispatcher(new SetGeneralSettingsAction(result.general.areNotificationsEnabled!))
}
+}
+
+export const saveInitialSettings = (settings: any) => async (dispatcher: Dispatch) => {
+
+ const defaultSettings = {general:{ areNotificationsEnabled: false }, tables:{}};
+
+ const initialSettings = {...defaultSettings, ...settings};
+
+ if (initialSettings) {
+ if (initialSettings.general) {
+ const settingsActive = initialSettings.general.areNotificationsEnabled;
+
+ if (settingsActive) {
+ startWebsocketSession();
+ } else {
+ suspendWebsocketSession();
+ }
+ }
+
+ dispatcher(new LoadSettingsAction(initialSettings));
+ }
+ else {
+ dispatcher(new SettingsDoneLoadingAction());
+
+ }
+
+
+
} \ No newline at end of file