From ea149b68af0db94fba071ce16f602bfe8db1d80b Mon Sep 17 00:00:00 2001 From: Tobias Reich Date: Thu, 12 Mar 2015 12:57:48 +0100 Subject: [PATCH] Added Album::prepareData and improved thumbs response from API --- dist/main.js | Bin 171398 -> 171259 bytes dist/view.js | Bin 93584 -> 93596 bytes php/modules/Album.php | 86 +++++++++++++++++++++++++++++++------ php/modules/Photo.php | 5 ++- src/scripts/albums.js | 28 +++++------- src/scripts/build.js | 8 ++-- src/scripts/contextMenu.js | 8 ++-- 7 files changed, 96 insertions(+), 39 deletions(-) diff --git a/dist/main.js b/dist/main.js index e67a3469244578de3e905a4b55a102e485d2c9ff..9f079ff9b56c65b54693d75adc91df7f82ccb9d1 100644 GIT binary patch delta 348 zcmZqM&GmaHSHl*@zy&PD(FU>8OBXOI0a=D{mQn2V84DOygg~-2H5#dUB^jl;Nno`n zAmWB7;y|5HaU&FQpg9@~8D|L>Tczri<`w4`m87OX&6>`>h%rbABvD+FSX6`%pS_4N zQUoX-tyEB&l#`jP6bsW~vzReZ5Tv6hH90k}1S-7!%woo9R)|M5Rx)M*SwL&wtYnOU zcnQh^dK1Vp*iZPN4hvHa-y6Hf5 M;@i(%W!!Nb00C)&=>Px# delta 487 zcmeypldEkvSHl*@zy*v3(-$sal$xHufRTgI5Q%LBVyo~N)YNFC>Xl@a<|Y|T=UoUC zF+_+MLPU%ZB1Rw)nd$Kh8S7jPtWxz#^NRC}N>WpxCg^|-GQ^NDgh&`+NEl83u#hpx z31n1pNn%kE7L!oKkqkl+H<})@h%wRwXil_JL1|J>X0lQ&x|`5t5N4sv7)?L8h%wL} z8*Nu!%oxoIjDV&Uj9H98pRQnx07e0rG5}E~+wZJod@2u) n1DF-lFP~%#XEfNZcZ#uy3sq**6~8GkqAdfGnff>AJp*5kQt9oCTBxikWQR<;!?Y9soSZ B650R& delta 45 ucmbPpn{~o%)`l&N89s~#({p?nvlxx0-|}IMU^IkK1|Z60`!Qd}Yw`enXb?33 diff --git a/php/modules/Album.php b/php/modules/Album.php index 6ba81e0..dc690b0 100644 --- a/php/modules/Album.php +++ b/php/modules/Album.php @@ -52,6 +52,36 @@ class Album extends Module { } + public static function prepareData($data) { + + # This function requires the following album-attributes and turns them + # into a front-end friendly format: id, title, public, sysstamp, password + # Note that some attributes remain unchanged + + # Check dependencies + self::dependencies(isset($data)); + + # Init + $album = null; + + # Set unchanged attributes + $album['id'] = $data['id']; + $album['title'] = $data['title']; + $album['public'] = $data['public']; + + # Parse date + $album['sysdate'] = date('F Y', $data['sysstamp']); + + # Parse password + $album['password'] = ($data['password']=='' ? '0' : '1'); + + # Set placeholder for thumbs + $album['thumbs'] = array(); + + return $album; + + } + public function get() { # Check dependencies @@ -172,9 +202,8 @@ class Album extends Module { # For each album while ($album = $albums->fetch_assoc()) { - # Parse info - $album['sysdate'] = date('F Y', $album['sysstamp']); - $album['password'] = ($album['password']=='' ? '0' : '1'); + # Turn data from the database into a front-end friendly format + $album = Album::prepareData($album); # Thumbs if (($public===true&&$album['password']==='0')|| @@ -187,7 +216,7 @@ class Album extends Module { # For each thumb $k = 0; while ($thumb = $thumbs->fetch_object()) { - $album["thumb$k"] = LYCHEE_URL_UPLOADS_THUMB . $thumb->thumbUrl; + $album['thumbs'][$k] = LYCHEE_URL_UPLOADS_THUMB . $thumb->thumbUrl; $k++; } @@ -221,54 +250,87 @@ class Album extends Module { 'recent' => null ); + ### # Unsorted + ### + $query = Database::prepare($this->database, 'SELECT thumbUrl FROM ? WHERE album = 0 ' . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS)); $unsorted = $this->database->query($query); $i = 0; + + $return['unsorted'] = array( + 'thumbs' => array(), + 'num' => $unsorted->num_rows + ); + while($row = $unsorted->fetch_object()) { if ($i<3) { - $return['unsorted']["thumb$i"] = LYCHEE_URL_UPLOADS_THUMB . $row->thumbUrl; + $return['unsorted']['thumbs'][$i] = LYCHEE_URL_UPLOADS_THUMB . $row->thumbUrl; $i++; } else break; } - $return['unsorted']['num'] = $unsorted->num_rows; + ### # Starred + ### + $query = Database::prepare($this->database, 'SELECT thumbUrl FROM ? WHERE star = 1 ' . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS)); $starred = $this->database->query($query); $i = 0; + + $return['starred'] = array( + 'thumbs' => array(), + 'num' => $starred->num_rows + ); + while($row3 = $starred->fetch_object()) { if ($i<3) { - $return['starred']["thumb$i"] = LYCHEE_URL_UPLOADS_THUMB . $row3->thumbUrl; + $return['starred']['thumbs'][$i] = LYCHEE_URL_UPLOADS_THUMB . $row3->thumbUrl; $i++; } else break; } - $return['starred']['num'] = $starred->num_rows; + ### # Public + ### + $query = Database::prepare($this->database, 'SELECT thumbUrl FROM ? WHERE public = 1 ' . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS)); $public = $this->database->query($query); $i = 0; + + $return['public'] = array( + 'thumbs' => array(), + 'num' => $public->num_rows + ); + while($row2 = $public->fetch_object()) { if ($i<3) { - $return['public']["thumb$i"] = LYCHEE_URL_UPLOADS_THUMB . $row2->thumbUrl; + $return['public']['thumbs'][$i] = LYCHEE_URL_UPLOADS_THUMB . $row2->thumbUrl; $i++; } else break; } - $return['public']['num'] = $public->num_rows; + ### # Recent + ### + $query = Database::prepare($this->database, 'SELECT thumbUrl FROM ? WHERE LEFT(id, 10) >= unix_timestamp(DATE_SUB(NOW(), INTERVAL 1 DAY)) ' . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS)); $recent = $this->database->query($query); $i = 0; + + $return['recent'] = array( + 'thumbs' => array(), + 'num' => $recent->num_rows + ); + while($row3 = $recent->fetch_object()) { if ($i<3) { - $return['recent']["thumb$i"] = LYCHEE_URL_UPLOADS_THUMB . $row3->thumbUrl; + $return['recent']['thumbs'][$i] = LYCHEE_URL_UPLOADS_THUMB . $row3->thumbUrl; $i++; } else break; } - $return['recent']['num'] = $recent->num_rows; + # Return SmartAlbums return $return; } diff --git a/php/modules/Photo.php b/php/modules/Photo.php index 8bdd7d4..c23ad4c 100755 --- a/php/modules/Photo.php +++ b/php/modules/Photo.php @@ -532,10 +532,13 @@ class Photo extends Module { # into a front-end friendly format: id, title, tags, public, star, album, thumbUrl, takestamp, url # Note that some attributes remain unchanged + # Check dependencies + self::dependencies(isset($data)); + # Init $photo = null; - # Set unchanged attribute + # Set unchanged attributes $photo['id'] = $data['id']; $photo['title'] = $data['title']; $photo['tags'] = $data['tags']; diff --git a/src/scripts/albums.js b/src/scripts/albums.js index 72dbb81..9db151f 100644 --- a/src/scripts/albums.js +++ b/src/scripts/albums.js @@ -59,13 +59,13 @@ albums.load = function() { albums.parse = function(album) { if (album.password==='1'&&lychee.publicMode===true) { - album.thumb0 = 'src/images/password.svg'; - album.thumb1 = 'src/images/password.svg'; - album.thumb2 = 'src/images/password.svg'; + album.thumbs[0] = 'src/images/password.svg'; + album.thumbs[1] = 'src/images/password.svg'; + album.thumbs[2] = 'src/images/password.svg'; } else { - if (!album.thumb0) album.thumb0 = 'src/images/no_images.svg'; - if (!album.thumb1) album.thumb1 = 'src/images/no_images.svg'; - if (!album.thumb2) album.thumb2 = 'src/images/no_images.svg'; + if (!album.thumbs[0]) album.thumbs[0] = 'src/images/no_images.svg'; + if (!album.thumbs[1]) album.thumbs[1] = 'src/images/no_images.svg'; + if (!album.thumbs[2]) album.thumbs[2] = 'src/images/no_images.svg'; } } @@ -77,9 +77,7 @@ albums._createSmartAlbums = function(data) { title: 'Unsorted', sysdate: data.unsorted.num + ' photos', unsorted: '1', - thumb0: data.unsorted.thumb0, - thumb1: data.unsorted.thumb1, - thumb2: data.unsorted.thumb2 + thumbs: data.unsorted.thumbs }; data.starred = { @@ -87,9 +85,7 @@ albums._createSmartAlbums = function(data) { title: 'Starred', sysdate: data.starred.num + ' photos', star: '1', - thumb0: data.starred.thumb0, - thumb1: data.starred.thumb1, - thumb2: data.starred.thumb2 + thumbs: data.starred.thumbs }; data.public = { @@ -97,9 +93,7 @@ albums._createSmartAlbums = function(data) { title: 'Public', sysdate: data.public.num + ' photos', public: '1', - thumb0: data.public.thumb0, - thumb1: data.public.thumb1, - thumb2: data.public.thumb2 + thumbs: data.public.thumbs }; data.recent = { @@ -107,9 +101,7 @@ albums._createSmartAlbums = function(data) { title: 'Recent', sysdate: data.recent.num + ' photos', recent: '1', - thumb0: data.recent.thumb0, - thumb1: data.recent.thumb1, - thumb2: data.recent.thumb2 + thumbs: data.recent.thumbs }; } diff --git a/src/scripts/build.js b/src/scripts/build.js index 565eec4..159c846 100644 --- a/src/scripts/build.js +++ b/src/scripts/build.js @@ -73,13 +73,13 @@ build.album = function(data) { } - if (data.thumb0.split('.').pop()==='svg') typeThumb = 'nonretina'; + if (data.thumbs[0].split('.').pop()==='svg') typeThumb = 'nonretina'; html = `
- thumb - thumb - thumb + thumb + thumb + thumb

${ title }

${ data.sysdate } diff --git a/src/scripts/contextMenu.js b/src/scripts/contextMenu.js index 45ed35f..f966643 100644 --- a/src/scripts/contextMenu.js +++ b/src/scripts/contextMenu.js @@ -87,9 +87,9 @@ contextMenu.albumTitle = function(albumID, e) { var that = this, title = ''; - if (!that.thumb0) that.thumb0 = 'src/images/no_cover.svg'; + if (!that.thumbs[0]) that.thumbs[0] = 'src/images/no_cover.svg'; - title = "
" + that.title + "
"; + title = "
" + that.title + "
"; if (that.id!=albumID) items.push({ type: 'item', title, fn: function() { lychee.goto(that.id) } }); @@ -224,8 +224,8 @@ contextMenu.move = function(photoIDs, e) { var that = this; - if (!that.thumb0) that.thumb0 = 'src/images/no_cover.svg'; - that.title = "
" + that.title + "
"; + if (!that.thumbs[0]) that.thumbs[0] = 'src/images/no_cover.svg'; + that.title = "
" + that.title + "
"; if (that.id!=album.getID()) items.push({ type: 'item', title: that.title, fn: function() { photo.setAlbum(photoIDs, that.id) } });