Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Profiling System #41

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions hackIDE/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ class codes(Document):
run_status_memory=StringField(required=True)
run_status_output=StringField(required=True)
run_status_stderr=StringField(required=True)


class Users(Document):
username = StringField(required=True)
email = StringField(required=True)
password = StringField(required=True)
code = ListField()
title = ListField()
278 changes: 278 additions & 0 deletions hackIDE/static/hackIDE/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,4 +751,282 @@ $(document).ready(function(){
}


$("#register").click(function(){
var username = $('#signup_username').val();
var email = $("#signup_email").val();
var password = $("#signup_password").val();

$("#register").html("Registering");
$("#register").prop('disabled', true);

var csrf_token = $(":input[name='csrfmiddlewaretoken']").val();
var form_data = {username : username, email : email, password : password, csrfmiddlewaretoken : csrf_token};
$.ajax({
url : 'register/',
type : 'POST',
data : form_data,
dataType : 'json',
timeout : '10000',
success : function(response){
$("#error_username").html(response.error_username);
$("#error_email").html(response.error_email);
$("#error_password").html(response.error_password);

$("#register").prop('disabled', false);
$("#register").html("Register");

$("#msg").html(response.msg);
if (response.error_username == "" && response.error_email == "" && response.error_password == "")
{
$("#register").html("Registered");
location.reload();
}
},
});
});

$('#login').click(function(){
var username = $('#login_username').val();
var password = $("#login_password").val();

$("#login").html("Logging In");
$("#login").prop("disabled", true);
var csrf_token = $(":input[name='csrfmiddlewaretoken']").val();

var login_form_data = {username : username, password : password, csrfmiddlewaretoken : csrf_token};

$.ajax({
url : 'login/',
type : 'POST',
data : login_form_data,
dataType : 'json',
timeout : 10000,
success : function(response){

$("#login").prop("disabled", false);
$("#login").html("Login");

$('#login_msg').html(response.msg);
if(response.msg != "Invalid credentials")
{
$("#login").html("Logged In Sucessfully");
location.reload();
}

},
});
});

$("#logout").click(function(){
var csrf_token = $(":input[name='csrfmiddlewaretoken']").val();
logout_data = {csrfmiddlewaretoken:csrf_token}

$.ajax({
url : 'logout/',
type : 'POST',
data : logout_data,
dataType : 'json',
timeout : 10000,
success : function(response){
location.reload();
},
});
});

$("#title-save").click(function(){

// if a run request is ongoing
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all the code in this callback function is repeated, can you put it into a separate function and call it everywhere this code is repeated?

if(request_ongoing)
return;

$("#error_save_title").html("");
$("#save-code-profile").html("Saving");
$("#title-save").html("Saving");
// disable button when this method is called
$("#title-save").prop('disabled', true);
$("#compile-code").prop('disabled', true);
$("#run-code").prop('disabled', true);
$("#save-code-profile").prop('disabled', true);

// take recent content of the editor for compiling
updateContent();

var csrf_token = $(":input[name='csrfmiddlewaretoken']").val();

// if code_id present in url and update run URL
if(window.location.href.includes('code_id')) {
RUN_URL = '/../run/';
}

var input_given = $("#custom-input").val();
var code_title = $('#code-title').val();

request_ongoing = true;

if( $("#custom-input-checkbox").prop('checked') == true ){
var run_data = {
source: editorContent,
lang: languageSelected,
input: input_given,
code_title: code_title,
csrfmiddlewaretoken: csrf_token
};
// AJAX request to Django for running code with input
$.ajax({
url: 'savetoprofile/',
type: "POST",
data: run_data,
dataType: "json",
timeout: 10000,
success: function(response){
request_ongoing = false;
if ("error_save_title" in response){
$("#error_save_title").html(response.error_save_title);
$("#title-save").html("Save");
$("#save-code-profile").html("Save Code To Profile");
$("#compile-code").prop('disabled', false);
$("#run-code").prop('disabled', false);
$("#title-save").prop("disabled", false);
$("#save-code-profile").prop("disabled", false);
}
else
{
$("#save-code-profile").html("Save Code To Profile");
// enable button when this method is called
$("#compile-code").prop('disabled', false);
$("#run-code").prop('disabled', false);
$("#save-code-profile").prop('disabled', true);
$("#save-code-profile").html("Saved");
$("#title-save").html("Saved");
$("#code-title").val("");
}
},
error: function(error){

request_ongoing = false;
$("#save-code-profile").html("Save Code To Profile");
// enable button when this method is called
$("#compile-code").prop('disabled', false);
$("#run-code").prop('disabled', false);
$("#save-code-profile").prop('disabled', false);
}
});
}
else{
var run_data = {
source: editorContent,
lang: languageSelected,
code_title: code_title,
csrfmiddlewaretoken: csrf_token
};
// AJAX request to Django for running code without input\
var timeout_ms = 10000;
$.ajax({
url: 'savetoprofile/',
type: "POST",
data: run_data,
dataType: "json",
timeout: timeout_ms,
success: function(response){
request_ongoing = false;
if ("error_save_title" in response){
$("#error_save_title").html(response.error_save_title);
$("#title-save").html("Save");
$("#save-code-profile").html("Save Code To Profile");
$("#compile-code").prop('disabled', false);
$("#run-code").prop('disabled', false);
$("#title-save").prop("disabled", false);
$("#save-code-profile").prop("disabled", false);
}
else
{

$("#save-code-profile").html("Save Code To Profile");
// enable button when this method is called
$("#compile-code").prop('disabled', false);
$("#run-code").prop('disabled', false);
$("#save-code-profile").prop('disabled', true);
$("#save-code-profile").html("Saved");

$("#title-save").html("Saved");
$("#code-title").val("");
}
},
error: function(error){

request_ongoing = false;
$("#save-code-profile").html("Save Code To Profile");
// enable button when this method is called
$("#compile-code").prop('disabled', false);
$("#run-code").prop('disabled', false);
$("#save-code-profile").prop('disabled', false);
}
});
}

});

$("#data_table").on('click', '#close_data', function(){

var i = $(this).closest('tr').attr('id');
var parent = $(this).closest('tr');
var csrf_token = $(":input[name='csrfmiddlewaretoken']").val();
var remove_data = {csrfmiddlewaretoken:csrf_token, id:i};

$.ajax({
url: 'removecode/',
type: "POST",
data: remove_data,
dataType: "json",
timeout: 10000,
success : function(response){
parent.fadeOut('slow', function(){
parent.remove();
});
},
});
});

$("#profile_btn").click(function(){
var csrf_token = $(":input[name='csrfmiddlewaretoken']").val();

var profile_data = {csrfmiddlewaretoken:csrf_token};
$.ajax({
url: 'displayprofile/',
type: "POST",
data: profile_data,
dataType: "json",
timeout: 10000,
success : function(response){
$("#data_table").html("<tr><th>Code Id</th><th>Title</th><th></th></tr>");
if(location.port == "")
{
for(var i=0;i<response.code_id.length;i++)
{
var link = window.location.hostname + "/code_id=" + response.id[i] + "/";
$("#data_table").append("<tr id='"+ response.code_id[i] +"'><td>"+response.code_id[i]+"</td><td>"+ response.code_title[i] +"</td><td><a href='"+ link +"' class='btn btn-success'>Open</a><button type='button' id='close_data' class='close'><span id='close_data'>&times;</span></button></td></tr>");
}
}
else
{
for(var i=0;i<response.code_id.length;i++)
{
var link = window.location.hostname + ":" + location.port +"/code_id=" + response.code_id[i] + "/";
$("#data_table").append("<tr id='"+ response.code_id[i] +"'><td>"+response.code_id[i]+"</td><td>"+ response.code_title[i] +"</td><td><a href='"+ link +"' class='btn btn-success'>Open</a><button type='button' id='close_data' class='close'><span id='close_data'>&times;</span></button></td></tr>");
}
}
},

});

});


editor.on('change', function(){
$("#title-save").prop('disabled', false);
$("#title-save").html("Save");

$("#save-code-profile").prop('disabled', false);
$("#save-code-profile").html("Save Code To Profile");
});
});
Loading