Allow to trigger rescan via admin interface
authorJoey Schulze <joey@infodrom.org>
Sun, 25 Nov 2018 14:13:43 +0000 (15:13 +0100)
committerJoey Schulze <joey@infodrom.org>
Sun, 25 Nov 2018 16:03:00 +0000 (17:03 +0100)
class/ajax.class.php
html/admin/musiikki.js
templates/index.phtml
templates/rescan.phtml [new file with mode: 0644]

index 3ba8bfb..8a6f673 100644 (file)
@@ -114,4 +114,26 @@ class AJAX {
 
        return $ok;
     }
+
+    public static function getrescanAction()
+    {
+       $mtime = filemtime(Config::main()->get('cache'));
+
+       return array('modified' => date ("d. F Y H:i:s", $mtime));
+    }
+
+    public static function rescanAction()
+    {
+       $mtime = filemtime(Config::main()->get('cache'));
+       if ($mtime > time()-10)
+           return array('info' => 'Rescan läuft gerade und kann nicht erneut getriggert werden.');
+
+       if (($f = fopen(Config::main()->get('rescan_file'), 'w')) !== false) {
+           fwrite($f, time());
+           fclose($f);
+           return true;
+       }
+
+       return false;
+    }
 }
index 015f25a..38f2ddf 100644 (file)
@@ -71,6 +71,21 @@ function submit_shares() {
     return false;
 }
 
+function submit_rescan() {
+    $.post('index.php',
+          'action=rescan',
+          function(data){
+              if (data) {
+                  if (data.info)
+                      response(data.info);
+                  else
+                      response('Rescan wurde getriggert.<br>Die Medienliste wird neu aufgebaut.');
+              }
+          });
+
+    return false;
+}
+
 function submit_admin() {
     $.post('index.php',
           'action=admin&' + $('div.w3-container#admin form').serialize());
index 0d234c9..ae6faf9 100644 (file)
     <h3 class="w3-padding-64"><b><?=Config::main()->get('title')?></b></h3>
   </div>
   <div class="w3-bar-block" style="padding-top:5px;">
-    <a href="#" onclick="open_page('home')" class="w3-bar-item w3-button w3-hover-white">Home</a> 
+    <a href="/admin/" onclick="open_page('home')" class="w3-bar-item w3-button w3-hover-white">Home</a>
     <a href="#" onclick="open_page('datetime')" class="w3-bar-item w3-button w3-hover-white">Date/Time</a> 
     <a href="#" onclick="open_page('wifi')" class="w3-bar-item w3-button w3-hover-white">WiFi</a> 
     <a href="#" onclick="open_page('shares')" class="w3-bar-item w3-button w3-hover-white">Shares</a> 
+    <a href="#" onclick="open_page('rescan')" class="w3-bar-item w3-button w3-hover-white">Rescan</a>
     <a href="#" onclick="open_page('admin')" class="w3-bar-item w3-button w3-hover-white">Admin</a>
     <a href="#" onclick="open_page('halt')" class="w3-bar-item w3-button w3-hover-white">Shutdown</a> 
   </div>
@@ -47,6 +48,7 @@
 <?php echo Template::html('wifi'); ?>
 <?php echo Template::html('shares'); ?>
 <?php echo Template::html('admin'); ?>
+<?php echo Template::html('rescan'); ?>
 <?php echo Template::html('halt'); ?>
 <?php echo Template::html('response'); ?>
 
diff --git a/templates/rescan.phtml b/templates/rescan.phtml
new file mode 100644 (file)
index 0000000..0b01d03
--- /dev/null
@@ -0,0 +1,12 @@
+<!-- Rescan -->
+<div class="w3-container" id="rescan" style="margin-top:75px" style="display:none;">
+  <h1 class="w3-xxxlarge w3-text-blue"><b>Rescan.</b></h1>
+  <hr style="width:50px;border:5px solid blue" class="w3-round">
+  <form>
+    <div class="w3-section">
+      <label>Letzter kompletter Rescan</label>
+      <input class="w3-input w3-border" name="modified" requiblue="" type="text" readonly>
+    </div>
+    <button type="submit" class="w3-button w3-block w3-padding-large w3-blue w3-margin-bottom" onclick="return submit_rescan()">Rescan</button>
+  </form>
+</div>