]> source.dussan.org Git - nextcloud-server.git/commitdiff
navigate on galleries
authorBartek Przybylski <bart.p.pl@gmail.com>
Sat, 2 Jun 2012 22:29:10 +0000 (00:29 +0200)
committerBartek Przybylski <bart.p.pl@gmail.com>
Sun, 10 Jun 2012 11:15:39 +0000 (13:15 +0200)
apps/gallery/lib/managers.php
apps/gallery/lib/tiles.php
apps/gallery/templates/index.php

index 96669da27278dced7e26a75b989f0d1bb94996a3..6cb9b420ac6b6210b0d972930c8544c1eeeb3e61 100644 (file)
@@ -29,9 +29,11 @@ class DatabaseManager {
                if (!$image->loadFromFile($path)) {
                        return false;
                }
+               \OCP\DB::beginTransaction();
                $stmt = \OCP\DB::prepare('INSERT INTO *PREFIX*pictures_images_cache (uid_owner, path, width, height) VALUES (?, ?, ?, ?)');
                $stmt->execute(array(\OCP\USER::getUser(), $path, $image->width(), $image->height()));
                unset($image);
+               \OCP\DB::commit();
                return $this->getFileData($path);
        }
        
@@ -64,7 +66,7 @@ class ThumbnailsManager {
 
                $image->fixOrientation();
 
-               $ret = $image->preciseResize(floor((200*$image->width())/$image->height()), 200);
+               $ret = $image->preciseResize(floor((150*$image->width())/$image->height()), 150);
                
                if (!$ret) {
                        \OC_Log::write(self::TAG, 'Couldn\'t resize image', \OC_Log::ERROR);
index d7f5208ff83b4d3c6a7b93ab610052bd35b243ec..26ff3cbb9f87036310bfc9b63a8d243ee5157a01 100644 (file)
@@ -9,11 +9,12 @@ const TILE_PROPORTION_HORIZONTAL = 0;
 const TILE_PROPORTION_VERTICAL = 0;
 const GET_THUMBNAIL_PATH = '?app=gallery&getfile=ajax/thumbnail.php&filepath=';
 const TAG = 'Pictures';
+const IMAGE_WIDTH = 150;
 
 class TileBase {
   public function getWidth() { return false; }
 
-  public function getHeight() { return 200; }
+  public function getHeight() { return 150; }
 
   public function getOnHoverAction() { return false; }
   
@@ -64,8 +65,8 @@ class TilesLine {
          for ($i = 0; $i < count($this->tiles_array); $i++) {
                  $img_w = $this->tiles_array[$i]->getWidth();
                  $extra = '';
-                 if ($img_w != 200) $extra = ' style="width:'.$img_w.'px"';
-                 $r .= '<div class="gallery_div" '.$extra.' onmouseover="'.$this->tiles_array[$i]->getOnHoverAction().'" onmouseout="'.$this->tiles_array[$i]->getOnOutAction().'">'.$this->tiles_array[$i]->get().'</div>';
+                 if ($img_w != 150) $extra = ' style="width:'.$img_w.'px"';
+                 $r .= '<div class="gallery_div" '.$extra.' onmouseover="'.$this->tiles_array[$i]->getOnHoverAction().'" onmouseout="'.$this->tiles_array[$i]->getOnOutAction().'" onclick="'.$this->tiles_array[$i]->getOnClickAction().'">'.$this->tiles_array[$i]->get().'</div>';
          }
          
          $r .= '</div>';
@@ -93,18 +94,6 @@ class TileSingle extends TileBase {
     $a = ThumbnailsManager::getInstance()->getThumbnailInfo($this->file_path);
     return $a['width'];
   }
-
-  public function forceSize($width_must_fit=false) {
-      $current_height = $this->image->height();
-      $current_width = $this->image->width();
-      
-      // we need height of 250px but not for tiles stack
-      if ($current_width > $current_height && !$width_must_fit) {
-             $this->image->resize(floor((250*$current_width)/$current_height));
-      } else {
-                 $this->image->resize(200);
-         }
-  }
   
   public function get($extra = '') {
          return '<img src="'.GET_THUMBNAIL_PATH.urlencode($this->getPath()).'" '.$extra.'>';
@@ -117,6 +106,10 @@ class TileSingle extends TileBase {
   public function getPath() {
          return $this->file_path;
   }
+  
+  public function getOnClickAction() {
+         return 'javascript:openFile(\''.$this->file_path.'\');';
+  }
 
   private $file_path;
   private $image;
@@ -145,7 +138,7 @@ class TileStack extends TileBase {
     for ($i = 0; $i < count($this->tiles_array); $i++) {
            $max = max($max, $this->tiles_array[$i]->getWidth());
     }
-    return min(200, $max);
+    return min(IMAGE_WIDTH, $max);
   }
 
   public function get() {
@@ -155,11 +148,10 @@ class TileStack extends TileBase {
       $left = rand(-5, 5);
       $img_w = $this->tiles_array[$i]->getWidth();
       $extra = '';
-      if ($img_w < 200) {
+      if ($img_w < IMAGE_WIDTH) {
              $extra = 'width:'.$img_w.'px;';
       }
       $r .= '<div class="miniature_border gallery_div" style="background-image:url(\''.$this->tiles_array[$i]->getMiniatureSrc().'\');margin-top:'.$top.'px; margin-left:'.$left.'px;'.$extra.'"></div>';
-//      $r .= $this->tiles_array[$i]->get(' style="margin-top:'.$top.'px; margin-left:'.$left.'px; "');
     }
     return $r;
   }
@@ -175,6 +167,10 @@ class TileStack extends TileBase {
   public function getCount() {
          return count($this->tiles_array);
   }
+  
+  public function getOnClickAction() {
+         return 'javascript:openNewGal(\''.$this->stack_name.'\');';
+  }
 
   private $tiles_array;
   private $stack_name;
index 55710038c0a684b1a997e58aae64fe0b054c80b7..d3b281a2c382274a937c36976924ce0444bd302d 100644 (file)
@@ -1,17 +1,25 @@
 <?php
+OCP\Util::addStyle('files', 'files');
+OCP\Util::addscript('files_imageviewer', 'jquery.mousewheel-3.0.4.pack');
+OCP\Util::addscript('files_imageviewer', 'jquery.fancybox-1.3.4.pack');
+OCP\Util::addStyle( 'files_imageviewer', 'jquery.fancybox-1.3.4' );
+
 $l = OC_L10N::get('gallery');
 ?>
 <style>
-div.gallery_div {position:relative; display: inline-block; height: 202px; width: 200px; margin: 5px;}
-div.miniature_border {position:absolute; height: 200px; -webkit-transition-duration: .2s; background-position: 50%;}
-div.line {display:inline-block; border: 0; width: auto; height: 210px}
-div.gallery_div img{position:absolute; top: 1; left: 0; -webkit-transition-duration: 0.3s; height:200px; width: auto;}
+div.gallery_div {position:relative; display: inline-block; height: 152px; width: 150px; margin: 5px;}
+div.miniature_border {position:absolute; height: 150px; -webkit-transition-duration: .2s; background-position: 50%;}
+div.line {display:inline-block; border: 0; width: auto; height: 160px}
+div.gallery_div img{position:absolute; top: 1; left: 0; -webkit-transition-duration: 0.3s; height:150px; width: auto;}
 div.gallery_div img.shrinker {width:80px !important;}
-div.title { opacity: 0; text-align: center; vertical-align: middle; font-family: Arial; font-size: 12px; border: 0; position: absolute; text-overflow: ellipsis; bottom: 20px; left:10px; height:auto; padding: 5px; width: 170px; background-color: black; color: white; -webkit-transition: opacity 0.5s;  z-index:1000; border-radius: 7px}
+div.title { opacity: 0; text-align: center; vertical-align: middle; font-family: Arial; font-size: 12px; border: 0; position: absolute; text-overflow: ellipsis; bottom: 20px; left:5px; height:auto; padding: 5px; width: 140px; background-color: black; color: white; -webkit-transition: opacity 0.5s;  z-index:1000; border-radius: 7px}
 div.visible { opacity: 0.8;}
 </style>
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
 <script type="text/javascript">
+
+var root = "<?php echo !empty($_GET['root']) ? $_GET['root'] : '/'; ?>";
+
 function t(element) {
        $('div', element).each(function(index, elem) {
                if ($(elem).hasClass('title')) {
@@ -36,6 +44,20 @@ function o(element) {
        });
 }
 
+function openNewGal(album_name) {
+       root = root + album_name + "/";
+       var url = window.location.toString().replace(window.location.search, '');
+       url = url + "?app=gallery&root="+root;
+       
+       window.location = url;
+}
+
+function openFile(file_path) {
+       var url = window.location.toString().replace(window.location.search, '');
+       url = url + "?app=files&getfile=download.php?file="+file_path;
+       window.location = url;
+}
+
 </script>
 
 <?php
@@ -43,7 +65,7 @@ function o(element) {
 include('apps/gallery/lib/tiles.php');
 $root = empty($_GET['root'])?'/':$_GET['root'];
 
-$images = \OC_FileCache::searchByMime('image', null, '/'.\OCP\USER\getUser().'/files'.$root);
+$images = \OC_FileCache::searchByMime('image', null, '/'.\OCP\USER::getUser().'/files'.$root);
 sort($images);
 
 $arr = array();