Images taken from config and displayed at Bots Products Panel

This commit is contained in:
Luis Fernando Molina committed 2018-04-18 15:47:35 +02:00
1 parent 8f150c0c3d
commit 8edf372adb
5 files changed
+306 -57

No files matched your search

Binary file not shown.
+2 -5
View File
@@ -1,7 +1,4 @@
function newProductsPanel() {
function newProductsPanel() {
var thisObject = {
container: undefined,
@@ -31,7 +28,7 @@ function newProductsPanel() {
function initialize() {
thisObject.container.frame.width = 300;
thisObject.container.frame.width = 400;
thisObject.container.frame.height = viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topLeft.y + 15;
var position = {
+16 -17
View File
@@ -79,8 +79,8 @@
};
this.container.frame.position = position;
this.container.frame.width = 280;
this.container.frame.height = 60;
this.container.frame.width = 380;
this.container.frame.height = 80;
/* We retrieve the locally stored status of the Product */
@@ -290,32 +290,31 @@
*/
const devTeamImageSize = 45;
const botImageSize = 45;
let teamImagePoint = {
x: 10,
y: 5
y: thisObject.container.frame.height / 2 - devTeamImageSize / 2
};
teamImagePoint = thisObject.container.frame.frameThisPoint(teamImagePoint);
let teamImage = document.getElementById("AAMasters");
browserCanvasContext.drawImage(teamImage, teamImagePoint.x, teamImagePoint.y, 45, 45);
let teamImage = document.getElementById(thisObject.bot.devTeam + ".png");
browserCanvasContext.drawImage(teamImage, teamImagePoint.x, teamImagePoint.y, devTeamImageSize, devTeamImageSize);
centerPoint = {
x: thisObject.container.frame.width - 10,
y: thisObject.container.frame.height / 2
};
if (thisObject.bot.codeName === "AAOlivia") {
if (thisObject.bot.profilePicture !== undefined) {
let botImagePoint = {
x: thisObject.container.frame.width - 10 - 50,
y: 5
y: thisObject.container.frame.height / 2 - botImageSize / 2
};
botImagePoint = thisObject.container.frame.frameThisPoint(botImagePoint);
let botImage = document.getElementById("AAOlivia");
browserCanvasContext.drawImage(botImage, botImagePoint.x, botImagePoint.y, 45, 45);
let imageId = thisObject.bot.devTeam + "." + thisObject.bot.profilePicture;
let botImage = document.getElementById(imageId);
browserCanvasContext.drawImage(botImage, botImagePoint.x, botImagePoint.y, botImageSize, botImageSize);
}
@@ -379,7 +378,7 @@
labelPoint = {
x: 65,
y: thisObject.container.frame.height - 45
y: thisObject.container.frame.height / 2 - 15
};
labelPoint = thisObject.container.frame.frameThisPoint(labelPoint);
@@ -393,7 +392,7 @@
labelPoint = {
x: 65,
y: thisObject.container.frame.height - 30
y: thisObject.container.frame.height / 2 - 0
};
labelPoint = thisObject.container.frame.frameThisPoint(labelPoint);
@@ -407,7 +406,7 @@
labelPoint = {
x: 65,
y: thisObject.container.frame.height - 15
y: thisObject.container.frame.height / 2 + 15
};
labelPoint = thisObject.container.frame.frameThisPoint(labelPoint);
+3 -1
View File
@@ -75,6 +75,8 @@
<body id="body" style="margin: 0px; padding: 0px; border: 0px; overflow:hidden;" onload="dashboardStart();">
<canvas id="canvas" width="1400" height="600" border="0"></canvas>
<img id="AAMasters" width="0" height="0" src="https://avatars2.githubusercontent.com/u/36243600?s=400&u=4df23798487a2853d211e764efa55233b1147ddb&v=4">
<img id="AAOlivia" width="0" height="0" src="https://raw.githubusercontent.com/AAMasters/AAOlivia-Indicator-Bot/master/ProfilePicture.png">
<!--Images-->
</body>
</html>
+285 -34
View File
@@ -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' +
' <script type="text/javascript" src="Plotters/@devTeam@/@repo@/@module@.js"></script>'
function addPlotters() {
let devTeams = ecosystemObject.devTeams;
let hosts = ecosystemObject.hosts;
let htmlLine = '' + '\n' +
' <script type="text/javascript" src="Plotters/@devTeam@/@repo@/@module@.js"></script>'
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('<!--Plotters-->') + 15);
let secondPart = fileContent.substring(fileContent.indexOf('<!--Plotters-->') + 15);
fileContent = firstPart + stringToInsert + secondPart;
}
}
}
}
}
function addImages() {
const htmlLine = '' + '\n' +
' <img id="@id@" width="0" height="0" src="https://raw.githubusercontent.com/@devTeam@/@repo@/master/@image@">'
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('<!--Plotters-->') + 15);
let secondPart = fileContent.substring(fileContent.indexOf('<!--Plotters-->') + 15);
let firstPart = fileContent.substring(0, fileContent.indexOf('<!--Images-->') + 15);
let secondPart = fileContent.substring(fileContent.indexOf('<!--Images-->') + 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('<!--Images-->') + 15);
let secondPart = fileContent.substring(fileContent.indexOf('<!--Images-->') + 15);
fileContent = firstPart + stringToInsert + secondPart;
}
}
}
}
}
respondWithContent(fileContent, response);