Plotter Panels downloaded to the browser

This commit is contained in:
Luis Fernando Molina committed 2018-04-20 18:40:27 +02:00
1 parent e62fe04b14
commit 0b621b5b6a
7 files changed
+296 -8

No files matched your search

Binary file not shown.
+128
View File
@@ -0,0 +1,128 @@
function newImageButton() {
var thisObject = {
container: undefined,
draw: draw,
status: 'neutral',
type: undefined,
getContainer: getContainer,
initialize: initialize
};
var container = newContainer();
container.initialize();
container.isDraggeable = false;
container.isZoomeable = false;
container.isClickeable = true;
thisObject.container = container;
let idNeutralImage;
let idOnImage;
let idOffImage;
let idDisabledImage;
return thisObject;
function initialize(pX, pY, pWidth, pHeight, pIdNeutralImage, pIdOnImage, pIdOffImage, pIdDisabledImage) {
idNeutralImage = pIdNeutralImage;
idOnImage = pIdOnImage;
idOffImage = pIdOffImage;
idDisabledImage = pIdDisabledImage;
/* Lets set the basic dimensions of this thisObject. */
var position = {
x: pX,
y: pY
};
thisObject.container.frame.position = position;
thisObject.container.frame.width = pWidth;
thisObject.container.frame.height = pHeight;
/* Now we start listening to the onClick event from the mouse, so that we can allow users operate this thisObject. */
thisObject.container.eventHandler.listenToEvent('onMouseClick', buttonPressed, undefined);
}
function getContainer(point) {
var container;
/* First we check if this point is inside this space. */
if (this.container.frame.isThisPointHere(point, true) === true) {
return this.container;
} else {
/* This point does not belong to this space. */
return undefined;
}
}
function buttonPressed(event, extraData) {
switch (thisObject.status) {
case 'neutral':
browserCanvasContext.fillStyle = onFillStyle;
return;
case 'on':
thisObject.status = 'off';
break;
case 'off':
thisObject.status = 'on';
break;
case 'disabled':
return;
}
}
function draw() {
drawImage();
}
function drawImage() {
let image;
let imagePoint = {
x: 0,
y: 0
};
imagePoint = thisObject.container.frame.frameThisPoint(imagePoint);
switch (thisObject.status) {
case 'neutral':
image = document.getElementById(idNeutralImage);
break;
case 'on':
image = document.getElementById(idOnImage);
break;
case 'off':
image = document.getElementById(idOffImage);
break;
case 'disabled':
image = document.getElementById(idDisabledImage);
break;
}
browserCanvasContext.drawImage(image, imagePoint.x, imagePoint.y, thisObject.container.frame.width, thisObject.container.frame.height);
}
}
+2 -2
View File
@@ -1,9 +1,9 @@
function getNewPlotter(pDevTeamOrHost, pRepo, pModule) {
function getNewPlotter(pDevTeamOrHost, pPlotter, pModule) {
let plotter;
let fullCode = pDevTeamOrHost + pRepo + pModule;
let fullCode = pDevTeamOrHost + pPlotter + pModule;
fullCode = fullCode.replace(/-/g, "");
switch (fullCode) {
+19
View File
@@ -0,0 +1,19 @@
function getNewPlotterPanel(pDevTeamOrHost, pPlotter, pModule, pPanel) {
let plotterPanel;
let fullCode = pDevTeamOrHost + pPlotter + pModule + pPanel;
fullCode = fullCode.replace(/-/g, "");
switch (fullCode) {
// Cases
default:
{
throw ("getNewPlotterPanel: " + fullCode + " not found.")
}
}
return plotterPanel;
}
+7 -1
View File
@@ -38,6 +38,12 @@
<Compile Include="CompetitionStorage.js">
<SubType>Code</SubType>
</Compile>
<Compile Include="ImageButton.js">
<SubType>Code</SubType>
</Compile>
<Compile Include="PlotterPanel.js">
<SubType>Code</SubType>
</Compile>
<Compile Include="ProductCard.js">
<SubType>Code</SubType>
</Compile>
@@ -68,7 +74,7 @@
<Compile Include="FileCache.js">
<SubType>Code</SubType>
</Compile>
<Compile Include="Plotters.js">
<Compile Include="Plotter.js">
<SubType>Code</SubType>
</Compile>
<Compile Include="server.js" />
+9 -1
View File
@@ -4,9 +4,16 @@
<meta charset="utf-8" />
<title>Advanced Algos</title>
<!--Plotters-->
<script type="text/javascript" src="Plotters.js"></script>
<!--PlotterPanels-->
<script type="text/javascript" src="Plotter.js"></script>
<script type="text/javascript" src="PlotterPanel.js"></script>
<script type="text/javascript" src="ProductStorage.js"></script>
<script type="text/javascript" src="CompetitionStorage.js"></script>
<script type="text/javascript" src="ProductCard.js"></script>
@@ -21,6 +28,7 @@
<script type="text/javascript" src="Canvas.js"></script>
<script type="text/javascript" src="Button.js"></script>
<script type="text/javascript" src="TextButton.js"></script>
<script type="text/javascript" src="ImageButton.js"></script>
<script type="text/javascript" src="EventHandler.js"></script>
<script type="text/javascript" src="Frame.js"></script>
<script type="text/javascript" src="Container.js"></script>
+131 -4
View File
@@ -542,7 +542,7 @@ function onBrowserRequest(request, response) {
}
break;
case "Plotters.js":
case "Plotter.js":
{
/*
@@ -554,7 +554,7 @@ function onBrowserRequest(request, response) {
let fs = require('fs');
try {
let fileName = 'Plotters.js';
let fileName = 'Plotter.js';
fs.readFile(fileName, onFileRead);
function onFileRead(err, file) {
@@ -626,6 +626,95 @@ function onBrowserRequest(request, response) {
}
break;
case "PlotterPanel.js":
{
/*
This file is build dinamically because it has the code to instantiate the different configured Plotter Panels. The instantiation code
will be generated using a pre-defined string with replacement points. We will go through the configuration file to learn
about all the possible plotters panels the system can load.
*/
let fs = require('fs');
try {
let fileName = 'PlotterPanel.js';
fs.readFile(fileName, onFileRead);
function onFileRead(err, file) {
try {
let fileContent = file.toString();
/* This is the string we will use to insert into the Plotters.js script. */
let caseString = '' +
' case "@newFunctionName@":' + '\n' +
' {' + '\n' +
' plotterPanel = newPlotterPanelName();' + '\n' +
' }' + '\n' +
' break;' + '\n' + '\n'
let devTeams = ecosystemObject.devTeams;
let hosts = ecosystemObject.hosts;
addToFileContent(devTeams);
addToFileContent(hosts);
function addToFileContent(pDevTeamsOrHosts) {
for (let i = 0; i < pDevTeamsOrHosts.length; i++) {
let devTeam = pDevTeamsOrHosts[i];
for (let j = 0; j < devTeam.plotters.length; j++) {
let plotter = devTeam.plotters[j];
for (let k = 0; k < plotter.modules.length; k++) {
let module = plotter.modules[k];
for (let l = 0; l < module.panels.length; l++) {
let panel = module.panels[l];
let caseStringCopy = caseString;
let newFunctionName = devTeam.codeName + plotter.codeName + module.codeName + panel.codeName;
newFunctionName = newFunctionName.replace(/-/g, "");
let stringToInsert;
stringToInsert = caseStringCopy.replace('@newFunctionName@', newFunctionName);
stringToInsert = stringToInsert.replace('newPlotterPanelName', 'new' + newFunctionName);
let firstPart = fileContent.substring(0, fileContent.indexOf('// Cases'));
let secondPart = fileContent.substring(fileContent.indexOf('// Cases'));
fileContent = firstPart + stringToInsert + secondPart;
}
}
}
}
}
respondWithContent(fileContent, response);
}
catch (err) {
console.log("File Not Found: " + fileName + " or Error = " + err);
}
}
}
catch (err) {
console.log(err);
}
}
break;
case "Ecosystem.js":
{
/*
@@ -685,6 +774,25 @@ function onBrowserRequest(request, response) {
}
break;
case "PlotterPanels": // This means the PlotterPanels folder, not to be confused with the Plotter Panels scripts!
{
if (DEBUG_MODE === true) {
respondWithFile('../Plotters/' + requestParameters[2] + '/' + requestParameters[3] + '/' + requestParameters[4], response);
} else {
getGithubData(requestParameters[2], requestParameters[3], requestParameters[4], onDataArrived)
function onDataArrived(pData) {
respondWithContent(pData, response);
}
}
}
break;
case "Panels":
{
respondWithFile('./' + requestParameters[1] + '/' + requestParameters[2], response);
@@ -724,9 +832,12 @@ function onBrowserRequest(request, response) {
function addPlotters() {
let htmlLine = '' + '\n' +
let htmlLinePlotter = '' + '\n' +
' <script type="text/javascript" src="Plotters/@devTeam@/@repo@/@module@.js"></script>'
let htmlLinePlotterPanel = '' + '\n' +
' <script type="text/javascript" src="PlotterPanels/@devTeam@/@repo@/@module@.js"></script>'
let devTeams = ecosystemObject.devTeams;
let hosts = ecosystemObject.hosts;
@@ -747,7 +858,7 @@ function onBrowserRequest(request, response) {
let module = plotter.modules[k];
let htmlLineCopy = htmlLine;
let htmlLineCopy = htmlLinePlotter;
let stringToInsert;
stringToInsert = htmlLineCopy.replace('@devTeam@', devTeam.codeName);
@@ -759,6 +870,22 @@ function onBrowserRequest(request, response) {
fileContent = firstPart + stringToInsert + secondPart;
for (let l = 0; l < module.panels.length; l++) {
let panel = module.panels[l];
let htmlLineCopy = htmlLinePlotterPanel;
let stringToInsert;
stringToInsert = htmlLineCopy.replace('@devTeam@', devTeam.codeName);
stringToInsert = stringToInsert.replace('@repo@', plotter.repo);
stringToInsert = stringToInsert.replace('@module@', panel.moduleName);
let firstPart = fileContent.substring(0, fileContent.indexOf('<!--PlotterPanels-->') + 20);
let secondPart = fileContent.substring(fileContent.indexOf('<!--PlotterPanels-->') + 20);
fileContent = firstPart + stringToInsert + secondPart;
}
}
}
}