Skip to content

Commit

Permalink
Fixes partly fossasia#160 added button to add mutiple giturl input box
Browse files Browse the repository at this point in the history
  • Loading branch information
poonai committed Jun 23, 2017
1 parent 5912511 commit a1c8111
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 52 deletions.
75 changes: 38 additions & 37 deletions backend/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,42 @@ exports.executeScript = function (socket, formData) {
socket.emit('err-logs', "Failed to generated documentation due to an error in input fields");
return false;
}
var email = formData.email;
var gitUrl = formData.gitUrl;
var docTheme = formData.docTheme;
var uniqueId = uuidV4();
var webUI = "true"

var donePercent = 0;

const args = [
"-g", gitUrl,
"-t", docTheme,
"-m", email,
"-u", uniqueId,
"-w", webUI
];

var process = spawn("./generate.sh", args);

process.stdout.on('data', function (data) {
console.log(data.toString());
socket.emit('logs', {donePercent: (donePercent = donePercent + 4), data: data.toString()});
});

process.stderr.on('data', function (data) {
console.log(data.toString());
socket.emit('err-logs', data.toString());
});

process.on('exit', function (code) {
console.log('child process exited with code ' + code);
if (code === 0) {
socket.emit('success', {email: email, uniqueId: uniqueId, gitUrl: gitUrl});
} else {
socket.emit('failure', {errorCode: code});
}
});
return true;
var email = formData.email;
var gitUrl = formData.gitUrl[0];
var docTheme = formData.docTheme;
var webUI = "true"

var uniqueId = uuidV4();
var donePercent = 0;

const args = [
"-g", gitUrl,
"-t", docTheme,
"-m", email,
"-u", uniqueId,
"-w", webUI
];

var process = spawn("./generate.sh", args);

process.stdout.on('data', function (data) {
console.log(data.toString());
socket.emit('logs', {donePercent: (donePercent = donePercent + 4), data: data.toString()});
});

process.stderr.on('data', function (data) {
console.log(data.toString());
socket.emit('err-logs', data.toString());
});

process.on('exit', function (code) {
console.log('child process exited with code ' + code);
if (code === 0) {
socket.emit('success', {email: email, uniqueId: uniqueId, gitUrl: gitUrl});
} else {
socket.emit('failure', {errorCode: code});
}
});
return true;
}
};
6 changes: 3 additions & 3 deletions modules/scripts/genindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_toctree(dirpath, filenames):
toctree = ['.. toctree::', ' :maxdepth: 1']
caption_template = ' :caption: {caption}'
content_template = ' {document}'

caption = os.path.basename(dirpath).replace('_', ' ').title()
if caption == os.curdir:
caption = 'Contents'
Expand Down Expand Up @@ -52,9 +52,9 @@ def get_index(root):
index.append(get_include(root, 'README.rst'))
elif 'README.md' in root_files:
index.append(get_include(root, 'README.md'))

# Add toctrees as per the directory structure
for (dirpath, dirnames, filenames) in os.walk(os.curdir):
for (dirpath, dirnames, filenames) in os.walk(root):
if filenames:
toctree = get_toctree(dirpath, filenames)
if toctree:
Expand Down
17 changes: 13 additions & 4 deletions public/scripts/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ $(function () {
$("#btnGenerate").click(function () {
var formData = getData();

if (validation.isValid(formData)) {
socket.emit('execute', formData);
if (validation.isValid(formData)) {
socket.emit('execute', formData);
$(this).attr("disabled", "none");
} else {
$('.notification').append($('<li>')).text(validation.getMessages());
Expand Down Expand Up @@ -69,9 +69,18 @@ function getData() {
var formData = $("form").serializeArray();
$.each(formData, function (i, field) {
if (field.name === "email") { data.email = field.value.trim(); }
if (field.name === "git_url") { data.gitUrl = field.value.trim(); }
if (field.name === "git_url[]") {
if (data.git_url == undefined) {
data.git_url = [field.value]
} else {
data.git_url.push(field.value)
}
}
if (field.name === "doc_theme") { data.docTheme = field.value.trim(); }
});

return data;
}

function add() {
$("#git_input").append(`<input id="git_url" placeholder="Enter URL of Github Repository" name="git_url[]" class="form-control" type="text">`)
}
11 changes: 7 additions & 4 deletions public/scripts/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
}
}

if (formData.gitUrl !== "") {
if (formData.gitUrl.length > 0) {
regex = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/;
if(!regex.test(formData.gitUrl)) {
messages.push("Invalid URL");
valid = false;
for (var i = 0; i < formData.gitUrl.length; i++) {
if(!regex.test(formData.gitUrl[i])) {
messages.push("Invalid URL");
valid = false;
break;
}
}
}

Expand Down
13 changes: 12 additions & 1 deletion public/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ a {
#btnGenerate {
margin-bottom: 20px;
}
#btnAdd {
width: -moz-fit-content;
margin-bottom: 20px;
margin-left: 10px;
}

#btnDownload {
display: none;
Expand All @@ -52,6 +57,8 @@ a {
margin-left: 10px;
}



#notification-container {
position: absolute;
text-align: center;
Expand Down Expand Up @@ -95,4 +102,8 @@ a {
font-size: .7em;
opacity: 1;
font-weight: 700;
}
}

#git_url {
margin-bottom: 10px;
}
8 changes: 5 additions & 3 deletions views/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ block content
.form-group
label.control-label(for='email') Email:
input#email.form-control(type='email', placeholder='Enter Email', name='email', required='')
.form-group
label.control-label(for='git_url') GITURL:
input#git_url.form-control(type='text', placeholder='Enter URL of Github Repository', name='git_url')
.div#git_input
.form-group
label.control-label(for='git_url') GITURL:
input#git_url.form-control(type='text', placeholder='Enter URL of Github Repository', name='git_url[]')
.form-group
label.control-label(for='doc_theme') Doc Theme:
select#doc_theme.form-control(name='doc_theme')
Expand All @@ -36,6 +37,7 @@ block content
option(value='rtcat_sphinx_theme') rtcat_sphinx_theme
.form-group#buttons
button.btn.btn-default(type='button' id='btnGenerate') Generate Docs
button.btn.btn-default(type='button' id='btnAdd' onclick="add()") Add Repository
.row
a.btn.btn-default(type='button' id='btnDownload') Download
a.btn.btn-default(type='button' id='btnPreview' target='_blank') Preview
Expand Down

0 comments on commit a1c8111

Please sign in to comment.