formating everything in atom

This commit is contained in:
Unknown committed 2019-02-28 16:45:21 +01:00
1 parent 3f8f73502b
commit 460ad13445
11 files changed
+1483 -1725

No files matched your search

+109 -124
View File
@@ -1,163 +1,148 @@
function newPlayStopButton() {
var thisObject = {
container: undefined,
setDatetime: setDatetime,
draw: draw,
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
initialize: initialize
};
function newPlayStopButton () {
var thisObject = {
container: undefined,
setDatetime: setDatetime,
draw: draw,
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
initialize: initialize
}
var container = newContainer();
container.initialize();
thisObject.container = container;
var container = newContainer()
container.initialize()
thisObject.container = container
thisObject.container.frame.width = 50;
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT;
thisObject.container.frame.width = 50
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT
resize();
resize()
container.isDraggeable = false;
container.isClickeable = true;
container.isDraggeable = false
container.isClickeable = true
let play;
let stop;
let canDraw = false;
let showing = "Play";
let image;
let play
let stop
let canDraw = false
let showing = 'Play'
let image
let datetime;
let timePeriod;
let datetime
let timePeriod
return thisObject;
return thisObject
function initialize() {
function initialize () {
play = new Image()
play = new Image();
play.onload = onImageLoad;
function onImageLoad() {
image = play;
canDraw = true;
}
play.src = window.canvasApp.urlPrefix + "Images/Icons/play.png";
stop = new Image();
stop.src = window.canvasApp.urlPrefix + "Images/Icons/pause.png";
thisObject.container.eventHandler.listenToEvent("onMouseClick", onClick);
viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged);
timePeriod = INITIAL_TIME_PERIOD;
window.canvasApp.eventHandler.listenToEvent("Browser Resized", resize);
play.onload = onImageLoad
function onImageLoad () {
image = play
canDraw = true
}
function resize() {
container.frame.position.x = viewPort.visibleArea.topLeft.x + 150 * 5;
container.frame.position.y = viewPort.visibleArea.bottomLeft.y;
play.src = window.canvasApp.urlPrefix + 'Images/Icons/play.png'
}
stop = new Image()
stop.src = window.canvasApp.urlPrefix + 'Images/Icons/pause.png'
function onClick() {
thisObject.container.eventHandler.listenToEvent('onMouseClick', onClick)
let sessionToken = window.localStorage.getItem('sessionToken');
viewPort.eventHandler.listenToEvent('Zoom Changed', onZoomChanged)
timePeriod = INITIAL_TIME_PERIOD
if (sessionToken === null || sessionToken === "") {
window.canvasApp.eventHandler.listenToEvent('Browser Resized', resize)
}
function resize () {
container.frame.position.x = viewPort.visibleArea.topLeft.x + 150 * 5
container.frame.position.y = viewPort.visibleArea.bottomLeft.y
}
function onClick () {
let sessionToken = window.localStorage.getItem('sessionToken')
if (sessionToken === null || sessionToken === '') {
/* not logged in */
return;
return
}
switch (showing) {
case 'Play': {
image = stop
showing = 'Stop'
let UI_COMMANDS = {
beginDatetime: datetime,
endDatetime: undefined,
timePeriod: timePeriod,
startMode: window.CURRENT_START_MODE,
eventHandler: thisObject.container.eventHandler
}
switch (showing) {
cloudVM.onBotPlayPressed(UI_COMMANDS)
case "Play": {
image = stop;
showing = "Stop";
break
}
case 'Stop': {
image = play
showing = 'Play'
let UI_COMMANDS = {
beginDatetime: datetime,
endDatetime: undefined,
timePeriod: timePeriod,
startMode: window.CURRENT_START_MODE,
eventHandler: thisObject.container.eventHandler
};
cloudVM.onBotStopPressed()
cloudVM.onBotPlayPressed(UI_COMMANDS);
break;
}
case "Stop": {
image = play;
showing = "Play";
cloudVM.onBotStopPressed();
break;
}
}
break
}
}
}
function onZoomChanged(event) {
function onZoomChanged (event) {
timePeriod = recalculatePeriod(event.newLevel)
}
timePeriod = recalculatePeriod(event.newLevel);
function setDatetime (pDatetime) {
datetime = new Date(pDatetime)
}
}
function setDatetime(pDatetime) {
datetime = new Date(pDatetime);
}
function getContainer(point) {
let container;
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 {
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
return this.container
} else {
/* This point does not belong to this space. */
return undefined;
}
return undefined
}
}
function draw() {
function draw () {
let sessionToken = window.localStorage.getItem('sessionToken')
let sessionToken = window.localStorage.getItem('sessionToken');
if (sessionToken === null || sessionToken === "") {
if (sessionToken === null || sessionToken === '') {
/* not logged in */
return;
}
thisObject.container.frame.draw(false, false);
let breakpointsHeight = 14;
if (canDraw === false) { return; }
let imageHeight = 20;
let imageWidth = 20;
let imagePoint = {
x: thisObject.container.frame.width / 2 - imageWidth / 2,
y: thisObject.container.frame.height / 2 - imageHeight / 2 + breakpointsHeight
};
imagePoint = thisObject.container.frame.frameThisPoint(imagePoint);
browserCanvasContext.drawImage(image, imagePoint.x, imagePoint.y, imageWidth, imageHeight);
return
}
thisObject.container.frame.draw(false, false)
let breakpointsHeight = 14
if (canDraw === false) { return }
let imageHeight = 20
let imageWidth = 20
let imagePoint = {
x: thisObject.container.frame.width / 2 - imageWidth / 2,
y: thisObject.container.frame.height / 2 - imageHeight / 2 + breakpointsHeight
}
imagePoint = thisObject.container.frame.frameThisPoint(imagePoint)
browserCanvasContext.drawImage(image, imagePoint.x, imagePoint.y, imageWidth, imageHeight)
}
}
+108 -132
View File
@@ -1,160 +1,136 @@
function newCompetitionStorage(pName) {
function newCompetitionStorage (pName) {
const MODULE_NAME = 'Competition Storage'
const INFO_LOG = false
const ERROR_LOG = true
const logger = newWebDebugLog()
logger.fileName = MODULE_NAME
const MODULE_NAME = "Competition Storage";
const INFO_LOG = false;
const ERROR_LOG = true;
const logger = newWebDebugLog();
logger.fileName = MODULE_NAME;
let thisObject = {
let thisObject = {
competitorsSequences: [],
eventHandler: undefined,
initialize: initialize
competitorsSequences: [],
eventHandler: undefined,
initialize: initialize
}
}
thisObject.eventHandler = newEventHandler();
thisObject.eventHandler = newEventHandler()
/* We name the event Handler to easy debugging. */
thisObject.eventHandler.name = "Storage-" + pName;
thisObject.eventHandler.name = 'Storage-' + pName
let fileSequences = [];
let fileSequences = []
return thisObject;
return thisObject
function initialize(pHost, pCompetition, pExchange, pMarket, callBackFunction) {
function initialize (pHost, pCompetition, pExchange, pMarket, callBackFunction) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> key = ' + pHost.codeName + '-' + pCompetition.codeName) }
try {
let dataSetsToLoad = 0
let dataSetsLoaded = 0
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
if (INFO_LOG === true) { logger.write("[INFO] initialize -> key = " + pHost.codeName + "-" + pCompetition.codeName); }
fileSequences = []
let dataSetsToLoad = 0;
let dataSetsLoaded = 0;
for (let j = 0; j < pCompetition.participants.length; j++) {
let devTeam = ecosystem.getTeam(pCompetition.participants[j].devTeam)
let bot = ecosystem.getBot(devTeam, pCompetition.participants[j].bot)
let pOperationsId = pCompetition.participants[j].pOperationsId
let product = ecosystem.getProduct(bot, 'Competition Trading History')
fileSequences = [];
if (INFO_LOG === true) { logger.write('[INFO] initialize -> key = ' + devTeam.codeName + '-' + bot.codeName + '-' + product.codeName) }
for (let j = 0; j < pCompetition.participants.length; j++) {
for (let i = 0; i < product.dataSets.length; i++) {
let thisSet = product.dataSets[i]
let devTeam = ecosystem.getTeam(pCompetition.participants[j].devTeam);
let bot = ecosystem.getBot(devTeam, pCompetition.participants[j].bot);
let pOperationsId = pCompetition.participants[j].pOperationsId;
let product = ecosystem.getProduct(bot, "Competition Trading History");
switch (thisSet.type) {
case 'File Sequence': {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> File Sequence -> key = ' + pHost.codeName + '-' + pCompetition.codeName + '-' + devTeam.codeName + '-' + bot.codeName + '-' + product.codeName) }
if (INFO_LOG === true) { logger.write("[INFO] initialize -> key = " + devTeam.codeName + "-" + bot.codeName + "-" + product.codeName); }
let fileSequence = newFileSequence()
fileSequence.initialize(devTeam, bot, product, thisSet, pExchange, pMarket, onFileSequenceReady, pOperationsId)
fileSequences.push(fileSequence)
dataSetsToLoad++
}
break
}
for (let i = 0; i < product.dataSets.length; i++) {
function onFileSequenceReady (err, pCaller) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady -> key = ' + pHost.codeName + '-' + pCompetition.codeName + '-' + devTeam.codeName + '-' + bot.codeName + '-' + product.codeName) }
let thisSet = product.dataSets[i];
switch (thisSet.type) {
case 'File Sequence': {
if (INFO_LOG === true) { logger.write("[INFO] initialize -> File Sequence -> key = " + pHost.codeName + "-" + pCompetition.codeName + "-" + devTeam.codeName + "-" + bot.codeName + "-" + product.codeName); }
let fileSequence = newFileSequence();
fileSequence.initialize(devTeam, bot, product, thisSet, pExchange, pMarket, onFileSequenceReady, pOperationsId);
fileSequences.push(fileSequence);
dataSetsToLoad++;
}
break;
}
function onFileSequenceReady(err, pCaller) {
try {
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Entering function."); }
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> key = " + pHost.codeName + "-" + pCompetition.codeName + "-" + devTeam.codeName + "-" + bot.codeName + "-" + product.codeName); }
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Received OK Response."); }
break;
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Received FAIL Response."); }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
return;
}
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Received CUSTOM FAIL Response."); }
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> err.message = " + err.message); }
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> This bot has not starting competing yet."); }
break;
}
default: {
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Received Unexpected Response."); }
callBackFunction(err);
return;
}
}
let event = {
totalValue: pCaller.getExpectedFiles(),
currentValue: pCaller.getFilesLoaded()
}
thisObject.eventHandler.raiseEvent('File Sequence Loaded', event);
if (event.currentValue === event.totalValue) {
dataSetsLoaded++;
checkInitializeComplete();
}
} catch (err) {
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onFileSequenceReady -> err = " + err); }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
}
}
function checkInitializeComplete() {
try {
if (INFO_LOG === true) { logger.write("[INFO] checkInitializeComplete -> Entering function."); }
if (INFO_LOG === true) { logger.write("[INFO] checkInitializeComplete -> key = " + pHost.codeName + "-" + pCompetition.codeName + "-" + devTeam.codeName + "-" + bot.codeName + "-" + product.codeName); }
if (dataSetsLoaded === dataSetsToLoad) {
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE);
}
} catch (err) {
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> checkInitializeComplete -> err = " + err); }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
}
}
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady -> Received OK Response.') }
break
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady -> Received FAIL Response.') }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady -> Received CUSTOM FAIL Response.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady -> err.message = ' + err.message) }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady -> This bot has not starting competing yet.') }
break
}
default: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady -> Received Unexpected Response.') }
callBackFunction(err)
return
}
}
let event = {
totalValue: pCaller.getExpectedFiles(),
currentValue: pCaller.getFilesLoaded()
}
thisObject.eventHandler.raiseEvent('File Sequence Loaded', event)
if (event.currentValue === event.totalValue) {
dataSetsLoaded++
checkInitializeComplete()
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onFileSequenceReady -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
thisObject.competitorsSequences.push(fileSequences);
function checkInitializeComplete () {
try {
if (INFO_LOG === true) { logger.write('[INFO] checkInitializeComplete -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] checkInitializeComplete -> key = ' + pHost.codeName + '-' + pCompetition.codeName + '-' + devTeam.codeName + '-' + bot.codeName + '-' + product.codeName) }
if (pCompetition.participants.length === 0) { //If there are no competitions, respond OK
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE);
if (dataSetsLoaded === dataSetsToLoad) {
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE)
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> checkInitializeComplete -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
} catch (err) {
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
}
}
}
}
thisObject.competitorsSequences.push(fileSequences)
if (pCompetition.participants.length === 0) { // If there are no competitions, respond OK
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE)
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
}
+192 -235
View File
@@ -1,11 +1,10 @@
function newFileCloud() {
const MODULE_NAME = "File Cloud";
const INFO_LOG = false;
const ERROR_LOG = true;
const logger = newWebDebugLog();
logger.fileName = MODULE_NAME;
function newFileCloud () {
const MODULE_NAME = 'File Cloud'
const INFO_LOG = false
const ERROR_LOG = true
const logger = newWebDebugLog()
logger.fileName = MODULE_NAME
/*
@@ -13,249 +12,207 @@ function newFileCloud() {
*/
var thisObject = {
getFile: getFile,
initialize: initialize
};
var thisObject = {
getFile: getFile,
initialize: initialize
}
let blobService;
let blobService
return thisObject;
return thisObject
function initialize(pBot) {
function initialize (pBot) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> pBot = ' + pBot.codeName) }
try {
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
if (INFO_LOG === true) { logger.write("[INFO] initialize -> pBot = " + pBot.codeName); }
blobService = AzureStorage.Blob.createBlobServiceWithSas(pBot.storage.fileUri, pBot.storage.sas);
} catch (err) {
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); }
//callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); TODO> Handle this callback.
}
blobService = AzureStorage.Blob.createBlobServiceWithSas(pBot.storage.fileUri, pBot.storage.sas)
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err) }
// callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); TODO> Handle this callback.
}
}
function getFile(pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction, pOperationsId) {
function getFile (pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction, pOperationsId) {
try {
if (INFO_LOG === true) { logger.write('[INFO] getFile -> Entering function.') }
const MAX_RETRIES = 3
if (pOperationsId !== undefined) {
getFileRecursively(0, pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction, pOperationsId)
} else {
getFileRecursively(0, pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction)
}
function getFileRecursively (pRetryCounter, pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction, pOperationsId) {
try {
if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pSet.filePath + '-' + pSet.fileName) }
if (INFO_LOG === true) { logger.write("[INFO] getFile -> Entering function."); }
let fileName
let filePath
const MAX_RETRIES = 3;
if (pOperationsId !== undefined ) {
getFileRecursively(0, pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction, pOperationsId)
if (pDataRange === undefined) {
fileName = pSet.fileName
filePath = pSet.filePath
} else {
if (pSet.dataRange !== undefined) {
fileName = pSet.dataRange.fileName
filePath = pSet.dataRange.filePath
} else {
getFileRecursively(0, pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction)
let customErr = {
result: GLOBAL.CUSTOM_FAIL_RESPONSE.result,
message: 'Missing Configuration.'
}
if (ERROR_LOG === true) { logger.write('[WARN] getFile -> getFileRecursively -> onFileReceived -> customErr.message = ' + customErr.message) }
if (ERROR_LOG === true) { logger.write('[WARN] getFile -> getFileRecursively -> onFileReceived -> Data Range configuration could not be found. ') }
callBackFunction(customErr)
return
}
function getFileRecursively(pRetryCounter, pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction, pOperationsId) {
try {
if (INFO_LOG === true) { logger.write("[INFO] getFile -> getFileRecursively -> Entering function."); }
if (INFO_LOG === true) { logger.write("[INFO] getFile -> getFileRecursively -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pSet.filePath + "-" + pSet.fileName); }
let fileName;
let filePath;
if (pDataRange === undefined) {
fileName = pSet.fileName;
filePath = pSet.filePath;
} else {
if (pSet.dataRange !== undefined) {
fileName = pSet.dataRange.fileName;
filePath = pSet.dataRange.filePath;
} else {
let customErr = {
result: GLOBAL.CUSTOM_FAIL_RESPONSE.result,
message: "Missing Configuration."
};
if (ERROR_LOG === true) { logger.write("[WARN] getFile -> getFileRecursively -> onFileReceived -> customErr.message = " + customErr.message); }
if (ERROR_LOG === true) { logger.write("[WARN] getFile -> getFileRecursively -> onFileReceived -> Data Range configuration could not be found. "); }
callBackFunction(customErr);
return;
}
}
if (fileName === undefined) {
logger.write("[ERROR] getFile -> getFileRecursively -> Inconsistant data. Check the following: ");
logger.write("[ERROR] getFile -> getFileRecursively -> pDevTeam = " + JSON.stringify(pDevTeam));
logger.write("[ERROR] getFile -> getFileRecursively -> pBot = " + JSON.stringify(pBot));
logger.write("[ERROR] getFile -> getFileRecursively -> pSet = " + JSON.stringify(pSet));
logger.write("[ERROR] getFile -> getFileRecursively -> pExchange = " + JSON.stringify(pExchange));
logger.write("[ERROR] getFile -> getFileRecursively -> pMarket = " + JSON.stringify(pMarket));
logger.write("[ERROR] getFile -> getFileRecursively -> pPeriodName = " + JSON.stringify(pPeriodName));
throw ("Inconsistant data received.");
}
if (pMarket !== undefined) {
fileName = fileName.replace("@AssetA", pMarket.assetA);
fileName = fileName.replace("@AssetB", pMarket.assetB);
}
if (pDevTeam !== undefined) {
filePath = filePath.replace("@DevTeam", pDevTeam.codeName);
}
if (pBot !== undefined) {
if (pOperationsId !== undefined ) {
filePath = filePath.replace("@Bot", pBot.codeName + "-" + pOperationsId);
} else {
filePath = filePath.replace("@Bot", pBot.codeName);
}
}
if (pExchange !== undefined) {
filePath = filePath.replace("@Exchange", pExchange.name);
}
filePath = filePath.replace("@Period", pPeriodName);
if (pDatetime !== undefined) {
filePath = filePath.replace("@Year", pDatetime.getUTCFullYear());
filePath = filePath.replace("@Month", pad(pDatetime.getUTCMonth() + 1, 2));
filePath = filePath.replace("@Day", pad(pDatetime.getUTCDate(), 2));
filePath = filePath.replace("@Hour", pad(pDatetime.getUTCHours(), 2));
filePath = filePath.replace("@Minute", pad(pDatetime.getUTCMinutes(), 2));
}
if (pSequence !== undefined) {
fileName = fileName.replace("@Sequence", pSequence);
}
if (INFO_LOG === true) { logger.write("[INFO] getFile -> getFileRecursively -> filePath = " + filePath); }
if (INFO_LOG === true) { logger.write("[INFO] getFile -> getFileRecursively -> fileName = " + fileName); }
let containerName;
containerName = pDevTeam.codeName.toLowerCase();
blobService.getBlobToText(containerName, filePath + "/" + fileName, onFileReceived);
function onFileReceived(err, text, response) {
try {
if (INFO_LOG === true) { logger.write("[INFO] getFile -> getFileRecursively -> onFileReceived -> Entering function."); }
if (INFO_LOG === true) { logger.write("[INFO] getFile -> getFileRecursively -> onFileReceived -> filePath = " + filePath); }
if (INFO_LOG === true) { logger.write("[INFO] getFile -> getFileRecursively -> onFileReceived -> fileName = " + fileName); }
let data;
if (err) {
if (err.code === "BlobNotFound" | err.code === "FileNotFound" | err.code === "ParentNotFound") {
let customErr = {
result: GLOBAL.CUSTOM_FAIL_RESPONSE.result,
message: "File does not exist."
};
if (INFO_LOG === true) { logger.write("[WARN] getFile -> getFileRecursively -> onFileReceived -> customErr.message = " + customErr.message); }
callBackFunction(customErr);
return;
}
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> containerName = " + containerName); }
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> filePath = " + filePath); }
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> fileName = " + fileName); }
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> Unexpected Error Ocurred."); }
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> err = " + err); }
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> text = " + text); }
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> response = " + response); }
if (err.message === "XHR error") {
if (pRetryCounter < MAX_RETRIES) {
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> Retrying to get this file. "); }
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> MAX_RETRIES = " + MAX_RETRIES); }
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> pRetryCounter = " + pRetryCounter); }
getFileRecursively(pRetryCounter + 1, pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction)
return;
} else {
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> Could not get this file from storage. "); }
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> MAX_RETRIES = " + MAX_RETRIES); }
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> pRetryCounter = " + pRetryCounter); }
}
}
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
return;
} else {
try {
data = JSON.parse(text);
if (INFO_LOG === true) { logger.write("[INFO] getFile -> getFileRecursively -> onFileReceived -> Data received is valid JSON."); }
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, data);
return;
} catch (err) {
if (INFO_LOG === true) { logger.write("[WARN] getFile -> getFileRecursively -> onFileReceived -> err = " + err); }
let customErr = {
result: GLOBAL.CUSTOM_OK_RESPONSE.result,
message: "Data not in JSON Format."
};
if (INFO_LOG === true) { logger.write("[WARN] getFile -> getFileRecursively -> onFileReceived -> customErr.message = " + customErr.message); }
callBackFunction(customErr, text);
return;
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> err = " + err); }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> err = " + err); }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
}
if (fileName === undefined) {
logger.write('[ERROR] getFile -> getFileRecursively -> Inconsistant data. Check the following: ')
logger.write('[ERROR] getFile -> getFileRecursively -> pDevTeam = ' + JSON.stringify(pDevTeam))
logger.write('[ERROR] getFile -> getFileRecursively -> pBot = ' + JSON.stringify(pBot))
logger.write('[ERROR] getFile -> getFileRecursively -> pSet = ' + JSON.stringify(pSet))
logger.write('[ERROR] getFile -> getFileRecursively -> pExchange = ' + JSON.stringify(pExchange))
logger.write('[ERROR] getFile -> getFileRecursively -> pMarket = ' + JSON.stringify(pMarket))
logger.write('[ERROR] getFile -> getFileRecursively -> pPeriodName = ' + JSON.stringify(pPeriodName))
throw ('Inconsistant data received.')
}
if (pMarket !== undefined) {
fileName = fileName.replace('@AssetA', pMarket.assetA)
fileName = fileName.replace('@AssetB', pMarket.assetB)
}
if (pDevTeam !== undefined) {
filePath = filePath.replace('@DevTeam', pDevTeam.codeName)
}
if (pBot !== undefined) {
if (pOperationsId !== undefined) {
filePath = filePath.replace('@Bot', pBot.codeName + '-' + pOperationsId)
} else {
filePath = filePath.replace('@Bot', pBot.codeName)
}
}
if (pExchange !== undefined) {
filePath = filePath.replace('@Exchange', pExchange.name)
}
filePath = filePath.replace('@Period', pPeriodName)
if (pDatetime !== undefined) {
filePath = filePath.replace('@Year', pDatetime.getUTCFullYear())
filePath = filePath.replace('@Month', pad(pDatetime.getUTCMonth() + 1, 2))
filePath = filePath.replace('@Day', pad(pDatetime.getUTCDate(), 2))
filePath = filePath.replace('@Hour', pad(pDatetime.getUTCHours(), 2))
filePath = filePath.replace('@Minute', pad(pDatetime.getUTCMinutes(), 2))
}
if (pSequence !== undefined) {
fileName = fileName.replace('@Sequence', pSequence)
}
if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> filePath = ' + filePath) }
if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> fileName = ' + fileName) }
let containerName
containerName = pDevTeam.codeName.toLowerCase()
blobService.getBlobToText(containerName, filePath + '/' + fileName, onFileReceived)
function onFileReceived (err, text, response) {
try {
if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> onFileReceived -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> onFileReceived -> filePath = ' + filePath) }
if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> onFileReceived -> fileName = ' + fileName) }
let data
if (err) {
if (err.code === 'BlobNotFound' | err.code === 'FileNotFound' | err.code === 'ParentNotFound') {
let customErr = {
result: GLOBAL.CUSTOM_FAIL_RESPONSE.result,
message: 'File does not exist.'
}
if (INFO_LOG === true) { logger.write('[WARN] getFile -> getFileRecursively -> onFileReceived -> customErr.message = ' + customErr.message) }
callBackFunction(customErr)
return
}
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> containerName = ' + containerName) }
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> filePath = ' + filePath) }
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> fileName = ' + fileName) }
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> Unexpected Error Ocurred.') }
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> err = ' + err) }
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> text = ' + text) }
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> response = ' + response) }
if (err.message === 'XHR error') {
if (pRetryCounter < MAX_RETRIES) {
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> Retrying to get this file. ') }
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> MAX_RETRIES = ' + MAX_RETRIES) }
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> pRetryCounter = ' + pRetryCounter) }
getFileRecursively(pRetryCounter + 1, pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction)
return
} else {
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> Could not get this file from storage. ') }
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> MAX_RETRIES = ' + MAX_RETRIES) }
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> pRetryCounter = ' + pRetryCounter) }
}
}
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
} else {
try {
data = JSON.parse(text)
if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> onFileReceived -> Data received is valid JSON.') }
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, data)
return
} catch (err) {
if (INFO_LOG === true) { logger.write('[WARN] getFile -> getFileRecursively -> onFileReceived -> err = ' + err) }
let customErr = {
result: GLOBAL.CUSTOM_OK_RESPONSE.result,
message: 'Data not in JSON Format.'
}
if (INFO_LOG === true) { logger.write('[WARN] getFile -> getFileRecursively -> onFileReceived -> customErr.message = ' + customErr.message) }
callBackFunction(customErr, text)
return
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> err = " + err); }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
}
+280 -332
View File
@@ -1,227 +1,200 @@
function newFileSequence() {
const MODULE_NAME = "File Sequence";
const INFO_LOG = false;
const ERROR_LOG = true;
const logger = newWebDebugLog();
logger.fileName = MODULE_NAME;
function newFileSequence () {
const MODULE_NAME = 'File Sequence'
const INFO_LOG = false
const ERROR_LOG = true
const logger = newWebDebugLog()
logger.fileName = MODULE_NAME
let thisObject = {
eventHandler: undefined,
getFile: getFile,
getExpectedFiles: getExpectedFiles,
getFilesLoaded: getFilesLoaded,
initialize: initialize,
finalize: finalize
let thisObject = {
eventHandler: undefined,
getFile: getFile,
getExpectedFiles: getExpectedFiles,
getFilesLoaded: getFilesLoaded,
initialize: initialize,
finalize: finalize
}
let filesLoaded = 0
let fileCloud
let files = new Map()
let maxSequence = -1 // This is replaced by the content of the sequence file, which contains an index that starts on zero. In the case that the sequence file is not found the default value is -1 so when you add 1 it gives you the amount of files in the sequence, zero.
let market
let devTeam
let bot
let thisSet
let product
thisObject.eventHandler = newEventHandler()
let intervalHandle
return thisObject
function finalize () {
try {
if (INFO_LOG === true) { logger.write('[INFO] finalize -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] finalize -> devTeam = ' + devTeam.codeName) }
if (INFO_LOG === true) { logger.write('[INFO] finalize -> bot = ' + bot.codeName) }
if (INFO_LOG === true) { logger.write('[INFO] finalize -> thisSet = ' + thisSet.codeName) }
if (INFO_LOG === true) { logger.write('[INFO] finalize -> intervalHandle = ' + intervalHandle) }
clearInterval(intervalHandle)
filesLoaded = undefined
fileCloud = undefined
files = undefined
maxSequence = undefined
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err) }
}
}
let filesLoaded = 0;
let fileCloud;
let files = new Map;
let maxSequence = -1; // This is replaced by the content of the sequence file, which contains an index that starts on zero. In the case that the sequence file is not found the default value is -1 so when you add 1 it gives you the amount of files in the sequence, zero.
let market;
let devTeam;
let bot;
let thisSet;
let product;
function initialize (pDevTeam, pBot, pProduct, pSet, pExchange, pMarket, callBackFunction, pOperationsId) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pProduct.codeName) }
thisObject.eventHandler = newEventHandler();
exchange = ecosystem.getExchange(pProduct, pExchange)
let intervalHandle;
if (exchange === undefined) {
throw 'Exchange not supoorted by this pProduct of the ecosystem! - pDevTeam.codeName = ' + pDevTeam.codeName + ', pBot.codeName = ' + pBot.codeName + ', pProduct.codeName = ' + pProduct.codeName + ', pExchange = ' + pExchange
}
return thisObject;
intervalHandle = setInterval(updateFiles, _1_MINUTE_IN_MILISECONDS)
function finalize() {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> intervalHandle = ' + intervalHandle) }
try {
market = pMarket
devTeam = pDevTeam
bot = pBot
thisSet = pSet
product = pProduct
if (INFO_LOG === true) { logger.write("[INFO] finalize -> Entering function."); }
if (INFO_LOG === true) { logger.write("[INFO] finalize -> devTeam = " + devTeam.codeName); }
if (INFO_LOG === true) { logger.write("[INFO] finalize -> bot = " + bot.codeName); }
if (INFO_LOG === true) { logger.write("[INFO] finalize -> thisSet = " + thisSet.codeName); }
if (INFO_LOG === true) { logger.write("[INFO] finalize -> intervalHandle = " + intervalHandle); }
clearInterval(intervalHandle);
filesLoaded = undefined;
fileCloud = undefined;
files = undefined;
maxSequence = undefined;
} catch (err) {
if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err); }
}
}
function initialize(pDevTeam, pBot, pProduct, pSet, pExchange, pMarket, callBackFunction, pOperationsId) {
try {
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
if (INFO_LOG === true) { logger.write("[INFO] initialize -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); }
exchange = ecosystem.getExchange(pProduct, pExchange);
if (exchange === undefined) {
throw "Exchange not supoorted by this pProduct of the ecosystem! - pDevTeam.codeName = " + pDevTeam.codeName + ", pBot.codeName = " + pBot.codeName + ", pProduct.codeName = " + pProduct.codeName + ", pExchange = " + pExchange;
}
intervalHandle = setInterval(updateFiles, _1_MINUTE_IN_MILISECONDS);
if (INFO_LOG === true) { logger.write("[INFO] initialize -> intervalHandle = " + intervalHandle); }
market = pMarket;
devTeam = pDevTeam;
bot = pBot;
thisSet = pSet;
product = pProduct;
fileCloud = newFileCloud();
fileCloud.initialize(bot);
fileCloud = newFileCloud()
fileCloud.initialize(bot)
/* First we will get the sequence max number */
if (pOperationsId !== undefined ) {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, "Sequence", undefined, onSequenceFileReceived, pOperationsId);
} else {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, "Sequence", undefined, onSequenceFileReceived);
if (pOperationsId !== undefined) {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, 'Sequence', undefined, onSequenceFileReceived, pOperationsId)
} else {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, 'Sequence', undefined, onSequenceFileReceived)
}
function onSequenceFileReceived (err, file) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> key = ' + devTeam.codeName + '-' + bot.codeName + '-' + product.codeName) }
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> Received OK Response.') }
break
}
function onSequenceFileReceived(err, file) {
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> Received FAIL Response.') }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
try {
case GLOBAL.CUSTOM_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> Received CUSTOM OK Response.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> err.message = ' + err.message) }
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Entering function."); }
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> key = " + devTeam.codeName + "-" + bot.codeName + "-" + product.codeName); }
callBackFunction(err)
return
}
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> Received CUSTOM FAIL Response.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> err.message = ' + err.message) }
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received OK Response."); }
break;
}
callBackFunction(err, thisObject)
return
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
default: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> Received Unexpected Response.') }
callBackFunction(err)
return
}
}
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received FAIL Response."); }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
return;
}
maxSequence = Number(file)
case GLOBAL.CUSTOM_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received CUSTOM OK Response."); }
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> err.message = " + err.message); }
callBackFunction(err);
return;
}
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received CUSTOM FAIL Response."); }
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> err.message = " + err.message); }
callBackFunction(err, thisObject);
return;
}
default: {
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received Unexpected Response."); }
callBackFunction(err);
return;
}
}
maxSequence = Number(file);
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> maxSequence = " + maxSequence); }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> maxSequence = ' + maxSequence) }
/* Now we will get the sequence of files */
for (let i = 0; i <= maxSequence; i++) {
if (pOperationsId !== undefined ) {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, i, undefined, onFileReceived, pOperationsId);
} else {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, i, undefined, onFileReceived);
}
function onFileReceived(err, file) {
try {
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received OK Response."); }
break;
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received FAIL Response."); }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
return;
}
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received CUSTOM FAIL Response."); }
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> err.message = " + err.message); }
callBackFunction(err);
return;
}
default: {
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received Unexpected Response."); }
callBackFunction(err);
return;
}
}
files.set(i, file);
filesLoaded++;
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, thisObject); // Note that the callback is called for every file loaded.
} catch (err) {
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onSequenceFileReceived -> onFileReceived -> err = " + err); }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
}
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onSequenceFileReceived -> err = " + err); }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
}
for (let i = 0; i <= maxSequence; i++) {
if (pOperationsId !== undefined) {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, i, undefined, onFileReceived, pOperationsId)
} else {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, i, undefined, onFileReceived)
}
function onFileReceived (err, file) {
try {
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received OK Response.') }
break
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received FAIL Response.') }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
return
}
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received CUSTOM FAIL Response.') }
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> err.message = ' + err.message) }
callBackFunction(err)
return
}
default: {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received Unexpected Response.') }
callBackFunction(err)
return
}
}
files.set(i, file)
filesLoaded++
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, thisObject) // Note that the callback is called for every file loaded.
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onSequenceFileReceived -> onFileReceived -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onSequenceFileReceived -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err) }
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
}
}
function updateFiles() {
function updateFiles () {
try {
let updateFiles = 0
try {
let updateFiles = 0;
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> Entering function."); }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> Entering function.') }
/*
@@ -233,170 +206,145 @@ function newFileSequence() {
*/
let currentMaxSequence = maxSequence;
let currentMaxSequence = maxSequence
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> currentMaxSequence = " + currentMaxSequence); }
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> intervalHandle = " + intervalHandle); }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> currentMaxSequence = ' + currentMaxSequence) }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> intervalHandle = ' + intervalHandle) }
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> devTeam = " + devTeam.codeName); }
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> bot = " + bot.codeName); }
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> thisSet = " + thisSet.codeName); }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> devTeam = ' + devTeam.codeName) }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> bot = ' + bot.codeName) }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> thisSet = ' + thisSet.codeName) }
if (pOperationsId !== undefined) {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, 'Sequence', undefined, onSequenceFileReceived, pOperationsId)
} else {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, 'Sequence', undefined, onSequenceFileReceived)
}
if (pOperationsId !== undefined ) {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, "Sequence", undefined, onSequenceFileReceived, pOperationsId);
} else {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, "Sequence", undefined, onSequenceFileReceived);
function onSequenceFileReceived (err, file) {
try {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> key = ' + devTeam.codeName + '-' + bot.codeName + '-' + product.codeName) }
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> Received OK Response.') }
break
}
function onSequenceFileReceived(err, file) {
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> Received FAIL Response.') }
return
}
try {
case GLOBAL.CUSTOM_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> Received CUSTOM OK Response.') }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> err.message = ' + err.message) }
return
}
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> Entering function."); }
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> key = " + devTeam.codeName + "-" + bot.codeName + "-" + product.codeName); }
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> Received CUSTOM FAIL Response.') }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> err.message = ' + err.message) }
return
}
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
default: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> Received Unexpected Response.') }
return
}
}
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> Received OK Response."); }
break;
}
maxSequence = Number(file)
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> Received FAIL Response."); }
return;
}
case GLOBAL.CUSTOM_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> Received CUSTOM OK Response."); }
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> err.message = " + err.message); }
return;
}
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> Received CUSTOM FAIL Response."); }
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> err.message = " + err.message); }
return;
}
default: {
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> Received Unexpected Response."); }
return;
}
}
maxSequence = Number(file);
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> maxSequence = " + maxSequence); }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> maxSequence = ' + maxSequence) }
/* Now we will get the sequence of files, but in this case only from the currentMaxSequence and above. */
for (let i = currentMaxSequence; i <= maxSequence; i++) {
for (let i = currentMaxSequence; i <= maxSequence; i++) {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> i = ' + i) }
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> i = " + i); }
if (pOperationsId !== undefined ) {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, i, undefined, onFileReceived, pOperationsId);
} else {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, i, undefined, onFileReceived);
}
function onFileReceived(err, file) {
try {
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> Received OK Response."); }
break;
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> Received FAIL Response."); }
return;
}
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> Received CUSTOM FAIL Response."); }
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> err.message = " + err.message); }
return;
}
default: {
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> Received Unexpected Response."); }
return;
}
}
files.set(i, file);
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> File Updated."); }
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> i = " + i); }
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> file.length = " + file.length); }
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> filesLoaded = " + filesLoaded); }
if (i !== currentMaxSequence) {
filesLoaded++;
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> filesLoaded = " + filesLoaded); }
}
if (filesLoaded === maxSequence + 1) {
thisObject.eventHandler.raiseEvent("Files Updated", undefined);
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> Files Updated event Raised."); }
}
} catch (err) {
if (ERROR_LOG === true) { logger.write("[ERROR] updateFiles -> onSequenceFileReceived -> onFileReceived -> err = " + err); }
}
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write("[ERROR] updateFiles -> onSequenceFileReceived -> err = " + err); }
}
if (pOperationsId !== undefined) {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, i, undefined, onFileReceived, pOperationsId)
} else {
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, i, undefined, onFileReceived)
}
function onFileReceived (err, file) {
try {
switch (err.result) {
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> Received OK Response.') }
break
}
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> Received FAIL Response.') }
return
}
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> Received CUSTOM FAIL Response.') }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> err.message = ' + err.message) }
return
}
default: {
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> Received Unexpected Response.') }
return
}
}
files.set(i, file)
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> File Updated.') }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> i = ' + i) }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> file.length = ' + file.length) }
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> filesLoaded = ' + filesLoaded) }
if (i !== currentMaxSequence) {
filesLoaded++
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> filesLoaded = ' + filesLoaded) }
}
if (filesLoaded === maxSequence + 1) {
thisObject.eventHandler.raiseEvent('Files Updated', undefined)
if (INFO_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> Files Updated event Raised.') }
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] updateFiles -> onSequenceFileReceived -> onFileReceived -> err = ' + err) }
}
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write("[ERROR] updateFiles -> err = " + err); }
if (ERROR_LOG === true) { logger.write('[ERROR] updateFiles -> onSequenceFileReceived -> err = ' + err) }
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] updateFiles -> err = ' + err) }
}
}
function getFile(pSequence) {
function getFile (pSequence) {
if (INFO_LOG === true) { logger.write('[INFO] getFile -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] getFile -> pSequence = ' + pSequence) }
if (INFO_LOG === true) { logger.write("[INFO] getFile -> Entering function."); }
if (INFO_LOG === true) { logger.write("[INFO] getFile -> pSequence = " + pSequence); }
return files.get(pSequence)
}
return files.get(pSequence);
function getExpectedFiles () {
if (INFO_LOG === true) { logger.write('[INFO] getExpectedFiles -> Entering function.') }
}
return maxSequence + 1
}
function getExpectedFiles() {
if (INFO_LOG === true) { logger.write("[INFO] getExpectedFiles -> Entering function."); }
return maxSequence + 1;
}
function getFilesLoaded() {
if (INFO_LOG === true) { logger.write("[INFO] getFilesLoaded -> Entering function."); }
return filesLoaded;
}
function getFilesLoaded () {
if (INFO_LOG === true) { logger.write('[INFO] getFilesLoaded -> Entering function.') }
return filesLoaded
}
}
+95 -106
View File
@@ -1,139 +1,128 @@
function newTopSpace() {
var thisObject = {
container: undefined,
draw: draw,
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
companyLogo: undefined,
endUser: undefined,
devTeam: undefined,
currentBot: undefined,
currentProcess: undefined,
currentStartMode: undefined,
currentEvent: undefined,
login: undefined,
initialize: initialize
};
function newTopSpace () {
var thisObject = {
container: undefined,
draw: draw,
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
companyLogo: undefined,
endUser: undefined,
devTeam: undefined,
currentBot: undefined,
currentProcess: undefined,
currentStartMode: undefined,
currentEvent: undefined,
login: undefined,
initialize: initialize
}
var container = newContainer();
container.initialize();
thisObject.container = container;
var container = newContainer()
container.initialize()
thisObject.container = container
resize();
resize()
container.isDraggeable = false;
container.isDraggeable = false
return thisObject;
return thisObject
function initialize() {
let sharedStatus = {
currentDevTeamIndex: 0,
currentEventIndex: 0,
currentUserBotIndex: 0,
currentProcessIndex: 0,
currentBotType: "",
eventHandler: newEventHandler()
};
thisObject.login = newLogin();
thisObject.login.initialize(sharedStatus, onLoginInitialized);
thisObject.companyLogo = newCompanyLogo();
thisObject.endUser = newEndUser();
thisObject.currentBot = newCurrentBot();
thisObject.currentProcess = newCurrentProcess();
thisObject.currentStartMode = newCurrentStartMode();
thisObject.currentEvent = newCurrentEvent();
thisObject.devTeam = newDevTeam();
window.canvasApp.eventHandler.listenToEvent("Browser Resized", resize);
function onLoginInitialized() {
thisObject.companyLogo.initialize();
thisObject.endUser.initialize();
thisObject.currentBot.initialize(sharedStatus);
thisObject.currentProcess.initialize(sharedStatus);
thisObject.currentStartMode.initialize(sharedStatus);
thisObject.currentEvent.initialize(sharedStatus);
thisObject.devTeam.initialize(sharedStatus);
}
function initialize () {
let sharedStatus = {
currentDevTeamIndex: 0,
currentEventIndex: 0,
currentUserBotIndex: 0,
currentProcessIndex: 0,
currentBotType: '',
eventHandler: newEventHandler()
}
function resize() {
thisObject.login = newLogin()
thisObject.login.initialize(sharedStatus, onLoginInitialized)
thisObject.container.frame.width = browserCanvas.width;
thisObject.container.frame.height = TOP_SPACE_HEIGHT;
thisObject.companyLogo = newCompanyLogo()
thisObject.endUser = newEndUser()
thisObject.currentBot = newCurrentBot()
thisObject.currentProcess = newCurrentProcess()
thisObject.currentStartMode = newCurrentStartMode()
thisObject.currentEvent = newCurrentEvent()
thisObject.devTeam = newDevTeam()
container.frame.position.x = 0;
container.frame.position.y = viewPort.visibleArea.bottomLeft.y;
window.canvasApp.eventHandler.listenToEvent('Browser Resized', resize)
function onLoginInitialized () {
thisObject.companyLogo.initialize()
thisObject.endUser.initialize()
thisObject.currentBot.initialize(sharedStatus)
thisObject.currentProcess.initialize(sharedStatus)
thisObject.currentStartMode.initialize(sharedStatus)
thisObject.currentEvent.initialize(sharedStatus)
thisObject.devTeam.initialize(sharedStatus)
}
}
function getContainer(point) {
function resize () {
thisObject.container.frame.width = browserCanvas.width
thisObject.container.frame.height = TOP_SPACE_HEIGHT
let container;
container.frame.position.x = 0
container.frame.position.y = viewPort.visibleArea.bottomLeft.y
}
container = thisObject.companyLogo.getContainer(point);
if (container !== undefined) { return container; }
function getContainer (point) {
let container
container = thisObject.endUser.getContainer(point);
if (container !== undefined) { return container; }
container = thisObject.companyLogo.getContainer(point)
if (container !== undefined) { return container }
container = thisObject.devTeam.getContainer(point);
if (container !== undefined) { return container; }
container = thisObject.endUser.getContainer(point)
if (container !== undefined) { return container }
container = thisObject.currentBot.getContainer(point);
if (container !== undefined) { return container; }
container = thisObject.devTeam.getContainer(point)
if (container !== undefined) { return container }
container = thisObject.currentProcess.getContainer(point);
if (container !== undefined) { return container; }
container = thisObject.currentBot.getContainer(point)
if (container !== undefined) { return container }
container = thisObject.currentStartMode.getContainer(point);
if (container !== undefined) { return container; }
container = thisObject.currentProcess.getContainer(point)
if (container !== undefined) { return container }
container = thisObject.currentEvent.getContainer(point);
if (container !== undefined) { return container; }
container = thisObject.currentStartMode.getContainer(point)
if (container !== undefined) { return container }
container = thisObject.login.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 }
/* The point does not belong to any inner container, so we return the current container. */
return thisObject.container;
return thisObject.container
}
}
function draw () {
thisObject.container.frame.draw(false, false)
function draw() {
drawBackground()
thisObject.companyLogo.draw()
thisObject.endUser.draw()
thisObject.devTeam.draw()
thisObject.currentBot.draw()
thisObject.currentProcess.draw()
thisObject.currentStartMode.draw()
thisObject.currentEvent.draw()
thisObject.login.draw()
}
thisObject.container.frame.draw(false, false);
function drawBackground () {
let opacity = 1
drawBackground();
thisObject.companyLogo.draw();
thisObject.endUser.draw();
thisObject.devTeam.draw();
thisObject.currentBot.draw();
thisObject.currentProcess.draw();
thisObject.currentStartMode.draw();
thisObject.currentEvent.draw();
thisObject.login.draw();
browserCanvasContext.beginPath()
}
browserCanvasContext.rect(0, 0, thisObject.container.frame.width, thisObject.container.frame.height)
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ')'
function drawBackground() {
browserCanvasContext.closePath()
let opacity = 1;
browserCanvasContext.beginPath();
browserCanvasContext.rect(0, 0, thisObject.container.frame.width, thisObject.container.frame.height);
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ')';
browserCanvasContext.closePath();
browserCanvasContext.fill();
}
browserCanvasContext.fill()
}
}
+105 -124
View File
@@ -1,156 +1,137 @@
function newCurrentBot() {
let thisObject = {
container: undefined,
draw: draw,
getContainer: getContainer,
initialize: initialize
};
function newCurrentBot () {
let thisObject = {
container: undefined,
draw: draw,
getContainer: getContainer,
initialize: initialize
}
let container = newContainer();
container.initialize();
thisObject.container = container;
let container = newContainer()
container.initialize()
thisObject.container = container
thisObject.container.frame.width = 150;
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT;
thisObject.container.frame.width = 150
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT
resize();
resize()
container.isDraggeable = false;
container.isClickeable = true;
container.isDraggeable = false
container.isClickeable = true
const NOT_FOUND = "";
const NOT_FOUND = ''
let sharedStatus;
let sharedStatus
return thisObject;
return thisObject
function initialize(pSharedStatus) {
function initialize (pSharedStatus) {
sharedStatus = pSharedStatus
sharedStatus = pSharedStatus;
if (window.USER_PROFILE.devTeams.length === 0) {
window.CURRENT_BOT_DISPLAY_NAME = NOT_FOUND;
} else {
if (window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length === 0) {
window.CURRENT_BOT_DISPLAY_NAME = NOT_FOUND;
window.CURRENT_BOT_REPO = "NO REPO";
window.CURRENT_BOT_CODE_NAME = "";
} else {
window.CURRENT_BOT_DISPLAY_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName;
window.CURRENT_BOT_REPO = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].repo;
window.CURRENT_BOT_CODE_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].codeName;
}
}
thisObject.container.eventHandler.listenToEvent("onMouseClick", onClick);
sharedStatus.eventHandler.listenToEvent("devTeam Changed", onDevTeamChanged);
window.canvasApp.eventHandler.listenToEvent("Browser Resized", resize);
if (window.USER_PROFILE.devTeams.length === 0) {
window.CURRENT_BOT_DISPLAY_NAME = NOT_FOUND
} else {
if (window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length === 0) {
window.CURRENT_BOT_DISPLAY_NAME = NOT_FOUND
window.CURRENT_BOT_REPO = 'NO REPO'
window.CURRENT_BOT_CODE_NAME = ''
} else {
window.CURRENT_BOT_DISPLAY_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName
window.CURRENT_BOT_REPO = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].repo
window.CURRENT_BOT_CODE_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].codeName
}
}
function resize() {
thisObject.container.eventHandler.listenToEvent('onMouseClick', onClick)
sharedStatus.eventHandler.listenToEvent('devTeam Changed', onDevTeamChanged)
container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 1;
container.frame.position.y = viewPort.visibleArea.bottomLeft.y;
window.canvasApp.eventHandler.listenToEvent('Browser Resized', resize)
}
function resize () {
container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 1
container.frame.position.y = viewPort.visibleArea.bottomLeft.y
}
function onDevTeamChanged () {
if (window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length > 0) {
sharedStatus.currentUserBotIndex = 0
window.CURRENT_BOT_DISPLAY_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName
window.CURRENT_BOT_REPO = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].repo
window.CURRENT_BOT_CODE_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].codeName
sharedStatus.eventHandler.raiseEvent('userBot Changed')
} else {
window.CURRENT_BOT_DISPLAY_NAME = NOT_FOUND
}
}
function onDevTeamChanged() {
function onClick () {
let sessionToken = window.localStorage.getItem('sessionToken')
if (window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length > 0) {
sharedStatus.currentUserBotIndex = 0;
window.CURRENT_BOT_DISPLAY_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName;
window.CURRENT_BOT_REPO = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].repo;
window.CURRENT_BOT_CODE_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].codeName;
sharedStatus.eventHandler.raiseEvent("userBot Changed");
} else {
window.CURRENT_BOT_DISPLAY_NAME = NOT_FOUND;
}
}
function onClick() {
let sessionToken = window.localStorage.getItem('sessionToken');
if (sessionToken === null || sessionToken === "") {
if (sessionToken === null || sessionToken === '') {
/* not logged in */
return;
}
if (sharedStatus.currentUserBotIndex + 1 === window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length) {
sharedStatus.currentUserBotIndex = 0;
window.CURRENT_BOT_DISPLAY_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName;
window.CURRENT_BOT_REPO = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].repo;
window.CURRENT_BOT_CODE_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].codeName;
sharedStatus.eventHandler.raiseEvent("userBot Changed");
return;
}
if (sharedStatus.currentUserBotIndex + 1 < window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length) {
sharedStatus.currentUserBotIndex++;
window.CURRENT_BOT_DISPLAY_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName;
window.CURRENT_BOT_REPO = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].repo;
window.CURRENT_BOT_CODE_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].codeName;
sharedStatus.eventHandler.raiseEvent("userBot Changed");
return;
}
return
}
function getContainer(point) {
if (sharedStatus.currentUserBotIndex + 1 === window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length) {
sharedStatus.currentUserBotIndex = 0
window.CURRENT_BOT_DISPLAY_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName
window.CURRENT_BOT_REPO = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].repo
window.CURRENT_BOT_CODE_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].codeName
let container;
sharedStatus.eventHandler.raiseEvent('userBot Changed')
return
}
if (sharedStatus.currentUserBotIndex + 1 < window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length) {
sharedStatus.currentUserBotIndex++
window.CURRENT_BOT_DISPLAY_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName
window.CURRENT_BOT_REPO = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].repo
window.CURRENT_BOT_CODE_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].codeName
sharedStatus.eventHandler.raiseEvent('userBot 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 {
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
return this.container
} else {
/* This point does not belong to this space. */
return undefined;
}
return undefined
}
}
function draw() {
function draw () {
let sessionToken = window.localStorage.getItem('sessionToken')
let sessionToken = window.localStorage.getItem('sessionToken');
if (sessionToken === null || sessionToken === "") {
if (sessionToken === null || sessionToken === '') {
/* not logged in */
return;
}
thisObject.container.frame.draw(false, false);
let breakpointsHeight = 14;
let fontSize = 12;
let label = window.CURRENT_BOT_DISPLAY_NAME;
if (label === undefined) { label = "" };
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);
return
}
thisObject.container.frame.draw(false, false)
let breakpointsHeight = 14
let fontSize = 12
let label = window.CURRENT_BOT_DISPLAY_NAME
if (label === undefined) { label = '' };
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)
}
}
+159 -173
View File
@@ -1,212 +1,198 @@
function newCurrentEvent() {
function newCurrentEvent () {
let thisObject = {
container: undefined,
draw: draw,
getContainer: getContainer,
initialize: initialize
}
let thisObject = {
container: undefined,
draw: draw,
getContainer: getContainer,
initialize: initialize
};
const ecosystemBase =
const ecosystemBase =
[{
"codeName": "AAArena",
"displayName": "AA Arena",
"competitions": [{
"codeName": "Weekend-Deathmatch",
"description": "First AA Internal Competition. Bots will be trading during 3 days at the USDT/BTC market of Poloniex to see who can make the gratest return over investment (ROI).",
"displayName": "AA Internal Challenge",
"startDatetime": "2019-03-05T16:00:00.000Z",
"finishDatetime": "2019-02-07T16:59:59.999Z",
"formula": "ROI",
"plotter": {
"codeName": "PlottersROI",
"host": "AAArena",
"repo": "Plotters-ROI",
"moduleName": "CombinedProfits"
},
"participants": [
],
"repo": "Weekend-Deathmatch",
"configFile": "this.competition.config.json"
'codeName': 'AAArena',
'displayName': 'AA Arena',
'competitions': [{
'codeName': 'Weekend-Deathmatch',
'description': 'First AA Internal Competition. Bots will be trading during 3 days at the USDT/BTC market of Poloniex to see who can make the gratest return over investment (ROI).',
'displayName': 'AA Internal Challenge',
'startDatetime': '2019-03-05T16:00:00.000Z',
'finishDatetime': '2019-02-07T16:59:59.999Z',
'formula': 'ROI',
'plotter': {
'codeName': 'PlottersROI',
'host': 'AAArena',
'repo': 'Plotters-ROI',
'moduleName': 'CombinedProfits'
},
'participants': [
],
'repo': 'Weekend-Deathmatch',
'configFile': 'this.competition.config.json'
}],
'plotters': [{
'displayName': 'Plotters ROI',
'codeName': 'PlottersROI',
'devTeam': 'AAMasters',
'modules': [{
'codeName': 'CombinedProfits',
'moduleName': 'CombinedProfits',
'description': 'Plots participants of a competition by the ROI each one had over time.',
'panels': []
}],
"plotters": [{
"displayName": "Plotters ROI",
"codeName": "PlottersROI",
"devTeam": "AAMasters",
"modules": [{
"codeName": "CombinedProfits",
"moduleName": "CombinedProfits",
"description": "Plots participants of a competition by the ROI each one had over time.",
"panels": []
}],
"repo": "Plotters-ROI",
"configFile": "this.plotter.config.json"
}]
}];
'repo': 'Plotters-ROI',
'configFile': 'this.plotter.config.json'
}]
}]
function buildEcosystemEventsHack(reload) {
let hackedEcosystem = ecosystemBase;
function buildEcosystemEventsHack (reload) {
let hackedEcosystem = ecosystemBase
let ecosysTemp = window.localStorage.getItem('currentEventObject');
if (!(ecosysTemp === null || ecosysTemp === "[]" || ecosysTemp === "")) {
let parsedEcosysTemp = JSON.parse(ecosysTemp);
hackedEcosystem[0].competitions[0].startDatetime = new Date(parsedEcosysTemp.startDatetime*1000).toISOString();
hackedEcosystem[0].competitions[0].finishDatetime = new Date(parsedEcosysTemp.endDatetime*1000).toISOString();
parsedEcosysTemp.participants.forEach(function(participant) {
hackedEcosystem[0].competitions[0].participants.push({
devTeam: participant.clone.team.slug,
bot: participant.clone.bot.slug,
pOperationsId: participant.clone.id,
release: "1.0.0"
});
});
}
window.localStorage.setItem('ecosystemEventsHack', JSON.stringify(hackedEcosystem));
ecosystem.setEvent(hackedEcosystem);
if (reload) {
dashboard.start();
}
let ecosysTemp = window.localStorage.getItem('currentEventObject')
if (!(ecosysTemp === null || ecosysTemp === '[]' || ecosysTemp === '')) {
let parsedEcosysTemp = JSON.parse(ecosysTemp)
hackedEcosystem[0].competitions[0].startDatetime = new Date(parsedEcosysTemp.startDatetime * 1000).toISOString()
hackedEcosystem[0].competitions[0].finishDatetime = new Date(parsedEcosysTemp.endDatetime * 1000).toISOString()
parsedEcosysTemp.participants.forEach(function (participant) {
hackedEcosystem[0].competitions[0].participants.push({
devTeam: participant.clone.team.slug,
bot: participant.clone.bot.slug,
pOperationsId: participant.clone.id,
release: '1.0.0'
})
})
}
let container = newContainer();
container.initialize();
thisObject.container = container;
window.localStorage.setItem('ecosystemEventsHack', JSON.stringify(hackedEcosystem))
ecosystem.setEvent(hackedEcosystem)
if (reload) {
dashboard.start()
}
}
thisObject.container.frame.width = 150;
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT;
let container = newContainer()
container.initialize()
thisObject.container = container
resize();
thisObject.container.frame.width = 150
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT
container.isDraggeable = false;
container.isClickeable = true;
resize()
const NOT_FOUND = "Event NOT FOUND";
container.isDraggeable = false
container.isClickeable = true
let sharedStatus;
let storedEvents;
let label = "Event -"
const NOT_FOUND = 'Event NOT FOUND'
return thisObject;
let sharedStatus
let storedEvents
let label = 'Event -'
function initialize(pSharedStatus) {
return thisObject
let sessionToken = window.localStorage.getItem('sessionToken');
function initialize (pSharedStatus) {
let sessionToken = window.localStorage.getItem('sessionToken')
if (sessionToken === null || 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 if (sharedStatus.currentEventIndex === -1){
storedEvents = JSON.parse(storedEvents)
window.EVENTS = storedEvents;
window.CURRENT_EVENT_TITLE = "";
label = "Select an event";
} else {
storedEvents = JSON.parse(storedEvents)
window.EVENTS = storedEvents;
window.CURRENT_EVENT_TITLE = storedEvents[sharedStatus.currentEventIndex].title;
label = "Event - " + storedEvents[sharedStatus.currentEventIndex].title;
window.localStorage.setItem('currentEventObject', JSON.stringify(storedEvents[sharedStatus.currentEventIndex]));
buildEcosystemEventsHack(false);
sharedStatus.eventHandler.raiseEvent('Event Changed');
}
thisObject.container.eventHandler.listenToEvent("onMouseClick", onClick);
window.canvasApp.eventHandler.listenToEvent("Browser Resized", resize);
return
}
function resize() {
container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 2;
container.frame.position.y = viewPort.visibleArea.bottomLeft.y;
sharedStatus = pSharedStatus
storedEvents = window.localStorage.getItem('currentEvents')
if (storedEvents === null || storedEvents === '[]' || storedEvents === '') {
window.EVENTS = ''
window.CURRENT_EVENT_TITLE = ''
label = NOT_FOUND
} else if (sharedStatus.currentEventIndex === -1) {
storedEvents = JSON.parse(storedEvents)
window.EVENTS = storedEvents
window.CURRENT_EVENT_TITLE = ''
label = 'Select an event'
} else {
storedEvents = JSON.parse(storedEvents)
window.EVENTS = storedEvents
window.CURRENT_EVENT_TITLE = storedEvents[sharedStatus.currentEventIndex].title
label = 'Event - ' + storedEvents[sharedStatus.currentEventIndex].title
window.localStorage.setItem('currentEventObject', JSON.stringify(storedEvents[sharedStatus.currentEventIndex]))
buildEcosystemEventsHack(false)
sharedStatus.eventHandler.raiseEvent('Event Changed')
}
function onClick() {
thisObject.container.eventHandler.listenToEvent('onMouseClick', onClick)
let sessionToken = window.localStorage.getItem('sessionToken');
window.canvasApp.eventHandler.listenToEvent('Browser Resized', resize)
}
if (sessionToken === null || sessionToken === "") {
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;
window.localStorage.setItem('currentEventObject', JSON.stringify(storedEvents[sharedStatus.currentEventIndex]));
buildEcosystemEventsHack(true);
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;
window.localStorage.setItem('currentEventObject', JSON.stringify(storedEvents[sharedStatus.currentEventIndex]));
buildEcosystemEventsHack(true);
sharedStatus.eventHandler.raiseEvent('Event Changed');
return;
}
return
}
function getContainer(point) {
if (sharedStatus.currentEventIndex + 1 === window.EVENTS.length) {
sharedStatus.currentEventIndex = 0
window.CURRENT_EVENT_TITLE = storedEvents[sharedStatus.currentEventIndex].title
label = 'Event - ' + storedEvents[sharedStatus.currentEventIndex].title
window.localStorage.setItem('currentEventObject', JSON.stringify(storedEvents[sharedStatus.currentEventIndex]))
buildEcosystemEventsHack(true)
sharedStatus.eventHandler.raiseEvent('Event Changed')
return
}
let container;
if (sharedStatus.currentEventIndex + 1 < window.EVENTS.length) {
sharedStatus.currentEventIndex++
window.CURRENT_EVENT_TITLE = storedEvents[sharedStatus.currentEventIndex].title
label = 'Event - ' + storedEvents[sharedStatus.currentEventIndex].title
window.localStorage.setItem('currentEventObject', JSON.stringify(storedEvents[sharedStatus.currentEventIndex]))
buildEcosystemEventsHack(true)
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 {
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
return this.container
} else {
/* This point does not belong to this space. */
return undefined;
}
return undefined
}
}
function draw() {
function draw () {
let sessionToken = window.localStorage.getItem('sessionToken')
let sessionToken = window.localStorage.getItem('sessionToken');
if (sessionToken === null || 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);
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)
}
}
+95 -115
View File
@@ -1,150 +1,130 @@
function newCurrentProcess() {
let thisObject = {
container: undefined,
draw: draw,
getContainer: getContainer,
initialize: initialize
};
function newCurrentProcess () {
let thisObject = {
container: undefined,
draw: draw,
getContainer: getContainer,
initialize: initialize
}
let container = newContainer();
container.initialize();
thisObject.container = container;
let container = newContainer()
container.initialize()
thisObject.container = container
thisObject.container.frame.width = 150;
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT;
thisObject.container.frame.width = 150
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT
resize()
resize()
container.isDraggeable = false;
container.isClickeable = true;
container.isDraggeable = false
container.isClickeable = true
const NOT_FOUND = "";
const NOT_FOUND = ''
let sharedStatus;
let sharedStatus
return thisObject;
return thisObject
function initialize(pSharedStatus) {
function initialize (pSharedStatus) {
sharedStatus = pSharedStatus
sharedStatus = pSharedStatus;
if (window.USER_PROFILE.devTeams.length === 0) {
window.CURRENT_PROCESS = NOT_FOUND;
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 {
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;
}
}
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);
window.canvasApp.eventHandler.listenToEvent("Browser Resized", resize);
}
}
function resize() {
thisObject.container.eventHandler.listenToEvent('onMouseClick', onClick)
sharedStatus.eventHandler.listenToEvent('userBot Changed', onUserBotChanged)
container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 3;
container.frame.position.y = viewPort.visibleArea.bottomLeft.y;
window.canvasApp.eventHandler.listenToEvent('Browser Resized', resize)
}
function resize () {
container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 3
container.frame.position.y = viewPort.visibleArea.bottomLeft.y
}
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
}
}
function onUserBotChanged() {
window.CURRENT_PROCESS = NOT_FOUND
}
if ( window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length > 0) {
function onClick () {
let sessionToken = window.localStorage.getItem('sessionToken')
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() {
let sessionToken = window.localStorage.getItem('sessionToken');
if (sessionToken === null || sessionToken === "") {
if (sessionToken === null || sessionToken === '') {
/* not logged in */
return;
}
if (sharedStatus.currentProcessIndex + 1 === window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].processes.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[sharedStatus.currentUserBotIndex].processes.length) {
sharedStatus.currentProcessIndex++;
window.CURRENT_PROCESS = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].processes[sharedStatus.currentProcessIndex].name;
return;
}
return
}
function getContainer(point) {
if (sharedStatus.currentProcessIndex + 1 === window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].processes.length) {
sharedStatus.currentProcessIndex = 0
window.CURRENT_PROCESS = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].processes[sharedStatus.currentProcessIndex].name
return
}
let container;
if (sharedStatus.currentProcessIndex + 1 < window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].processes.length) {
sharedStatus.currentProcessIndex++
window.CURRENT_PROCESS = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].processes[sharedStatus.currentProcessIndex].name
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 {
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
return this.container
} else {
/* This point does not belong to this space. */
return undefined;
}
return undefined
}
}
function draw() {
function draw () {
let sessionToken = window.localStorage.getItem('sessionToken')
let sessionToken = window.localStorage.getItem('sessionToken');
if (sessionToken === null || sessionToken === "") {
if (sessionToken === null || sessionToken === '') {
/* not logged in */
return;
}
thisObject.container.frame.draw(false, false);
let breakpointsHeight = 14;
let fontSize = 12;
let label = window.CURRENT_PROCESS;
if (label === undefined) { label = "" };
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);
return
}
thisObject.container.frame.draw(false, false)
let breakpointsHeight = 14
let fontSize = 12
let label = window.CURRENT_PROCESS
if (label === undefined) { label = '' };
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)
}
}
+81 -93
View File
@@ -1,122 +1,110 @@
function newCurrentStartMode() {
var thisObject = {
container: undefined,
draw: draw,
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
initialize: initialize
};
function newCurrentStartMode () {
var thisObject = {
container: undefined,
draw: draw,
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
initialize: initialize
}
var container = newContainer();
container.initialize();
thisObject.container = container;
var container = newContainer()
container.initialize()
thisObject.container = container
thisObject.container.frame.width = 150;
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT;
thisObject.container.frame.width = 150
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT
resize();
resize()
container.isDraggeable = false;
container.isClickeable = true;
container.isDraggeable = false
container.isClickeable = true
return thisObject;
return thisObject
function initialize() {
function initialize () {
window.CURRENT_START_MODE = window.localStorage.getItem('currentStartMode')
window.CURRENT_START_MODE = window.localStorage.getItem("currentStartMode");
if (window.CURRENT_START_MODE === null) {
window.CURRENT_START_MODE = "Backtest";
}
thisObject.container.eventHandler.listenToEvent("onMouseClick", onClick);
window.canvasApp.eventHandler.listenToEvent("Browser Resized", resize);
if (window.CURRENT_START_MODE === null) {
window.CURRENT_START_MODE = 'Backtest'
}
function resize() {
thisObject.container.eventHandler.listenToEvent('onMouseClick', onClick)
container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 4;
container.frame.position.y = viewPort.visibleArea.bottomLeft.y;
window.canvasApp.eventHandler.listenToEvent('Browser Resized', resize)
}
}
function resize () {
container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 4
container.frame.position.y = viewPort.visibleArea.bottomLeft.y
}
function onClick() {
function onClick () {
let sessionToken = window.localStorage.getItem('sessionToken')
let sessionToken = window.localStorage.getItem('sessionToken');
if (sessionToken === null || sessionToken === "") {
if (sessionToken === null || sessionToken === '') {
/* not logged in */
return;
}
if (window.CURRENT_BOT_DISPLAY_NAME === "") { return; }
switch (window.CURRENT_START_MODE) {
case "Backtest": {
window.CURRENT_START_MODE = "Live";
break;
}
case "Live": {
window.CURRENT_START_MODE = "Competition";
break;
}
case "Competition": {
window.CURRENT_START_MODE = "Backtest";
break;
}
}
return
}
function getContainer(point) {
if (window.CURRENT_BOT_DISPLAY_NAME === '') { return }
let container;
switch (window.CURRENT_START_MODE) {
case 'Backtest': {
window.CURRENT_START_MODE = 'Live'
break
}
case 'Live': {
window.CURRENT_START_MODE = 'Competition'
break
}
case 'Competition': {
window.CURRENT_START_MODE = 'Backtest'
break
}
}
}
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 {
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
return this.container
} else {
/* This point does not belong to this space. */
return undefined;
}
return undefined
}
}
function draw() {
function draw () {
let sessionToken = window.localStorage.getItem('sessionToken')
let sessionToken = window.localStorage.getItem('sessionToken');
if (sessionToken === null || sessionToken === "") {
if (sessionToken === null || sessionToken === '') {
/* not logged in */
return;
}
if (window.CURRENT_BOT_DISPLAY_NAME === "") { return;}
thisObject.container.frame.draw(false, false);
let breakpointsHeight = 14;
let fontSize = 12;
let label = window.CURRENT_START_MODE + " Mode";
if (label === "undefined Mode") { label = "" };
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);
return
}
if (window.CURRENT_BOT_DISPLAY_NAME === '') { return }
thisObject.container.frame.draw(false, false)
let breakpointsHeight = 14
let fontSize = 12
let label = window.CURRENT_START_MODE + ' Mode'
if (label === 'undefined Mode') { label = '' };
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)
}
}
+92 -106
View File
@@ -1,139 +1,125 @@
function newDevTeam() {
function newDevTeam () {
let thisObject = {
container: undefined,
draw: draw,
getContainer: getContainer,
initialize: initialize
}
let thisObject = {
container: undefined,
draw: draw,
getContainer: getContainer,
initialize: initialize
};
let container = newContainer()
container.initialize()
thisObject.container = container
let container = newContainer();
container.initialize();
thisObject.container = container;
thisObject.container.frame.width = 150
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT
thisObject.container.frame.width = 150;
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT;
resize()
resize();
container.isDraggeable = false
container.isClickeable = true
container.isDraggeable = false;
container.isClickeable = true;
const NOT_FOUND = 'Team NOT FOUND'
const NOT_FOUND = "Team NOT FOUND";
let sharedStatus
let label = ''
let sharedStatus;
let label = ""
return thisObject
return thisObject;
function initialize (pSharedStatus) {
let sessionToken = window.localStorage.getItem('sessionToken')
function initialize(pSharedStatus) {
let sessionToken = window.localStorage.getItem('sessionToken');
if (sessionToken === null || sessionToken === "") {
if (sessionToken === null || sessionToken === '') {
/* not logged in */
return;
}
sharedStatus = pSharedStatus;
let storedTeams = window.localStorage.getItem('userTeams');
if (storedTeams === null || storedTeams === "[]" || storedTeams === "") {
window.TEAMS = "";
window.DEV_TEAM = "";
label = NOT_FOUND;
} else {
storedTeams = JSON.parse(storedTeams)
window.TEAMS = storedTeams;
window.DEV_TEAM = storedTeams[sharedStatus.currentDevTeamIndex].slug;
label = storedTeams[sharedStatus.currentDevTeamIndex].name;
sharedStatus.eventHandler.raiseEvent("devTeam Changed");
}
thisObject.container.eventHandler.listenToEvent("onMouseClick", onClick);
window.canvasApp.eventHandler.listenToEvent("Browser Resized", resize);
return
}
function resize() {
sharedStatus = pSharedStatus
container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 0;
container.frame.position.y = viewPort.visibleArea.bottomLeft.y;
let storedTeams = window.localStorage.getItem('userTeams')
if (storedTeams === null || storedTeams === '[]' || storedTeams === '') {
window.TEAMS = ''
window.DEV_TEAM = ''
label = NOT_FOUND
} else {
storedTeams = JSON.parse(storedTeams)
window.TEAMS = storedTeams
window.DEV_TEAM = storedTeams[sharedStatus.currentDevTeamIndex].slug
label = storedTeams[sharedStatus.currentDevTeamIndex].name
sharedStatus.eventHandler.raiseEvent('devTeam Changed')
}
function onClick() {
thisObject.container.eventHandler.listenToEvent('onMouseClick', onClick)
let sessionToken = window.localStorage.getItem('sessionToken');
window.canvasApp.eventHandler.listenToEvent('Browser Resized', resize)
}
if (sessionToken === null || sessionToken === "") {
function resize () {
container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 0
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.currentDevTeamIndex + 1 === window.TEAMS.length) {
sharedStatus.currentDevTeamIndex = 0;
window.DEV_TEAM = window.TEAMS[sharedStatus.currentDevTeamIndex].slug;
label = window.TEAMS[sharedStatus.currentDevTeamIndex].name;
sharedStatus.eventHandler.raiseEvent("devTeam Changed");
return;
}
if (sharedStatus.currentDevTeamIndex + 1 < window.TEAMS.length) {
sharedStatus.currentDevTeamIndex++;
window.DEV_TEAM = window.TEAMS[sharedStatus.currentDevTeamIndex].slug;
label = window.TEAMS[sharedStatus.currentDevTeamIndex].name;
sharedStatus.eventHandler.raiseEvent("devTeam Changed");
return;
}
return
}
function getContainer(point) {
if (sharedStatus.currentDevTeamIndex + 1 === window.TEAMS.length) {
sharedStatus.currentDevTeamIndex = 0
window.DEV_TEAM = window.TEAMS[sharedStatus.currentDevTeamIndex].slug
label = window.TEAMS[sharedStatus.currentDevTeamIndex].name
sharedStatus.eventHandler.raiseEvent('devTeam Changed')
return
}
let container;
if (sharedStatus.currentDevTeamIndex + 1 < window.TEAMS.length) {
sharedStatus.currentDevTeamIndex++
window.DEV_TEAM = window.TEAMS[sharedStatus.currentDevTeamIndex].slug
label = window.TEAMS[sharedStatus.currentDevTeamIndex].name
sharedStatus.eventHandler.raiseEvent('devTeam 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 {
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
return this.container
} else {
/* This point does not belong to this space. */
return undefined;
}
return undefined
}
}
function draw() {
function draw () {
let sessionToken = window.localStorage.getItem('sessionToken')
let sessionToken = window.localStorage.getItem('sessionToken');
if (sessionToken === null || 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);
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)
}
}
+167 -185
View File
@@ -1,64 +1,60 @@
function newLogin() {
let thisObject = {
container: undefined,
draw: draw,
getContainer: getContainer,
initialize: initialize
};
function newLogin () {
let thisObject = {
container: undefined,
draw: draw,
getContainer: getContainer,
initialize: initialize
}
let container = newContainer();
container.initialize();
thisObject.container = container;
let container = newContainer()
container.initialize()
thisObject.container = container
thisObject.container.frame.width = 200;
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT;
thisObject.container.frame.width = 200
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT
container.frame.position.x = viewPort.visibleArea.topRight.x - thisObject.container.frame.width * 1;
container.frame.position.y = viewPort.visibleArea.bottomLeft.y;
container.frame.position.x = viewPort.visibleArea.topRight.x - thisObject.container.frame.width * 1
container.frame.position.y = viewPort.visibleArea.bottomLeft.y
container.isDraggeable = false;
container.isClickeable = true;
container.isDraggeable = false
container.isClickeable = true
let currentLabel;
let currentLabel
let userAuthorization;
let userAuthorization
return thisObject;
return thisObject
function initialize(pSharedStatus, callBackFunction) {
function initialize (pSharedStatus, callBackFunction) {
const accessToken = window.localStorage.getItem('access_token')
let user = window.localStorage.getItem('user')
sharedStatus = pSharedStatus
const accessToken = window.localStorage.getItem("access_token");
let user = window.localStorage.getItem("user");
sharedStatus = pSharedStatus;
if (user === null) {
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.
window.localStorage.removeItem("loggedInUser");
window.localStorage.removeItem('sessionToken');
return;
}
window.localStorage.removeItem('loggedInUser')
window.localStorage.removeItem('sessionToken')
return
}
user = JSON.parse(user);
user = JSON.parse(user)
const authId = user.authId;
const authId = user.authId
let sessionToken;
let sessionToken
const apolloClient = new Apollo.lib.ApolloClient({
networkInterface: Apollo.lib.createNetworkInterface({
uri: window.canvasApp.graphQL.masterAppApiUrl,
transportBatching: true,
}),
connectToDevTools: true,
})
const apolloClient = new Apollo.lib.ApolloClient({
networkInterface: Apollo.lib.createNetworkInterface({
uri: window.canvasApp.graphQL.masterAppApiUrl,
transportBatching: true
}),
connectToDevTools: true
})
const QUERY = Apollo.gql`
const QUERY = Apollo.gql`
query($authId: String){
users_UserByAuthId (authId: $authId){
id
@@ -82,46 +78,46 @@ function newLogin() {
}
}
`
const getUser = () => {
return new Promise((resolve, reject) => {
apolloClient.query({
query: QUERY,
variables: {
authId: authId
}
})
const getUser = () => {
return new Promise((resolve, reject) => {
apolloClient.query({
query: QUERY,
variables: {
authId: authId
}
})
.then(response => {
sessionToken = response.data.users_UserByAuthId.sessionToken;
sessionToken = response.data.users_UserByAuthId.sessionToken
window.localStorage.setItem('loggedInUser', JSON.stringify(response.data.users_UserByAuthId));
resolve({ user: response.data.users_UserByAuthId})
window.localStorage.setItem('loggedInUser', JSON.stringify(response.data.users_UserByAuthId))
resolve({ user: response.data.users_UserByAuthId})
})
.catch(error => {
console.log("apolloClient error getting user query", error)
reject(error)
});
});
}
console.log('apolloClient error getting user query', error)
reject(error)
})
})
}
const networkInterfaceTeams = Apollo.lib.createNetworkInterface({
uri: window.canvasApp.graphQL.masterAppApiUrl
});
const networkInterfaceTeams = Apollo.lib.createNetworkInterface({
uri: window.canvasApp.graphQL.masterAppApiUrl
})
networkInterfaceTeams.use([{
applyMiddleware(req, next) {
req.options.headers = {
authorization: `Bearer ${accessToken}`
};
next();
}
}]);
networkInterfaceTeams.use([{
applyMiddleware (req, next) {
req.options.headers = {
authorization: `Bearer ${accessToken}`
}
next()
}
}])
const apolloClientTeams = new Apollo.lib.ApolloClient({
networkInterface: networkInterfaceTeams,
connectToDevTools: true,
});
const apolloClientTeams = new Apollo.lib.ApolloClient({
networkInterface: networkInterfaceTeams,
connectToDevTools: true
})
const TEAM_BY_OWNER_QUERY = Apollo.gql`
const TEAM_BY_OWNER_QUERY = Apollo.gql`
query teamsByOwnerQuery {
teams_TeamsByOwner {
id
@@ -155,36 +151,35 @@ function newLogin() {
}
`
const getTeamByOwner = () => {
return new Promise((resolve, reject) => {
apolloClientTeams.query({
query: TEAM_BY_OWNER_QUERY
})
const getTeamByOwner = () => {
return new Promise((resolve, reject) => {
apolloClientTeams.query({
query: TEAM_BY_OWNER_QUERY
})
.then(response => {
window.localStorage.setItem('userTeams', JSON.stringify(response.data.teams_TeamsByOwner));
resolve({ teams: response.data.teams_TeamsByOwner})
window.localStorage.setItem('userTeams', JSON.stringify(response.data.teams_TeamsByOwner))
resolve({ teams: response.data.teams_TeamsByOwner})
})
.catch(error => {
console.log("apolloClient error getting user teams", error)
reject (error)
});
console.log('apolloClient error getting user teams', error)
reject(error)
})
}
})
}
// Gettings events
const networkInterfaceEvents = Apollo.lib.createNetworkInterface({
uri: window.canvasApp.graphQL.masterAppApiUrl
})
const networkInterfaceEvents = Apollo.lib.createNetworkInterface({
uri: window.canvasApp.graphQL.masterAppApiUrl
});
const apolloClientEvents = new Apollo.lib.ApolloClient({
networkInterface: networkInterfaceEvents,
connectToDevTools: true,
addTypename: false
})
const apolloClientEvents = new Apollo.lib.ApolloClient({
networkInterface: networkInterfaceEvents,
connectToDevTools: true,
addTypename: false
});
const EVENTS = Apollo.gql`
const EVENTS = Apollo.gql`
query events($maxStartDate: Int, $minEndDate: Int){
events_Events(maxStartDate: $maxStartDate, minEndDate: $minEndDate){
id
@@ -207,125 +202,112 @@ function newLogin() {
`
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 }
})
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));
currentEvent = window.localStorage.getItem('currentEventObject');
if (currentEvent === null || currentEvent === "[]" || currentEvent === "") {
sharedStatus.currentEventIndex = -1;
} else {
currentEvent = JSON.parse(currentEvent);
sharedStatus.currentEventIndex = response.data.events_Events.findIndex(function(element) {
return element.id == currentEvent.id;
});
}
resolve({ currentEvents: response.data.events_Events})
window.localStorage.setItem('currentEvents', JSON.stringify(response.data.events_Events))
currentEvent = window.localStorage.getItem('currentEventObject')
if (currentEvent === null || currentEvent === '[]' || currentEvent === '') {
sharedStatus.currentEventIndex = -1
} else {
currentEvent = JSON.parse(currentEvent)
sharedStatus.currentEventIndex = response.data.events_Events.findIndex(function (element) {
return element.id == currentEvent.id
})
}
resolve({ currentEvents: response.data.events_Events})
})
.catch(error => {
console.log("apolloClient error getting current events", error)
reject (error)
});
})
console.log('apolloClient error getting current events', error)
reject(error)
})
})
}
// To avoid race conditions, add asynchronous fetches to array
let fetchDataPromises = [];
let fetchDataPromises = []
fetchDataPromises.push(getUser(), getTeamByOwner(), getCurrentEvents());
fetchDataPromises.push(getUser(), getTeamByOwner(), getCurrentEvents())
// When all asynchronous fetches resolve, authenticate user or throw error.
Promise.all(fetchDataPromises).then(result => {
Promise.all(fetchDataPromises).then(result => {
/* this is the time to authenticate the user at AAWeb */
authenticateUser();
authenticateUser()
}, err => {
console.error('fetchData error', err)
})
}, err => {
console.error("fetchData error", err)
});
thisObject.container.eventHandler.listenToEvent('onMouseClick', onClick)
thisObject.container.eventHandler.listenToEvent("onMouseClick", onClick);
function authenticateUser () {
if (sessionToken === undefined) { sessionToken = '' }
function authenticateUser() {
let path = window.canvasApp.urlPrefix + 'AABrowserAPI/authenticateUser/' + sessionToken
if (sessionToken === undefined) { sessionToken = "" }
callServer(undefined, path, onServerReponded)
let path = window.canvasApp.urlPrefix + "AABrowserAPI/authenticateUser/" + sessionToken;
function onServerReponded (pResponseFromServer) {
let responseFromServer = JSON.parse(pResponseFromServer)
callServer(undefined, path, onServerReponded);
err = responseFromServer.err
function onServerReponded(pResponseFromServer) {
let responseFromServer = JSON.parse(pResponseFromServer);
err = responseFromServer.err;
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
console.log("Please make sure you create a new team!");
return;
}
window.USER_PROFILE = responseFromServer.userProfile;
window.localStorage.setItem('sessionToken', sessionToken);
currentLabel = "Logged In"
callBackFunction();
}
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
console.log('Please make sure you create a new team!')
return
}
window.USER_PROFILE = responseFromServer.userProfile
window.localStorage.setItem('sessionToken', sessionToken)
currentLabel = 'Logged In'
callBackFunction()
}
}
}
function onClick () {
function onClick() {
}
}
function getContainer(point) {
let container;
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 {
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
return this.container
} else {
/* This point does not belong to this space. */
return undefined;
}
return undefined
}
}
function draw () {
return // nothing to show.
thisObject.container.frame.draw(false, false)
let fontSize = 12
let label = currentLabel
if (label === undefined) { label = '' };
let point = {
x: thisObject.container.frame.width * 1 / 3,
y: (thisObject.container.frame.height / 2) + 4
}
function draw() {
point = thisObject.container.frame.frameThisPoint(point)
return; // nothing to show.
thisObject.container.frame.draw(false, false);
let fontSize = 12;
let label = currentLabel;
if (label === undefined) { label = "" };
let point = {
x: thisObject.container.frame.width * 1 / 3,
y: (thisObject.container.frame.height / 2) + 4
};
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);
}
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)'
browserCanvasContext.fillText(label, point.x, point.y)
}
}