Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/templates/runs/_launch_ask.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<template class="launch-ask">{% call ask(L, gone, back) %}{{ items }}{% endcall %}</template>{% endif %}
{%- endmacro %}

{#- One dialog for every launch: a button fills it from its launch's template (`asks`: button class -> template class),
{#- One dialog for every launch: a button fills it from its launch's template, else the page's (`asks`: button class -> template class),
or from the server (the button's data-ask);
?delete=<key> opens the Delete question on load. #}
{% macro dialogs(asks={'launch-delete-btn': 'launch-ask'}) %}
Expand All @@ -40,7 +40,7 @@
const r = await nulliusFetch(b.dataset.ask);
if (!r.ok) { b.title = await r.text(); return; }
d.innerHTML = await r.text();
} else d.replaceChildren(l.querySelector('template.' + asks[cls]).content.cloneNode(true));
} else d.replaceChildren((l.querySelector('template.' + asks[cls]) || document.querySelector('template.' + asks[cls])).content.cloneNode(true)); // the row's own, or the page's one
d.showModal();
};
const sel = Object.keys(asks).map(c => '.' + c).join(',');
Expand Down
31 changes: 20 additions & 11 deletions app/templates/runs/launches.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,37 @@
{%- elif c.key == 'size' %}{% call cell(c, sort=r.bytes, class='nowrap') %}{{ r.bytes|filesizeformat }}{% endcall %}
{%- elif c.key == 'ws' %}{% call cell(c, sort=wss|map(attribute='label')|sort|join(' ')) %}{% for w in wss %}{{ open_at(w, L, w.label) }}{% if not loop.last %}<br>{% endif %}{% else %}<span class="faint">none</span>{% endfor %}{% endcall %}
{%- elif c.key == 'actions' %}{% call cell(c, class='acts-col') %}
{% set others = workspaces|rejectattr('name', 'in', wss|map(attribute='name')|list)|list %}
<button type="button" class="icon-btn launch-add-btn" aria-haspopup="dialog" aria-label="Add launch {{ L.title }} to a workspace" title="Add to workspace"><svg class="ic"><use href="#i-ws-add"/></svg></button>
<template class="launch-add">
<div class="std-how-head"><h2 id="launch-delete-h">Add launch {{ L.title }}</h2></div>
<form method="post" action="{{ url_for('launch_add', key=L.key) }}">
<input type="hidden" name="csrf" value="{{ csrf_token() }}">
<label>Workspace <select name="workspace">{% for w in others %}<option value="{{ w.name }}">{{ w.label }}</option>{% endfor %}<option value="">New workspace…</option></select></label>
<label class="launch-add-new">Name <input type="text" name="label" placeholder="Optional" spellcheck="false" autocomplete="off"></label>
<div class="launch-delete-acts"><button type="submit" formmethod="dialog" class="btn ghost">Cancel</button><button type="submit" class="btn">Add</button></div>
</form>
</template>
<button type="button" class="icon-btn launch-add-btn" aria-haspopup="dialog" aria-label="Add launch {{ L.title }} to a workspace" title="Add to workspace" data-add="{{ url_for('launch_add', key=L.key) }}" data-title="{{ L.title }}"><svg class="ic"><use href="#i-ws-add"/></svg></button>
{% if not r.why %}{{ delete_ask(L, none, 'launches', icon=true) }}
{%- else %}{{ greyed('Delete launch ' ~ L.title, 'Delete launch', r.why, 'why-' ~ L.key) }}{% endif %}
{% endcall %}
{%- endif %}
{% endcall %}
{#- Add, once for the page: its button fills in the launch, and drops the workspaces its row already lists. #}
<template class="launch-add">
<div class="std-how-head"><h2 id="launch-delete-h"></h2></div>
<form method="post">
<input type="hidden" name="csrf" value="{{ csrf_token() }}">
<label>Workspace <select name="workspace">{% for w in workspaces %}<option value="{{ w.name }}">{{ w.label }}</option>{% endfor %}<option value="">New workspace…</option></select></label>
<label class="launch-add-new">Name <input type="text" name="label" placeholder="Optional" spellcheck="false" autocomplete="off"></label>
<div class="launch-delete-acts"><button type="submit" formmethod="dialog" class="btn ghost">Cancel</button><button type="submit" class="btn">Add</button></div>
</form>
</template>
{{ dialogs({'launch-delete-btn': 'launch-ask', 'launch-add-btn': 'launch-add'}) }}
<script>
(() => {
// ?ws= ticked its workspace alone at load; from here the filter lives in the page, as the others do
const url = new URL(location.href);
if (url.searchParams.has('ws')) { url.searchParams.delete('ws'); history.replaceState(history.state, '', url); }
// after dialogs() has drawn the Add template: this launch's heading, action and the workspaces it is not in yet
document.addEventListener('click', e => {
const b = e.target.closest('.launch-add-btn');
if (!b) return;
const d = document.getElementById('launch-delete'), has = b.closest('[data-launch]').dataset.fWs.split('\n');
d.querySelector('h2').textContent = 'Add launch ' + b.dataset.title;
d.querySelector('form').action = b.dataset.add;
d.querySelectorAll('option[value]:not([value=""])').forEach(o => { if (has.includes(o.value)) o.remove(); });
});
})();
</script>
{% else %}
Expand Down
23 changes: 23 additions & 0 deletions app/templates/workspaces/_roots.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{#- The Roots dialog of a workspace (`workspace_roots`), fetched when it opens: each root's Unlink asked here, its Delete asked of the server. #}
{% from '_tables.html' import greyed %}
<div class="std-how-head"><h2 id="ws-dialog-h"{% if clash %} title="{{ ws.name }}"{% endif %}>Roots of {{ ws.label }}</h2>
<a class="btn sm" href="{{ url_for('import_page', into=ws.name) }}"><svg class="ic" aria-hidden="true"><use href="#i-plus"/></svg>Add a root</a></div>
<ul class="ws-root-list">
{% for r in rs %}
<li data-holder><span class="mono">{{ r.path }}</span>
<span class="ws-root-acts">
<button type="button" class="icon-btn" data-ask="ask-unlink" aria-label="Unlink {{ r.path }}" title="Unlink from this workspace"><svg class="ic"><use href="#i-unlink"/></svg></button>
{%- if not r.why %}<button type="button" class="icon-btn danger" data-ask="{{ url_for('workspace_root_ask', name=ws.name, root=r.path) }}" aria-haspopup="dialog" aria-label="Delete folder {{ r.path }}" title="Delete folder"><svg class="ic"><use href="#i-trash"/></svg></button>
{%- else %}{{ greyed('Delete folder ' ~ r.path, 'Delete folder', r.why, 'why-' ~ ws.name ~ '-' ~ loop.index) }}{% endif %}
</span>
<template class="ask-unlink">
<div class="std-how-head"><h2 id="ws-dialog-h"{% if clash %} title="{{ ws.name }}"{% endif %}>Unlink a root of {{ ws.label }}</h2></div>
<form method="post" action="{{ url_for('workspace_unlink', name=ws.name) }}">
<input type="hidden" name="csrf" value="{{ csrf_token() }}"><input type="hidden" name="root" value="{{ r.path }}">
<p><span class="mono">{{ r.path }}</span> leaves {{ ws.label }}. Its files stay.</p>
<div class="launch-delete-acts"><button type="button" class="btn ghost" data-back autofocus>Keep it</button><button type="submit" class="btn">Unlink</button></div>
</form>
</template>
</li>
{% else %}<li class="faint">No root.</li>{% endfor %}
</ul>
76 changes: 37 additions & 39 deletions app/templates/workspaces/workspaces.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<link rel="stylesheet" href="{{ url_for('static', filename='workspaces/workspaces.css') }}">
<script src="{{ url_for('static', filename='tables.js') }}"></script>{% endblock %}
{#- A workspace's row: the open one marked, what its search reads. #}
{% macro ws_tr(ws) %} class="{{ 'ws-current' if workspace and ws.name == workspace.name }}" data-ws="{{ ws.name }}" data-search="{{ ws.label }} {{ ws.name }}" data-holder{% endmacro %}
{% macro ws_tr(ws) %} class="{{ 'ws-current' if workspace and ws.name == workspace.name }}" data-ws="{{ ws.name }}" data-search="{{ ws.label }} {{ ws.name }}"{% endmacro %}

{% block body %}
{% set actions %}<a class="btn sm" href="{{ url_for('import_page', new=1) }}"><svg class="ic" aria-hidden="true"><use href="#i-plus"/></svg>New workspace</a>{% endset %}
Expand All @@ -20,7 +20,7 @@
dict(key='checks', label='Checks', type='num'), dict(key='opened', label='Last opened', type='num', align='left'),
dict(key='launches', label='Launches', type='num', align='right'), dict(key='roots', label='Roots', type='num', align='right'), dict(key='actions', label='Actions', blank=true)] %}
{% call(ws, c) table('workspaces', cols, workspaces, ws_tr, class='ws-table', search='Search by name', noun='workspaces') %}
{%- set current = workspace and ws.name == workspace.name %}{% set rs = roots[ws.name] %}{% set clash = labels.count(ws.label) > 1 %}
{%- set current = workspace and ws.name == workspace.name %}{% set clash = labels.count(ws.label) > 1 %}
{%- if c.key == 'open' %}{% call cell(c) %}{% if current %}<span class="ok" role="img" aria-label="Open" title="Open">●</span>{% endif %}{% endcall %}
{%- elif c.key == 'name' %}{% call cell(c, sort=ws.label, class='ws-name') %}

Expand All @@ -39,54 +39,40 @@
{%- elif c.key == 'opened' %}{% call cell(c, sort=ws.opened[:19]|replace('-', '')|replace(':', '')|replace('T', '') or 0, class='mono faint nowrap') %}{{ ws.opened[:16]|replace('T', ' ') }}{% endcall %}
{%- elif c.key == 'launches' %}{% call cell(c) %}{% set n = n_launches[ws.name] %}{% if n %}<a class="btn ghost sm count-btn" href="{{ url_for('launches_page', ws=ws.name) }}" aria-label="Launches of {{ ws.label }}: {{ n }}" title="Launches of {{ ws.label }}"><svg class="ic" aria-hidden="true"><use href="#i-launches"/></svg>{{ n }}</a>
{%- else %}{{ greyed('Launches of ' ~ ws.label ~ ': 0', '', 'No launches in ' ~ ws.label, 'none-' ~ ws.name, icon='launches', class='btn ghost sm count-btn', text='0') }}{% endif %}{% endcall %}
{%- elif c.key == 'roots' %}{% call cell(c, sort=rs|length) %}
<button type="button" class="btn ghost sm count-btn ws-roots-btn" data-ask="ws-roots" aria-haspopup="dialog" aria-label="Roots of {{ ws.label }}: {{ rs|length }}" title="Roots"><svg class="ic" aria-hidden="true"><use href="#i-folder"/></svg>{{ rs|length }}</button>
<template class="ws-roots">
<div class="std-how-head"><h2 id="ws-dialog-h"{% if clash %} title="{{ ws.name }}"{% endif %}>Roots of {{ ws.label }}</h2>
<a class="btn sm" href="{{ url_for('import_page', into=ws.name) }}"><svg class="ic" aria-hidden="true"><use href="#i-plus"/></svg>Add a root</a></div>
<ul class="ws-root-list">
{% for r in rs %}
<li data-holder><span class="mono">{{ r.path }}</span>
<span class="ws-root-acts">
<button type="button" class="icon-btn" data-ask="ask-unlink" aria-label="Unlink {{ r.path }}" title="Unlink from this workspace"><svg class="ic"><use href="#i-unlink"/></svg></button>
{%- if not r.why %}<button type="button" class="icon-btn danger" data-ask="{{ url_for('workspace_root_ask', name=ws.name, root=r.path) }}" aria-haspopup="dialog" aria-label="Delete folder {{ r.path }}" title="Delete folder"><svg class="ic"><use href="#i-trash"/></svg></button>
{%- else %}{{ greyed('Delete folder ' ~ r.path, 'Delete folder', r.why, 'why-' ~ ws.name ~ '-' ~ loop.index) }}{% endif %}
</span>
<template class="ask-unlink">
<div class="std-how-head"><h2 id="ws-dialog-h"{% if clash %} title="{{ ws.name }}"{% endif %}>Unlink a root of {{ ws.label }}</h2></div>
<form method="post" action="{{ url_for('workspace_unlink', name=ws.name) }}">
<input type="hidden" name="csrf" value="{{ csrf }}"><input type="hidden" name="root" value="{{ r.path }}">
<p><span class="mono">{{ r.path }}</span> leaves {{ ws.label }}. Its files stay.</p>
<div class="launch-delete-acts"><button type="button" class="btn ghost" data-back autofocus>Keep it</button><button type="submit" class="btn">Unlink</button></div>
</form>
</template>
</li>
{% else %}<li class="faint">No root.</li>{% endfor %}
</ul>
</template>
{%- elif c.key == 'roots' %}{% call cell(c, sort=ws.roots|length) %}
<button type="button" class="btn ghost sm count-btn ws-roots-btn" data-ask="{{ url_for('workspace_roots', name=ws.name) }}" aria-haspopup="dialog" aria-label="Roots of {{ ws.label }}: {{ ws.roots|length }}" title="Roots"><svg class="ic" aria-hidden="true"><use href="#i-folder"/></svg>{{ ws.roots|length }}</button>
{% endcall %}
{%- elif c.key == 'actions' %}{% call cell(c, class='acts-col') %}
<button type="button" class="icon-btn danger" data-ask="ws-ask-delete" aria-haspopup="dialog" aria-label="Delete workspace {{ ws.label }}" title="Delete workspace"><svg class="ic"><use href="#i-trash"/></svg></button>
<template class="ws-ask-delete">
<div class="std-how-head"><h2 id="ws-dialog-h">Delete workspace {{ ws.label }}</h2></div>
<form method="post" action="{{ url_for('workspace_delete', name=ws.name) }}">
<input type="hidden" name="csrf" value="{{ csrf }}">
<p>{% set n = n_judged[ws.name] %}{% if n %}Its judgements ({{ n }}) are deleted. {% endif %}Its run folders stay on disk.</p>
<div class="launch-delete-acts"><button type="submit" formmethod="dialog" class="btn ghost" autofocus>Keep it</button><button type="submit" class="btn danger">Delete workspace</button></div>
</form>
</template>
<button type="button" class="icon-btn danger" data-ask="ws-ask-delete" data-label="{{ ws.label }}" data-action="{{ url_for('workspace_delete', name=ws.name) }}" data-judged="{{ n_judged[ws.name] }}" aria-haspopup="dialog" aria-label="Delete workspace {{ ws.label }}" title="Delete workspace"><svg class="ic"><use href="#i-trash"/></svg></button>
{% endcall %}
{%- endif %}
{% endcall %}
{#- every row's Delete, filled from its button #}
<template id="ws-ask-delete">
<div class="std-how-head"><h2 id="ws-dialog-h">Delete workspace </h2></div>
<form method="post">
<input type="hidden" name="csrf" value="{{ csrf }}">
<p>Its run folders stay on disk.</p>
<div class="launch-delete-acts"><button type="submit" formmethod="dialog" class="btn ghost" autofocus>Keep it</button><button type="submit" class="btn danger">Delete workspace</button></div>
</form>
</template>
<dialog class="std-how launch-delete" id="ws-dialog" aria-labelledby="ws-dialog-h"></dialog>
<script>
(() => {
// One dialog: a [data-ask] button fills it from the template of that class in its [data-holder]. An ask
// opened inside it (a root's Unlink or Delete) goes back to what it replaced on Keep it.
// One dialog: a [data-ask] button fills it from the template of that class in its [data-holder], a row's
// Delete from the page's one template, the Roots from the server. An ask opened inside it (a root's Unlink
// or Delete) goes back to what it replaced on Keep it.
const d = document.getElementById('ws-dialog');
let opener = null, back = null;
// a template of the page, or, for an address, the server's answer: what a Delete takes is worked out only now
const content = async b => {
if (b.dataset.ask === 'ws-ask-delete') {
const c = document.getElementById('ws-ask-delete').content.cloneNode(true), n = +b.dataset.judged;
c.querySelector('h2').append(b.dataset.label);
c.querySelector('form').action = b.dataset.action;
if (n) c.querySelector('p').prepend(`Its judgements (${n}) are deleted. `);
return c;
}
if (!b.dataset.ask.startsWith('/')) return b.closest('[data-holder]').querySelector('template.' + b.dataset.ask).content.cloneNode(true);
const r = await nulliusFetch(b.dataset.ask);
if (!r.ok) { b.title = await r.text(); return null; }
Expand All @@ -100,11 +86,23 @@
back = {nodes, b};
d.replaceChildren(c);
d.querySelector('[autofocus]')?.focus();
} else if (b?.classList.contains('ws-roots-btn')) { // the Roots: a skeleton until the server lists them
opener = b; back = null;
d.classList.add('wide');
d.setAttribute('aria-busy', 'true');
d.innerHTML = '<div class="page-skeleton" aria-hidden="true"><div class="skel skel-title"></div>' + '<div class="skel skel-line"></div>'.repeat(3) + '</div>';
d.showModal();
const r = await nulliusFetch(b.dataset.ask).catch(() => null), html = r?.ok ? await r.text().catch(() => null) : null;
if (opener !== b || !d.open) return; // closed, or another opened, while it loaded
d.removeAttribute('aria-busy');
if (html !== null) d.replaceChildren(document.createRange().createContextualFragment(html));
else d.innerHTML = '<p id="ws-dialog-h">Could not load the roots. Close and try again.</p>';
d.querySelector('a[href], button:not([aria-disabled])')?.focus();
} else if (b) {
const c = await content(b);
if (!c) return;
opener = b; back = null;
d.classList.toggle('wide', b.dataset.ask === 'ws-roots');
d.classList.remove('wide');
d.replaceChildren(c);
d.showModal();
} else if (e.target.closest('[data-back]') && back) {
Expand Down
3 changes: 2 additions & 1 deletion app/ui_tests/test_cli_agreement_more.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ def test_workspace_list_says_what_the_workspaces_page_renders(self):
for row in rows:
with self.subTest(workspace=row["name"]):
block = page.split(f'data-ws="{row["name"]}"', 1)[1].split("</tr>", 1)[0]
roots = self.page(f'/workspaces/{row["name"]}/roots') # its Roots dialog, fetched when it opens
for root in row["roots"]:
self.assertIn(f'<span class="mono">{html.escape(root)}</span>', block)
self.assertIn(f'<span class="mono">{html.escape(root)}</span>', roots)
self.assertIn(row["opened"][:16].replace("T", " "), block)
# the open workspace is the one the page marks, its label in the rename box
self.assertEqual(rows[0]["name"], self.ws.name)
Expand Down
Loading
Loading