Added Album::prepareData and improved thumbs response from API

This commit is contained in:
Tobias Reich 2015-03-12 12:57:48 +01:00
parent 8102574b85
commit ea149b68af
7 changed files with 96 additions and 39 deletions

BIN
dist/main.js vendored

Binary file not shown.

BIN
dist/view.js vendored

Binary file not shown.

View File

@ -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() { public function get() {
# Check dependencies # Check dependencies
@ -172,9 +202,8 @@ class Album extends Module {
# For each album # For each album
while ($album = $albums->fetch_assoc()) { while ($album = $albums->fetch_assoc()) {
# Parse info # Turn data from the database into a front-end friendly format
$album['sysdate'] = date('F Y', $album['sysstamp']); $album = Album::prepareData($album);
$album['password'] = ($album['password']=='' ? '0' : '1');
# Thumbs # Thumbs
if (($public===true&&$album['password']==='0')|| if (($public===true&&$album['password']==='0')||
@ -187,7 +216,7 @@ class Album extends Module {
# For each thumb # For each thumb
$k = 0; $k = 0;
while ($thumb = $thumbs->fetch_object()) { while ($thumb = $thumbs->fetch_object()) {
$album["thumb$k"] = LYCHEE_URL_UPLOADS_THUMB . $thumb->thumbUrl; $album['thumbs'][$k] = LYCHEE_URL_UPLOADS_THUMB . $thumb->thumbUrl;
$k++; $k++;
} }
@ -221,54 +250,87 @@ class Album extends Module {
'recent' => null 'recent' => null
); );
###
# Unsorted # Unsorted
###
$query = Database::prepare($this->database, 'SELECT thumbUrl FROM ? WHERE album = 0 ' . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS)); $query = Database::prepare($this->database, 'SELECT thumbUrl FROM ? WHERE album = 0 ' . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS));
$unsorted = $this->database->query($query); $unsorted = $this->database->query($query);
$i = 0; $i = 0;
$return['unsorted'] = array(
'thumbs' => array(),
'num' => $unsorted->num_rows
);
while($row = $unsorted->fetch_object()) { while($row = $unsorted->fetch_object()) {
if ($i<3) { if ($i<3) {
$return['unsorted']["thumb$i"] = LYCHEE_URL_UPLOADS_THUMB . $row->thumbUrl; $return['unsorted']['thumbs'][$i] = LYCHEE_URL_UPLOADS_THUMB . $row->thumbUrl;
$i++; $i++;
} else break; } else break;
} }
$return['unsorted']['num'] = $unsorted->num_rows;
###
# Starred # Starred
###
$query = Database::prepare($this->database, 'SELECT thumbUrl FROM ? WHERE star = 1 ' . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS)); $query = Database::prepare($this->database, 'SELECT thumbUrl FROM ? WHERE star = 1 ' . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS));
$starred = $this->database->query($query); $starred = $this->database->query($query);
$i = 0; $i = 0;
$return['starred'] = array(
'thumbs' => array(),
'num' => $starred->num_rows
);
while($row3 = $starred->fetch_object()) { while($row3 = $starred->fetch_object()) {
if ($i<3) { if ($i<3) {
$return['starred']["thumb$i"] = LYCHEE_URL_UPLOADS_THUMB . $row3->thumbUrl; $return['starred']['thumbs'][$i] = LYCHEE_URL_UPLOADS_THUMB . $row3->thumbUrl;
$i++; $i++;
} else break; } else break;
} }
$return['starred']['num'] = $starred->num_rows;
###
# Public # Public
###
$query = Database::prepare($this->database, 'SELECT thumbUrl FROM ? WHERE public = 1 ' . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS)); $query = Database::prepare($this->database, 'SELECT thumbUrl FROM ? WHERE public = 1 ' . $this->settings['sorting'], array(LYCHEE_TABLE_PHOTOS));
$public = $this->database->query($query); $public = $this->database->query($query);
$i = 0; $i = 0;
$return['public'] = array(
'thumbs' => array(),
'num' => $public->num_rows
);
while($row2 = $public->fetch_object()) { while($row2 = $public->fetch_object()) {
if ($i<3) { if ($i<3) {
$return['public']["thumb$i"] = LYCHEE_URL_UPLOADS_THUMB . $row2->thumbUrl; $return['public']['thumbs'][$i] = LYCHEE_URL_UPLOADS_THUMB . $row2->thumbUrl;
$i++; $i++;
} else break; } else break;
} }
$return['public']['num'] = $public->num_rows;
###
# Recent # 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)); $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); $recent = $this->database->query($query);
$i = 0; $i = 0;
$return['recent'] = array(
'thumbs' => array(),
'num' => $recent->num_rows
);
while($row3 = $recent->fetch_object()) { while($row3 = $recent->fetch_object()) {
if ($i<3) { if ($i<3) {
$return['recent']["thumb$i"] = LYCHEE_URL_UPLOADS_THUMB . $row3->thumbUrl; $return['recent']['thumbs'][$i] = LYCHEE_URL_UPLOADS_THUMB . $row3->thumbUrl;
$i++; $i++;
} else break; } else break;
} }
$return['recent']['num'] = $recent->num_rows;
# Return SmartAlbums
return $return; return $return;
} }

View File

@ -532,10 +532,13 @@ class Photo extends Module {
# into a front-end friendly format: id, title, tags, public, star, album, thumbUrl, takestamp, url # into a front-end friendly format: id, title, tags, public, star, album, thumbUrl, takestamp, url
# Note that some attributes remain unchanged # Note that some attributes remain unchanged
# Check dependencies
self::dependencies(isset($data));
# Init # Init
$photo = null; $photo = null;
# Set unchanged attribute # Set unchanged attributes
$photo['id'] = $data['id']; $photo['id'] = $data['id'];
$photo['title'] = $data['title']; $photo['title'] = $data['title'];
$photo['tags'] = $data['tags']; $photo['tags'] = $data['tags'];

View File

@ -59,13 +59,13 @@ albums.load = function() {
albums.parse = function(album) { albums.parse = function(album) {
if (album.password==='1'&&lychee.publicMode===true) { if (album.password==='1'&&lychee.publicMode===true) {
album.thumb0 = 'src/images/password.svg'; album.thumbs[0] = 'src/images/password.svg';
album.thumb1 = 'src/images/password.svg'; album.thumbs[1] = 'src/images/password.svg';
album.thumb2 = 'src/images/password.svg'; album.thumbs[2] = 'src/images/password.svg';
} else { } else {
if (!album.thumb0) album.thumb0 = 'src/images/no_images.svg'; if (!album.thumbs[0]) album.thumbs[0] = 'src/images/no_images.svg';
if (!album.thumb1) album.thumb1 = 'src/images/no_images.svg'; if (!album.thumbs[1]) album.thumbs[1] = 'src/images/no_images.svg';
if (!album.thumb2) album.thumb2 = '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', title: 'Unsorted',
sysdate: data.unsorted.num + ' photos', sysdate: data.unsorted.num + ' photos',
unsorted: '1', unsorted: '1',
thumb0: data.unsorted.thumb0, thumbs: data.unsorted.thumbs
thumb1: data.unsorted.thumb1,
thumb2: data.unsorted.thumb2
}; };
data.starred = { data.starred = {
@ -87,9 +85,7 @@ albums._createSmartAlbums = function(data) {
title: 'Starred', title: 'Starred',
sysdate: data.starred.num + ' photos', sysdate: data.starred.num + ' photos',
star: '1', star: '1',
thumb0: data.starred.thumb0, thumbs: data.starred.thumbs
thumb1: data.starred.thumb1,
thumb2: data.starred.thumb2
}; };
data.public = { data.public = {
@ -97,9 +93,7 @@ albums._createSmartAlbums = function(data) {
title: 'Public', title: 'Public',
sysdate: data.public.num + ' photos', sysdate: data.public.num + ' photos',
public: '1', public: '1',
thumb0: data.public.thumb0, thumbs: data.public.thumbs
thumb1: data.public.thumb1,
thumb2: data.public.thumb2
}; };
data.recent = { data.recent = {
@ -107,9 +101,7 @@ albums._createSmartAlbums = function(data) {
title: 'Recent', title: 'Recent',
sysdate: data.recent.num + ' photos', sysdate: data.recent.num + ' photos',
recent: '1', recent: '1',
thumb0: data.recent.thumb0, thumbs: data.recent.thumbs
thumb1: data.recent.thumb1,
thumb2: data.recent.thumb2
}; };
} }

View File

@ -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 = ` html = `
<div class='album' data-id='${ data.id }'> <div class='album' data-id='${ data.id }'>
<img src='${ data.thumb2 }' width='200' height='200' alt='thumb' data-type='nonretina'> <img src='${ data.thumbs[2] }' width='200' height='200' alt='thumb' data-type='nonretina'>
<img src='${ data.thumb1 }' width='200' height='200' alt='thumb' data-type='nonretina'> <img src='${ data.thumbs[1] }' width='200' height='200' alt='thumb' data-type='nonretina'>
<img src='${ data.thumb0 }' width='200' height='200' alt='thumb' data-type='${ typeThumb }'> <img src='${ data.thumbs[0] }' width='200' height='200' alt='thumb' data-type='${ typeThumb }'>
<div class='overlay'> <div class='overlay'>
<h1 title='${ longTitle }'>${ title }</h1> <h1 title='${ longTitle }'>${ title }</h1>
<a>${ data.sysdate }</a> <a>${ data.sysdate }</a>

View File

@ -87,9 +87,9 @@ contextMenu.albumTitle = function(albumID, e) {
var that = this, var that = this,
title = ''; title = '';
if (!that.thumb0) that.thumb0 = 'src/images/no_cover.svg'; if (!that.thumbs[0]) that.thumbs[0] = 'src/images/no_cover.svg';
title = "<img class='cover' width='16' height='16' src='" + that.thumb0 + "'><div class='title'>" + that.title + "</div>"; title = "<img class='cover' width='16' height='16' src='" + that.thumbs[0] + "'><div class='title'>" + that.title + "</div>";
if (that.id!=albumID) items.push({ type: 'item', title, fn: function() { lychee.goto(that.id) } }); 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; var that = this;
if (!that.thumb0) that.thumb0 = 'src/images/no_cover.svg'; if (!that.thumbs[0]) that.thumbs[0] = 'src/images/no_cover.svg';
that.title = "<img class='cover' width='16' height='16' src='" + that.thumb0 + "'><div class='title'>" + that.title + "</div>"; that.title = "<img class='cover' width='16' height='16' src='" + that.thumbs[0] + "'><div class='title'>" + that.title + "</div>";
if (that.id!=album.getID()) items.push({ type: 'item', title: that.title, fn: function() { photo.setAlbum(photoIDs, that.id) } }); if (that.id!=album.getID()) items.push({ type: 'item', title: that.title, fn: function() { photo.setAlbum(photoIDs, that.id) } });