Merge pull request #754 from electerious/develop

* Drag and Drop Sorting using Jquery-ui

* Updating database tables

* version 3.1.7
This commit is contained in:
Fly Man 2018-02-24 01:41:07 +01:00
parent ab0f86f5fb
commit 20a1ff2d61
No known key found for this signature in database
GPG Key ID: 2DDA5DB4F6486124
11 changed files with 90 additions and 2 deletions

BIN
dist/main.css vendored

Binary file not shown.

BIN
dist/main.js vendored

Binary file not shown.

BIN
dist/view.js vendored

Binary file not shown.

View File

@ -26,6 +26,7 @@ final class Admin extends Access {
case 'Album::setTitle': self::setAlbumTitleAction(); break;
case 'Album::setDescription': self::setAlbumDescriptionAction(); break;
case 'Album::setPublic': self::setAlbumPublicAction(); break;
case 'Album::setPosition': self::setPositionAction(); break;
case 'Album::delete': self::deleteAlbumAction(); break;
case 'Album::merge': self::mergeAlbumsAction(); break;
@ -115,6 +116,15 @@ final class Admin extends Access {
}
private static function setPositionAction() {
Validator::required(isset($_POST['albumID'],$_POST['photoOrder']), __METHOD__);
$album = new Album($_POST['albumID']);
Response::json($album->setPosition());
}
private static function setAlbumPublicAction() {
Validator::required(isset($_POST['albumID'], $_POST['password'], $_POST['visible'], $_POST['downloadable']), __METHOD__);

View File

@ -344,6 +344,41 @@ final class Album {
}
public function setPosition(){
// Check dependencies
Validator::required(isset($_POST['photoOrder']), __METHOD__);
// Call plugins
Plugins::get()->activate(__METHOD__, 0, func_get_args());
$id_list = implode(',', $_POST['photoOrder']);
$indices = [];
$size = count(explode(',',$id_list));
for($i = 0; $i < $size; $i++){
$indices[$i] = $i;
}
$whens = implode(
" ",
array_map(
function ($id, $value) {
return "WHEN {$id} THEN {$value}";
},
explode(',',$id_list),
$indices
)
);
$query = Database::prepare(Database::get(), "UPDATE ? SET position = CASE id ? END WHERE id IN (?)", array(LYCHEE_TABLE_PHOTOS, $whens, $id_list));
$result = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
// Call plugins
Plugins::get()->activate(__METHOD__, 1, func_get_args());
if ($result===false) return false;
return true;
}
/**
* @return boolean Returns true when successful.
*/

View File

@ -24,6 +24,7 @@ CREATE TABLE IF NOT EXISTS `?` (
`album` bigint(20) unsigned NOT NULL,
`checksum` char(40) DEFAULT NULL,
`medium` tinyint(1) NOT NULL DEFAULT '0',
`position` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
KEY `Index_album` (`album`),
KEY `Index_star` (`star`)

View File

@ -0,0 +1,25 @@
<?php
/**
* Update to version 3.1.7
*/
use Lychee\Modules\Database;
use Lychee\Modules\Response;
// Add position to photos
$query = Database::prepare($connection, "SELECT `position` FROM `?` LIMIT 1", array(LYCHEE_TABLE_PHOTOS));
$result = Database::execute($connection, $query, 'update_030107', __LINE__);
if ($result===false) {
$query = Database::prepare($connection, "ALTER TABLE `?` ADD `position` TINYINT(1) NOT NULL", array(LYCHEE_TABLE_PHOTOS));
$result = Database::execute($connection, $query, 'update_030107', __LINE__);
if ($result===false) Response::error('Could not add position to database!');
}
// Set version
if (Database::setVersion($connection, '030107')===false) Response::error('Could not update version of database!');
?>

View File

@ -83,6 +83,7 @@ paths.main = {
],
scripts: [
'node_modules/jquery/dist/jquery.min.js',
'node_modules/jquery-ui-dist/jquery-ui.min.js',
'node_modules/mousetrap/mousetrap.min.js',
'node_modules/mousetrap/plugins/global-bind/mousetrap-global-bind.min.js',
'node_modules/basiccontext/dist/basicContext.min.js',

View File

@ -28,6 +28,7 @@
"gulp-sass": "^3.1.0",
"gulp-uglify": "^2.1.1",
"jquery": "^3.2.0",
"jquery-ui": "^1.12.1",
"mousetrap": "^1.6.0"
}
}

View File

@ -30,6 +30,21 @@ album.getID = function() {
}
album.load = function(albumID, refresh = false) {
$('.content').sortable({
stop: function(event, ui){
let albumID = ui.item.data('album-id');
let photoOrder = $('.content').children().map(function(){
return $(this).data('id');
}).get();
let params = {
albumID: albumID,
photoOrder: photoOrder
};
api.post('Album::setPosition', params, function(data) {
if (data!==true) lychee.error(null, params, data)
})
}
});
password.get(albumID, function() {

View File

@ -5,8 +5,8 @@
lychee = {
title : document.title,
version : '3.1.6',
versionCode : '030106',
version : '3.1.7',
versionCode : '030107',
updatePath : '//update.electerious.com/index.json',
updateURL : 'https://github.com/electerious/Lychee',