diff --git a/index.html b/index.html index a816ada..0d8ef7c 100644 --- a/index.html +++ b/index.html @@ -23,7 +23,8 @@ - + + @@ -54,6 +55,9 @@ × + + + @@ -70,6 +74,9 @@ + + + @@ -141,4 +148,4 @@ - \ No newline at end of file + diff --git a/php/Access/Admin.php b/php/Access/Admin.php index cd575c7..1005399 100644 --- a/php/Access/Admin.php +++ b/php/Access/Admin.php @@ -74,8 +74,14 @@ final class Admin extends Access { private static function getAlbumsAction() { $albums = new Albums(); - Response::json($albums->get(false)); - + if (isset ($_POST['filterParams'])) + { + Response::json($albums->get(false, $_POST['filterParams'])); + } + else + { + Response::json($albums->get(false)); + } } // Album functions @@ -351,4 +357,4 @@ final class Admin extends Access { } -?> \ No newline at end of file +?> diff --git a/php/Modules/Albums.php b/php/Modules/Albums.php index e57ee84..ce286b4 100644 --- a/php/Modules/Albums.php +++ b/php/Modules/Albums.php @@ -16,7 +16,7 @@ final class Albums { /** * @return array|false Returns an array of albums or false on failure. */ - public function get($public = true) { + public function get($public = true, $filter_params = null) { // Call plugins Plugins::get()->activate(__METHOD__, 0, func_get_args()); @@ -32,8 +32,47 @@ final class Albums { if ($public===false) $return['smartalbums'] = $this->getSmartAlbums(); // Albums query - if ($public===false) $query = Database::prepare(Database::get(), 'SELECT id, title, public, sysstamp, password FROM ? ' . Settings::get()['sortingAlbums'], array(LYCHEE_TABLE_ALBUMS)); - else $query = Database::prepare(Database::get(), 'SELECT id, title, public, sysstamp, password FROM ? WHERE public = 1 AND visible <> 0 ' . Settings::get()['sortingAlbums'], array(LYCHEE_TABLE_ALBUMS)); + if ($public===false) $sql = 'SELECT id, title, public, sysstamp, password FROM ? '; + else $sql = 'SELECT id, title, public, sysstamp, password FROM ? WHERE public = 1 AND visible <> 0 '; + + $query_params1 = array (LYCHEE_TABLE_ALBUMS); + $query_params2 = array (); + + $filter_where1 = ''; + $filter_where2 = ''; + + if ($filter_params !== null) + { + $query_params1[] = LYCHEE_TABLE_PHOTOS; + + $xary = array (); + if (isset ($filter_params['star']) && $filter_params['star']) + { + $xary[] = 'star = 1'; + } + if (isset ($filter_params['tags']) && $filter_params['tags']) + { + $xary[] = "tags LIKE '%?%'"; + $query_params1[] = $filter_params['tags']; + $query_params2[] = $filter_params['tags']; + } + + $filter_where1 = join (" AND ", $xary); + $filter_where2 = "AND " . join (" AND ", $xary); + if ($public) + { + $sql .= "AND "; + } + else + { + $sql .= "WHERE "; + } + + $sql .= "id IN (SELECT DISTINCT album FROM ? WHERE $filter_where1) "; + } + + $sql .= Settings::get()['sortingAlbums']; + $query = Database::prepare (Database::get (), $sql, $query_params1); // Execute query $albums = Database::execute(Database::get(), $query, __METHOD__, __LINE__); @@ -51,7 +90,11 @@ final class Albums { ($public===false)) { // Execute query - $query = Database::prepare(Database::get(), "SELECT thumbUrl FROM ? WHERE album = '?' ORDER BY star DESC, " . substr(Settings::get()['sortingPhotos'], 9) . " LIMIT 3", array(LYCHEE_TABLE_PHOTOS, $album['id'])); + $query = Database::prepare(Database::get(), "SELECT thumbUrl FROM ? WHERE album = '?' " + . $filter_where2 + . " ORDER BY star DESC, " + . substr(Settings::get()['sortingPhotos'], 9) + . " LIMIT 3", array_merge (array(LYCHEE_TABLE_PHOTOS, $album['id']), $query_params2)); $thumbs = Database::execute(Database::get(), $query, __METHOD__, __LINE__); if ($thumbs===false) return false; @@ -188,4 +231,4 @@ final class Albums { } -?> \ No newline at end of file +?> diff --git a/src/images/ionicons.svg b/src/images/ionicons.svg index 67b9919..5780f7e 100755 --- a/src/images/ionicons.svg +++ b/src/images/ionicons.svg @@ -1 +1 @@ - \ No newline at end of file + diff --git a/src/scripts/albums.js b/src/scripts/albums.js index d6913d6..d753eb9 100644 --- a/src/scripts/albums.js +++ b/src/scripts/albums.js @@ -16,7 +16,14 @@ albums.load = function() { if (albums.json===null) { - api.post('Albums::get', {}, function(data) { + params = {} + filterParams = filter.getFilterParams () + if (filterParams !== null) + { + params.filterParams = filterParams; + } + + api.post('Albums::get', params, function(data) { let waitTime = 0 @@ -153,4 +160,4 @@ albums.refresh = function() { albums.json = null -} \ No newline at end of file +} diff --git a/src/scripts/filter.js b/src/scripts/filter.js new file mode 100644 index 0000000..f8fcef2 --- /dev/null +++ b/src/scripts/filter.js @@ -0,0 +1,120 @@ +/** + * @description Applies filters to album + */ + +var filter = {}; + +filter.currentState = { + star: 0, + tags: '' +}; + +filter.setFilter = function() { + + const action = function() { + + filter.currentState.star = 0; + if ($('#filter_star').prop('checked')) + { + filter.currentState.star = 1; + } + + filter.currentState.tags = ''; + if ($('#filter_tags').val() !== 'undefined') + { + filter.currentState.tags = $('#filter_tags').val().trim(); + } + + basicModal.close(); + + albums.refresh(); + if (album.json !== null) + { + album.load(album.json.id, true); + } + else + { + albums.load(); + } + }; + + let msg = ` +

+ Starred: + +

+

+ Tags match: + +

+ `; + + basicModal.show({ + body: msg, + buttons: { + action: { + title: 'Apply Filter', + fn: action + }, + cancel: { + title: 'Cancel', + fn: basicModal.close + } + } + }); + + + if (filter.currentState.star) + { + $('#filter_star').prop ('checked', true); + } + $('#filter_tags').val(filter.currentState.tags); + +} + +filter.checkPhoto = function(p) +{ + if (filter.currentState.star === 1) + { + if (p.star !== "1") + { + return false; + } + } + + if (filter.currentState.tags !== '') + { + if (!p.tags.includes (filter.currentState.tags)) + { + return false; + } + } + + return true; +} + +filter.isFilterActive = function () +{ + if (filter.currentState.star) + { + return true; + } + + if (filter.currentState.tags !== '') + { + return true; + } + + return false; +} + + +filter.getFilterParams = function () +{ + if (!filter.isFilterActive()) + { + return null; + } + + return filter.currentState; +} diff --git a/src/scripts/header.js b/src/scripts/header.js index ee48783..9ca9c53 100644 --- a/src/scripts/header.js +++ b/src/scripts/header.js @@ -49,6 +49,7 @@ header.bind = function() { header.dom('.header__hostedwith') .on(eventName, function() { window.open(lychee.website) }) header.dom('#button_trash_album') .on(eventName, function() { album.delete([ album.getID() ]) }) header.dom('#button_trash') .on(eventName, function() { photo.delete([ photo.getID() ]) }) + header.dom('.button_filter') .on(eventName, function() { filter.setFilter () }) header.dom('#button_archive') .on(eventName, function() { album.getArchive(album.getID()) }) header.dom('#button_star') .on(eventName, function() { photo.setStar([ photo.getID() ]) }) header.dom('#button_back_home') .on(eventName, function() { lychee.goto() }) @@ -177,4 +178,4 @@ header.setEditable = function(editable) { return true -} \ No newline at end of file +} diff --git a/src/scripts/view.js b/src/scripts/view.js index 57246ee..14f7047 100644 --- a/src/scripts/view.js +++ b/src/scripts/view.js @@ -15,7 +15,14 @@ view.albums = { title: function() { - lychee.setTitle('Albums', false) + if (filter.isFilterActive()) + { + lychee.setTitle('Albums (filtered)', false) + } + else + { + lychee.setTitle('Albums', false) + } }, @@ -114,25 +121,36 @@ view.album = { if ((visible.album() || !album.json.init) && !visible.photo()) { + title = ''; + editable = false; + switch (album.getID()) { case 'f': - lychee.setTitle('Starred', false) + title = 'Starred' break case 's': - lychee.setTitle('Public', false) + title = 'Public' break case 'r': - lychee.setTitle('Recent', false) + title = 'Recent' break case '0': - lychee.setTitle('Unsorted', false) + title = 'Unsorted' break default: - if (album.json.init) sidebar.changeAttr('title', album.json.title) - lychee.setTitle(album.json.title, true) + title = album.json.title + editable = true break } + if (filter.isFilterActive()) + { + title += " (filtered)" + } + + if (editable && album.json.init) sidebar.changeAttr('title', title) + lychee.setTitle(title, editable) + } }, @@ -147,7 +165,10 @@ view.album = { // Build photos $.each(album.json.content, function() { - photosData += build.photo(this) + if (filter.checkPhoto (this)) + { + photosData += build.photo(this) + } }) } @@ -452,4 +473,4 @@ view.photo = { } -} \ No newline at end of file +} diff --git a/view.php b/view.php index c66c18e..77cd7c3 100644 --- a/view.php +++ b/view.php @@ -38,7 +38,8 @@ - + +