Initial Commit

This commit is contained in:
Wu
2020-12-19 17:14:40 +00:00
commit 62d68374e1
29 changed files with 2681 additions and 0 deletions

View File

@@ -0,0 +1,92 @@
$( document ).ready( () => {
$('body').scrollspy({ target: '#main-nav', offset: 130 })
$('#fullpage').fullpage({
// anchors: ['underPage', 'gradPage', 'phdPage'],
sectionsColor: ['#ffffff', '#f8f8f8'],
autoScrolling: false,
css3: true,
fitToSection: false,
afterLoad: function(anchorLink, index) {
// history.pushState(null, null, "");
// console.log(anchorLink);
}
});
$("a").on('click', function(event) {
// Make sure this.hash has a value before overriding default behavior
if (this.hash !== "") {
// Prevent default anchor click behavior
event.preventDefault();
// Store hash
var hash = this.hash;
// Using jQuery's animate() method to add smooth page scroll
// The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
var offset = 0;
if (hash === "#home")
{
offset = -100;
}
else {
offset = -60;
}
$('html, body').animate({
scrollTop: ($(hash).offset().top + offset)
}, 1000, function(){
// Add hash (#) to URL when done scrolling (default click behavior)
// window.location.hash = hash;
});
}
});
// initialize with defaults
// $("#uploadfile").fileinput();
// with plugin options
$("#uploadfile").fileinput({
// theme: "fa",
'theme': 'fas',
showUpload:false,
previewFileType:'py',
maxFileCount: 1,
allowedFileExtensions: ["py"]
});
ConsoleLogHTML.connect(document.getElementById("console")); // Redirect log messages
// ConsoleLogHTML.disconnect(); // Stop redirecting
var url = window.location;
// GET REQUEST
$("#btnGetFiles").click( (event) => {
event.preventDefault();
ajaxGet();
});
// DO GET
function ajaxGet(){
$.ajax({
type : "GET",
url : "/api/files/getall",
success: (data) => {
//clear old data
$("#listFiles").html("");
/*
render list of files
*/
$("#listFiles").append('<ul>');
$.each(data, (index, filename) => {
$("#listFiles").append('<li><a href=' + url + 'api/files/' + filename +'>' + filename + '</a></li>');
});
$("#listFiles").append('</ul>');
},
error : (err) => {
$("#listFiles").html(err.responseText);
}
});
}
})

View File

@@ -0,0 +1,81 @@
// warn the user when leaving
window.onbeforeunload = function(){
return "Make sure to save your graph locally before leaving";
};
var socket = io();
socket.on('connect', () => {
$("#session_id").text(socket.id);
window.id = socket.id
console.log('Session Id: ', socket.id); // an alphanumeric id...
});
socket.on('users_count', (clients) => {
$("#user_counts").text(clients);
});
socket.on('start', () => {
console.log('Building start');
});
$(document).ready( () => {
$("#btnSubmit").click((event) => {
//stop submit the form, we will post it manually.
event.preventDefault();
doAjax();
});
$('#uploadfile').change(function(e){
if(e.target.files[0])
{
var fileName = e.target.files[0].name;
if(fileName !== "my_model.py")
{
alert('Please upload my_model.py');
$('#btnSubmit').prop('disabled', true);
}
else
{
$('#btnSubmit').prop('disabled', false);
}
}
});
});
function doAjax() {
// Get form
var form = $('#fileUploadForm')[0];
var data = new FormData(form);
var file = data.get('uploadfile');
var renameFile =new File([file], window.id + '.py' ,{type:file.type});
var formdata = new FormData();
formdata.append('uploadfile', renameFile);
// console.log(formdata.get('uploadfile'))
if(window.id) {
$.ajax({
type: "POST",
enctype: 'multipart/form-data',
url: "/api/files/upload",
data: formdata,
processData: false, //prevent jQuery from automatically transforming the data into a query string
contentType: false,
cache: false,
success: (data) => {
// $("#listFiles").text(data);
console.log('Emit build request')
socket.emit('build', {});
},
error: (e) => {
$("#listFiles").text(e.responseText);
}
});
}
else
{
alert('Failed to connect to server');
}
}