From 5d470480dec9c154b4a97cdba99e164b95efbf69 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 15 Jun 2018 07:50:10 +0200 Subject: [PATCH] Process Button Implemented --- TopSpace/CurrentBot.js | 17 ++++++---- TopSpace/CurrentProcess.js | 69 ++++++++++++++++++++++++++++++++++---- TopSpace/DevTeam.js | 10 +++--- TopSpace/EndUser.js | 6 ++-- 4 files changed, 82 insertions(+), 20 deletions(-) diff --git a/TopSpace/CurrentBot.js b/TopSpace/CurrentBot.js index 584a1e772..73c05ad8d 100644 --- a/TopSpace/CurrentBot.js +++ b/TopSpace/CurrentBot.js @@ -1,14 +1,14 @@  function newCurrentBot() { - var thisObject = { + let thisObject = { container: undefined, draw: draw, - getContainer: getContainer, // returns the inner most container that holds the point received by parameter. + getContainer: getContainer, initialize: initialize }; - var container = newContainer(); + let container = newContainer(); container.initialize(); thisObject.container = container; @@ -21,6 +21,8 @@ function newCurrentBot() { container.isDraggeable = false; container.isClickeable = true; + const NOT_FOUND = "You have no Bots"; + let sharedStatus; return thisObject; @@ -30,11 +32,11 @@ function newCurrentBot() { sharedStatus = pSharedStatus; if (window.USER_PROFILE.devTeams.length === 0) { - window.CURRENT_BOT = "You have no Bots"; + window.CURRENT_BOT = NOT_FOUND; } else { if (window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length === 0) { - window.CURRENT_BOT = "You have no Bots"; + window.CURRENT_BOT = NOT_FOUND; } else { window.CURRENT_BOT = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName; } @@ -50,10 +52,11 @@ function newCurrentBot() { sharedStatus.currentUserBotIndex = 0; window.CURRENT_BOT = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName; + sharedStatus.eventHandler.raiseEvent("userBot Changed"); } else { - window.CURRENT_BOT = "You have no Bots"; + window.CURRENT_BOT = NOT_FOUND; } } @@ -64,6 +67,7 @@ function newCurrentBot() { sharedStatus.currentUserBotIndex = 0; window.CURRENT_BOT = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName; + sharedStatus.eventHandler.raiseEvent("userBot Changed"); return; } @@ -71,6 +75,7 @@ function newCurrentBot() { sharedStatus.currentUserBotIndex++; window.CURRENT_BOT = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName; + sharedStatus.eventHandler.raiseEvent("userBot Changed"); return; } } diff --git a/TopSpace/CurrentProcess.js b/TopSpace/CurrentProcess.js index 43a672c56..46dac05fc 100644 --- a/TopSpace/CurrentProcess.js +++ b/TopSpace/CurrentProcess.js @@ -1,14 +1,14 @@  function newCurrentProcess() { - var thisObject = { + let thisObject = { container: undefined, draw: draw, - getContainer: getContainer, // returns the inner most container that holds the point received by parameter. + getContainer: getContainer, initialize: initialize }; - var container = newContainer(); + let container = newContainer(); container.initialize(); thisObject.container = container; @@ -19,15 +19,70 @@ function newCurrentProcess() { container.frame.position.y = 0; container.isDraggeable = false; + container.isClickeable = true; + + const NOT_FOUND = "No Process Found"; + + let sharedStatus; return thisObject; - function initialize() { + function initialize(pSharedStatus) { - window.CURRENT_PROCESS = window.localStorage.getItem("currentProcess"); + sharedStatus = pSharedStatus; - if (window.CURRENT_PROCESS === null) { - window.CURRENT_PROCESS = ""; + if (window.USER_PROFILE.devTeams.length === 0) { + window.CURRENT_PROCESS = NOT_FOUND; + } else { + + if (window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length === 0) { + window.CURRENT_PROCESS = NOT_FOUND; + } else { + + if (window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].processes.length === 0) { + window.CURRENT_PROCESS = NOT_FOUND; + } else { + + window.CURRENT_PROCESS = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].processes[sharedStatus.currentProcessIndex].name; + + } + } + } + + thisObject.container.eventHandler.listenToEvent("onMouseClick", onClick); + sharedStatus.eventHandler.listenToEvent("userBot Changed", onUserBotChanged); + } + + function onUserBotChanged() { + + if ( window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length > 0) { + + if (window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].processes.length > 0) { + + sharedStatus.currentProcessIndex = 0; + window.CURRENT_PROCESS = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].processes[sharedStatus.currentProcessIndex].name; + + return; + } + } + + window.CURRENT_PROCESS = NOT_FOUND; + } + + function onClick() { + + if (sharedStatus.currentProcessIndex + 1 === window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length) { + + sharedStatus.currentProcessIndex = 0; + window.CURRENT_PROCESS = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].processes[sharedStatus.currentProcessIndex].name; + return; + } + + if (sharedStatus.currentProcessIndex + 1 < window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length) { + + sharedStatus.currentProcessIndex++; + window.CURRENT_PROCESS = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].processes[sharedStatus.currentProcessIndex].name; + return; } } diff --git a/TopSpace/DevTeam.js b/TopSpace/DevTeam.js index bad342f67..4a6431d3b 100644 --- a/TopSpace/DevTeam.js +++ b/TopSpace/DevTeam.js @@ -1,14 +1,14 @@  function newDevTeam() { - var thisObject = { + let thisObject = { container: undefined, draw: draw, - getContainer: getContainer, // returns the inner most container that holds the point received by parameter. + getContainer: getContainer, initialize: initialize }; - var container = newContainer(); + let container = newContainer(); container.initialize(); thisObject.container = container; @@ -21,6 +21,8 @@ function newDevTeam() { container.isDraggeable = false; container.isClickeable = true; + const NOT_FOUND = "Not a devTeam Member"; + let sharedStatus; return thisObject; @@ -30,7 +32,7 @@ function newDevTeam() { sharedStatus = pSharedStatus; if (window.USER_PROFILE.devTeams.length === 0) { - window.DEV_TEAM = "Not a devTeam Member"; + window.DEV_TEAM = NOT_FOUND; } else { window.DEV_TEAM = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].displayName; } diff --git a/TopSpace/EndUser.js b/TopSpace/EndUser.js index aae1219ee..47ff40866 100644 --- a/TopSpace/EndUser.js +++ b/TopSpace/EndUser.js @@ -1,14 +1,14 @@  function newEndUser() { - var thisObject = { + let thisObject = { container: undefined, draw: draw, - getContainer: getContainer, // returns the inner most container that holds the point received by parameter. + getContainer: getContainer, initialize: initialize }; - var container = newContainer(); + let container = newContainer(); container.initialize(); thisObject.container = container;