Skip to content

Commit

Permalink
Allow setting classXML, outputDir and namespaceholder before execution.
Browse files Browse the repository at this point in the history
  • Loading branch information
weshouman committed Sep 9, 2018
1 parent 0556c9d commit 8f0928c
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 11 deletions.
112 changes: 103 additions & 9 deletions app/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,95 @@
'use strict'

function getClassXMLDir(){
// // Use a real directory
// var classXMLDirValue = "'/home/walid/shared_on_wifi/xml/'"
// // Use null to be translated to None by the json parser
// // Follow https://docs.python.org/2/library/json.html#encoders-and-decoders
// classXMLDirValue = "null"

var classXMLDir = "";

var checkboxValue = document.getElementById('class_xml_dir_check').checked;
if (checkboxValue == true) {
var classXMLDirValue;

var textValue = document.getElementById('class_xml_dir_text').value;
if (textValue == '') {
classXMLDirValue = "null";
}
else {
classXMLDirValue = "\""+ textValue +"\"";
}

classXMLDir = '\"classXMLDir\":' + classXMLDirValue;
}

return classXMLDir;
}

function getClassXML(){
var classXML = "";

var checkboxValue = document.getElementById('class_xml_check').checked;
if (checkboxValue == true) {
var classXMLValue;

var textValue = document.getElementById('class_xml_text').value;
if (textValue == '') {
classXMLValue = "null";
}
else {
classXMLValue = "\""+ textValue +"\"";
}

classXML = '\"classXML\":' + classXMLValue;
}

return classXML;
}

function getNamespacePlaceholder(){
var namespacePlaceholder = "";

var checkboxValue = document.getElementById('namespace_placeholder_check').checked;
if (checkboxValue == true) {
var namespacePlaceholderValue;

var textValue = document.getElementById('namespace_placeholder_text').value;
if (textValue == '') {
namespacePlaceholderValue = "null";
}
else {
namespacePlaceholderValue = "\""+ textValue +"\"";
}

namespacePlaceholder = '\"NAMESPACE_PLACEHOLDER\":' + namespacePlaceholderValue;
}

return namespacePlaceholder;
}

function getOutputDir(){
var outputDir = "";

var checkboxValue = document.getElementById('output_dir_check').checked;
if (checkboxValue == true) {
var outputDirValue;

var textValue = document.getElementById('output_dir_text').value;
if (textValue == '') {
outputDirValue = "null";
}
else {
outputDirValue = "\""+ textValue +"\"";
}

outputDir = '\"OUTPUT_DIR\":' + outputDirValue;
}

return outputDir;
}

function attachDOMListeners(){
document.getElementById('run_langform').addEventListener('click', () => {
//langform_start
Expand All @@ -10,16 +100,21 @@ function attachDOMListeners(){

var executablePath = "/home/walid/Documents/python_shell_simple_com/zmq_client";

// Use a real directory
var classXMLDirValue = "'/home/walid/shared_on_wifi/xml/'"
// Use null to be translated to None by the json parser
// Follow https://docs.python.org/2/library/json.html#encoders-and-decoders
classXMLDirValue = "null"

var classXMLDir = '\"classXMLDir\":' + classXMLDirValue +''
var classXMLDir = getClassXMLDir();
var classXML = getClassXML();
var namespacePlaceholder = getNamespacePlaceholder();
var outputDir = getOutputDir();

var settings = "\"settings\": {"
settings += classXMLDir

if (classXMLDir != "" && classXML != "")
settings += classXMLDir + ", ";
if (classXML != "" && namespacePlaceholder != "")
settings += classXML + ", ";
if (namespacePlaceholder != "" && outputDir != "")
settings += namespacePlaceholder + ", ";
settings += outputDir;

settings += "}"

var msg = "{" + settings + "}"
Expand All @@ -29,7 +124,6 @@ function attachDOMListeners(){

var parameters = ["--msg="+msg, "--localhost="+localhost, "--port="+port];


console.log("Set to send: "+ msg +" over "+ localhost +":"+ port +".");

var fs = require('fs');
Expand Down
24 changes: 22 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,30 @@
<h3>Set Langform Settings and Run:</h3>
<br>
<div class="row">
<div class="five columns">
<div class="setting">
<label for="classXMLDir">Class XML Dir</label>
<input class="u-full-width" placeholder="eg: /home/walid/tutorial/docs/xml" id="class_xml_dir" type="text">
<input type="checkbox" id="class_xml_dir_check" checked><label for="class_xml_dir_label"> Overwrite default </label>
<input type="text" id="class_xml_dir_text" class="u-full-width" placeholder="eg: /home/walid/tutorial/docs/xml" value="/home/walid/shared_on_wifi/xml/">
</div>

<div class="setting">
<label for="classXMLDir">Class XML</label>
<input type="checkbox" id="class_xml_check" checked><label for="class_xml_label"> Overwrite default </label>
<input type="text" id="class_xml_text" class="u-full-width" placeholder="eg: /home/walid/tutorial/docs/xml/classEntry.xml" value="/home/walid/shared_on_wifi/classEntry.xml">
</div>

<div class="setting">
<label for="classXMLDir">Namespace placeholder</label>
<input type="checkbox" id="namespace_placeholder_check" checked><label for="namespace_placeholder_label"> Overwrite default </label>
<input type="text" id="namespace_placeholder_text" class="u-full-width" placeholder="eg: __ns__" value="__ns__">
</div>

<div class="setting">
<label for="classXMLDir">Output Directory</label>
<input type="checkbox" id="output_dir_check" checked><label for="output_dir_label"> Overwrite default </label>
<input type="text" id="output_dir_text" class="u-full-width" placeholder="eg: generated/" value="generated/">
</div>

<div class="two columns">
<label for="run langform" class="invisible"></label>
<input class="button-primary" value="run" id="run_langform" type="button">
Expand Down

0 comments on commit 8f0928c

Please sign in to comment.