Kaynağa Gözat

Allow updating single consoles

Colin Powell 3 yıl önce
ebeveyn
işleme
c574f8929a

+ 4 - 5
games/views.py

@@ -160,15 +160,14 @@ class GameCollectionDetail(DetailView, LoginRequiredMixin):
 
 @login_required
 def trigger_rom_update(request):
-    game_systems = request.GET.getlist("game_systems")
-    full_scan = request.GET.get("full_scan")
-
+    full_scan = request.GET.get("full_scan", False)
     if full_scan == "true":
         full_scan = True
-    else:
-        full_scan = False
+
+    game_systems = request.GET.getlist("game_systems")
     if not game_systems:
         game_systems = list(settings.GAME_SYSTEM_DEFAULTS.keys())
+
     try:
         update_roms.delay(game_systems, full_scan=full_scan)
     except FileNotFoundError:

+ 0 - 24
templates/base.html

@@ -11,26 +11,6 @@
         <script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
         <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
         <script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.10/clipboard.min.js"></script>
-        <script>
-        $('#library-update-form').on('submit', function(event){
-            event.preventDefault();
-            console.log("form submitted!")  // sanity check
-            $.ajax({
-                url : "library/update/",
-                type : "GET",
-                // handle a successful response
-                success : function(json) {
-                    $('#library-update-form').html("<button id='library-update-btn' class='btn btn-secondary my-2 my-sm-0' type='submit' disabled>Update</button>");
-                    console.log(json); // log the returned json to the console
-                },
-
-                // handle a non-successful response
-                error : function(xhr,errmsg,err) {
-                    console.log(xhr.status + ": " + xhr.responseText); // provide a bit more info about the error to the console
-                }
-            });
-        });
-        </script>
 
         <style type="text/css">
         dl {
@@ -110,10 +90,6 @@
                 <input class="form-control mr-sm-2" name="q" type="search" placeholder="Search" aria-label="Search">
                 <button class="btn btn-primary my-2 my-sm-0" type="submit">Search</button>
                 </form>
-                &nbsp;
-                <form id="library-update-form" class="form-inline my-2 my-lg-0" method="get" action="{% url 'games:game_library_update' %}">
-                <button id="library-update-btn" class="btn btn-warning my-2 my-sm-0" type="submit" {% if update_in_progress %}disabled{% endif %}>Update</button>
-                </form>
             </div>
             <a class="nav-link" href="{% url 'account_logout' %}">Logout<span class="sr-only"></span></a>
             {% endif %}

+ 31 - 0
templates/games/game_library_list.html

@@ -3,7 +3,38 @@
 
 {% block title %}All games by rating{% endblock %}
 
+{% block head_extra %}
+
+<script>
+$(document).ready(function () {
+    $('#library-update-form').on('submit', function(event){
+        event.preventDefault();
+        console.log("form submitted!")  // sanity check
+        $.ajax({
+            url : "/library/update/",
+            type : "GET",
+            // handle a successful response
+            success : function(json) {
+                $('#library-update-form').html("<button id='library-update-btn' class='btn btn-secondary my-2 my-sm-0' type='submit' disabled>Update</button>");
+                console.log(json); // log the returned json to the console
+            },
+
+            // handle a non-successful response
+            error : function(xhr,errmsg,err) {
+                console.log(xhr.status + ": " + xhr.responseText); // provide a bit more info about the error to the console
+            }
+        });
+    });
+});
+</script>
+{% endblock %}
+
 {% block content %}
+    <form id="library-update-form" class="form-inline my-2 my-lg-0" method="get" action="{% url 'games:game_library_update' %}">
+    <button id="library-update-btn" class="btn btn-warning my-2 my-sm-0" type="submit" {% if update_in_progress %}disabled{% endif %}>Update</button>
+    </form>
+    &nbsp;
+
     {% include "games/_game_table.html" %}
     {% include "games/_pagination.html" %}
 {% endblock %}

+ 20 - 18
templates/games/gamesystem_detail.html

@@ -3,24 +3,25 @@
 
 {% block title %}{{object.name}}{% endblock %}
 
-{% block extra_head %}
+{% block head_extra %}
     <script>
-    $('#library-update-form').on('submit', function(event){
-        event.preventDefault();
-        console.log("form submitted!")  // sanity check
-        $.ajax({
-            url : "library/update/",
-            type : "GET",
-            // handle a successful response
-            success : function(json) {
-                $('#library-update-form').html("<button id='library-update-btn' class='btn btn-secondary my-2 my-sm-0' type='submit' disabled>Update</button>");
-                console.log(json); // log the returned json to the console
-            },
+    $(document).ready(function () {
+        console.log('Loading this code');
 
-            // handle a non-successful response
-            error : function(xhr,errmsg,err) {
-                console.log(xhr.status + ": " + xhr.responseText); // provide a bit more info about the error to the console
-            }
+        $('#{{object.retropie_slug}}-update-form').submit(function(event){
+            console.log('Form submitted');
+            event.preventDefault();
+            $.ajax({
+                url : '/library/update/?game_systems={{object.retropie_slug}}',
+                type : "GET",
+                success : function(json) {
+                    $('#{{object.retropie_slug}}-update-form').html("<button id='library-update-btn' class='btn btn-warning my-2 my-sm-0' type='submit' disabled>Update {{object.name}}</button>");
+                    console.log(json);
+                },
+                error : function(xhr,errmsg,err) {
+                    console.log(xhr.status + ": " + xhr.responseText);
+                }
+            });
         });
     });
     </script>
@@ -29,9 +30,10 @@
 {% block content %}
     <h4>Browsing {{object_list.count}} games</h4>
 
-    <form id="library-update-form" class="form-inline my-2 my-lg-0" method="get" action="{% url 'games:game_library_update' %}?game_systems={{object.retropie_slug}}">
-    <button id="library-update-btn" class="btn btn-warning my-2 my-sm-0" type="submit" {% if update_in_progress %}disabled{% endif %}>Update {{object.name}}</button>
+    <form id="{{object.retropie_slug}}-update-form" class="my-2 my-lg-0" method="get">
+    <button id="{{object.retropie_slug}}-update-btn" class="btn btn-warning my-2 my-sm-0" type="submit" {% if update_in_progress %}disabled{% endif %}>Update {{object.name}}</button>
     </form>
+    &nbsp;
 
      <div class="d-flex flex-column">
         <div class="image-grid-container">