From b28d11ad794c3ed438e42a232dc1bd42ab1691ff Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 21 Jan 2020 17:01:33 +0530 Subject: added sorl code search for cloud --- website/static/website/js/cloud.js | 51 +++++++++++++++---- website/static/website/templates/index.html | 14 ++---- website/static/website/templates/search_code.html | 28 +++++++++++ website/urls.py | 2 + website/views.py | 61 +++++++++++++++++++++-- 5 files changed, 132 insertions(+), 24 deletions(-) create mode 100644 website/static/website/templates/search_code.html diff --git a/website/static/website/js/cloud.js b/website/static/website/js/cloud.js index f2f7f19..9a632e7 100644 --- a/website/static/website/js/cloud.js +++ b/website/static/website/js/cloud.js @@ -922,8 +922,10 @@ $(document.body).ready(function() { /********************************************/ $(document).on("click", "#search", function() { ajax_loader(this); - $("#relevant").html(''); var search_string = jQuery.trim($("#search-input").val()); + if(search_string != ''){ + if($("input[name='optradio']:checked").val() == 'bybook'){ + $("#relevant").html(''); if (search_string == '') { search_string = 'Null'; } @@ -935,12 +937,16 @@ $(document.body).ready(function() { search_string: search_string, }, success: function(data) { + if(data.length > 0 ){ $("#relevant").html('

Relevant


'); for (var i = 0; i < data.length; i++) { $("#relevant").append( '' + data[i].book + ' (Author: ' + data[i].author + ')
'); + } + }else{ + $("#relevant").append('Oops! This book is not availabe!'); } ajax_loader("clear"); } @@ -961,7 +967,6 @@ $(document.body).ready(function() { } ajax_loader("clear"); } - }), $.ajax({ url: 'search_book/recent/', @@ -977,9 +982,33 @@ $(document.body).ready(function() { '' + data[i].book + ' (Author: ' + data[i].author + ')
'); } - ajax_loader("clear"); } }); + } else{ + ajax_loader(this); + $.ajax({ + url: 'search_in_code/', + dataType: 'JSON', + type: 'GET', + data: { + search_string: search_string, + }, + success: function(data) { + if(data.error != 'True'){ + console.log(data.data); + $("#searched_code_data").html(""); + $("#searched_code").html(data.data); + }else{ + alert("Oops! Search engine is away, please try after some time!") + } + } + }); + ajax_loader("clear"); + } + }else{ + alert("Please enter the search string!"); + } + ajax_loader("clear"); }); $(document).on("click", "#search_book", function(e) { @@ -1083,14 +1112,14 @@ function doSubmit(){ } function checkserver(){ - - $.ajax({url: api_url, - dataType: "jsonp", - statusCode: { - 404: function (response) { - alert("Oops! R cloud server is not available, please try after some time"); - } - } + $.ajax({url: 'check_server/', + dataType: "json", + success : function (data) { + if((data.status == 200) || (data.error != 'True')){ + }else{ + alert("R cloud server is not available, please try after some time"); + } + } }); } diff --git a/website/static/website/templates/index.html b/website/static/website/templates/index.html index 27dbca9..6d68515 100644 --- a/website/static/website/templates/index.html +++ b/website/static/website/templates/index.html @@ -46,7 +46,7 @@