Parcourir la source

Update of manage of BASE_URL

Jérôme BUISINE il y a 4 ans
Parent
commit
a10c743eac

+ 2 - 2
README.md

@@ -83,13 +83,13 @@ WEBEXPE_PREFIX_URL=experience make deploy
 Using custom API base URL using `WEB_API_PREFIX_URL`:
 
 ```
-WEBEXPE_PREFIX_URL=experience WEB_API_PREFIX_URL=expe/api python manage.py runserver
+WEBEXPE_PREFIX_URL=experience/ WEB_API_PREFIX_URL=expe/api python manage.py runserver
 ```
 
 or using docker:
 
 ```
-WEBEXPE_PREFIX_URL=experience WEB_API_PREFIX_URL=expe/api make deploy
+WEBEXPE_PREFIX_URL=experience/ WEB_API_PREFIX_URL=expe/api make deploy
 ```
 
 ## How to contribute ?

+ 12 - 5
ThesisWebExpeDjango/urls.py

@@ -19,8 +19,15 @@ from django.views.generic import RedirectView
 
 from .settings import WEBEXPE_PREFIX_URL
 
-urlpatterns = [
-    path('', RedirectView.as_view(url=WEBEXPE_PREFIX_URL)),
-    path(WEBEXPE_PREFIX_URL + '/', include('expe.urls', namespace='expe')),
-    path(WEBEXPE_PREFIX_URL + '/admin/', admin.site.urls),
-]
+
+if WEBEXPE_PREFIX_URL == '':
+    urlpatterns = [
+        path('', include('expe.urls', namespace='expe')),
+        path('admin/', admin.site.urls),
+    ]
+else:
+    urlpatterns = [
+        path('', RedirectView.as_view(url=WEBEXPE_PREFIX_URL)),
+        path(WEBEXPE_PREFIX_URL + '/', include('expe.urls', namespace='expe')),
+        path(WEBEXPE_PREFIX_URL + '/admin/', admin.site.urls),
+    ]

+ 1 - 1
expe/config.py

@@ -30,7 +30,7 @@ expes_configuration         = {
             'end_text': "Experience is finished. Thanks for your participation",
         },
         'params':{
-            'iterations': 20
+            'iterations': 4
         }
     }
 }

+ 10 - 3
expe/templates/base.html

@@ -25,10 +25,17 @@
 
     <!-- Global scripts used -->
     <script type="text/javascript"> 
-        const BASE_URL = "{{BASE_URL}}"
+
+        // add by default '/' into BASE
+        const BASE     = "{{BASE}}"
         const host     = window.location.host
-        const baseUrl  = location.protocol + '//' + host + '/' + BASE_URL
-        const expeUrl  = baseUrl + '/expe'     
+        var baseUrl  = location.protocol + '//' + host + '/'
+
+        if (BASE != ''){
+            baseUrl += BASE + '/'
+        }
+
+        const expeUrl  = baseUrl + 'expe'     
         console.log(expeUrl)
     </script>
     {% block javascripts %}

+ 5 - 1
expe/templates/expe/expe.html

@@ -17,7 +17,11 @@
 
     <!-- TODO : Load    img from bitmap with javascript `loadImg.js` -->
     {% if not request.session.expe_finished %}
-        <img id="expeImg" src="/{{BASE_URL}}/{{img_merged_path}}" data-img="{{request.session.img_merged}}"/>
+        {% if BASE != '' %}
+            <img id="expeImg" src="/{{BASE}}/{{img_merged_path}}" data-img="{{request.session.img_merged}}"/>
+        {% else %}
+            <img id="expeImg" src="{{img_merged_path}}" data-img="{{request.session.img_merged}}"/>
+        {% endif %}
     {% endif %}
 
     {% block javascripts %}

+ 6 - 1
expe/templates/expe/expe_list.html

@@ -11,7 +11,12 @@
 
     <div class="row">
         <div class="col-md-4 offset-md-4">
-            <form action="/{{BASE_URL}}/indications" id="expeChoice">
+
+            {% if BASE != '' %}
+                <form action="/{{BASE}}/indications" id="expeChoice">
+            {% else %}
+                <form action="/indications" id="expeChoice">
+            {% endif %}
 
                 <div class="form-group">
                     <label for="scene">Select scene:</label>

+ 1 - 1
expe/views.py

@@ -42,7 +42,7 @@ def get_base_data():
     '''
     data = {}
 
-    data['BASE_URL'] = settings.WEBEXPE_PREFIX_URL
+    data['BASE'] = settings.WEBEXPE_PREFIX_URL
 
     return data
 

+ 0 - 2
static/js/indications.js

@@ -10,8 +10,6 @@ urlParams = new URLSearchParams(window.location.search);
 var scene = urlParams.get('scene')
 var expe  = urlParams.get('expe')
 
-console.log(expeUrl)
-
 function checkKey(e) {
 
    e = e || window.event;

+ 7 - 1
static/js/results.js

@@ -6,7 +6,13 @@ const toggleClass = (elem, class1, class2) => elem.className = elem.className ==
 const downloadContent = path => {
     const csrfToken = document.querySelector('[name=csrfmiddlewaretoken]').value
 
-    fetch('/' + BASE_URL + '/admin/download', {
+    if (BASE == ''){
+        var downloadUrl = '/admin/download'
+    }else{
+        var downloadUrl = '/' + BASE + '/admin/download'
+    }
+
+    fetch(downloadUrl, {
         method: 'POST',
         body: `path=${path}`,
         headers: {