瀏覽代碼

Add rudimentary rom updats

Colin Powell 3 年之前
父節點
當前提交
b95e82b1f0
共有 4 個文件被更改,包括 43 次插入3 次删除
  1. 9 0
      games/context_processors.py
  2. 5 2
      games/views.py
  3. 24 1
      templates/base.html
  4. 5 0
      templates/games/gamesystem_detail.html

+ 9 - 0
games/context_processors.py

@@ -1,8 +1,17 @@
+from celery import states
 from games.models import GameSystem, GameCollection
 
+from django_celery_results.models import TaskResult
+
+IN_PROGRESS_STATES = [states.PENDING, states.STARTED, states.RETRY]
+
 
 def game_systems(request):
     return {
         "game_systems": GameSystem.objects.all(),
         "game_collections": GameCollection.objects.all(),
+        "update_in_progress": TaskResult.objects.filter(
+            task_name="games.tasks.update_roms",
+            status__in=IN_PROGRESS_STATES,
+        ),
     }

+ 5 - 2
games/views.py

@@ -160,14 +160,17 @@ 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")
+
     if full_scan == "true":
         full_scan = True
     else:
         full_scan = False
-    all_slugs = list(settings.GAME_SYSTEM_DEFAULTS.keys())
+    if not game_systems:
+        game_systems = list(settings.GAME_SYSTEM_DEFAULTS.keys())
     try:
-        update_roms.delay(all_slugs, full_scan=full_scan)
+        update_roms.delay(game_systems, full_scan=full_scan)
     except FileNotFoundError:
         return HttpResponse(
             json.dumps({"success": False, "msg": "Skyscraper is not installed"}),

+ 24 - 1
templates/base.html

@@ -11,7 +11,26 @@
         <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 {
@@ -89,7 +108,11 @@
                 </ul>
                 <form class="form-inline my-2 my-lg-0" method="get" action="{% url 'search:search' %}">
                 <input class="form-control mr-sm-2" name="q" type="search" placeholder="Search" aria-label="Search">
-                <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
+                <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>

+ 5 - 0
templates/games/gamesystem_detail.html

@@ -5,6 +5,11 @@
 
 {% 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>
+
      <div class="d-flex flex-column">
         <div class="image-grid-container">
         {% for  game in object_list %}