From 0b621b5b6a2e4d1194c1ce1a718b0f0432e32ba5 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 20 Apr 2018 18:40:27 +0200 Subject: [PATCH] Plotter Panels downloaded to the browser --- .vs/AAWeb/v15/.suo | Bin 38912 -> 41984 bytes ImageButton.js | 128 ++++++++++++++++++++++++++++++++++++ Plotters.js => Plotter.js | 4 +- PlotterPanel.js | 19 ++++++ Project.njsproj | 8 ++- index.html | 10 ++- server.js | 135 ++++++++++++++++++++++++++++++++++++-- 7 files changed, 296 insertions(+), 8 deletions(-) create mode 100644 ImageButton.js rename Plotters.js => Plotter.js (69%) create mode 100644 PlotterPanel.js diff --git a/.vs/AAWeb/v15/.suo b/.vs/AAWeb/v15/.suo index 9b74c487ae581f434052c3c535ca56f5f3964a4a..cf5017af6d679a6133cefc1502d5b0e623351702 100644 GIT binary patch literal 41984 zcmeHQdypK(d7qO2=|lnsJ&eRlD6)`+_OyGqw|6UHp?#dt(>kQn!{iL?-R_-E>^-u3 z5)zUu^E4PEWGmQC84^RVjT1j`fn6@*SdPm@;Xg3M1}c?c5Ki$hi7}2{WmhVo{C?Bj zyED5pJ2Shpy1Qa~>)Y;`>FKZg>+bLS`s>F$_w0EmANtOMSG5wiTAQxDcdA)C%W%KR z5Y|4RX)|#>4e;KnQ>XZd&k=06DMW#-+9-bG+Cr^M8-btG4zMa+yLsA~g*rdm;jOWs z{@*u#_;0^xx*YL-^cNy>H!zNBd$jeyK7de{w%;KY^W%Biv?e3D%}=ebj^Z|&ukI9n z;vLhn$U#oa0Jeb^DL_WXv-1|C2Q0$F^8n0;T|DFcb8xYV9S3fUwij5k+7QZ57&Kr` z;!aLPv;7DDCiYR%)Ghuci2L*`k>m_`?-~gx!|c-+;Th95KIXf|>kH)dCh5G5!>7UYP@?D zU=1J!hyxOUB!KwW!oM1@0iaUei0}siTMYNQ5mxzC@ur&ZXa84y3S_Z#-QV0W!v4RE zPd_B0sQy<&|1Z=LX>WEfg zPoKQ)3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7$#T;cve-a$P@CS`XEk@ASRteQl^|#)Wu=~_lk0OFeIOwON(R; zV-vt^>jIWDql}FQtlCdlU%kb@(mgHEI8$KQlt7LPOyn~DVw%9_wxuK$Qp+>o3XkVs zUZtW0C94f%IV-n= zvvZA{iF0vn+&*z>HW@m$*C<__1KoDF(g-15y?VREV*^;Keg18>$BGAEr7tjAeV?h< zW0qNgfB7)fV+2FhiKnkrz*618$4m+0PT?~`8B@ji!FGI?x~!$mUfSmHG{FT&4&?2s zhqDJl!PGp;#PtxN!PVU8fT(s8+-|N9t7>`0zNKMzbIU$EZD41KiGHiI$?kmK;n+*u zT%{hT%i$E4ftD8$wbJhFuscnyuFlRUQ=tHMwq&p&Via%ndYtyU2Krs@ayy(2d+esh zHbhLxbB1mK$0^}(tsRE@^5Jf4=F@P2Qgi`~>^1*)PO>bPsusCXny0z& z=o^<1H`iT6{}qz|;vcm*_bsk)mqD&W6G|~d&y4W*u+VBIL!`mkgkqMHnDAK?^%Mn= zVHBkvxlw&l6By|zX0cSI$c+jvYQp1heq7A#h(J|}NtMO(g^c{c{4ph4PSx!;Oq7$B z&kQcDW-5P789$2>v_2p0-LsTA~~<))c8tT=f^BBou~TjD~A91|`j`u&y>MX&-kGtJPA@#%;$! zI{#3o&FN^h?{<^A^M$?u<5eN>_LJ6$LxuAz(+7}=%*%R8fRr%F%ifVQVUlAcX!Q_1Y`MzeouZDfCT*l!z- zSG0Zi##`y*pQpbBcg->W44;3{f?9#bTDD?^P#~;cZ9PPOH^SAyWcaiv0~!Z>Xkjs= z98Y`}^mMMzf_^%}F|mkwV2+^I&lU7=bLXP@vl>u}z~^EW0QFudyH6dn%BV@E3!?!*u`v diff --git a/ImageButton.js b/ImageButton.js new file mode 100644 index 000000000..53f121454 --- /dev/null +++ b/ImageButton.js @@ -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); + } +} \ No newline at end of file diff --git a/Plotters.js b/Plotter.js similarity index 69% rename from Plotters.js rename to Plotter.js index a481a565a..b1d992d56 100644 --- a/Plotters.js +++ b/Plotter.js @@ -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) { diff --git a/PlotterPanel.js b/PlotterPanel.js new file mode 100644 index 000000000..78c9fb92a --- /dev/null +++ b/PlotterPanel.js @@ -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; +} diff --git a/Project.njsproj b/Project.njsproj index 3868188aa..78ae6fc7c 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -38,6 +38,12 @@ Code + + Code + + + Code + Code @@ -68,7 +74,7 @@ Code - + Code diff --git a/index.html b/index.html index b1baf360a..798f66039 100644 --- a/index.html +++ b/index.html @@ -4,9 +4,16 @@ Advanced Algos + - + + + + + + + @@ -21,6 +28,7 @@ + diff --git a/server.js b/server.js index 312d44aca..1b4f9ade0 100644 --- a/server.js +++ b/server.js @@ -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' + ' ' + let htmlLinePlotterPanel = '' + '\n' + + ' ' + 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('') + 20); + let secondPart = fileContent.substring(fileContent.indexOf('') + 20); + + fileContent = firstPart + stringToInsert + secondPart; + } } } }