From f9ce1e01ab2f98fbcc40bfdd3ec9d70b9de15ac6 Mon Sep 17 00:00:00 2001
From: prashantsinalkar
Date: Wed, 18 Dec 2019 17:40:40 +0530
Subject: added api connection check call
---
website/static/website/js/cloud.js | 19 +++++++++++++++++++
website/static/website/templates/index.html | 3 +++
website/views.py | 20 ++++++++++++++------
3 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/website/static/website/js/cloud.js b/website/static/website/js/cloud.js
index a34f359..43f035f 100644
--- a/website/static/website/js/cloud.js
+++ b/website/static/website/js/cloud.js
@@ -1,3 +1,7 @@
+window.setInterval(function(){
+ checkserver();
+}, 5000);
+
/* Ajax loader */
function ajax_loader(key) {
if (key == "clear") {
@@ -38,6 +42,8 @@ function checkInput(){
/**************************** math captcha function end *******************/
$(document.body).ready(function() {
+ checkserver();
+
var editor = CodeMirror.fromTextArea(document.getElementById(
"code"), {
lineNumbers: true,
@@ -651,6 +657,7 @@ $(document.body).ready(function() {
$plotbox = $("#plotbox");
$(document).on("click", "#execute", function() {
+ checkserver();
if(editor.getValue() != ""){
ajax_loader(this);
$("#execute-inner").html("Executing...");
@@ -1060,3 +1067,15 @@ 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");
+ }
+ }
+ });
+}
+
diff --git a/website/static/website/templates/index.html b/website/static/website/templates/index.html
index fe31f5b..18dd01b 100644
--- a/website/static/website/templates/index.html
+++ b/website/static/website/templates/index.html
@@ -624,6 +624,9 @@
+
{% csrf_token %}
diff --git a/website/views.py b/website/views.py
index d6646f4..e554ef4 100644
--- a/website/views.py
+++ b/website/views.py
@@ -3,7 +3,8 @@ from django.http import HttpResponse
from django.template import loader
import requests
import uuid
-from R_on_Cloud.config import (API_URL_UPLOAD, API_URL_RESET, AUTH_KEY)
+from R_on_Cloud.config import (API_URL_UPLOAD, API_URL_RESET, AUTH_KEY,
+ API_URL_SERVER)
from website.models import *
from django.db.models import Q
import json as simplejson
@@ -83,6 +84,7 @@ def index(request):
user_id = uuid.uuid4()
context['api_url_upload'] = API_URL_UPLOAD
context['reset_req_url'] = API_URL_RESET
+ context['api_url'] = API_URL_SERVER
book_id = request.GET.get('book_id')
user = request.user
if not 'user_id' in request.session:
@@ -140,6 +142,7 @@ def index(request):
'api_url_upload': API_URL_UPLOAD,
'user_id': request.session['user_id'],
'key': AUTH_KEY,
+ 'api_url': API_URL_SERVER,
}
template = loader.get_template('index.html')
return HttpResponse(template.render(context, request))
@@ -172,6 +175,7 @@ def index(request):
}
context['api_url_upload'] = API_URL_UPLOAD
context['reset_req_url'] = API_URL_RESET
+ context['api_url'] = API_URL_SERVER
template = loader.get_template('index.html')
return HttpResponse(template.render(context, request))
@@ -212,6 +216,7 @@ def index(request):
}
context['api_url_upload'] = API_URL_UPLOAD
context['reset_req_url'] = API_URL_RESET
+ context['api_url'] = API_URL_SERVER
template = loader.get_template('index.html')
return HttpResponse(template.render(context, request))
@@ -241,7 +246,7 @@ def index(request):
preference_id = cursor.fetchone()
with connections['r'].cursor() as cursor:
rows_count = cursor.execute(GET_TBC_PREFERENCE_DETAIL_CATEGORY_SQL,
- params=[preference_id[0]])
+ params=[preference_id[0]])
if rows_count > 0:
books_detail = cursor.fetchone()
books = get_books(books_detail[1])
@@ -252,10 +257,11 @@ def index(request):
context = {
'catg': catg_all,
'err_msg': """This book is not supported by R on Cloud."""
- """ You are redirected to home page."""
+ """ You are redirected to home page."""
}
context['api_url_upload'] = API_URL_UPLOAD
context['reset_req_url'] = API_URL_RESET
+ context['api_url'] = API_URL_SERVER
template = loader.get_template('index.html')
return HttpResponse(template.render(context, request))
@@ -296,6 +302,7 @@ def index(request):
""" scilab on cloud."""
}
context['api_url_upload'] = API_URL_UPLOAD
+ context['api_url'] = API_URL_SERVER
template = loader.get_template('index.html')
return HttpResponse(template.render(context, request))
subcateg_all = get_subcategories(maincat_id)
@@ -330,6 +337,7 @@ def index(request):
# context['user'] = user
context['api_url_upload'] = API_URL_UPLOAD
context['reset_req_url'] = API_URL_RESET
+ context['api_url'] = API_URL_SERVER
template = loader.get_template('index.html')
return HttpResponse(template.render(context, request))
@@ -359,11 +367,11 @@ def reset(request):
for key, value in list(request.session.items()):
if key != 'user_id':
del request.session[key]
- response = {"data" : "ok"}
+ response = {"data": "ok"}
return HttpResponse(simplejson.dumps(response),
- content_type='application/json')
+ content_type='application/json')
except KeyError:
pass
- response = {"data" : "ok"}
+ response = {"data": "ok"}
return HttpResponse(simplejson.dumps(response),
content_type='application/json')
--
cgit