From b7e885a3400af4c4e1212eeb411bff702502a83c Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 21 Feb 2019 14:33:12 +0100 Subject: [PATCH] Setting up event's selector --- BottomSpace/PlayStopButton.js | 7 +- Project.njsproj | 5 +- Spaces/TopSpace.js | 11 ++- TopSpace/CurrentBot.js | 4 +- TopSpace/CurrentEvent.js | 139 ++++++++++++++++++++++++++++++++++ TopSpace/CurrentProcess.js | 8 +- TopSpace/CurrentStartMode.js | 6 +- TopSpace/DevTeam.js | 3 +- TopSpace/Login.js | 62 +++++++++++++-- 9 files changed, 221 insertions(+), 24 deletions(-) create mode 100644 TopSpace/CurrentEvent.js diff --git a/BottomSpace/PlayStopButton.js b/BottomSpace/PlayStopButton.js index 693e3e66a..254f02f0e 100644 --- a/BottomSpace/PlayStopButton.js +++ b/BottomSpace/PlayStopButton.js @@ -3,7 +3,7 @@ function newPlayStopButton() { var thisObject = { container: undefined, - setDatetime: setDatetime, + setDatetime: setDatetime, draw: draw, getContainer: getContainer, // returns the inner most container that holds the point received by parameter. initialize: initialize @@ -59,8 +59,7 @@ function newPlayStopButton() { } function resize() { - - container.frame.position.x = viewPort.visibleArea.topLeft.x + 150 * 4; + container.frame.position.x = viewPort.visibleArea.topLeft.x + 150 * 5; container.frame.position.y = viewPort.visibleArea.bottomLeft.y; } @@ -161,4 +160,4 @@ function newPlayStopButton() { browserCanvasContext.drawImage(image, imagePoint.x, imagePoint.y, imageWidth, imageHeight); } -} \ No newline at end of file +} diff --git a/Project.njsproj b/Project.njsproj index df482b062..981d47765 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -104,6 +104,9 @@ Code + + Code + Code @@ -223,4 +226,4 @@ - \ No newline at end of file + diff --git a/Spaces/TopSpace.js b/Spaces/TopSpace.js index 52ae3d410..4242403b5 100644 --- a/Spaces/TopSpace.js +++ b/Spaces/TopSpace.js @@ -11,6 +11,7 @@ function newTopSpace() { currentBot: undefined, currentProcess: undefined, currentStartMode: undefined, + currentEvent: undefined, login: undefined, initialize: initialize }; @@ -29,6 +30,7 @@ function newTopSpace() { let sharedStatus = { currentDevTeamIndex: 0, + currentEventIndex: 0, currentUserBotIndex: 0, currentProcessIndex: 0, currentBotType: "", @@ -43,6 +45,7 @@ function newTopSpace() { thisObject.currentBot = newCurrentBot(); thisObject.currentProcess = newCurrentProcess(); thisObject.currentStartMode = newCurrentStartMode(); + thisObject.currentEvent = newCurrentEvent(); thisObject.devTeam = newDevTeam(); window.canvasApp.eventHandler.listenToEvent("Browser Resized", resize); @@ -54,8 +57,8 @@ function newTopSpace() { thisObject.currentBot.initialize(sharedStatus); thisObject.currentProcess.initialize(sharedStatus); thisObject.currentStartMode.initialize(sharedStatus); + thisObject.currentEvent.initialize(sharedStatus); thisObject.devTeam.initialize(sharedStatus); - } } @@ -91,6 +94,9 @@ function newTopSpace() { container = thisObject.currentStartMode.getContainer(point); if (container !== undefined) { return container; } + container = thisObject.currentEvent.getContainer(point); + if (container !== undefined) { return container; } + container = thisObject.login.getContainer(point); if (container !== undefined) { return container; } @@ -111,6 +117,7 @@ function newTopSpace() { thisObject.currentBot.draw(); thisObject.currentProcess.draw(); thisObject.currentStartMode.draw(); + thisObject.currentEvent.draw(); thisObject.login.draw(); } @@ -129,4 +136,4 @@ function newTopSpace() { browserCanvasContext.fill(); } -} \ No newline at end of file +} diff --git a/TopSpace/CurrentBot.js b/TopSpace/CurrentBot.js index 99ba6f380..20bdfd245 100644 --- a/TopSpace/CurrentBot.js +++ b/TopSpace/CurrentBot.js @@ -4,7 +4,7 @@ function newCurrentBot() { let thisObject = { container: undefined, draw: draw, - getContainer: getContainer, + getContainer: getContainer, initialize: initialize }; @@ -153,4 +153,4 @@ function newCurrentBot() { browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)'; browserCanvasContext.fillText(label, point.x, point.y); } -} \ No newline at end of file +} diff --git a/TopSpace/CurrentEvent.js b/TopSpace/CurrentEvent.js new file mode 100644 index 000000000..784569bd3 --- /dev/null +++ b/TopSpace/CurrentEvent.js @@ -0,0 +1,139 @@ +function newCurrentEvent() { + + let thisObject = { + container: undefined, + draw: draw, + getContainer: getContainer, + initialize: initialize + }; + + let container = newContainer(); + container.initialize(); + thisObject.container = container; + + thisObject.container.frame.width = 150; + thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT; + + resize(); + + container.isDraggeable = false; + container.isClickeable = true; + + const NOT_FOUND = "Event NOT FOUND"; + + let sharedStatus; + let storedEvents; + let label = "Event -" + + return thisObject; + + function initialize(pSharedStatus) { + + let sessionToken = window.localStorage.getItem('sessionToken'); + + if (sessionToken === null || sessionToken === "") { + /* not logged in */ + return; + } + + sharedStatus = pSharedStatus; + + storedEvents = window.localStorage.getItem('currentEvents'); + if (storedEvents === null || storedEvents === "[]" || storedEvents === "") { + window.EVENTS = ""; + window.CURRENT_EVENT_TITLE = ""; + label = NOT_FOUND; + } else { + storedEvents = JSON.parse(storedEvents) + window.EVENTS = storedEvents; + window.CURRENT_EVENT_TITLE = storedEvents[sharedStatus.currentEventIndex].title; + label = "Event - " + storedEvents[sharedStatus.currentEventIndex].title; + sharedStatus.eventHandler.raiseEvent("Event Changed"); + } + + thisObject.container.eventHandler.listenToEvent("onMouseClick", onClick); + + window.canvasApp.eventHandler.listenToEvent("Browser Resized", resize); + } + + function resize() { + + container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 2; + container.frame.position.y = viewPort.visibleArea.bottomLeft.y; + + } + + function onClick() { + + let sessionToken = window.localStorage.getItem('sessionToken'); + + if (sessionToken === null || sessionToken === "") { + /* not logged in */ + return; + } + + if (sharedStatus.currentEventIndex + 1 === window.EVENTS.length) { + + sharedStatus.currentEventIndex = 0; + window.CURRENT_EVENT_TITLE = storedEvents[sharedStatus.currentEventIndex].title; + label = "Event - " + storedEvents[sharedStatus.currentEventIndex].title; + sharedStatus.eventHandler.raiseEvent("Event Changed"); + return; + } + + if (sharedStatus.currentEventIndex + 1 < window.EVENTS.length) { + + sharedStatus.currentEventIndex++; + window.CURRENT_EVENT_TITLE = storedEvents[sharedStatus.currentEventIndex].title; + label = "Event - " + storedEvents[sharedStatus.currentEventIndex].title; + sharedStatus.eventHandler.raiseEvent("Event Changed"); + return; + } + + } + + function getContainer(point) { + + let container; + + /* First we check if this point is inside this object UI. */ + + if (thisObject.container.frame.isThisPointHere(point, true) === true) { + + return this.container; + + } else { + + /* This point does not belong to this space. */ + + return undefined; + } + + } + + function draw() { + + let sessionToken = window.localStorage.getItem('sessionToken'); + + if (sessionToken === null || sessionToken === "") { + /* not logged in */ + return; + } + + thisObject.container.frame.draw(false, false); + + let breakpointsHeight = 14; + let fontSize = 12; + + let point = { + x: thisObject.container.frame.width / 2 - label.length / 2 * fontSize / 3, + y: thisObject.container.frame.height / 2 + fontSize / 2 + breakpointsHeight + }; + + point = thisObject.container.frame.frameThisPoint(point); + + browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY; + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)'; + browserCanvasContext.fillText(label, point.x, point.y); + } +} diff --git a/TopSpace/CurrentProcess.js b/TopSpace/CurrentProcess.js index 4e7d675ba..724e9c1f7 100644 --- a/TopSpace/CurrentProcess.js +++ b/TopSpace/CurrentProcess.js @@ -4,7 +4,7 @@ function newCurrentProcess() { let thisObject = { container: undefined, draw: draw, - getContainer: getContainer, + getContainer: getContainer, initialize: initialize }; @@ -56,7 +56,7 @@ function newCurrentProcess() { function resize() { - container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 2; + container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 3; container.frame.position.y = viewPort.visibleArea.bottomLeft.y; } @@ -71,7 +71,7 @@ function newCurrentProcess() { window.CURRENT_PROCESS = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].processes[sharedStatus.currentProcessIndex].name; return; - } + } } window.CURRENT_PROCESS = NOT_FOUND; @@ -147,4 +147,4 @@ function newCurrentProcess() { browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)'; browserCanvasContext.fillText(label, point.x, point.y); } -} \ No newline at end of file +} diff --git a/TopSpace/CurrentStartMode.js b/TopSpace/CurrentStartMode.js index eaff70645..9fd08d730 100644 --- a/TopSpace/CurrentStartMode.js +++ b/TopSpace/CurrentStartMode.js @@ -37,7 +37,7 @@ function newCurrentStartMode() { function resize() { - container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 3; + container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 4; container.frame.position.y = viewPort.visibleArea.bottomLeft.y; } @@ -100,7 +100,7 @@ function newCurrentStartMode() { } if (window.CURRENT_BOT_DISPLAY_NAME === "") { return;} - + thisObject.container.frame.draw(false, false); let breakpointsHeight = 14; @@ -119,4 +119,4 @@ function newCurrentStartMode() { browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)'; browserCanvasContext.fillText(label, point.x, point.y); } -} \ No newline at end of file +} diff --git a/TopSpace/DevTeam.js b/TopSpace/DevTeam.js index 1ca8ce15a..fcedd0537 100644 --- a/TopSpace/DevTeam.js +++ b/TopSpace/DevTeam.js @@ -1,5 +1,4 @@ - -function newDevTeam() { +function newDevTeam() { let thisObject = { container: undefined, diff --git a/TopSpace/Login.js b/TopSpace/Login.js index a94fd7871..0453cc5ab 100644 --- a/TopSpace/Login.js +++ b/TopSpace/Login.js @@ -29,7 +29,7 @@ function newLogin() { function initialize(callBackFunction) { - + const accessToken = window.localStorage.getItem("access_token"); let user = window.localStorage.getItem("user"); @@ -90,7 +90,7 @@ function newLogin() { }) .then(response => { sessionToken = response.data.users_UserByAuthId.sessionToken; - + window.localStorage.setItem('loggedInUser', JSON.stringify(response.data.users_UserByAuthId)); resolve({ user: response.data.users_UserByAuthId}) }) @@ -99,7 +99,7 @@ function newLogin() { reject(error) }); }); - } + } const networkInterfaceTeams = Apollo.lib.createNetworkInterface({ uri: window.canvasApp.graphQL.masterAppApiUrl @@ -169,17 +169,67 @@ function newLogin() { }) } + // Gettings events + + + const networkInterfaceEvents = Apollo.lib.createNetworkInterface({ + 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, + }); + + const EVENTS = Apollo.gql` + query events($maxStartDate: Int, $minEndDate: Int){ + events_Events(maxStartDate: $maxStartDate, minEndDate: $minEndDate){ + id + title + } + } + ` + + const getCurrentEvents = () => { + var d = new Date(); + var nowSeconds = Math.round(d.getTime() / 1000); + var twoWeeksAgoSeconds = nowSeconds - 1209600; + return new Promise((resolve, reject) => { + apolloClientEvents.query({ + query: EVENTS, + variables: { maxStartDate: nowSeconds, minEndDate: twoWeeksAgoSeconds } + }) + .then(response => { + window.localStorage.setItem('currentEvents', JSON.stringify(response.data.events_Events)); + resolve({ currentEvents: response.data.events_Events}) + }) + .catch(error => { + console.log("apolloClient error getting current events", error) + reject (error) + }); + }) + } + // To avoid race conditions, add asynchronous fetches to array let fetchDataPromises = []; - fetchDataPromises.push(getUser(), getTeamByOwner()); + fetchDataPromises.push(getUser(), getTeamByOwner(), getCurrentEvents()); // When all asynchronous fetches resolve, authenticate user or throw error. Promise.all(fetchDataPromises).then(result => { /* this is the time to authenticate the user at AAWeb */ - authenticateUser(); + authenticateUser(); }, err => { console.error("fetchData error", err) @@ -219,7 +269,7 @@ function newLogin() { function onClick() { - + } function getContainer(point) {