Added Album::prepareData and improved thumbs response from API
This commit is contained in:
parent
8102574b85
commit
ea149b68af
BIN
dist/main.js
vendored
BIN
dist/main.js
vendored
Binary file not shown.
BIN
dist/view.js
vendored
BIN
dist/view.js
vendored
Binary file not shown.
@ -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;
|
||||
|
||||
}
|
||||
|
@ -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'];
|
||||
|
@ -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
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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 = `
|
||||
<div class='album' data-id='${ data.id }'>
|
||||
<img src='${ data.thumb2 }' 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.thumb0 }' width='200' height='200' alt='thumb' data-type='${ typeThumb }'>
|
||||
<img src='${ data.thumbs[2] }' 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.thumbs[0] }' width='200' height='200' alt='thumb' data-type='${ typeThumb }'>
|
||||
<div class='overlay'>
|
||||
<h1 title='${ longTitle }'>${ title }</h1>
|
||||
<a>${ data.sysdate }</a>
|
||||
|
@ -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 = "<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) } });
|
||||
|
||||
@ -224,8 +224,8 @@ contextMenu.move = function(photoIDs, e) {
|
||||
|
||||
var that = this;
|
||||
|
||||
if (!that.thumb0) that.thumb0 = 'src/images/no_cover.svg';
|
||||
that.title = "<img class='cover' width='16' height='16' src='" + that.thumb0 + "'><div class='title'>" + that.title + "</div>";
|
||||
if (!that.thumbs[0]) that.thumbs[0] = 'src/images/no_cover.svg';
|
||||
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) } });
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user