From 10122ba4e0525c7729377aadbc8b28a95652ee47 Mon Sep 17 00:00:00 2001 From: sahil865gupta Date: Thu, 11 Aug 2016 21:46:31 +0530 Subject: [PATCH 1/6] added port no in old code links --- hackIDE/static/hackIDE/js/custom.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/hackIDE/static/hackIDE/js/custom.js b/hackIDE/static/hackIDE/js/custom.js index 682ee67..a66c4ca 100644 --- a/hackIDE/static/hackIDE/js/custom.js +++ b/hackIDE/static/hackIDE/js/custom.js @@ -364,7 +364,11 @@ $(document).ready(function(){ success: function(response){ request_ongoing = false; - $('#copy_code')[0].innerHTML = '' + window.location.hostname + '/code_id=' + response.code_id + '/'; + if(location.port == "") + $('#copy_code')[0].innerHTML = '' + window.location.hostname + '/code_id=' + response.code_id + '/'; + else + $('#copy_code')[0].innerHTML = '' + window.location.hostname + ':' + location.port +'/code_id=' + response.code_id + '/'; + $('#copy_code').css({'display': 'initial'}); // Change button text when this method is called @@ -464,7 +468,11 @@ $(document).ready(function(){ dataType: "json", timeout: timeout_ms, success: function(response){ - $('#copy_code')[0].innerHTML = '' + window.location.hostname + '/code_id=' + response.code_id + '/'; + if(location.port == "") + $('#copy_code')[0].innerHTML = '' + window.location.hostname + '/code_id=' + response.code_id + '/'; + else + $('#copy_code')[0].innerHTML = '' + window.location.hostname + ':' + location.port +'/code_id=' + response.code_id + '/'; + $('#copy_code').css({'display': 'initial'}); request_ongoing = false; From 22b2e5c159c9236198c96677e474c2c36731d731 Mon Sep 17 00:00:00 2001 From: sahil865gupta Date: Thu, 25 Aug 2016 23:02:01 +0530 Subject: [PATCH 2/6] Don't save same code again and removed print --- hackIDE/static/hackIDE/js/custom.js | 17 ++++++++--------- hackIDE/views.py | 15 +-------------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/hackIDE/static/hackIDE/js/custom.js b/hackIDE/static/hackIDE/js/custom.js index 4393acc..a873aec 100644 --- a/hackIDE/static/hackIDE/js/custom.js +++ b/hackIDE/static/hackIDE/js/custom.js @@ -790,7 +790,6 @@ $(document).ready(function(){ success : function(response){ $('#login_msg').html(response.msg); - console.log(response.msg); if(response.msg != "Invalid credentials") location.reload(); }, @@ -808,7 +807,6 @@ $(document).ready(function(){ dataType : 'json', timeout : 10000, success : function(response){ - console.log(response.msg); location.reload(); }, }); @@ -861,8 +859,7 @@ $(document).ready(function(){ $("#compile-code").prop('disabled', false); $("#run-code").prop('disabled', false); $("#save-code-profile").prop('disabled', false); - - console.log("Code Saved"); + $("#save-code-profile").html("Saved"); }, error: function(error){ @@ -873,7 +870,6 @@ $(document).ready(function(){ $("#compile-code").prop('disabled', false); $("#run-code").prop('disabled', false); $("#save-code-profile").prop('disabled', false); - console.log("Code Not Saved"); } }); } @@ -899,7 +895,8 @@ $(document).ready(function(){ $("#compile-code").prop('disabled', false); $("#run-code").prop('disabled', false); $("#save-code-profile").prop('disabled', false); - console.log("Code Saved"); + $("#save-code-profile").prop('disabled', true); + $("#save-code-profile").html("Saved"); }, error: function(error){ @@ -909,7 +906,6 @@ $(document).ready(function(){ $("#compile-code").prop('disabled', false); $("#run-code").prop('disabled', false); $("#save-code-profile").prop('disabled', false); - console.log("Code Not Saved"); } }); } @@ -920,7 +916,6 @@ $(document).ready(function(){ var i = $(this).closest('a').attr('id'); var parent = $(this).closest('a'); - console.log(i); var csrf_token = $(":input[name='csrfmiddlewaretoken']").val(); var remove_data = {csrfmiddlewaretoken:csrf_token, id:i}; @@ -933,7 +928,6 @@ $(document).ready(function(){ success : function(response){ parent.fadeOut('slow', function(){ parent.remove(); - console.log("removed"); }); }, }); @@ -973,4 +967,9 @@ $(document).ready(function(){ }); + + editor.on('change', function(){ + $("#save-code-profile").prop('disabled', false); + $("#save-code-profile").html("Save Code To Profile"); + }); }); diff --git a/hackIDE/views.py b/hackIDE/views.py index 169e6a5..2da150b 100644 --- a/hackIDE/views.py +++ b/hackIDE/views.py @@ -19,7 +19,7 @@ # access config variable DEBUG = (os.environ.get('HACKIDE_DEBUG') != None) # DEBUG = (os.environ.get('HACKIDE_DEBUG') or "").lower() == "true" -CLIENT_SECRET = os.environ['HE_CLIENT_SECRET'] if not DEBUG else "" +#CLIENT_SECRET = os.environ['HE_CLIENT_SECRET'] if not DEBUG else "" permitted_languages = ["C", "CPP", "CSHARP", "CLOJURE", "CSS", "HASKELL", "JAVA", "JAVASCRIPT", "OBJECTIVEC", "PERL", "PHP", "PYTHON", "R", "RUBY", "RUST", "SCALA"] @@ -240,7 +240,6 @@ def register(request): msg = "" flag = False - print users for user in users: if username == user.username: error_username = "Username already exist" @@ -249,17 +248,11 @@ def register(request): error_email = "Email already exist" flag = True - print error_username - print error_email - if flag == False: new_user = Users.objects.create(username=username, email=email, password=password, code="") new_user.save() request.session['username'] = username - msg = "Succesfully Registered" - print msg - r = {'msg':msg, 'error_username':error_username, 'error_email':error_email} return JsonResponse(r, safe=False) @@ -282,7 +275,6 @@ def login(request): msg = "Successfully logged in" request.session['username'] = username - print msg r = {'msg':msg, 'username' : username} return JsonResponse(r, safe=False) @@ -392,11 +384,8 @@ def savetoprofile(request): username = request.session['username'] user = Users.objects.get(username = username) - print r['code_id'] user.code = str(r['code_id']) + ',' + str(user.code) user.save() - print user - print "code" + user.code return JsonResponse(r, safe=False) else: @@ -432,7 +421,6 @@ def removecode(request): for i in range(0, len(code_id)): if code_id[i] == str(request.POST['id']): - print "deleted" + code_id[i] code_id.pop(i) break @@ -440,7 +428,6 @@ def removecode(request): user.code = code_id user.save() - print user r = {} return JsonResponse(r, safe=False) From 0e836626fbf624d16a189096b487b92ea1f23361 Mon Sep 17 00:00:00 2001 From: sahil865gupta Date: Fri, 26 Aug 2016 17:52:51 +0530 Subject: [PATCH 3/6] added title for saving code --- hackIDE/models.py | 6 ++---- hackIDE/static/hackIDE/js/custom.js | 32 +++++++++++++++++++--------- hackIDE/templates/hackIDE/index.html | 28 ++++++++++++++++++------ hackIDE/views.py | 24 ++++++++++----------- 4 files changed, 58 insertions(+), 32 deletions(-) diff --git a/hackIDE/models.py b/hackIDE/models.py index 0aa782b..21bf97d 100644 --- a/hackIDE/models.py +++ b/hackIDE/models.py @@ -30,7 +30,5 @@ class Users(Document): username = StringField(required=True) email = StringField(required=True) password = StringField(required=True) - code = StringField() - - def __str__(self): - return self.username + "-" + self.email + "-" + str(self.code) + code = ListField() + title = ListField() \ No newline at end of file diff --git a/hackIDE/static/hackIDE/js/custom.js b/hackIDE/static/hackIDE/js/custom.js index a873aec..8c83b57 100644 --- a/hackIDE/static/hackIDE/js/custom.js +++ b/hackIDE/static/hackIDE/js/custom.js @@ -812,14 +812,16 @@ $(document).ready(function(){ }); }); - $("#save-code-profile").click(function(){ + $("#title-save").click(function(){ // if a run request is ongoing if(request_ongoing) return; $("#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); @@ -835,6 +837,7 @@ $(document).ready(function(){ } var input_given = $("#custom-input").val(); + var code_title = $('#code-title').val(); request_ongoing = true; @@ -843,6 +846,7 @@ $(document).ready(function(){ source: editorContent, lang: languageSelected, input: input_given, + code_title: code_title, csrfmiddlewaretoken: csrf_token }; // AJAX request to Django for running code with input @@ -858,8 +862,10 @@ $(document).ready(function(){ // enable button when this method is called $("#compile-code").prop('disabled', false); $("#run-code").prop('disabled', false); - $("#save-code-profile").prop('disabled', false); + $("#save-code-profile").prop('disabled', true); $("#save-code-profile").html("Saved"); + $("#title-save").html("Saved"); + $("#code-title").val(""); }, error: function(error){ @@ -877,6 +883,7 @@ $(document).ready(function(){ var run_data = { source: editorContent, lang: languageSelected, + code_title: code_title, csrfmiddlewaretoken: csrf_token }; // AJAX request to Django for running code without input\ @@ -894,9 +901,11 @@ $(document).ready(function(){ // enable button when this method is called $("#compile-code").prop('disabled', false); $("#run-code").prop('disabled', false); - $("#save-code-profile").prop('disabled', false); $("#save-code-profile").prop('disabled', true); $("#save-code-profile").html("Saved"); + + $("#title-save").html("Saved"); + $("#code-title").val(""); }, error: function(error){ @@ -912,10 +921,10 @@ $(document).ready(function(){ }); - $("#profile_saved_data").on('click', '#close_data', function(){ + $("#data_table").on('click', '#close_data', function(){ - var i = $(this).closest('a').attr('id'); - var parent = $(this).closest('a'); + 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}; @@ -944,13 +953,13 @@ $(document).ready(function(){ dataType: "json", timeout: 10000, success : function(response){ - $("#profile_saved_data").html(""); + $("#data_table").html("Code IdTitle"); if(location.port == "") - { + { for(var i=0;i"+response.code_id[i]+" "); + $("#data_table").append(""+response.code_id[i]+""+ response.code_title[i] +"Open"); } } else @@ -958,7 +967,7 @@ $(document).ready(function(){ for(var i=0;i"+response.code_id[i]+""); + $("#data_table").append(""+response.code_id[i]+""+ response.code_title[i] +"Open"); } } }, @@ -969,6 +978,9 @@ $(document).ready(function(){ 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"); }); diff --git a/hackIDE/templates/hackIDE/index.html b/hackIDE/templates/hackIDE/index.html index 4ae1235..b8f8f6c 100644 --- a/hackIDE/templates/hackIDE/index.html +++ b/hackIDE/templates/hackIDE/index.html @@ -33,7 +33,7 @@ - +