set default sort order; --sort or volflag "sort"

This commit is contained in:
ed 2023-10-14 22:17:37 +00:00
parent 7086d2a305
commit 9f32e9e11d
6 changed files with 39 additions and 5 deletions

View file

@ -1144,6 +1144,7 @@ def add_ui(ap, retry):
ap2.add_argument("--lang", metavar="LANG", type=u, default="eng", help="language; one of the following: eng nor") ap2.add_argument("--lang", metavar="LANG", type=u, default="eng", help="language; one of the following: eng nor")
ap2.add_argument("--theme", metavar="NUM", type=int, default=0, help="default theme to use") ap2.add_argument("--theme", metavar="NUM", type=int, default=0, help="default theme to use")
ap2.add_argument("--themes", metavar="NUM", type=int, default=8, help="number of themes installed") ap2.add_argument("--themes", metavar="NUM", type=int, default=8, help="number of themes installed")
ap2.add_argument("--sort", metavar="C,C,C", type=u, default="href", help="default sort order, comma-separated column IDs (see header tooltips), prefix with '-' for descending. Examples: \033[32mhref -href ext sz ts tags/Album tags/.tn\033[0m (volflag=sort)")
ap2.add_argument("--unlist", metavar="REGEX", type=u, default="", help="don't show files matching REGEX in file list. Purely cosmetic! Does not affect API calls, just the browser. Example: [\033[32m\\.(js|css)$\033[0m] (volflag=unlist)") ap2.add_argument("--unlist", metavar="REGEX", type=u, default="", help="don't show files matching REGEX in file list. Purely cosmetic! Does not affect API calls, just the browser. Example: [\033[32m\\.(js|css)$\033[0m] (volflag=unlist)")
ap2.add_argument("--favico", metavar="TXT", type=u, default="c 000 none" if retry else "🎉 000 none", help="\033[33mfavicon-text\033[0m [ \033[33mforeground\033[0m [ \033[33mbackground\033[0m ] ], set blank to disable") ap2.add_argument("--favico", metavar="TXT", type=u, default="c 000 none" if retry else "🎉 000 none", help="\033[33mfavicon-text\033[0m [ \033[33mforeground\033[0m [ \033[33mbackground\033[0m ] ], set blank to disable")
ap2.add_argument("--mpmc", metavar="URL", type=u, default="", help="change the mediaplayer-toggle mouse cursor; URL to a folder with {2..5}.png inside (or disable with [\033[32m.\033[0m])") ap2.add_argument("--mpmc", metavar="URL", type=u, default="", help="change the mediaplayer-toggle mouse cursor; URL to a folder with {2..5}.png inside (or disable with [\033[32m.\033[0m])")

View file

@ -42,7 +42,7 @@ def vf_bmap() -> dict[str, str]:
def vf_vmap() -> dict[str, str]: def vf_vmap() -> dict[str, str]:
"""argv-to-volflag: simple values""" """argv-to-volflag: simple values"""
ret = {"th_convt": "convt", "th_size": "thsize"} ret = {"th_convt": "convt", "th_size": "thsize"}
for k in ("dbd", "lg_sbf", "md_sbf", "nrand", "unlist"): for k in ("dbd", "lg_sbf", "md_sbf", "nrand", "sort", "unlist"):
ret[k] = k ret[k] = k
return ret return ret
@ -149,6 +149,7 @@ flagcats = {
}, },
"client and ux": { "client and ux": {
"grid": "show grid/thumbnails by default", "grid": "show grid/thumbnails by default",
"sort": "default sort order",
"unlist": "dont list files matching REGEX", "unlist": "dont list files matching REGEX",
"html_head=TXT": "includes TXT in the <head>", "html_head=TXT": "includes TXT in the <head>",
"robots": "allows indexing by search engines (default)", "robots": "allows indexing by search engines (default)",

View file

@ -3833,6 +3833,7 @@ class HttpCli(object):
"acct": self.uname, "acct": self.uname,
"idx": e2d, "idx": e2d,
"itag": e2t, "itag": e2t,
"dsort": vf["sort"],
"lifetime": vn.flags.get("lifetime") or 0, "lifetime": vn.flags.get("lifetime") or 0,
"frand": bool(vn.flags.get("rand")), "frand": bool(vn.flags.get("rand")),
"unlist": unlist, "unlist": unlist,
@ -3857,6 +3858,7 @@ class HttpCli(object):
"sb_md": "" if "no_sb_md" in vf else (vf.get("md_sbf") or "y"), "sb_md": "" if "no_sb_md" in vf else (vf.get("md_sbf") or "y"),
"readme": readme, "readme": readme,
"dgrid": "grid" in vf, "dgrid": "grid" in vf,
"dsort": vf["sort"],
"themes": self.args.themes, "themes": self.args.themes,
"turbolvl": self.args.turbo, "turbolvl": self.args.turbo,
"idxh": int(self.args.ih), "idxh": int(self.args.ih),

View file

@ -3133,11 +3133,34 @@ function eval_hash() {
})(); })();
function read_dsort(txt) {
try {
var zt = txt.trim().split(/,+/g);
dsort = [];
for (var a = 0; a < zt.length; a++) {
var z = zt[a].trim(), n = 1, t = "";
if (z.startsWith("-")) {
z = z.slice(1);
n = -1;
}
if (z == "sz" || z.indexOf('/.') + 1)
t = "int";
dsort.push([z, n, t]);
}
}
catch (ex) {
toast.warn(10, 'failed to apply default sort order [' + txt + ']:\n' + ex);
}
}
read_dsort(dsort);
function sortfiles(nodes) { function sortfiles(nodes) {
if (!nodes.length) if (!nodes.length)
return nodes; return nodes;
var sopts = jread('fsort', [["href", 1, ""]]), var sopts = jread('fsort', jcp(dsort)),
dir1st = sread('dir1st') !== '0'; dir1st = sread('dir1st') !== '0';
try { try {
@ -5791,6 +5814,8 @@ var treectl = (function () {
if (res.files[a].tags === undefined) if (res.files[a].tags === undefined)
res.files[a].tags = {}; res.files[a].tags = {};
read_dsort(res.dsort);
srvinf = res.srvinf; srvinf = res.srvinf;
try { try {
ebi('srv_info').innerHTML = ebi('srv_info2').innerHTML = '<span>' + res.srvinf + '</span>'; ebi('srv_info').innerHTML = ebi('srv_info2').innerHTML = '<span>' + res.srvinf + '</span>';
@ -6354,6 +6379,7 @@ var filecols = (function () {
toh = ths[a].outerHTML, // !ff10 toh = ths[a].outerHTML, // !ff10
ttv = L.cols[ths[a].textContent]; ttv = L.cols[ths[a].textContent];
ttv = (ttv ? ttv + '$N' : '') + 'ID: <code>' + th.getAttribute('name') + '</code>';
if (!MOBILE && toh) { if (!MOBILE && toh) {
th.innerHTML = '<div class="cfg"><a href="#">-</a></div>' + toh; th.innerHTML = '<div class="cfg"><a href="#">-</a></div>' + toh;
th.getElementsByTagName('a')[0].onclick = ev_row_tgl; th.getElementsByTagName('a')[0].onclick = ev_row_tgl;

View file

@ -15,6 +15,7 @@ html {
max-width: min(34em, calc(100% - 7em)); max-width: min(34em, calc(100% - 7em));
color: #ddd; color: #ddd;
background: #333; background: #333;
background: var(--bg-u2);
border: 0 solid #777; border: 0 solid #777;
box-shadow: 0 .2em .5em #111; box-shadow: 0 .2em .5em #111;
border-radius: .4em; border-radius: .4em;
@ -159,9 +160,10 @@ html {
#modalc code, #modalc code,
#tt code { #tt code {
color: #eee; color: #eee;
color: var(--fg-max);
background: #444; background: #444;
background: var(--bg-u5);
padding: .1em .3em; padding: .1em .3em;
border-top: 1px solid #777;
border-radius: .3em; border-radius: .3em;
line-height: 1.7em; line-height: 1.7em;
} }
@ -182,8 +184,10 @@ html.y #toast {
box-shadow: 0 .3em 1em rgba(0,0,0,0.4); box-shadow: 0 .3em 1em rgba(0,0,0,0.4);
} }
html.y #tt code { html.y #tt code {
background: #060;
color: #fff; color: #fff;
color: var(--fg-max);
background: #060;
background: var(--bg-u5);
} }
#modalc code { #modalc code {
color: #060; color: #060;

View file

@ -483,7 +483,7 @@ function yscroll() {
function showsort(tab) { function showsort(tab) {
var v, vn, v1, v2, th = tab.tHead, var v, vn, v1, v2, th = tab.tHead,
sopts = jread('fsort', [["href", 1, ""]]); sopts = jread('fsort', jcp(dsort));
th && (th = th.rows[0]) && (th = th.cells); th && (th = th.rows[0]) && (th = th.cells);