From 49926f7ae421ab324e3c4d1b1a3cdce7e262e887 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 21 Feb 2019 16:03:13 +0100 Subject: [PATCH] Keeping selected on reload --- CompetitionStorage.js | 1 - Spaces/TopSpace.js | 2 +- TopSpace/CurrentEvent.js | 9 ++++++--- TopSpace/Login.js | 37 ++++++++++++++++++++++++++----------- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/CompetitionStorage.js b/CompetitionStorage.js index 007d07253..644554e0b 100644 --- a/CompetitionStorage.js +++ b/CompetitionStorage.js @@ -157,4 +157,3 @@ function newCompetitionStorage(pName) { } } - diff --git a/Spaces/TopSpace.js b/Spaces/TopSpace.js index 4242403b5..d8eebe3c5 100644 --- a/Spaces/TopSpace.js +++ b/Spaces/TopSpace.js @@ -38,7 +38,7 @@ function newTopSpace() { }; thisObject.login = newLogin(); - thisObject.login.initialize(onLoginInitialized); + thisObject.login.initialize(sharedStatus, onLoginInitialized); thisObject.companyLogo = newCompanyLogo(); thisObject.endUser = newEndUser(); diff --git a/TopSpace/CurrentEvent.js b/TopSpace/CurrentEvent.js index 784569bd3..42d935b32 100644 --- a/TopSpace/CurrentEvent.js +++ b/TopSpace/CurrentEvent.js @@ -48,7 +48,8 @@ window.EVENTS = storedEvents; window.CURRENT_EVENT_TITLE = storedEvents[sharedStatus.currentEventIndex].title; label = "Event - " + storedEvents[sharedStatus.currentEventIndex].title; - sharedStatus.eventHandler.raiseEvent("Event Changed"); + window.localStorage.setItem('currentEventObject', JSON.stringify(storedEvents[sharedStatus.currentEventIndex])); + sharedStatus.eventHandler.raiseEvent('Event Changed'); } thisObject.container.eventHandler.listenToEvent("onMouseClick", onClick); @@ -77,7 +78,8 @@ sharedStatus.currentEventIndex = 0; window.CURRENT_EVENT_TITLE = storedEvents[sharedStatus.currentEventIndex].title; label = "Event - " + storedEvents[sharedStatus.currentEventIndex].title; - sharedStatus.eventHandler.raiseEvent("Event Changed"); + window.localStorage.setItem('currentEventObject', JSON.stringify(storedEvents[sharedStatus.currentEventIndex])); + sharedStatus.eventHandler.raiseEvent('Event Changed'); return; } @@ -86,7 +88,8 @@ sharedStatus.currentEventIndex++; window.CURRENT_EVENT_TITLE = storedEvents[sharedStatus.currentEventIndex].title; label = "Event - " + storedEvents[sharedStatus.currentEventIndex].title; - sharedStatus.eventHandler.raiseEvent("Event Changed"); + window.localStorage.setItem('currentEventObject', JSON.stringify(storedEvents[sharedStatus.currentEventIndex])); + sharedStatus.eventHandler.raiseEvent('Event Changed'); return; } diff --git a/TopSpace/Login.js b/TopSpace/Login.js index 0453cc5ab..94e450100 100644 --- a/TopSpace/Login.js +++ b/TopSpace/Login.js @@ -27,12 +27,14 @@ function newLogin() { return thisObject; - function initialize(callBackFunction) { + function initialize(pSharedStatus, callBackFunction) { const accessToken = window.localStorage.getItem("access_token"); let user = window.localStorage.getItem("user"); + sharedStatus = pSharedStatus; + if (user === null) { // if there is no user that means that we are logged off, which means it is time to clean the local storage of things from the last log in. @@ -176,15 +178,6 @@ function newLogin() { uri: window.canvasApp.graphQL.masterAppApiUrl }); - networkInterfaceEvents.use([{ - applyMiddleware(req, next) { - req.options.headers = { - authorization: `Bearer ${accessToken}` - }; - next(); - } - }]); - const apolloClientEvents = new Apollo.lib.ApolloClient({ networkInterface: networkInterfaceEvents, connectToDevTools: true, @@ -195,6 +188,17 @@ function newLogin() { events_Events(maxStartDate: $maxStartDate, minEndDate: $minEndDate){ id title + startDatetime + endDatetime + participants{ + participant{ + name + profile{ + avatar + } + } + operationId + } } } ` @@ -209,7 +213,18 @@ function newLogin() { variables: { maxStartDate: nowSeconds, minEndDate: twoWeeksAgoSeconds } }) .then(response => { - window.localStorage.setItem('currentEvents', JSON.stringify(response.data.events_Events)); + currentEvent = window.localStorage.getItem('currentEventObject'); + if (currentEvent === null || currentEvent === "[]" || currentEvent === "") { + sharedStatus.currentEventIndex = 0; + } else { + currentEvent = JSON.parse(currentEvent); + sharedStatus.currentEventIndex = response.data.events_Events.findIndex(function(element) { + return element.id == currentEvent.id; + }); + if ( sharedStatus.currentEventIndex === -1 ) { + sharedStatus.currentEventIndex = 0; + } + } resolve({ currentEvents: response.data.events_Events}) }) .catch(error => {