]> source.dussan.org Git - nextcloud-server.git/commitdiff
gallery settings, defining scan root and shor order
authorBartek Przybylski <bart.p.pl@gmail.com>
Fri, 3 Feb 2012 20:38:44 +0000 (21:38 +0100)
committerBartek Przybylski <bart.p.pl@gmail.com>
Fri, 3 Feb 2012 20:38:44 +0000 (21:38 +0100)
apps/gallery/ajax/galleryOp.php
apps/gallery/css/styles.css
apps/gallery/js/album_cover.js
apps/gallery/js/albums.js
apps/gallery/lib/album.php
apps/gallery/templates/index.php

index 0c2674f885931aa5c4eb76b4ff7227e1b848c7ad..187cd8af2923b7f4cb9db552dd439132ce78bc77 100644 (file)
@@ -54,9 +54,11 @@ function handleGalleryScanning() {
   OC_JSON::success(array('albums' => OC_Gallery_Scanner::scan('/')));
 }
 
-function handleFilescan() {
+function handleFilescan($cleanup) {
   OC_JSON::checkLoggedIn();
-  $pathlist = OC_Gallery_Scanner::find_paths('/');
+  if ($cleanup) OC_Gallery_Album::cleanup();
+  $root = OC_Appconfig::getValue('gallery', 'root', '').'/';
+  $pathlist = OC_Gallery_Scanner::find_paths($root);
   sort($pathlist);
   OC_JSON::success(array('paths' => $pathlist));
 }
@@ -72,6 +74,25 @@ function handlePartialCreate($path) {
   OC_JSON::success(array('album_details' => $albums));
 }
 
+function handleStoreSettings($root, $order) {
+  OC_JSON::checkLoggedIn();
+  if (!OC_Filesystem::file_exists($root)) {
+    OC_JSON::error(array('cause' => 'No such file or directory'));
+    return;
+  }
+  if (!OC_Filesystem::is_dir($root)) {
+    OC_JSON::error(array('cause' => $root . ' is not a directory'));
+    return;
+  }
+
+  $current_root = OC_Appconfig::getValue('gallery', 'root', '/');
+  $root = trim(rtrim($root, '/'));
+  $rescan = $current_root==$root?'no':'yes';
+  OC_Appconfig::setValue('gallery', 'root', $root);
+  OC_Appconfig::setValue('gallery', 'order', $order);
+  OC_JSON::success(array('rescan' => $rescan));
+}
+
 if ($_GET['operation']) {
   switch($_GET['operation']) {
   case 'rename':
@@ -89,11 +110,14 @@ if ($_GET['operation']) {
     handleGalleryScanning();
     break;
   case 'filescan':
-    handleFilescan();
+    handleFilescan($_GET['cleanup']);
     break;
   case 'partial_create':
     handlePartialCreate($_GET['path']);
     break;
+  case 'store_settings':
+    handleStoreSettings($_GET['root'], $_GET['order']);
+    break;
   default:
     OC_JSON::error(array('cause' => 'Unknown operation'));
   }
index 7872b6445ca73ea348bcee627b6639faf95296ae..c039cd5ec02b47a20978248b5f15c44a1dad46a6 100644 (file)
@@ -12,3 +12,6 @@ div.gallery_control_overlay a { color:white; }
 #gallery_images.rightcontent { padding:10px 5px; bottom: 0px; overflow: auto; right:0px}
 #scan { position:absolute; right:13.5em; top:0em; }
 #scan #scanprogressbar { position:relative; display:inline-block; width:10em; height:1.5em; top:.4em; }
+#g-settings {position: absolute; left 13.5em; top: 0;}
+input[type=button] { -webkit-transition: opacity 0.5s ease-in-out; -moz-transition: opacity 0.5s ease-in-out; -o-transition: opacity 0.5s ease-in-out; opacity: 1}
+input[type=button]:disabled { opacity: 0.5 }
index e78db221cff52dd840a85945fdcfee5537501514..4ddac2f211131c379a50c6a095a554c128ee7881 100644 (file)
@@ -38,10 +38,12 @@ function createNewAlbum() {
 var albumCounter = 0;
 var totalAlbums = 0;
 
-function scanForAlbums() {
+function scanForAlbums(cleanup) {
+  cleanup = cleanup?true:false;
   var albumCounter = 0;
   var totalAlbums = 0;
-  $.getJSON('ajax/galleryOp.php?operation=filescan', function(r) {
+  $('#g-scan-button').attr('disabled', 'true');
+  $.getJSON('ajax/galleryOp.php?operation=filescan', {cleanup: cleanup}, function(r) {
 
     if (r.status == 'success') {
       totalAlbums = r.paths.length;
@@ -68,6 +70,7 @@ function scanForAlbums() {
             } else {
               alert('Error occured: no such layer `gallery_list`');
             }
+            $('#g-scan-button').attr('disabled', null);
           }
         });
       }
@@ -125,13 +128,13 @@ function galleryRename(name) {
                 $(this).dialog("close");
                 return;
               }
-              $.getJSON("ajax/galleryOp.php", {operation: "rename", oldname: name, newname: newname}, function(r) {
+              $.getJSON('ajax/galleryOp.php', {operation: 'rename', oldname: name, newname: newname}, function(r) {
                 if (r.status == "success") {
                   Albums.rename($(".gallery_album_box").filterAttr('data-album',name), newname);
                 } else {
                   alert("Error: " + r.cause);
                 }
-                $('#dialog-form').dialog("close");
+                $('#dialog-form').dialog('close');
               });
 
             }
@@ -139,10 +142,49 @@ function galleryRename(name) {
           {
             text: t('gallery', 'Cancel'),
             click: function() {
-              $( this ).dialog( "close" );
+              $( this ).dialog('close');
             }
           }
         ],
   });
 }
 
+function settings() {
+  $( '#g-dialog-settings' ).dialog({
+        height: 180,
+        width: 350,
+        modal: false,
+        buttons: [{
+            text: t('gallery', 'Apply'),
+            click: function() {
+              var scanning_root = $('#g-scanning-root').val();
+              var disp_order = $('#g-display-order option:selected').val();
+              if (scanning_root == '') {
+                alert('Scanning root cannot be empty');
+                return;
+              }
+              $.getJSON('ajax/galleryOp.php', {operation: 'store_settings', root: scanning_root, order: disp_order}, function(r) {
+                if (r.status == 'success') {
+                  if (r.rescan == 'yes') { 
+                    $('#g-dialog-settings').dialog('close');
+                    Albums.clear(document.getElementById('gallery_list'));
+                    scanForAlbums(true);
+                    return;
+                  }
+                } else {
+                  alert('Error: ' + r.cause);
+                  return;
+                }
+                $('#g-dialog-settings').dialog('close');
+              });
+            }
+          },
+          {
+            text: t('gallery', 'Cancel'),
+            click: function() {
+              $(this).dialog('close');
+            }
+          }
+        ],
+  });
+}
index d2b4d858b5580459d080cbfe5a96abac7c1fb044..01e146a2f12c8bacdd10686cf0f70965c0b1fdf3 100644 (file)
@@ -52,7 +52,7 @@ Albums={
     });
          $(".gallery_album_decoration a.remove", local).bind('click', {name: a.name},function(event){
                  event.preventDefault();
-                 galleryRemove(a.data.name);
+                 galleryRemove(event.data.name);
     });
          $("a.view", local).attr('href','?view='+a.name);
          $('h1',local).text(a.name);
@@ -80,6 +80,10 @@ Albums={
                $("a.view", element).attr("href", "?view="+new_name);
                $("h1", element).text(new_name);
        }
+  },
+  clear: function(element) {
+    Albums.albums = new Array();
+    element.innerHTML = '';
   }
 
 }
index 4eb12cc0b8155be6dd729ca44a922b2da5fdc058..502237481a91aa93e2e59553034fc62907a1f05c 100644 (file)
@@ -31,6 +31,14 @@ class OC_Gallery_Album {
            $stmt = OC_DB::prepare('UPDATE *PREFIX*gallery_albums SET album_name=? WHERE uid_owner=? AND album_name=?');
                $stmt->execute(array($newname, $owner, $oldname));
        }
+
+  public static function cleanup() {
+    $albums = self::find(OC_User::getUser());
+    while ($r = $albums->fetchRow()) {
+      OC_Gallery_Photo::removeByAlbumId($r['album_id']);
+      self::remove(OC_User::getUser(), $r['album_name']);
+    }
+  }
        
        public static function remove($owner, $name=null) {
                $sql = 'DELETE FROM *PREFIX*gallery_albums WHERE uid_owner = ?';
@@ -69,7 +77,8 @@ class OC_Gallery_Album {
       $sql .= ' AND album_path = ?';
       $args[] = $path;
     }
-    $sql .= ' ORDER BY album_name ASC';
+    $order = OC_Appconfig::getValue('gallery', 'order', 'ASC');
+    $sql .= ' ORDER BY album_name ' . $order;
 
                $stmt = OC_DB::prepare($sql);
                return $stmt->execute($args);
index 4c2fbcfe6c654ebd0afcb0064ca82cceb862387a..4e74be4c64ecdf3d21beff0e8b143c49a15fd9b5 100644 (file)
@@ -9,7 +9,10 @@ $l = new OC_L10N('gallery');
 <div id="controls">
   <div id="scan">
     <div id="scanprogressbar"></div>
-    <input type="button" value="<?php echo $l->t('Rescan');?>" onclick="javascript:scanForAlbums();" />
+    <input type="button" id="g-scan-button" value="<?php echo $l->t('Rescan');?>" onclick="javascript:scanForAlbums();" />
+  </div>
+  <div id="g-settings">
+    <input type="button" id="g-settings-button" value="<?php echo $l->t('Settings');?>" onclick="javascript:settings();"/>
   </div>
 </div>
 <div id="gallery_list">
@@ -28,3 +31,26 @@ $l = new OC_L10N('gallery');
        </form>
 </div>
 
+<div id="g-dialog-settings" title="<?php echo $l->t('Settings');?>" style="display:none">
+       <form>
+    <fieldset><?php $root = OC_Appconfig::getValue('gallery', 'root', '/'); $order = OC_Appconfig::getValue('gallery', 'order', 'ASC');?>
+    <label for="name"><?php echo $l->t('Scanning root');?></label>
+    <input type="text" name="g-scanning-root" id="g-scanning-root" class="text ui-widget-content ui-corner-all" value="<?php echo $root;?>" /><br/>
+
+    <label for="sort"><?php echo $l->t('Default sorting'); ?></label>
+    <select id="g-display-order">
+      <option value="ASC"<?php echo $order=='ASC'?'selected':'';?>><?php echo $l->t('Ascending'); ?></option>
+      <option value="DESC"<?php echo $order=='DESC'?'selected':'';?>><?php echo $l->t('Descending'); ?></option>
+    </select><br/>
+<!--
+    <label for="sort"><?php echo $l->t('Thumbnails size'); ?></label>
+    <select>
+      <option value="100">100px</option>
+      <option value="150">150px</option>
+      <option value="200">200px</option>
+      </select>
+      -->
+       </fieldset>
+       </form>
+</div>
+