diff options
author | prashantsinalkar | 2019-12-18 17:40:40 +0530 |
---|---|---|
committer | prashantsinalkar | 2019-12-18 17:40:40 +0530 |
commit | f9ce1e01ab2f98fbcc40bfdd3ec9d70b9de15ac6 (patch) | |
tree | a5fda278294710b2e6e44a34d7aed44cb4bbe4d8 | |
parent | 44df4d59795560026b547c323f55e113f097afb2 (diff) | |
download | R_on_Cloud_Web_Interface-f9ce1e01ab2f98fbcc40bfdd3ec9d70b9de15ac6.tar.gz R_on_Cloud_Web_Interface-f9ce1e01ab2f98fbcc40bfdd3ec9d70b9de15ac6.tar.bz2 R_on_Cloud_Web_Interface-f9ce1e01ab2f98fbcc40bfdd3ec9d70b9de15ac6.zip |
added api connection check call
-rw-r--r-- | website/static/website/js/cloud.js | 19 | ||||
-rw-r--r-- | website/static/website/templates/index.html | 3 | ||||
-rw-r--r-- | 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 @@ <script src="{% static 'website/js/javascript.js'%}"></script> <script src="{% static 'website/js/fullscreen.js'%}"></script> <script src="{% static 'website/js/placeholder.js'%}"></script> + <script> + var api_url = "{{ api_url }}"; + </script> <script src="{% static 'website/js/cloud.js' %}"></script> <script src="{% static 'website/js/jsdiff.js'%}"></script> {% 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') |