Browse Source

Added album sorting #98

Tobias Reich 9 years ago
parent
commit
90ac81acf1

File diff suppressed because it is too large
+ 0 - 0
dist/main.js


+ 7 - 2
php/access/Admin.php

@@ -279,9 +279,14 @@ class Admin extends Access {
 
 	private function setSorting() {
 
-		Module::dependencies(isset($_POST['type'], $_POST['order']));
+		Module::dependencies(isset($_POST['typeAlbums'], $_POST['orderAlbums'], $_POST['typePhotos'], $_POST['orderPhotos']));
 		$this->settings = new Settings($this->database);
-		echo $this->settings->setSorting($_POST['type'], $_POST['order']);
+
+		$sA = $this->settings->setSortingAlbums($_POST['typeAlbums'], $_POST['orderAlbums']);
+		$sP = $this->settings->setSortingPhotos($_POST['typePhotos'], $_POST['orderPhotos']);
+
+		if ($sA===true&&$sP===true)	echo true;
+		else						echo false;
 
 	}
 

+ 12 - 0
php/database/update_030001.php

@@ -23,6 +23,18 @@ if (!$result) {
 	return false;
 }
 
+# Add album sorting to settings
+$query	= Database::prepare($database, "SELECT `key` FROM `?` WHERE `key` = 'sortingAlbums' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
+$result	= $database->query($query);
+if ($result->num_rows===0) {
+	$query	= Database::prepare($database, "INSERT INTO `?` (`key`, `value`) VALUES ('sortingAlbums', 'ORDER BY id DESC')", array(LYCHEE_TABLE_SETTINGS));
+	$result	= $database->query($query);
+	if (!$result) {
+		Log::error($database, 'update_030001', __LINE__, 'Could not update database (' . $database->error . ')');
+		return false;
+	}
+}
+
 # Set version
 if (Database::setVersion($database, '030001')===false) return false;
 

+ 2 - 2
php/modules/Album.php

@@ -189,8 +189,8 @@ class Album extends Module {
 		if ($public===false) $return['smartalbums'] = $this->getSmartInfo();
 
 		# Albums query
-		if ($public===false)	$query = Database::prepare($this->database, 'SELECT id, title, public, sysstamp, password FROM ?', array(LYCHEE_TABLE_ALBUMS));
-		else					$query = Database::prepare($this->database, 'SELECT id, title, public, sysstamp, password FROM ? WHERE public = 1 AND visible <> 0', array(LYCHEE_TABLE_ALBUMS));
+		if ($public===false)	$query = Database::prepare($this->database, 'SELECT id, title, public, sysstamp, password FROM ? ' . $this->settings['sortingAlbums'], array(LYCHEE_TABLE_ALBUMS));
+		else					$query = Database::prepare($this->database, 'SELECT id, title, public, sysstamp, password FROM ? WHERE public = 1 AND visible <> 0 ' . $this->settings['sortingAlbums'], array(LYCHEE_TABLE_ALBUMS));
 
 		# Execute query
 		$albums = $this->database->query($query);

+ 3 - 0
php/modules/Session.php

@@ -68,9 +68,12 @@ class Session extends Module {
 			# Unset unused vars
 			unset($return['config']['thumbQuality']);
 			unset($return['config']['sorting']);
+			unset($return['config']['sortingAlbums']);
 			unset($return['config']['dropboxKey']);
 			unset($return['config']['login']);
 			unset($return['config']['location']);
+			unset($return['config']['imagick']);
+			unset($return['config']['medium']);
 			unset($return['config']['plugins']);
 
 		}

+ 58 - 1
php/modules/Settings.php

@@ -129,7 +129,7 @@ class Settings extends Module {
 
 	}
 
-	public function setSorting($type, $order) {
+	public function setSortingPhotos($type, $order) {
 
 		# Check dependencies
 		self::dependencies(isset($this->database, $type, $order));
@@ -182,6 +182,7 @@ class Settings extends Module {
 		# Execute query
 		# Do not prepare $sorting because it is a true statement
 		# Preparing (escaping) the sorting would destroy it
+		# $sorting is save and can't contain user-input
 		$query	= Database::prepare($this->database, "UPDATE ? SET value = '$sorting' WHERE `key` = 'sorting'", array(LYCHEE_TABLE_SETTINGS));
 		$result	= $this->database->query($query);
 
@@ -193,6 +194,62 @@ class Settings extends Module {
 
 	}
 
+	public function setSortingAlbums($type, $order) {
+
+		# Check dependencies
+		self::dependencies(isset($this->database, $type, $order));
+
+		$sorting = 'ORDER BY ';
+
+		# Set row
+		switch ($type) {
+
+			case 'id':			$sorting .= 'id';
+								break;
+
+			case 'title':		$sorting .= 'title';
+								break;
+
+			case 'description':	$sorting .= 'description';
+								break;
+
+			case 'public':		$sorting .= 'public';
+								break;
+
+			default:			exit('Error: Unknown type for sorting!');
+
+		}
+
+		$sorting .= ' ';
+
+		# Set order
+		switch ($order) {
+
+			case 'ASC':		$sorting .= 'ASC';
+							break;
+
+			case 'DESC':	$sorting .= 'DESC';
+							break;
+
+			default:		exit('Error: Unknown order for sorting!');
+
+		}
+
+		# Execute query
+		# Do not prepare $sorting because it is a true statement
+		# Preparing (escaping) the sorting would destroy it
+		# $sorting is save and can't contain user-input
+		$query	= Database::prepare($this->database, "UPDATE ? SET value = '$sorting' WHERE `key` = 'sortingAlbums'", array(LYCHEE_TABLE_SETTINGS));
+		$result	= $this->database->query($query);
+
+		if (!$result) {
+			Log::error($this->database, __METHOD__, __LINE__, $this->database->error);
+			return false;
+		}
+		return true;
+
+	}
+
 }
 
 ?>

+ 3 - 5
src/scripts/contextMenu.js

@@ -96,7 +96,7 @@ contextMenu.albumTitle = function(albumID, e) {
 
 				title = "<img class='cover' width='16' height='16' src='" + that.thumbs[0] + "'><div class='title'>" + that.title + "</div>";
 
-				if (that.id!=albumID) items.unshift({ type: 'item', title, fn: function() { lychee.goto(that.id) } });
+				if (that.id!=albumID) items.push({ type: 'item', title, fn: function() { lychee.goto(that.id) } });
 
 			});
 
@@ -127,9 +127,7 @@ contextMenu.mergeAlbum = function(albumID, e) {
 				if (!that.thumbs[0]) that.thumbs[0] = 'src/images/no_cover.svg';
 				that.contextTitle = "<img class='cover' width='16' height='16' src='" + that.thumbs[0] + "'><div class='title'>" + that.title + "</div>";
 
-				if (that.id!=album.getID()) {
-					items.unshift({ type: 'item', title: that.contextTitle, fn: function() { album.merge([albumID, that.id]) } });
-				}
+				if (that.id!=albumID) items.push({ type: 'item', title: that.contextTitle, fn: function() { album.merge([albumID, that.id]) } });
 
 			});
 
@@ -257,7 +255,7 @@ contextMenu.move = function(photoIDs, e) {
 				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.unshift({ 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) } });
 
 			});
 

+ 2 - 0
src/scripts/lychee.js

@@ -19,6 +19,7 @@ lychee = {
 
 	checkForUpdates:'1',
 	sorting:		'',
+	sortingAlbums:	'',
 	location:		'',
 
 	dropbox:		false,
@@ -49,6 +50,7 @@ lychee.init = function() {
 			// Logged in
 
 			lychee.sorting			= data.config.sorting			|| '';
+			lychee.sortingAlbums	= data.config.sortingAlbums		|| '';
 			lychee.dropboxKey		= data.config.dropboxKey		|| '';
 			lychee.location			= data.config.location			|| '';
 			lychee.checkForUpdates	= data.config.checkForUpdates	|| '1';

+ 42 - 11
src/scripts/settings.js

@@ -281,7 +281,8 @@ settings.setLogin = function() {
 
 settings.setSorting = function() {
 
-	var sorting = [],
+	var sortingPhotos = [],
+		sortingAlbums = [],
 		action,
 		msg = '';
 
@@ -289,21 +290,27 @@ settings.setSorting = function() {
 
 		var params;
 
-		sorting[0] = $('.basicModal select#settings_type').val();
-		sorting[1] = $('.basicModal select#settings_order').val();
+		sortingAlbums[0] = $('.basicModal select#settings_albums_type').val();
+		sortingAlbums[1] = $('.basicModal select#settings_albums_order').val();
+
+		sortingPhotos[0] = $('.basicModal select#settings_photos_type').val();
+		sortingPhotos[1] = $('.basicModal select#settings_photos_order').val();
 
 		basicModal.close();
 		albums.refresh();
 
 		params = {
-			type: sorting[0],
-			order: sorting[1]
+			typeAlbums:		sortingAlbums[0],
+			orderAlbums:	sortingAlbums[1],
+			typePhotos:		sortingPhotos[0],
+			orderPhotos:	sortingPhotos[1]
 		}
 
 		api.post('Settings::setSorting', params, function(data) {
 
 			if (data===true) {
-				lychee.sorting = 'ORDER BY ' + sorting[0] + ' ' + sorting[1];
+				lychee.sortingAlbums	= 'ORDER BY ' + sortingAlbums[0] + ' ' + sortingAlbums[1];
+				lychee.sorting			= 'ORDER BY ' + sortingPhotos[0] + ' ' + sortingPhotos[1];
 				lychee.load();
 			} else lychee.error(null, params, data);
 
@@ -312,9 +319,24 @@ settings.setSorting = function() {
 	}
 
 	msg =	`
+			<p>
+				Sort albums by
+				<select id='settings_albums_type'>
+					<option value='id'>Creation Time</option>
+					<option value='title'>Title</option>
+					<option value='description'>Description</option>
+					<option value='public'>Public</option>
+				</select>
+				in an
+				<select id='settings_albums_order'>
+					<option value='ASC'>Ascending</option>
+					<option value='DESC'>Descending</option>
+				</select>
+				order.
+			</p>
 			<p>
 				Sort photos by
-				<select id='settings_type'>
+				<select id='settings_photos_type'>
 					<option value='id'>Upload Time</option>
 					<option value='takestamp'>Take Date</option>
 					<option value='title'>Title</option>
@@ -324,7 +346,7 @@ settings.setSorting = function() {
 					<option value='type'>Photo Format</option>
 				</select>
 				in an
-				<select id='settings_order'>
+				<select id='settings_photos_order'>
 					<option value='ASC'>Ascending</option>
 					<option value='DESC'>Descending</option>
 				</select>
@@ -346,12 +368,21 @@ settings.setSorting = function() {
 		}
 	});
 
+	if (lychee.sortingAlbums!=='') {
+
+		sortingAlbums = lychee.sortingAlbums.replace('ORDER BY ', '').split(' ');
+
+		$('.basicModal select#settings_albums_type').val(sortingAlbums[0]);
+		$('.basicModal select#settings_albums_order').val(sortingAlbums[1]);
+
+	}
+
 	if (lychee.sorting!=='') {
 
-		sorting = lychee.sorting.replace('ORDER BY ', '').split(' ');
+		sortingPhotos = lychee.sorting.replace('ORDER BY ', '').split(' ');
 
-		$('.basicModal select#settings_type').val(sorting[0]);
-		$('.basicModal select#settings_order').val(sorting[1]);
+		$('.basicModal select#settings_photos_type').val(sortingPhotos[0]);
+		$('.basicModal select#settings_photos_order').val(sortingPhotos[1]);
 
 	}
 

+ 1 - 3
src/scripts/view.js

@@ -46,9 +46,7 @@ view.albums = {
 
 				$.each(albums.json.albums, function() {
 					albums.parse(this);
-
-					// Display albums in reverse order
-					albumsData = build.album(this) + albumsData;
+					albumsData += build.album(this);
 				});
 
 				// Add divider

Some files were not shown because too many files changed in this diff