From 8edf372adbd2b755ea4bbfba65c1d15d38b1a342 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 18 Apr 2018 15:47:35 +0200 Subject: [PATCH] Images taken from config and displayed at Bots Products Panel --- .vs/AAWebPlatform/v15/.suo | Bin 76800 -> 79360 bytes Panels/ProductsPanel.js | 7 +- ProductCard.js | 33 ++-- index.html | 4 +- server.js | 319 +++++++++++++++++++++++++++++++++---- 5 files changed, 306 insertions(+), 57 deletions(-) diff --git a/.vs/AAWebPlatform/v15/.suo b/.vs/AAWebPlatform/v15/.suo index 3fa100778a92635ce4fb0a10188eb5c501cc40e8..3c88494f1c28ac09082830372cade86c0a198b32 100644 GIT binary patch delta 3176 zcmd6pdr(wW9LMiDySx#0fkgw<1yK=~hlrV>$@`(GtPfP85mb~MRN~>2VoCE+S+YMB z(abvI*i4xZZh$lCq*ngJOqw}`n7Pd4)HsIbjG2|t_rRrD%*+|9>Fj*=_dCCP-rsZX zxwcll?V5gTES0|MF~FcGK8m8~KxbE17mUJy`G_@``xMx2zZLw|7c3VMTQ05PYuH@6 z#n&-+TCH2_x(ea+!SstRs5%8Ms&}Uu@FTzgEfx$b+s=d?uEk1W`-6cX2#f|#0e6rN z!hs2RfIv_TWaGZDcVR7BJ_>fIqC_j9a3aBS;0YcBv0x?`4+4N}K&B!(sUKXu#3?cf zzE#T`VP`o#lQj~Y^3yb5ui1%C&*s3N0{Uq&Z_SQ?^#dcp)Sj3}*IYQy04jC~$zRYD z?HZ=p#hM)g`z&|@4Ax?DL^7>JJ_I}m%0LB>@k-bgU>T4LPY#z5y$u;VFYzh3QMXrW znu`2=G~Ix()YL7kIv#E!=+$y8{9Y|(H&V+%U=fh{d$p9YF?e>bmQN!lb(UJnGEz&a zsitMGl(gHu-vlY4EHesLN|*%3f!SaJNCuCC81N+U2d-cqh@&g+gVV6Vu|0ZPkxQSU z`B|Estl4bX9FPX2gtFJ^njKba^^eNaGV*~`B_BvtWL_p`b=K2nkCCjr*4m$~tF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CCax~ywZpGOjqI61}#a%+;?Z=p6LEr<(gL)wwG$T|c@{Nfaw&~ekc zkaHVPSq_F z{fFzu`*7oRTZ!Gbc(@~GvM!=SPf+f+UsZ+(5wgp$T71@UDkXPqha#Ep@j1M>tklrQ@ zGf*RG@SDrrOQHp13W z&wHl`oT|@ZO_ViI&mNql%NiraHs2u3NLf3Trx86JQ~|WMeRAw!BI&wD2ur2xGbP*Q z&sr7k_bZ`XjB%e(h}~lZ5@|$WJ66nRO0bK1&B*P^4J!y3CqgQW?MqdvgjB0wb@xTV z_kA-Vug?;?T4=@eDBDHZ=M?OBq9BSH)uFz8 zzO+II5K|d!V_LYsSL4SQ-~wy51G?|)AmiY&I5S>C{2D?l6w>j}Eac3gKQg`fBOTTPsO4zmO))}WZkPr~I1YzOe+ro+?o=C59RYTq&`lE|HjsKY6EsSXS;_FrD(TwB`M z-0C}9>Y%A6?&D0pkAoi$Xdeg|9nSP@M^=?N&6$zOekVZh83&C9azUJ&Mb$rKA;p8m zW^$YKA5ABFVCY^kH15|z-CP4y+&u((dpIN~M-Ljb - + + + \ No newline at end of file diff --git a/server.js b/server.js index 6fb2d9dee..688473d01 100644 --- a/server.js +++ b/server.js @@ -121,6 +121,8 @@ function initialize() { let host = ecosystemObject.hosts[i]; + /* In this first section we will load the competitions configurations. */ + for (let j = 0; j < host.competitions.length; j++) { let competition = host.competitions[j]; @@ -153,7 +155,7 @@ function initialize() { if (requestsSent === responsesReceived) { - readBotsConfig(); + readBotsAndPlottersConfig(); } } @@ -197,7 +199,97 @@ function initialize() { if (requestsSent === responsesReceived) { - readBotsConfig(); + readBotsAndPlottersConfig(); + + } + + } + catch (err) { + console.log("readCompetitionsConfig -> onDataArrived -> Error = " + err); + } + } + } + } + + /* In this second section we will load the plotters configurations. */ + + for (let j = 0; j < host.plotters.length; j++) { + + let plotter = host.plotters[j]; + + requestsSent++; + + if (DEBUG_MODE === true) { + + let fs = require('fs'); + try { + let fileName = '../Plotters/' + host.codeName + '/' + plotter.repo + '/' + plotter.configFile; + fs.readFile(fileName, onFileRead); + + function onFileRead(err, pData) { + + try { + responsesReceived++; + + pData = pData.toString(); + pData = pData.trim(); // remove first byte with some encoding. + + let configObj = JSON.parse(pData); + + /* Since we are going to replace the full bot object and we dont want to lose these two properties, we do this: */ + + configObj.repo = plotter.repo; + configObj.configFile = plotter.configFile; + + host.plotters[j] = configObj; + + if (requestsSent === responsesReceived) { + + readBotsAndPlottersConfig(); + + } + } + catch (err) { + console.log("readCompetitionsConfig -> onFileRead -> File = " + fileName + " Error = " + err); + } + + } + } + catch (err) { + console.log(err); + } + + } else { + + getGithubData(host.codeName, plotter.repo, plotter.configFile, onDataArrived) + + function onDataArrived(pData) { + + try { + + if (CONSOLE_LOG === true) { + + console.log("readCompetitionsConfig -> onDataArrived -> pData = " + pData); + + } + + responsesReceived++; + + pData = pData.toString(); + pData = pData.trim(); // remove first byte with some encoding. + + let configObj = JSON.parse(pData); + + /* Since we are going to replace the full bot object and we dont want to lose these two properties, we do this: */ + + configObj.repo = plotter.repo; + configObj.configFile = plotter.configFile; + + host.plotters[j] = configObj; + + if (requestsSent === responsesReceived) { + + readBotsAndPlottersConfig(); } @@ -211,18 +303,20 @@ function initialize() { } } - function readBotsConfig() { + function readBotsAndPlottersConfig() { if (CONSOLE_LOG === true) { - console.log("I am entering the readBotsConfig function."); + console.log("I am entering the readBotsAndPlottersConfig function."); } /* Each bot has its configuration at its own repo since each team must be able to change it at will. So what we do here is to use the master config at the AAPlatform repo that we already have on - memory and inject into it the config of each bot. + memory and inject into it the config of each bot. + + Inmediatelly after that, we also load the Plotters configs using the same technique. */ @@ -233,6 +327,8 @@ function initialize() { let devTeam = ecosystemObject.devTeams[i]; + /* In the next section we are loading the bots configurations. */ + for (let j = 0; j < devTeam.bots.length; j++) { let bot = devTeam.bots[j]; @@ -270,7 +366,7 @@ function initialize() { } } catch (err) { - console.log("readBotsConfig -> onFileRead -> File = " + fileName + " Error = " + err); + console.log("readBotsAndPlottersConfig -> onFileRead -> File = " + fileName + " Error = " + err); } } @@ -289,7 +385,7 @@ function initialize() { if (CONSOLE_LOG === true) { - console.log("readBotsConfig -> onDataArrived -> pData = " + pData); + console.log("readBotsAndPlottersConfig -> onDataArrived -> pData = " + pData); } @@ -315,7 +411,97 @@ function initialize() { } catch (err) { - console.log("readBotsConfig -> onDataArrived -> Error = " + err); + console.log("readBotsAndPlottersConfig -> onDataArrived -> Error = " + err); + } + } + } + } + + /* In the next section we are loading the plotters configurations. */ + + for (let j = 0; j < devTeam.plotters.length; j++) { + + let plotter = devTeam.plotters[j]; + + requestsSent++; + + if (DEBUG_MODE === true) { + + let fs = require('fs'); + try { + let fileName = '../Plotters/' + devTeam.codeName + '/' + plotter.repo + '/' + plotter.configFile; + fs.readFile(fileName, onFileRead); + + function onFileRead(err, pData) { + + try { + responsesReceived++; + + pData = pData.toString(); + pData = pData.trim(); // remove first byte with some encoding. + + let configObj = JSON.parse(pData); + + /* Since we are going to replace the full plotter object and we dont want to lose these two properties, we do this: */ + + configObj.repo = plotter.repo; + configObj.configFile = plotter.configFile; + + devTeam.plotters[j] = configObj; + + if (requestsSent === responsesReceived) { + + startHtttpServer(); + + } + } + catch (err) { + console.log("readPlottersConfig -> onFileRead -> File = " + fileName + " Error = " + err); + } + + } + } + catch (err) { + console.log(err); + } + + } else { + + getGithubData(devTeam.codeName, plotter.repo, plotter.configFile, onDataArrived) + + function onDataArrived(pData) { + + try { + + if (CONSOLE_LOG === true) { + + console.log("readBotsAndPlottersConfig -> onDataArrived -> pData = " + pData); + + } + + responsesReceived++; + + pData = pData.toString(); + pData = pData.trim(); // remove first byte with some encoding. + + let configObj = JSON.parse(pData); + + /* Since we are going to replace the full plotter object and we dont want to lose these two properties, we do this: */ + + configObj.repo = plotter.repo; + configObj.configFile = plotter.configFile; + + devTeam.plotters[j] = configObj; + + if (requestsSent === responsesReceived) { + + startHtttpServer(); + + } + + } + catch (err) { + console.log("readBotsAndPlottersConfig -> onDataArrived -> Error = " + err); } } } @@ -402,20 +588,24 @@ function onBrowserRequest(request, response) { let plotter = devTeam.plotters[j]; - let caseStringCopy = caseString; + for (let k = 0; k < plotter.modules.length; k++) { - let newFunctionName = devTeam.codeName + plotter.repo + plotter.moduleName; - newFunctionName = newFunctionName.replace(/-/g, ""); + let module = plotter.modules[k]; - let stringToInsert; - stringToInsert = caseStringCopy.replace('@newFunctionName@', newFunctionName); - stringToInsert = stringToInsert.replace('newPlotterName', 'new' + newFunctionName); + let caseStringCopy = caseString; - let firstPart = fileContent.substring(0, fileContent.indexOf('// Cases')); - let secondPart = fileContent.substring(fileContent.indexOf('// Cases')); + let newFunctionName = devTeam.codeName + plotter.repo + module.codeName; + newFunctionName = newFunctionName.replace(/-/g, ""); - fileContent = firstPart + stringToInsert + secondPart; + let stringToInsert; + stringToInsert = caseStringCopy.replace('@newFunctionName@', newFunctionName); + stringToInsert = stringToInsert.replace('newPlotterName', 'new' + newFunctionName); + let firstPart = fileContent.substring(0, fileContent.indexOf('// Cases')); + let secondPart = fileContent.substring(fileContent.indexOf('// Cases')); + + fileContent = firstPart + stringToInsert + secondPart; + } } } } @@ -529,44 +719,105 @@ function onBrowserRequest(request, response) { let fileContent = file.toString(); - /* This is the string we will use to insert into the Plotters.js script. */ + addPlotters(); + addImages(); - let htmlLine = '' + '\n' + - ' ' + function addPlotters() { - let devTeams = ecosystemObject.devTeams; - let hosts = ecosystemObject.hosts; + let htmlLine = '' + '\n' + + ' ' - addScript(devTeams); - addScript(hosts); + let devTeams = ecosystemObject.devTeams; + let hosts = ecosystemObject.hosts; - function addScript(pDevTeamsOrHosts) { + addScript(devTeams); + addScript(hosts); - for (let i = 0; i < pDevTeamsOrHosts.length; i++) { + function addScript(pDevTeamsOrHosts) { - let devTeam = pDevTeamsOrHosts[i]; + for (let i = 0; i < pDevTeamsOrHosts.length; i++) { - for (let j = 0; j < devTeam.plotters.length; j++) { + let devTeam = pDevTeamsOrHosts[i]; - let plotter = devTeam.plotters[j]; + for (let j = 0; j < devTeam.plotters.length; j++) { - /* Now each of these layers has a plotter that we need to define on the Plotter.js file. */ + let plotter = devTeam.plotters[j]; + + for (let k = 0; k < plotter.modules.length; k++) { + + let module = plotter.modules[k]; + + let htmlLineCopy = htmlLine; + + let stringToInsert; + stringToInsert = htmlLineCopy.replace('@devTeam@', devTeam.codeName); + stringToInsert = stringToInsert.replace('@repo@', plotter.repo); + stringToInsert = stringToInsert.replace('@module@', module.moduleName); + + let firstPart = fileContent.substring(0, fileContent.indexOf('') + 15); + let secondPart = fileContent.substring(fileContent.indexOf('') + 15); + + fileContent = firstPart + stringToInsert + secondPart; + + } + } + } + } + } + + function addImages() { + + const htmlLine = '' + '\n' + + ' ' + + let devTeams = ecosystemObject.devTeams; + + addScript(devTeams); + + function addScript(pDevTeams) { + + for (let i = 0; i < pDevTeams.length; i++) { + + let devTeam = pDevTeams[i]; let htmlLineCopy = htmlLine; let stringToInsert; stringToInsert = htmlLineCopy.replace('@devTeam@', devTeam.codeName); - stringToInsert = stringToInsert.replace('@repo@', plotter.repo); - stringToInsert = stringToInsert.replace('@module@', plotter.moduleName); + stringToInsert = stringToInsert.replace('@repo@', devTeam.codeName + "-Dev-Team"); + stringToInsert = stringToInsert.replace('@image@', devTeam.codeName + ".png"); + stringToInsert = stringToInsert.replace('@id@', devTeam.codeName + ".png"); - let firstPart = fileContent.substring(0, fileContent.indexOf('') + 15); - let secondPart = fileContent.substring(fileContent.indexOf('') + 15); + let firstPart = fileContent.substring(0, fileContent.indexOf('') + 15); + let secondPart = fileContent.substring(fileContent.indexOf('') + 15); fileContent = firstPart + stringToInsert + secondPart; + for (let j = 0; j < devTeam.bots.length; j++) { + + let bot = devTeam.bots[j]; + + if (bot.profilePicture !== undefined) { + + let htmlLineCopy = htmlLine; + + let stringToInsert; + stringToInsert = htmlLineCopy.replace('@devTeam@', devTeam.codeName); + stringToInsert = stringToInsert.replace('@repo@', bot.repo); + stringToInsert = stringToInsert.replace('@image@', bot.profilePicture); + stringToInsert = stringToInsert.replace('@id@', devTeam.codeName + "." + bot.profilePicture); + + let firstPart = fileContent.substring(0, fileContent.indexOf('') + 15); + let secondPart = fileContent.substring(fileContent.indexOf('') + 15); + + fileContent = firstPart + stringToInsert + secondPart; + + } + } } } } + respondWithContent(fileContent, response);