Check-in by ben on 2024-10-06 22:07:27

 Preserve user list sort order through page navigation. Use
 "normal" sort order parameters, which makes selectors easier to
 read.

 INSERTED    DELETED
       13         11 src/list/index.dcgi.m4
        8          8 src/listsort/index.dcgi.m4
       21         19 TOTAL over 2 changed files

Index: src/list/index.dcgi.m4
==================================================================
--- src/list/index.dcgi.m4
+++ src/list/index.dcgi.m4
@@ -11,29 +11,31 @@
incl(src/util.awk)

function main(     acct, client_url, cmd, count, creator, iaout, id,
    is_private, items, label, list_id, name, name_slug, numfound,
    order, order_name, order_names, order_param, page, pages, rows,
-    query, title, type, url)
+    query, sort_param, title, type, url)
{
-    order_names["creatorSorter"] = creator
+    order_names["creator"] = "creatorSorter"
    order_names["date"] = "date"
-    order_names["titleSorter"] = "title"
+    order_names["title"] = "titleSorter"
    order_names["week"] = "week"

    rows = 15
    page = 1
    order = ""
+    sort_param = ""

    # parse out page number and sort order
    for (i in parts) {
        if (parts[i] ~ /^rows[0-9][0-9]*$/) {
            rows = substr(parts[i], 5)
        } else if (parts[i] ~ /^page[0-9][0-9]*$/) {
            page = substr(parts[i], 5)
        } else if (parts[i] ~ /^sort/) {
            if (length(order) == 0) {
+                sort_param = parts[i]
                order = substr(parts[i], 5)
            }
        }
    }

@@ -88,19 +90,19 @@
    gsub(/%20/, "-", name_slug)
    client_url = api_ssl_endpoint "/details/" acct "/lists/" list_id \
        "/" name_slug
    order_param = ""
    if (length(order) > 0) {
-        split(order, parts, ":")
+        split(order, parts, " ")
        order_name = order_names[parts[1]]
        if (length(order_name) > 0) {
            if (parts[2] == "desc") {
-                client_url = client_url "?-" order_name
+                client_url = client_url "?-" parts[1]
            } else {
-                client_url = client_url "?" order_name
+                client_url = client_url "?" parts[1]
            }
-            order_param = "&sort=" uri_encode(order)
+            order_param = "&sort=" uri_encode(order_name ":" parts[2])
        }
    }
    url = api_ssl_endpoint "/services/search/beta/page_production/" \
        "?user_query=identifier:(" query ")"                        \
        "&hits_per_page=" rows                                      \
@@ -168,19 +170,19 @@

    print ""

    # only show "page back" if the user is past page 1
    if (page > 1) {
-        printf "[1|[<<] Page %d|%s/list/page%d/rows%d/%%09%s/%d|%s|%s]\n",
-            page - 1, cgipath, page - 1, rows,
+        printf "[1|[<<] Page %d|%s/list/page%d/rows%d/%s%%09%s/%d|%s|%s]\n",
+            page - 1, cgipath, page - 1, rows, sort_param,
            acct, list_id, server, port
    }

    # only show "next page" if the current page is completely full
    if (count == rows) {
-        printf "[1|[>>] Page %d|%s/list/page%d/rows%d/%%09%s/%d|%s|%s]\n",
-            page + 1, cgipath, page + 1, rows,
+        printf "[1|[>>] Page %d|%s/list/page%d/rows%d/%s%%09%s/%d|%s|%s]\n",
+            page + 1, cgipath, page + 1, rows, sort_param,
            acct, list_id, server, port
    }

    # only show "sort" if there's more than one item to sort
    if (numfound > 1) {

Index: src/listsort/index.dcgi.m4
==================================================================
--- src/listsort/index.dcgi.m4
+++ src/listsort/index.dcgi.m4
@@ -10,25 +10,25 @@

function main(     acct, i, lbl, list_id, opt) {
    lbl[1] = "Relevance"
    opt[1] = ""
    lbl[2] = "Weekly views [^]"
-    opt[2] = "week:asc"
+    opt[2] = "week asc"
    lbl[3] = "Weekly views [v]"
-    opt[3] = "week:desc"
+    opt[3] = "week desc"
    lbl[4] = "Title [^]"
-    opt[4] = "titleSorter:asc"
+    opt[4] = "title asc"
    lbl[5] = "Title [v]"
-    opt[5] = "titleSorter:desc"
+    opt[5] = "title desc"
    lbl[6] = "Date published [^]"
-    opt[6] = "date:asc"
+    opt[6] = "date asc"
    lbl[7] = "Date published [v]"
-    opt[7] = "date:desc"
+    opt[7] = "date desc"
    lbl[8] = "Creator [^]"
-    opt[8] = "creatorSorter:asc"
+    opt[8] = "creator asc"
    lbl[9] = "Creator [v]"
-    opt[9] = "creatorSorter:desc"
+    opt[9] = "creator desc"

    split(search, parts, "/")
    acct = parts[1]
    list_id = parts[2]