Begin adding additional sort order for most recently read comics
This commit is contained in:
parent
43af1b078e
commit
4e582d96e1
30
ajax/cyclesortorder.php
Normal file
30
ajax/cyclesortorder.php
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require '../header.php';
|
||||||
|
|
||||||
|
$orders = [SORTBYNAME => SORTBYDATE, SORTBYDATE => SORTBYREAD, SORTBYREAD => SORTBYNAME];
|
||||||
|
|
||||||
|
$validated = require_login(NOREDIRECT);
|
||||||
|
|
||||||
|
$data = array();
|
||||||
|
$data["error"] = false;
|
||||||
|
$data["message"] = "";
|
||||||
|
$data["validated"] = $validated;
|
||||||
|
|
||||||
|
if ( !$validated ) {
|
||||||
|
$data["error"] = true;
|
||||||
|
$data["message"] = "Clients must validate accounts";
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
echo json_encode($data);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
$_SESSION['sortorder'] = $orders[$_SESSION['sortorder']];
|
||||||
|
|
||||||
|
$data["order"] = $_SESSION['sortorder'];
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
echo json_encode($data);
|
||||||
|
exit();
|
||||||
|
|
||||||
|
// vim: set ts=4 sw=4 et:
|
|
@ -36,8 +36,9 @@ $adultcomics = getAdultComics();
|
||||||
$compath = $_SESSION['compath'];
|
$compath = $_SESSION['compath'];
|
||||||
$fullcompath = COMICSDIR . (($compath == "/") ? "" : $compath) . "/";
|
$fullcompath = COMICSDIR . (($compath == "/") ? "" : $compath) . "/";
|
||||||
|
|
||||||
// build up a list of comics and issues which have been
|
// Build up a list of comics and issues which have been read in descending order by lastupdate
|
||||||
$query = "SELECT comic, issue FROM pagetracker WHERE username=:username";
|
$query = "SELECT comic, issue FROM pagetracker WHERE username=:username";
|
||||||
|
//$query = "SELECT comic, issue FROM pagetracker WHERE username=:username ORDER BY lastupdate DESC";
|
||||||
$fields = array();
|
$fields = array();
|
||||||
$fields[":username"] = $_SESSION['username'];
|
$fields[":username"] = $_SESSION['username'];
|
||||||
$sth = $globaldbh->prepare($query);
|
$sth = $globaldbh->prepare($query);
|
||||||
|
|
26
ajax/getsortorder.php
Normal file
26
ajax/getsortorder.php
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require '../header.php';
|
||||||
|
|
||||||
|
$validated = require_login(NOREDIRECT);
|
||||||
|
|
||||||
|
$data = array();
|
||||||
|
$data["error"] = false;
|
||||||
|
$data["message"] = "";
|
||||||
|
$data["validated"] = $validated;
|
||||||
|
|
||||||
|
if ( !$validated ) {
|
||||||
|
$data["error"] = true;
|
||||||
|
$data["message"] = "Clients must validate accounts";
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
echo json_encode($data);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
$data["order"] = $_SESSION['sortorder'];
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
echo json_encode($data);
|
||||||
|
exit();
|
||||||
|
|
||||||
|
// vim: set ts=4 sw=4 et:
|
15
index.php
15
index.php
|
@ -4,23 +4,10 @@ require 'header.php';
|
||||||
|
|
||||||
require_login();
|
require_login();
|
||||||
|
|
||||||
if ( isset($_REQUEST['sortorder']) ) {
|
|
||||||
if ( ($_REQUEST['sortorder'] == SORTBYNAME) || ($_REQUEST['sortorder'] == SORTBYDATE) ) {
|
|
||||||
$_SESSION['sortorder'] = $_REQUEST['sortorder'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
require_once 'htmlheader.php';
|
require_once 'htmlheader.php';
|
||||||
?>
|
?>
|
||||||
<div class='header' id='header'>
|
<div class='header' id='header'>
|
||||||
<div class='sorter'>Sort:<?php
|
<div class='sorter'>Sort: <span id="sortorder"></span></div>
|
||||||
if ( $_SESSION['sortorder'] == SORTBYNAME ) {
|
|
||||||
echo "<a href='index.php?sortorder=", SORTBYDATE, "'>Name</a>";
|
|
||||||
} else {
|
|
||||||
echo "<a href='index.php?sortorder=", SORTBYNAME, "'>Date</a>";
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</div>
|
|
||||||
<div id="path" class='name link'></div>
|
<div id="path" class='name link'></div>
|
||||||
</div>
|
</div>
|
||||||
<div id="list" class='list'></div>
|
<div id="list" class='list'></div>
|
||||||
|
|
94
js/comics.js
94
js/comics.js
|
@ -1,3 +1,5 @@
|
||||||
|
const NOREFRESH = false;
|
||||||
|
|
||||||
var curpath = "/";
|
var curpath = "/";
|
||||||
var parentpath = "/";
|
var parentpath = "/";
|
||||||
var foldername = "";
|
var foldername = "";
|
||||||
|
@ -5,16 +7,77 @@ var foldername = "";
|
||||||
// This function is executed after the page load completes on the client
|
// This function is executed after the page load completes on the client
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$("#path").click(function() { changeFolder(parentpath, parentpath); });
|
$("#path").click(function() { changeFolder(parentpath, parentpath); });
|
||||||
getFolderContents();
|
$("#sortorder").on("click", cycleSortOrder);
|
||||||
|
getSortOrder();
|
||||||
});
|
});
|
||||||
|
|
||||||
var lightbox = null;
|
var lightbox = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redirects the user to the login page by replacing the current location with "index.php".
|
||||||
|
* Logs a message to the console before redirecting.
|
||||||
|
*/
|
||||||
function redirectToLogin() {
|
function redirectToLogin() {
|
||||||
console.log("Redirecting for login...");
|
console.log("Redirecting for login...");
|
||||||
window.location.replace("index.php");
|
window.location.replace("index.php");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current sort order and optionally refreshes the folder contents.
|
||||||
|
* @param {boolean} [refresh=true] - Whether to refresh the folder contents after getting the sort order.
|
||||||
|
*/
|
||||||
|
function getSortOrder(refresh = true) {
|
||||||
|
$.ajax({
|
||||||
|
url : 'ajax/getsortorder.php',
|
||||||
|
dataType : 'json',
|
||||||
|
success : function(data, stat, jqo) {
|
||||||
|
if ( !data.validated ) {
|
||||||
|
redirectToLogin();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
$("#sortorder").html(data.order);
|
||||||
|
if ( refresh ) getFolderContents();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends an AJAX request to update and display the current sort order.
|
||||||
|
* If the user is not validated, redirects to the login page.
|
||||||
|
* On success, updates the #sortorder element with the new order and refreshes folder contents.
|
||||||
|
*/
|
||||||
|
function cycleSortOrder() {
|
||||||
|
$.ajax({
|
||||||
|
url : 'ajax/cyclesortorder.php',
|
||||||
|
dataType : 'json',
|
||||||
|
success : function(data, stat, jqo) {
|
||||||
|
if ( !data.validated ) {
|
||||||
|
redirectToLogin();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
$("#sortorder").html(data.order);
|
||||||
|
getFolderContents();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads and displays the contents of the current comic folder.
|
||||||
|
*
|
||||||
|
* - Clears the current list of displayed items.
|
||||||
|
* - Shows a loading notification to the user.
|
||||||
|
* - Sends an AJAX request to retrieve folder contents as JSON.
|
||||||
|
* - If the user is not validated, redirects to the login page.
|
||||||
|
* - Updates the current path and path navigator.
|
||||||
|
* - Appends each folder or issue entry to the list.
|
||||||
|
* - Attaches click handlers to folder and issue elements for navigation and reading.
|
||||||
|
* - Removes the loading notification upon completion.
|
||||||
|
*
|
||||||
|
* @function
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
function getFolderContents() {
|
function getFolderContents() {
|
||||||
$("#list").html("");
|
$("#list").html("");
|
||||||
toastr.info("Loading folder contents. Comics containing a large number of issues, or issues with a large number of pages, that have not been opened recently may take some time to load. Thank you for your patience!", "Loading Contents...", {timeOut: 15000});
|
toastr.info("Loading folder contents. Comics containing a large number of issues, or issues with a large number of pages, that have not been opened recently may take some time to load. Thank you for your patience!", "Loading Contents...", {timeOut: 15000});
|
||||||
|
@ -38,6 +101,13 @@ function getFolderContents() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the navigation path displayed in the element with id "path".
|
||||||
|
* If the current path is the root ("/"), it sets the navigation path to "/".
|
||||||
|
* Otherwise, it sets the navigation path to "/Comics" followed by the parent path.
|
||||||
|
*
|
||||||
|
* Assumes the existence of global variables `curpath` and `parentpath`.
|
||||||
|
*/
|
||||||
function updatePathNavigator() {
|
function updatePathNavigator() {
|
||||||
var navpath = "";
|
var navpath = "";
|
||||||
if ( curpath == "/" ) {
|
if ( curpath == "/" ) {
|
||||||
|
@ -48,8 +118,15 @@ function updatePathNavigator() {
|
||||||
$("#path").html(navpath);
|
$("#path").html(navpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the current folder by sending an AJAX request to update the path on the server.
|
||||||
|
* Displays a notification to the user and updates global variables upon success.
|
||||||
|
*
|
||||||
|
* @param {string} name - The display name of the folder to open.
|
||||||
|
* @param {string} path - The path of the folder to open.
|
||||||
|
*/
|
||||||
function changeFolder(name, path) {
|
function changeFolder(name, path) {
|
||||||
toastr.success("If this is the first time it may take a while to generate thumbnails.", "Opening comic \"" + name + "\"");
|
toastr.success("If this is the first time it may take a while to generate thumbnails.", "Opening folder \"" + name + "\"");
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url : 'ajax/setpath.php',
|
url : 'ajax/setpath.php',
|
||||||
data : {path: path},
|
data : {path: path},
|
||||||
|
@ -59,15 +136,24 @@ function changeFolder(name, path) {
|
||||||
redirectToLogin();
|
redirectToLogin();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(data.message);
|
|
||||||
curpath = path;
|
curpath = path;
|
||||||
parentpath = data.parentpath;
|
parentpath = data.parentpath;
|
||||||
foldername = data.foldername;
|
foldername = data.foldername;
|
||||||
|
toastr.remove();
|
||||||
getFolderContents();
|
getFolderContents();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends the current page number to the server via AJAX to update the user's current page
|
||||||
|
* in the comic being read.
|
||||||
|
* If the server response indicates the user is not validated, redirects to the login page.
|
||||||
|
* Logs the server response message to the console on success.
|
||||||
|
*
|
||||||
|
* @function
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
function updateCurrentPage() {
|
function updateCurrentPage() {
|
||||||
var currentPage = lightbox.currentPosition;
|
var currentPage = lightbox.currentPosition;
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
@ -113,3 +199,5 @@ function showComic(comic, name) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// vim: ts=3 sw=3 ai:
|
||||||
|
|
|
@ -47,5 +47,6 @@ define('DEBUG_SHOWCOMICAJAX', false);
|
||||||
//
|
//
|
||||||
// Constants
|
// Constants
|
||||||
//
|
//
|
||||||
define('SORTBYNAME', 10000001);
|
define('SORTBYNAME', "Name");
|
||||||
define('SORTBYDATE', 10000002);
|
define('SORTBYDATE', "Date");
|
||||||
|
define('SORTBYREAD', "Read");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user