toggle upload widgets in spa

This commit is contained in:
ed 2021-02-21 20:50:12 +01:00
parent 2a6dd7b512
commit b14b86990f
8 changed files with 106 additions and 42 deletions

View file

@ -77,6 +77,8 @@ class HttpCli(object):
self.loud_reply(str(ex), status=ex.code)
return self.keepalive
# time.sleep(0.4)
# normalize incoming headers to lowercase;
# outgoing headers however are Correct-Case
for header_line in headerlines[1:]:
@ -1267,9 +1269,16 @@ class HttpCli(object):
srv_info = "</span> /// <span>".join(srv_info)
perms = []
if self.readable:
perms.append("read")
if self.writable:
perms.append("write")
if is_ls:
[x.pop(k) for k in ["name", "dt"] for y in [dirs, files] for x in y]
ret = json.dumps({"dirs": dirs, "files": files, "srvinf": srv_info})
ret = {"dirs": dirs, "files": files, "srvinf": srv_info, "perms": perms}
ret = json.dumps(ret)
self.reply(ret.encode("utf-8", "replace"), mime="application/json")
return True
@ -1289,10 +1298,9 @@ class HttpCli(object):
vdir=quotep(self.vpath),
vpnodes=vpnodes,
files=dirs,
can_upload=self.writable,
can_read=self.readable,
have_up2k_idx=self.args.e2d,
ts=ts,
perms=json.dumps(perms),
have_up2k_idx=self.args.e2d,
prologue=logues[0],
epilogue=logues[1],
title=html_escape(self.vpath),

View file

@ -730,6 +730,11 @@ class Up2k(object):
if etag == prev.get(k, None):
return
try:
os.mkdir(os.path.join(k, ".hist"))
except:
pass
path2 = "{}.{}".format(path, os.getpid())
j = json.dumps(reg, indent=2, sort_keys=True).encode("utf-8")
with gzip.GzipFile(path2, "wb") as f:

View file

@ -336,7 +336,6 @@ a,
box-shadow: 0 0 1em #222 inset;
}
#ops {
display: none;
background: #333;
margin: 1.7em 1.5em 0 1.5em;
padding: .3em .6em;
@ -426,6 +425,7 @@ input[type="checkbox"]:checked+label {
padding: .3em .5em;
font-size: 1.5em;
display: inline-block;
min-width: 12em;
width: 100%;
}
#treefiles #files tbody {
@ -434,9 +434,6 @@ input[type="checkbox"]:checked+label {
#treefiles #files thead th:nth-child(1) {
border-radius: .7em 0 0 0;
}
#tree li {
list-style: none;
}
#tree ul,
#tree li {
padding: 0;
@ -447,6 +444,8 @@ input[type="checkbox"]:checked+label {
}
#tree li {
margin-left: 1em;
list-style: none;
white-space: nowrap;
}
#tree a.hl {
color: #400;
@ -454,9 +453,6 @@ input[type="checkbox"]:checked+label {
border-radius: .3em;
text-shadow: none;
}
#tree li {
white-space: nowrap;
}
#tree a {
display: inline-block;
}
@ -497,4 +493,6 @@ input[type="checkbox"]:checked+label {
padding: 0 1.2em 0 0;
font-size: 4em;
animation: spin 1s linear infinite;
position: absolute;
z-index: 9;
}

View file

@ -7,36 +7,29 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=0.8">
<link rel="stylesheet" type="text/css" media="screen" href="/.cpr/browser.css{{ ts }}">
{%- if can_upload %}
<link rel="stylesheet" type="text/css" media="screen" href="/.cpr/upload.css{{ ts }}">
{%- endif %}
</head>
<body>
<div id="ops">
<a href="#" data-dest="">---</a>
{%- if can_read %}
<a href="#" data-dest="search">🔎</a>
{%- endif %}
{%- if can_upload %}
<a href="#" data-perm="read" data-dest="search">🔎</a>
{%- if have_up2k_idx %}
<a href="#" data-dest="up2k">🚀</a>
<a href="#" data-dest="bup">🎈</a>
<a href="#" data-dest="mkdir">📂</a>
<a href="#" data-dest="new_md">📝</a>
<a href="#" data-dest="msg">📟</a>
{%- else %}
<a href="#" data-perm="write" data-dest="up2k">🚀</a>
{%- endif %}
<a href="#" data-perm="write" data-dest="bup">🎈</a>
<a href="#" data-perm="write" data-dest="mkdir">📂</a>
<a href="#" data-perm="write" data-dest="new_md">📝</a>
<a href="#" data-perm="write" data-dest="msg">📟</a>
</div>
{%- if can_read %}
<div id="op_search" class="opview">
<table id="srch_form"></table>
<div id="srch_q"></div>
</div>
{%- endif %}
{%- if can_upload %}
{%- include 'upload.html' %}
{%- endif %}
<h1 id="path">
<a href="#" id="entree">🌲</a>
@ -45,7 +38,6 @@
{%- endfor %}
</h1>
{%- if can_read %}
{%- if prologue %}
<div id="pro" class="logue">{{ prologue }}</div>
{%- endif %}
@ -54,9 +46,7 @@
<tr>
<td id="tree">
<a href="#" id="detree">🍞...</a>
<ul id="treeul">
<div class="dumb_loader_thing">🌲</div>
</ul>
<ul id="treeul"></ul>
</td>
<td id="treefiles"></td>
</tr>
@ -84,7 +74,6 @@
{%- if epilogue %}
<div id="epi" class="logue">{{ epilogue }}</div>
{%- endif %}
{%- endif %}
<h2><a href="?h">control-panel</a></h2>
@ -103,14 +92,11 @@
</div>
<script src="/.cpr/util.js{{ ts }}"></script>
{%- if can_read %}
<script src="/.cpr/browser.js{{ ts }}"></script>
{%- endif %}
{%- if can_upload %}
<script src="/.cpr/up2k.js{{ ts }}"></script>
{%- endif %}
<script>
apply_perms({{ perms }});
</script>
</body>
</html>

View file

@ -732,6 +732,7 @@ function autoplay_blocked() {
xhr.open('GET', dst + '?tree=' + top, true);
xhr.onreadystatechange = recvtree;
xhr.send();
enspin('#tree');
}
function recvtree() {
@ -776,6 +777,7 @@ function autoplay_blocked() {
}
}
document.querySelector('#treeul>li>a+a').textContent = '[root]';
despin('#tree');
reload_tree();
var q = '#tree';
@ -817,6 +819,7 @@ function autoplay_blocked() {
xhr.onreadystatechange = recvls;
xhr.send();
get_tree('.', xhr.top);
enspin('#files');
}
function treegrow(e) {
@ -865,6 +868,8 @@ function autoplay_blocked() {
html = html.join('\n');
ebi('files').tBodies[0].innerHTML = html;
history.pushState(html, this.top, this.top);
apply_perms(res.perms);
despin('#files');
var o = ebi('pro');
if (o) o.parentNode.removeChild(o);
@ -946,6 +951,51 @@ function autoplay_blocked() {
})();
function enspin(sel) {
despin(sel);
var d = document.createElement('div');
d.setAttribute('class', 'dumb_loader_thing');
d.innerHTML = '🌲';
var tgt = document.querySelector(sel);
tgt.insertBefore(d, tgt.childNodes[0]);
}
function despin(sel) {
var o = document.querySelectorAll(sel + '>.dumb_loader_thing');
for (var a = o.length - 1; a >= 0; a--)
o[a].parentNode.removeChild(o[a]);
}
function apply_perms(perms) {
var o = document.querySelectorAll('#ops>a[data-perm]');
for (var a = 0; a < o.length; a++)
o[a].style.display = 'none';
for (var a = 0; a < perms.length; a++) {
o = document.querySelectorAll('#ops>a[data-perm="' + perms[a] + '"]');
for (var b = 0; b < o.length; b++)
o[b].style.display = 'inline';
}
var act = document.querySelector('#ops>a.act');
var areq = act.getAttribute('data-perm');
if (areq && !has(perms, areq))
goto();
var have_write = has(perms, "write");
var tds = document.querySelectorAll('#u2conf td');
for (var a = 0; a < tds.length; a++) {
tds[a].style.display =
(have_write || tds[a].getAttribute('data-perm') == 'read') ?
'table-cell' : 'none';
}
if (!have_write)
up2k.set_fsearch();
}
function reload_browser(not_mp) {
makeSortable(ebi('files'));

View file

@ -1049,6 +1049,11 @@ function up2k_init(have_crypto) {
ebi('u2tab').setAttribute('class', fsearch ? 'srch' : '');
}
function set_fsearch() {
if (!fsearch)
tgl_fsearch();
}
function tgl_flag_en() {
flag_en = !flag_en;
bcfg_set('flag_en', flag_en);
@ -1099,5 +1104,9 @@ function up2k_init(have_crypto) {
bumpthread({ "target": 1 })
return { "init_deps": init_deps }
return { "init_deps": init_deps, "set_fsearch": set_fsearch }
}
if (document.querySelector('#op_up2k.act'))
goto_up2k();

View file

@ -50,12 +50,12 @@
<label for="flag_en" alt="ensure only one tab is uploading at a time $N (other tabs must have this enabled too)">💤</label>
</td>
{%- if have_up2k_idx %}
<td rowspan="2">
<td data-perm="read" rowspan="2">
<input type="checkbox" id="fsearch" />
<label for="fsearch" alt="don't actually upload, instead check if the files already $N exist on the server (will scan all folders you can read)">🔎</label>
</td>
{%- endif %}
<td rowspan="2" id="u2btn_cw"></td>
<td data-perm="read" rowspan="2" id="u2btn_cw"></td>
</tr>
<tr>
<td>

View file

@ -172,7 +172,6 @@ function goto(dest) {
if (op !== null && op !== '.')
goto(op);
}
ebi('ops').style.display = 'block';
})();
@ -223,4 +222,13 @@ function get_vpath() {
function unix2iso(ts) {
return new Date(ts * 1000).toISOString().replace("T", " ").slice(0, -5);
}
}
function has(haystack, needle) {
for (var a = 0; a < haystack.length; a++)
if (haystack[a] == needle)
return true;
return false;
}