heyquilt 0.3.181 → 0.3.183
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -97
- package/RELEASES.md +17 -0
- package/bin/quilt.js +32 -32
- package/desktop/main.js +1 -1
- package/package.json +1 -1
- package/src/account.js +2 -2
- package/src/admit-policy.js +2 -2
- package/src/agent-join.js +3 -3
- package/src/agent-task-workflow.js +14 -14
- package/src/ai-vm.js +1 -1
- package/src/api/agent-placement.js +2 -2
- package/src/api/audit.js +1 -1
- package/src/api/file-paths.js +1 -1
- package/src/api/file-store.js +1 -1
- package/src/api/invite-email.js +4 -4
- package/src/api/join-text.js +5 -5
- package/src/api/notify.js +7 -7
- package/src/api/permissions.js +1 -1
- package/src/api/routes/agent-wake.js +1 -1
- package/src/api/routes/agents.js +2 -2
- package/src/api/routes/ai-vm.js +5 -5
- package/src/api/routes/connections.js +13 -13
- package/src/api/routes/grants.js +2 -2
- package/src/api/routes/mail.js +10 -10
- package/src/api/routes/relay.js +1 -1
- package/src/api/routes/secrets.js +11 -11
- package/src/api/routes/session-invites.js +5 -5
- package/src/api/routes/sessions.js +3 -3
- package/src/api/routes/workspace-agents.js +14 -14
- package/src/api/routes/workspace-files.js +12 -12
- package/src/api/routes/workspace-invites.js +5 -5
- package/src/api/routes/workspaces.js +11 -11
- package/src/api/secrets-access.js +1 -1
- package/src/api/server.js +3 -3
- package/src/api/team-access.js +1 -1
- package/src/api/workspace-access.js +1 -1
- package/src/api/workspace-reach.js +3 -3
- package/src/app-tools.js +10 -10
- package/src/autowork.js +4 -4
- package/src/branch-view.js +1 -1
- package/src/catchup.js +5 -5
- package/src/chat-links.js +18 -18
- package/src/connection.js +11 -11
- package/src/control.js +5 -5
- package/src/conversation.js +1 -1
- package/src/doctor.js +2 -2
- package/src/duties.js +1 -1
- package/src/fsutil.js +1 -1
- package/src/gitstate.js +117 -1
- package/src/held.js +4 -4
- package/src/hooks.js +3 -3
- package/src/hosted-client.js +2 -2
- package/src/identity.js +1 -1
- package/src/inbox.js +1 -1
- package/src/key-cli.js +1 -1
- package/src/mail-tools.js +11 -11
- package/src/mcp-proxy.js +1 -1
- package/src/mcp.js +59 -59
- package/src/new-session.js +112 -0
- package/src/project-rules.js +2 -2
- package/src/relay-ask.js +2 -2
- package/src/relay-cluster.js +3 -3
- package/src/relay-live-write.js +3 -3
- package/src/relay-mcp.js +56 -56
- package/src/relay-prune.js +1 -1
- package/src/relay-turn-sync.js +1 -1
- package/src/repo-ref.js +54 -0
- package/src/secret-import.js +1 -1
- package/src/secret-names.js +6 -6
- package/src/secret-run.js +3 -3
- package/src/server.js +41 -41
- package/src/session-access.js +3 -3
- package/src/session-name.js +1 -1
- package/src/session.js +118 -52
- package/src/setup.js +7 -7
- package/src/status.js +2 -2
- package/src/tasks.js +1 -1
- package/src/turn-sync.js +4 -4
- package/src/ui/account-sessions.js +2 -2
- package/src/ui/agent-env-key.js +1 -1
- package/src/ui/agent-guide.js +35 -35
- package/src/ui/agent-kinds.js +8 -8
- package/src/ui/agent-place.js +16 -16
- package/src/ui/agents-table.js +6 -6
- package/src/ui/app.css +357 -0
- package/src/ui/app.js +29 -14
- package/src/ui/board.js +2 -2
- package/src/ui/catchup.js +5 -5
- package/src/ui/changes-seen.js +2 -2
- package/src/ui/changes.js +3 -3
- package/src/ui/cloud-ai.js +12 -12
- package/src/ui/common.js +1 -1
- package/src/ui/connections.js +1 -1
- package/src/ui/diffview.js +2 -2
- package/src/ui/feed.js +1 -1
- package/src/ui/feedback.js +4 -4
- package/src/ui/files.js +120 -14
- package/src/ui/fileview.js +3 -3
- package/src/ui/git-rule.js +3 -3
- package/src/ui/home.js +95 -67
- package/src/ui/index.html +1 -1
- package/src/ui/invite.js +8 -8
- package/src/ui/invites.js +3 -3
- package/src/ui/new-session.js +151 -0
- package/src/ui/prail-model.js +22 -0
- package/src/ui/prail.js +43 -0
- package/src/ui/project-board.js +359 -0
- package/src/ui/project-model.js +197 -0
- package/src/ui/project-pop.js +451 -0
- package/src/ui/projects.js +406 -0
- package/src/ui/sandbox-keys.js +3 -3
- package/src/ui/secrets-view.js +5 -5
- package/src/ui/session-words.js +2 -2
- package/src/ui/session.js +156 -43
- package/src/ui/tree.js +3 -3
- package/src/ui/voice.js +6 -6
- package/src/ui/workspaces.js +23 -23
- package/src/ui-server.js +104 -26
- package/src/update-check.js +2 -2
- package/src/voice.js +7 -7
- package/src/wake-tool.js +1 -1
- package/src/webhooks.js +1 -1
- package/src/workspace-cli.js +12 -12
- package/src/workspace-tools.js +33 -33
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// Create a codebase: the pop-up a new session starts from. Three ways in, listed on the left:
|
|
2
|
+
// import a repository from GitHub (cloned here), start from scratch (a new folder, with what you
|
|
3
|
+
// want to build as the first task), or a folder already on this computer. Whichever it is, the
|
|
4
|
+
// folder has git when the session starts in it (src/new-session.js makes it ready).
|
|
5
|
+
import { I, state, $, esc, api } from './common.js'
|
|
6
|
+
|
|
7
|
+
const WAYS = [
|
|
8
|
+
{ id: 'github', label: 'Import from GitHub', icon: 'github', from: 'GitHub', busy: 'Cloning…' },
|
|
9
|
+
{ id: 'scratch', label: 'Start from scratch', icon: 'plus', from: 'Scratch', busy: 'Setting up…' },
|
|
10
|
+
{ id: 'folder', label: 'Use a folder', heading: 'A folder on this computer', icon: 'folder', from: 'A folder', busy: 'Connecting…' }
|
|
11
|
+
]
|
|
12
|
+
const LOOK_MS = 250
|
|
13
|
+
|
|
14
|
+
const card = (title, lead, body) => `<section class="card settings-sec"><div class="sec-intro"><h2>${title}</h2><p>${lead}</p></div><div class="sec-body">${body}</div></section>`
|
|
15
|
+
const where = (verb) => `<p class="nc-where"><span>${verb}</span><code data-nc-dir>…</code><span class="spacer"></span><button type="button" class="btn sm ghost" data-nc-change>Change</button></p>`
|
|
16
|
+
|
|
17
|
+
/** What the form would send for the way picked: the body of POST /api/sessions, less `mode`. */
|
|
18
|
+
export function newCodebaseBody (way, v) {
|
|
19
|
+
if (way === 'github') return { source: 'github', repo: v.repo.trim(), ...(v.into ? { into: v.into } : {}) }
|
|
20
|
+
if (way === 'scratch') return { source: 'scratch', name: v.name.trim(), brief: v.brief.trim(), ...(v.into ? { into: v.into } : {}) }
|
|
21
|
+
return { source: 'folder', dir: v.dir.trim() }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The line under a folder's path: what Quilt does about git there. `look`: the server's answer for it, or null. */
|
|
25
|
+
export function folderGitNote (look) {
|
|
26
|
+
if (!look) return ''
|
|
27
|
+
if (look.git) return 'This folder has git already. Quilt uses it as it is.'
|
|
28
|
+
if (look.exists) return 'No git here yet. Quilt sets it up and saves what is there as the first commit.'
|
|
29
|
+
return 'This folder is new. Quilt makes it and sets up git.'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Opens the pop-up. `workspace`: the workspace the session starts in, if any. `submit`, `tildify`
|
|
34
|
+
* and `pickFolder` are Home's (home.js): starting the session, showing a path, choosing a folder.
|
|
35
|
+
*/
|
|
36
|
+
export function openNewCodebase ({ workspace = '', submit, tildify, pickFolder }) {
|
|
37
|
+
$('#nc-back')?.remove()
|
|
38
|
+
const v = { repo: '', name: '', brief: '', dir: tildify(state.lastCreateDir || state.defaults.cwd || ''), into: '' }
|
|
39
|
+
let way = 'github'
|
|
40
|
+
let look = null // the server's answer for what is typed now: { dir, name, exists, git }
|
|
41
|
+
let asked = 0
|
|
42
|
+
let timer = null
|
|
43
|
+
const inWorkspace = workspace ? state.workspaces?.find((w) => w.id === workspace)?.name || 'this project' : ''
|
|
44
|
+
const back = document.createElement('div')
|
|
45
|
+
back.id = 'nc-back'
|
|
46
|
+
back.className = 'modal-back settings-back'
|
|
47
|
+
back.innerHTML = `
|
|
48
|
+
<form class="settings-modal nc-pop" role="dialog" aria-modal="true" aria-labelledby="nc-title" autocomplete="off">
|
|
49
|
+
<nav class="ss-nav settings-nav" aria-label="Where it starts from">
|
|
50
|
+
<h3 id="nc-title">Create a codebase</h3>
|
|
51
|
+
<p class="lead settings-scope">A place to code together, live${inWorkspace ? `, in ${esc(inWorkspace)}` : ''}. It comes with git, for you and for everyone who joins.</p>
|
|
52
|
+
<div class="label nc-label">Start from</div>
|
|
53
|
+
<div class="ss-tabs settings-tabs" role="tablist" aria-orientation="vertical">${WAYS.map((w) => `<button type="button" role="tab" class="ss-tab" data-nc-way="${w.id}">${I[w.icon]}<span>${w.label}</span></button>`).join('')}</div>
|
|
54
|
+
<div class="nc-sum" data-nc-sum></div>
|
|
55
|
+
</nav>
|
|
56
|
+
<div class="ss-main">
|
|
57
|
+
<div class="ss-head"><h4 class="ss-name"></h4><button class="btn sm ghost icon ss-close" type="button" data-nc-close aria-label="Close">${I.x}</button></div>
|
|
58
|
+
<div class="settings-body" role="tabpanel"></div>
|
|
59
|
+
<div class="nc-foot"><div class="grow"><span class="hint" data-nc-hint>Nothing is shared until you start it.</span><p class="error" id="nc-error"></p></div>
|
|
60
|
+
<button type="button" class="btn ghost" data-nc-close>Cancel</button><button class="btn primary" type="submit"></button></div>
|
|
61
|
+
<input type="hidden" data-nc-into>
|
|
62
|
+
</div>
|
|
63
|
+
</form>`
|
|
64
|
+
document.body.appendChild(back)
|
|
65
|
+
const form = $('form', back)
|
|
66
|
+
const body = $('.settings-body', back)
|
|
67
|
+
const close = () => { clearTimeout(timer); back.remove() }
|
|
68
|
+
back.addEventListener('mousedown', (e) => { if (e.target === back) close() })
|
|
69
|
+
back.addEventListener('keydown', (e) => { if (e.key === 'Escape') close() })
|
|
70
|
+
back.querySelectorAll('[data-nc-close]').forEach((b) => { b.onclick = close })
|
|
71
|
+
|
|
72
|
+
const bodies = {
|
|
73
|
+
github: () => card('Repository', 'Paste its address, or type it as owner/name. Quilt clones it with git on this computer.', `
|
|
74
|
+
<div class="field"><label for="nc-repo">Repository</label><input class="input mono" id="nc-repo" spellcheck="false" placeholder="owner/name or https://github.com/owner/name" value="${esc(v.repo)}" required>
|
|
75
|
+
<span class="hint warn" data-nc-warn hidden></span></div>
|
|
76
|
+
${where('It is cloned to')}`),
|
|
77
|
+
scratch: () => card('What do you want to build?', 'Quilt makes the folder, sets up git, and puts what you write on the board as the first task.', `
|
|
78
|
+
<div class="field"><label for="nc-name">Name</label><input class="input" id="nc-name" placeholder="neon-dungeon" maxlength="80" value="${esc(v.name)}" required></div>
|
|
79
|
+
<div class="field"><label for="nc-brief">The idea</label><textarea class="input nc-brief" id="nc-brief" rows="4" maxlength="8000" placeholder="A small browser game: one level to start, keyboard controls.">${esc(v.brief)}</textarea></div>
|
|
80
|
+
${where('It goes in')}`),
|
|
81
|
+
folder: () => card('Folder', 'Any folder on this computer, on GitHub or not.', `
|
|
82
|
+
<div class="field"><label for="nc-dir">Folder</label>
|
|
83
|
+
<div class="row"><input class="input grow mono" id="nc-dir" spellcheck="false" placeholder="~/code/my-app" value="${esc(v.dir)}" required>
|
|
84
|
+
<button type="button" class="btn icon" data-nc-browse title="Browse" aria-label="Browse">${I.folder}</button></div>
|
|
85
|
+
<span class="hint" data-nc-git></span></div>`)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const draw = () => {
|
|
89
|
+
const w = WAYS.find((x) => x.id === way)
|
|
90
|
+
const name = (look && look.name) || ''
|
|
91
|
+
$('button[type=submit]', back).innerHTML = `<span>${esc(name ? `Start ${name}` : 'Start')}</span>${I.arrowRight}`
|
|
92
|
+
const dir = $('[data-nc-dir]', body)
|
|
93
|
+
if (dir) dir.textContent = look ? tildify(look.dir) : '…'
|
|
94
|
+
const git = $('[data-nc-git]', body)
|
|
95
|
+
if (git) git.textContent = folderGitNote(look)
|
|
96
|
+
const rows = [['Name', name || '…'], ['From', w.from], ['Folder', look ? tildify(look.dir) : '…'],
|
|
97
|
+
['Git', way === 'github' ? 'Cloned for you' : way === 'folder' && look && look.git ? 'Already there' : 'Set up for you']]
|
|
98
|
+
$('[data-nc-sum]', back).innerHTML = `<div class="label">This codebase</div>${rows.map(([k, val]) => `<div class="nc-sum-row"><span>${k}</span><b title="${esc(val)}">${esc(val)}</b></div>`).join('')}`
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// What the server says starting from this would do: where it goes, what it is called, whether git is there.
|
|
102
|
+
const lookNow = async () => {
|
|
103
|
+
const n = ++asked
|
|
104
|
+
const warn = $('[data-nc-warn]', body)
|
|
105
|
+
const typed = way === 'github' ? v.repo : way === 'scratch' ? v.name : v.dir
|
|
106
|
+
if (!typed.trim()) { look = null; if (warn) warn.hidden = true; draw(); return }
|
|
107
|
+
try {
|
|
108
|
+
const r = await api('POST', '/api/new-session/look', newCodebaseBody(way, v))
|
|
109
|
+
if (n !== asked) return
|
|
110
|
+
look = r
|
|
111
|
+
if (warn) warn.hidden = true
|
|
112
|
+
} catch (err) {
|
|
113
|
+
if (n !== asked) return
|
|
114
|
+
look = null
|
|
115
|
+
if (warn) { warn.textContent = err.message; warn.hidden = false }
|
|
116
|
+
}
|
|
117
|
+
draw()
|
|
118
|
+
}
|
|
119
|
+
const lookSoon = () => { clearTimeout(timer); timer = setTimeout(lookNow, LOOK_MS) }
|
|
120
|
+
|
|
121
|
+
const pick = (id) => {
|
|
122
|
+
way = id
|
|
123
|
+
look = null
|
|
124
|
+
for (const b of back.querySelectorAll('[data-nc-way]')) { b.classList.toggle('on', b.dataset.ncWay === id); b.setAttribute('aria-selected', b.dataset.ncWay === id) }
|
|
125
|
+
const w = WAYS.find((x) => x.id === id)
|
|
126
|
+
$('.ss-name', back).textContent = w.heading || w.label
|
|
127
|
+
$('#nc-error', back).textContent = ''
|
|
128
|
+
body.innerHTML = bodies[id]()
|
|
129
|
+
body.scrollTop = 0
|
|
130
|
+
const bind = (sel, key) => { const el = $(sel, body); if (el) el.oninput = () => { v[key] = el.value; lookSoon() } }
|
|
131
|
+
bind('#nc-repo', 'repo'); bind('#nc-name', 'name'); bind('#nc-brief', 'brief'); bind('#nc-dir', 'dir')
|
|
132
|
+
const browse = $('[data-nc-browse]', body)
|
|
133
|
+
if (browse) browse.onclick = async () => { const el = $('#nc-dir', body); await pickFolder(el); if (el.value !== v.dir) { v.dir = el.value; lookNow() } }
|
|
134
|
+
// Change: the folder a clone or a new project is made in, instead of the one in Settings.
|
|
135
|
+
const change = $('[data-nc-change]', body)
|
|
136
|
+
if (change) change.onclick = async () => { into.value = v.into; await pickFolder(into); if (into.value !== v.into) { v.into = into.value; lookNow() } }
|
|
137
|
+
draw()
|
|
138
|
+
lookNow()
|
|
139
|
+
$('input', body)?.focus()
|
|
140
|
+
}
|
|
141
|
+
const into = $('[data-nc-into]', back)
|
|
142
|
+
back.querySelectorAll('[data-nc-way]').forEach((b) => { b.onclick = () => pick(b.dataset.ncWay) })
|
|
143
|
+
|
|
144
|
+
form.onsubmit = async (e) => {
|
|
145
|
+
e.preventDefault()
|
|
146
|
+
if (way === 'folder') state.lastCreateDir = v.dir
|
|
147
|
+
if (await submit(form, '#nc-error', { mode: 'create', workspace, ...newCodebaseBody(way, v) }, WAYS.find((x) => x.id === way).busy)) close()
|
|
148
|
+
else draw() // the button says what it starts again
|
|
149
|
+
}
|
|
150
|
+
pick(way)
|
|
151
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// The strip on the far left, as plain logic (no DOM): which project a page belongs to, and the
|
|
2
|
+
// tiles the strip shows. prail.js puts them on the page.
|
|
3
|
+
|
|
4
|
+
/** The project a view belongs to: its own page, its All files, or a codebase in it. '' for Home and the pages beside it. */
|
|
5
|
+
export function projectOf (view, sessions = new Map()) {
|
|
6
|
+
const v = String(view || '')
|
|
7
|
+
const m = /^(?:ws|wsfiles):(.+)$/.exec(v)
|
|
8
|
+
if (m) return m[1]
|
|
9
|
+
return (sessions.get(v) && sessions.get(v).workspace) || ''
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** A project's tile: its first letter (a digit or a sign counts), upper case; '?' for a name with nothing in it. */
|
|
13
|
+
export const tileLetter = (name) => ([...String(name || '').trim()][0] || '?').toUpperCase()
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The strip's tiles, in the order the projects came: { id, name, letter, color, on }. `here`: the
|
|
17
|
+
* project the open page belongs to. An archived project is off the strip, except while it is the
|
|
18
|
+
* one open (opened from Settings): its tile and its settings are how it is brought back.
|
|
19
|
+
*/
|
|
20
|
+
export function railTiles (projects = [], here = '', colors = {}) {
|
|
21
|
+
return projects.filter((p) => p && p.id && (!p.archivedAt || p.id === here)).map((p) => ({ id: p.id, name: p.name || '', letter: tileLetter(p.name), color: colors[p.color] || Object.values(colors)[0] || '', on: p.id === here }))
|
|
22
|
+
}
|
package/src/ui/prail.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// The strip on the far left of every page, once projects are on: Home, a tile for each project,
|
|
2
|
+
// a new project, and at its foot the open project's settings and the bug and idea buttons.
|
|
3
|
+
// It is how you move between projects, and it shows which one you are in.
|
|
4
|
+
import { I, state, $, esc, COLORS } from './common.js'
|
|
5
|
+
import { projectOf, railTiles } from './prail-model.js'
|
|
6
|
+
import { feedbackDockHtml, bindFeedback } from './feedback.js'
|
|
7
|
+
|
|
8
|
+
/** Where a bug or an idea was sent from, as its form says it: the codebase, the project, or Home. */
|
|
9
|
+
function where () {
|
|
10
|
+
const s = state.sessions.get(state.view)
|
|
11
|
+
if (s) return s.status?.sessionName || 'a codebase'
|
|
12
|
+
const id = projectOf(state.view, state.sessions)
|
|
13
|
+
return (state.workspaces || []).find((w) => w.id === id)?.name || 'Home'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Draws the strip for the page that is open, or hides it while projects are off. `go(view)` opens a
|
|
18
|
+
* page; `addProject()` starts a new project; `projectSettings(id)` opens a project's settings.
|
|
19
|
+
*/
|
|
20
|
+
export function renderRail ({ go, addProject, projectSettings }) {
|
|
21
|
+
const el = $('#prail')
|
|
22
|
+
if (!el) return
|
|
23
|
+
const on = !!state.workspacesOn && !!state.account
|
|
24
|
+
el.hidden = !on
|
|
25
|
+
document.body.classList.toggle('has-rail', on)
|
|
26
|
+
if (!on) { el.innerHTML = ''; return }
|
|
27
|
+
const here = projectOf(state.view, state.sessions)
|
|
28
|
+
const tiles = railTiles(state.workspaces || [], here, COLORS)
|
|
29
|
+
const open = tiles.find((t) => t.on)
|
|
30
|
+
const atHome = !here && !state.sessions.has(state.view)
|
|
31
|
+
el.innerHTML = `
|
|
32
|
+
<button type="button" class="rail-home${atHome ? ' on' : ''}" data-rail-go="home" title="Home" aria-label="Home"${atHome ? ' aria-current="page"' : ''}>${I.home}</button>
|
|
33
|
+
<hr>
|
|
34
|
+
${tiles.map((t) => `<button type="button" class="rail-tile${t.on ? ' on' : ''}" data-rail-go="ws:${esc(t.id)}" title="${esc(t.name)}" aria-label="${esc(t.name)}"${t.on ? ' aria-current="true"' : ''} style="background:${esc(t.color)}">${esc(t.letter)}</button>`).join('')}
|
|
35
|
+
<button type="button" class="add" data-rail-add title="New project" aria-label="New project">${I.plus}</button>
|
|
36
|
+
<span class="rail-foot">${open ? `<button type="button" class="fb-btn rail-gear" data-rail-settings="${esc(open.id)}" title="${esc(open.name)}: project settings" aria-label="${esc(open.name)}: project settings">${I.gear}</button>` : ''}${feedbackDockHtml('rail')}</span>`
|
|
37
|
+
el.querySelectorAll('[data-rail-go]').forEach((b) => { b.onclick = () => go(b.dataset.railGo) })
|
|
38
|
+
el.querySelector('[data-rail-add]').onclick = () => addProject()
|
|
39
|
+
const gear = el.querySelector('[data-rail-settings]')
|
|
40
|
+
if (gear) gear.onclick = () => projectSettings(gear.dataset.railSettings)
|
|
41
|
+
// The forms file into the codebase that is open, or ask which when none is. Bound once: the strip is drawn again and again.
|
|
42
|
+
bindFeedback(el, { session: () => (state.sessions.has(state.view) ? state.view : null), where })
|
|
43
|
+
}
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
// One task board for a project, across its codebases (the Tasks row of a project's sidebar). It is
|
|
2
|
+
// the board a codebase has (board.js draws both), with a row of chips to narrow it to one codebase
|
|
3
|
+
// and each card wearing its codebase's name. A task lives in its codebase's document, so the board
|
|
4
|
+
// shows the codebases open on this computer and says which are not; a change is saved to the
|
|
5
|
+
// codebase the task is in (the same routes a codebase's own board uses).
|
|
6
|
+
import { I, state, $, esc, api, toast, ago } from './common.js'
|
|
7
|
+
import { renderBoard, openTaskMenu, taskNotesModalHtml, matchesSearch, foldPlan, ticketHtml } from './board.js'
|
|
8
|
+
import { projectCodebases, projectBoard, splitBoardTaskId, boardAssignment, openTaskCount, tasksToKeep } from './project-model.js'
|
|
9
|
+
|
|
10
|
+
// What you picked on a project's board, kept while the app is open: the codebase, who, the search, folded columns.
|
|
11
|
+
const prefs = new Map()
|
|
12
|
+
const prefsOf = (id) => { if (!prefs.has(id)) prefs.set(id, { code: '', show: '', archived: false, query: '', opened: [], shut: [], into: '', draft: '', scroll: [], refocus: false }); return prefs.get(id) }
|
|
13
|
+
let live = null // the board on the page: { el, ro, later, leave }
|
|
14
|
+
|
|
15
|
+
// Each codebase's tasks as this computer last saw them ({ room: { at, tasks } }), so a codebase that
|
|
16
|
+
// is not open still shows on its project's board, to read.
|
|
17
|
+
const SEEN = 'quilt.boardSeen'
|
|
18
|
+
let seen = null
|
|
19
|
+
const seenNow = () => { if (!seen) { try { seen = JSON.parse(localStorage.getItem(SEEN) || '{}') || {} } catch { seen = {} } } return seen }
|
|
20
|
+
function remember (b) {
|
|
21
|
+
const all = seenNow(); let changed = false
|
|
22
|
+
for (const c of b.open) {
|
|
23
|
+
if (!c.room) continue
|
|
24
|
+
const tasks = tasksToKeep(state.sessions.get(c.id)?.status?.tasks || [])
|
|
25
|
+
if (all[c.room] && JSON.stringify(all[c.room].tasks) === JSON.stringify(tasks)) continue
|
|
26
|
+
all[c.room] = { at: Date.now(), tasks }; changed = true
|
|
27
|
+
}
|
|
28
|
+
if (changed) { try { localStorage.setItem(SEEN, JSON.stringify(all)) } catch { /* not kept: it is shown again when the codebase is open */ } }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The board of the open project, from what the app knows now. */
|
|
32
|
+
function boardOf (d) {
|
|
33
|
+
return projectBoard(projectCodebases(d, state.sessions, `person:${state.account?.id}`), state.sessions, seenNow())
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** How many tasks are open across the project's codebases on this computer (the sidebar's count). */
|
|
37
|
+
export const projectOpenTasks = (d) => openTaskCount(boardOf(d).tasks)
|
|
38
|
+
|
|
39
|
+
/** Whether the board is being used right now (a card dragged, a name or a search typed, a menu or notes open). */
|
|
40
|
+
const busy = (el) => {
|
|
41
|
+
if (el.querySelector('.task.dragging, .task-title[contenteditable="true"], .board-filter-panel:not([hidden])') || document.querySelector('.task-menu, .task-notes-back')) return true
|
|
42
|
+
const at = document.activeElement
|
|
43
|
+
if (!at || !el.contains(at) || !/^(INPUT|SELECT|TEXTAREA)$/.test(at.tagName)) return false
|
|
44
|
+
return at.id !== 'task-add' || !!at.value.trim() // an empty "What needs doing?" is put back with its cursor
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Asked before a project's page is drawn again. True while the board on it is being used: the
|
|
49
|
+
* page is then left as it is, and `later()` is called once to try again. Otherwise the board
|
|
50
|
+
* remembers what the fresh drawing puts back (how far each column was scrolled, the cursor).
|
|
51
|
+
*/
|
|
52
|
+
export function holdProjectBoard (later) {
|
|
53
|
+
if (!live || !live.el.isConnected) return false
|
|
54
|
+
clearTimeout(live.later)
|
|
55
|
+
if (busy(live.el)) { live.later = setTimeout(later, 1200); return true }
|
|
56
|
+
live.leave()
|
|
57
|
+
return false
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Draws the board into `el` for the project `d` and keeps it working. `changed()`: the open count
|
|
62
|
+
* may have changed (the sidebar shows it). `reload()`: the project is read again and its page drawn
|
|
63
|
+
* (a codebase was opened from the board).
|
|
64
|
+
*/
|
|
65
|
+
export function mountProjectBoard (el, { d, go, reload = () => {}, changed = () => {} }) {
|
|
66
|
+
const id = d.workspace.id
|
|
67
|
+
const st = prefsOf(id)
|
|
68
|
+
const data = () => (state.workspace && state.workspace.workspace.id === id ? state.workspace : d)
|
|
69
|
+
let b = boardOf(data())
|
|
70
|
+
const taskOf = (e) => b.tasks.find((t) => !t.stale && t.id === e.target.closest('.task, .task-archived, [data-task]')?.dataset.task)
|
|
71
|
+
const me = () => state.profile?.name || ''
|
|
72
|
+
const shows = (t) => !st.code || t.code === st.code
|
|
73
|
+
|
|
74
|
+
/** Saves a change to the codebase the task is in, and takes that codebase's tasks as it answers. */
|
|
75
|
+
const save = async (code, path, body) => {
|
|
76
|
+
const r = await api('POST', `/api/sessions/${code}/tasks${path}`, body)
|
|
77
|
+
const s = state.sessions.get(code)
|
|
78
|
+
if (s && r.tasks) s.status.tasks = r.tasks
|
|
79
|
+
draw()
|
|
80
|
+
return r
|
|
81
|
+
}
|
|
82
|
+
const change = (t, patch, path = '/update') => save(t.code, path, { id: splitBoardTaskId(t.id)[1], ...patch }).catch((err) => { toast(err.message); draw() })
|
|
83
|
+
|
|
84
|
+
// Which cards the codebase picked and the search leave on the board, and what each column then counts.
|
|
85
|
+
const apply = () => {
|
|
86
|
+
const board = $('.board', el)
|
|
87
|
+
if (!board) return
|
|
88
|
+
for (const c of board.querySelectorAll('.pj-chip')) { const on = (c.dataset.code || '') === st.code; c.classList.toggle('on', on); c.setAttribute('aria-pressed', String(on)) }
|
|
89
|
+
for (const col of board.querySelectorAll('.board-col')) {
|
|
90
|
+
let n = 0
|
|
91
|
+
for (const card of col.querySelectorAll('.task')) {
|
|
92
|
+
const t = b.tasks.find((x) => x.id === card.dataset.task)
|
|
93
|
+
const show = !!t && shows(t) && matchesSearch(card.dataset.search, st.query)
|
|
94
|
+
card.hidden = !show
|
|
95
|
+
if (show) n++
|
|
96
|
+
}
|
|
97
|
+
for (const x of col.querySelectorAll('.board-n, .board-strip-n')) x.textContent = String(n)
|
|
98
|
+
col.querySelector('.pj-empty')?.remove()
|
|
99
|
+
if (!n && !col.querySelector('.board-empty:not(.pj-empty)')) col.querySelector('.board-list').insertAdjacentHTML('beforeend', '<p class="board-empty pj-empty">Nothing here.</p>')
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// As many columns open as fit, work in flight first; the rest fold to strips (foldPlan, as a codebase's board).
|
|
103
|
+
const layout = ({ animate = false } = {}) => {
|
|
104
|
+
const board = $('.board', el)
|
|
105
|
+
const cols = board?.querySelector('.board-cols')
|
|
106
|
+
if (!cols) return
|
|
107
|
+
if (!animate) cols.classList.add('still')
|
|
108
|
+
const all = [...cols.querySelectorAll('.board-col')]
|
|
109
|
+
const counts = {}
|
|
110
|
+
for (const col of all) counts[col.dataset.column] = col.querySelectorAll('.task').length
|
|
111
|
+
const pad = parseFloat(getComputedStyle(cols).paddingLeft) || 0
|
|
112
|
+
const plan = foldPlan({ picked: st.opened, folded: st.shut, counts, room: cols.clientWidth - 2 * pad })
|
|
113
|
+
const open = new Set(plan.open)
|
|
114
|
+
board.dataset.layout = plan.layout
|
|
115
|
+
for (const col of all) {
|
|
116
|
+
const isOpen = open.has(col.dataset.column)
|
|
117
|
+
col.classList.toggle('folded', !isOpen)
|
|
118
|
+
col.querySelector('.board-strip').inert = isOpen
|
|
119
|
+
for (const part of col.querySelectorAll(':scope > h3, :scope > .board-list')) part.inert = !isOpen
|
|
120
|
+
const fold = col.querySelector('.board-fold')
|
|
121
|
+
if (fold) fold.hidden = isOpen && open.size === 1
|
|
122
|
+
}
|
|
123
|
+
if (!animate) { void cols.offsetWidth; cols.classList.remove('still') }
|
|
124
|
+
}
|
|
125
|
+
const openColumn = (id) => {
|
|
126
|
+
const { order, folded } = foldPlan({ picked: st.opened, folded: st.shut, room: 0 })
|
|
127
|
+
st.opened = [id, ...order.filter((x) => x !== id)]
|
|
128
|
+
st.shut = folded.filter((x) => x !== id)
|
|
129
|
+
layout({ animate: true })
|
|
130
|
+
}
|
|
131
|
+
const foldColumn = (id) => {
|
|
132
|
+
const { order, folded } = foldPlan({ picked: st.opened, folded: st.shut, room: 0 })
|
|
133
|
+
st.shut = [...new Set([...folded, id])]
|
|
134
|
+
st.opened = [...order.filter((x) => x !== id), id]
|
|
135
|
+
layout({ animate: true })
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function draw () {
|
|
139
|
+
b = boardOf(data())
|
|
140
|
+
remember(b)
|
|
141
|
+
const codes = [...b.open, ...b.stale]
|
|
142
|
+
if (st.code && !codes.some((c) => c.id === st.code)) st.code = ''
|
|
143
|
+
if (st.archived && !b.tasks.some((t) => t.archived)) st.archived = false
|
|
144
|
+
if (!b.open.some((c) => c.id === st.into)) st.into = (b.open.find((c) => c.id === st.code) || b.open[0] || {}).id || ''
|
|
145
|
+
const name = d.workspace.name
|
|
146
|
+
if (!codes.length) {
|
|
147
|
+
el.innerHTML = `<div class="board"><div class="board-head"><h2 class="board-title">Tasks</h2></div><p class="hint pj-board-none">${b.closed.length ? `A task lives in its codebase, and none of ${esc(name)}'s codebases is open on this computer. Open one from the sidebar and its tasks show here.` : `${esc(name)} has no codebases yet. Tasks belong to a codebase: start one and its board shows here.`}</p></div>`
|
|
148
|
+
return changed()
|
|
149
|
+
}
|
|
150
|
+
const lists = [...el.querySelectorAll('.board-list')]
|
|
151
|
+
const scroll = lists.length ? lists.map((l) => l.scrollTop) : st.scroll
|
|
152
|
+
const draft = $('#task-add', el)?.value ?? st.draft
|
|
153
|
+
el.innerHTML = renderBoard(st.archived ? b.tasks.filter(shows) : b.tasks, me(), b.people, '', { show: st.show, archived: st.archived })
|
|
154
|
+
const board = $('.board', el)
|
|
155
|
+
board.querySelector('.board-title')?.setAttribute('title', `One board for all of ${name}. Assign a task to a person or their AI.`)
|
|
156
|
+
for (const card of board.querySelectorAll('.task')) {
|
|
157
|
+
const t = b.tasks.find((x) => x.id === card.dataset.task)
|
|
158
|
+
if (!t) continue
|
|
159
|
+
if (t.stale) { // as last seen: to read, changed from inside its codebase
|
|
160
|
+
card.classList.add('pj-stale'); card.inert = true; card.draggable = false
|
|
161
|
+
card.querySelector('.task-main').insertAdjacentHTML('afterend', `<div class="pj-tags"><span class="tag pj-tag">${I.folder}${esc(t.codeName)}</span><span class="hint">as last seen</span></div>`)
|
|
162
|
+
continue
|
|
163
|
+
}
|
|
164
|
+
// Its codebase, then its ticket's branch in that codebase's folder (each codebase is on a branch of its own).
|
|
165
|
+
card.querySelector('.task-main').insertAdjacentHTML('afterend', `<div class="pj-tags"><button type="button" class="tag pj-tag" data-code-open="${esc(t.code)}" title="Its codebase. Open ${esc(t.codeName)}.">${I.folder}${esc(t.codeName)}</button></div>${ticketHtml(t, b.open.find((c) => c.id === t.code)?.git)}`)
|
|
166
|
+
}
|
|
167
|
+
// A new task says which codebase it belongs to.
|
|
168
|
+
if (!b.open.length) board.querySelector('#task-add-form')?.remove() // nowhere to put a new task until a codebase is open
|
|
169
|
+
board.querySelector('.board-add-assign')?.insertAdjacentHTML('beforebegin', `<div class="board-add-assign pj-add-in"><label for="pj-add-in">In</label>
|
|
170
|
+
<select id="pj-add-in" class="task-add-assign" aria-label="The codebase the new task belongs to">${b.open.map((c) => `<option value="${esc(c.id)}"${c.id === st.into ? ' selected' : ''}>${esc(c.name)}</option>`).join('')}</select></div>`)
|
|
171
|
+
const all = b.tasks.filter((t) => !t.archived)
|
|
172
|
+
const chip = (code, label, n) => `<button type="button" class="pj-chip" data-code="${esc(code)}" aria-pressed="false">${code ? I.folder : ''}<span>${esc(label)}</span><span class="n">${n}</span></button>`
|
|
173
|
+
if (!st.archived) {
|
|
174
|
+
board.querySelector('.board-head').insertAdjacentHTML('afterend', `<div class="pj-tagbar" role="group" aria-label="Show the tasks of one codebase">
|
|
175
|
+
${chip('', 'All', all.length)}<span class="pj-tagbar-sep"></span>${codes.map((c) => chip(c.id, c.name, all.filter((t) => t.code === c.id).length)).join('')}
|
|
176
|
+
<span class="spacer"></span>
|
|
177
|
+
${b.stale.map((c) => `<span class="hint pj-seen" title="${esc(c.name)} is not open on this computer. Its tasks are as this computer last saw them, to read: open it to change them.">${esc(c.name)}: as of ${esc(ago(c.at))}</span>${c.dir ? `<button type="button" class="btn sm" data-open-here="${esc(c.dir)}">Open</button>` : ''}`).join('')}
|
|
178
|
+
${b.closed.length ? `<span class="hint" title="A task lives in its codebase: open it on this computer to see its tasks here.">Not open here: ${esc(b.closed.join(', '))}</span>` : ''}</div>`)
|
|
179
|
+
}
|
|
180
|
+
const search = board.querySelector('#board-search')
|
|
181
|
+
if (search) search.value = st.query
|
|
182
|
+
const add = $('#task-add', el)
|
|
183
|
+
if (add && draft) add.value = draft
|
|
184
|
+
layout()
|
|
185
|
+
apply()
|
|
186
|
+
board.querySelectorAll('.board-list').forEach((l, i) => { l.scrollTop = scroll[i] || 0 })
|
|
187
|
+
changed()
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const rename = (title, t) => {
|
|
191
|
+
if (!title || title.isContentEditable) return
|
|
192
|
+
title.contentEditable = 'true'
|
|
193
|
+
title.focus()
|
|
194
|
+
document.getSelection().selectAllChildren(title)
|
|
195
|
+
const done = (keep) => { title.onblur = null; const text = title.textContent.trim(); title.contentEditable = 'false'; if (keep && text && text !== t.title) change(t, { title: text }); else draw() }
|
|
196
|
+
title.onkeydown = (k) => { if (k.key === 'Enter') { k.preventDefault(); done(true) } else if (k.key === 'Escape') done(false) }
|
|
197
|
+
title.onblur = () => done(true)
|
|
198
|
+
}
|
|
199
|
+
const notes = (t, instant = false) => { // the same notes and comments pop-up a codebase's board has
|
|
200
|
+
document.querySelector('.task-notes-back')?.remove()
|
|
201
|
+
const back = document.createElement('div')
|
|
202
|
+
back.className = 'modal-back task-notes-back'
|
|
203
|
+
back.innerHTML = taskNotesModalHtml(t)
|
|
204
|
+
document.body.appendChild(back)
|
|
205
|
+
const close = () => { back.remove(); draw() }
|
|
206
|
+
back.addEventListener('mousedown', (e) => { if (e.target === back) close() })
|
|
207
|
+
back.addEventListener('keydown', (e) => { if (e.key === 'Escape') { e.preventDefault(); close() } })
|
|
208
|
+
back.querySelector('[data-close-notes]').onclick = close
|
|
209
|
+
const form = back.querySelector('.task-comment-form')
|
|
210
|
+
const box = back.querySelector('.task-comment-text')
|
|
211
|
+
box.addEventListener('keydown', (e) => { if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) { e.preventDefault(); form.requestSubmit() } })
|
|
212
|
+
form.addEventListener('submit', async (e) => {
|
|
213
|
+
e.preventDefault()
|
|
214
|
+
const text = box.value.trim()
|
|
215
|
+
if (!text) return
|
|
216
|
+
try {
|
|
217
|
+
await save(t.code, '/comment', { id: splitBoardTaskId(t.id)[1], text })
|
|
218
|
+
const again = boardOf(data()).tasks.find((x) => x.id === t.id)
|
|
219
|
+
if (again) notes(again, true)
|
|
220
|
+
} catch (err) { toast(err.message) }
|
|
221
|
+
})
|
|
222
|
+
if (instant) { back.classList.add('is-open'); back.querySelector('.task-comment-text').focus() } else {
|
|
223
|
+
;(t.comments?.length || t.qaNotes || t.verified ? back.querySelector('[data-close-notes]') : box).focus()
|
|
224
|
+
requestAnimationFrame(() => requestAnimationFrame(() => back.classList.add('is-open')))
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Opening a ticket moves that codebase's folder onto the ticket's branch; leaving takes it back.
|
|
229
|
+
const ticket = async (btn, t) => {
|
|
230
|
+
if (btn.disabled) return
|
|
231
|
+
const opening = btn.matches('[data-task-open]')
|
|
232
|
+
btn.disabled = true
|
|
233
|
+
try {
|
|
234
|
+
const r = await api('POST', `/api/sessions/${t.code}/tasks/${opening ? 'open' : 'leave'}`, opening ? { id: splitBoardTaskId(t.id)[1] } : {})
|
|
235
|
+
const s = state.sessions.get(t.code)
|
|
236
|
+
if (s && r.tasks) s.status.tasks = r.tasks
|
|
237
|
+
const br = r.branch
|
|
238
|
+
if (!br) toast(opening ? `${t.codeName}'s folder is not a git clone, so tickets have no branch there.` : 'You are not on a ticket\'s branch.')
|
|
239
|
+
else if (br.stayed) toast(`Your ${t.codeName} folder stays on ${br.stayed}: ${br.why}`)
|
|
240
|
+
else if (opening) toast(`Your ${t.codeName} folder is on "${t.title}" now (${br.branch}).`)
|
|
241
|
+
else toast(`Your ${t.codeName} folder is back on ${br.branch}. What you had not committed stays on the ticket.`)
|
|
242
|
+
} catch (err) { toast(err.message) }
|
|
243
|
+
draw()
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// A codebase on this computer that is not open: opened in place, so its tasks can be changed from this board.
|
|
247
|
+
const openHere = async (btn) => {
|
|
248
|
+
btn.disabled = true
|
|
249
|
+
try {
|
|
250
|
+
const sum = await api('POST', '/api/sessions', { mode: 'rejoin', dir: btn.dataset.openHere })
|
|
251
|
+
state.sessions.set(sum.id, sum)
|
|
252
|
+
await reload()
|
|
253
|
+
} catch (err) { toast(err.message); btn.disabled = false }
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
el.onclick = (e) => {
|
|
257
|
+
const hit = (q) => e.target.closest(q)
|
|
258
|
+
const t = taskOf(e)
|
|
259
|
+
if (hit('.pj-chip')) { st.code = hit('.pj-chip').dataset.code || ''; if (st.code) st.into = st.code; return draw() }
|
|
260
|
+
if (hit('[data-code-open]')) return go(hit('[data-code-open]').dataset.codeOpen)
|
|
261
|
+
if (hit('[data-open-here]')) return openHere(hit('[data-open-here]'))
|
|
262
|
+
if (hit('[data-unfold]')) return openColumn(hit('[data-unfold]').dataset.unfold)
|
|
263
|
+
if (hit('[data-fold]')) return foldColumn(hit('[data-fold]').dataset.fold)
|
|
264
|
+
if (hit('[data-filter-toggle]')) { const panel = $('.board-filter-panel', el); panel.hidden = !panel.hidden; hit('[data-filter-toggle]').setAttribute('aria-expanded', String(!panel.hidden)); if (!panel.hidden) $('#board-search', el)?.focus(); return }
|
|
265
|
+
if (hit('[data-show-pick]')) { st.show = hit('[data-show-pick]').dataset.showPick; return draw() }
|
|
266
|
+
if (hit('[data-filter-clear]')) { st.show = ''; st.query = ''; return draw() }
|
|
267
|
+
if (hit('[data-archived-toggle]')) { st.archived = !st.archived; return draw() }
|
|
268
|
+
if (hit('[data-task-remove-ask]')) return hit('.task-archived').classList.add('confirming')
|
|
269
|
+
if (hit('[data-task-remove-cancel]')) return hit('.task-archived').classList.remove('confirming')
|
|
270
|
+
if (!t) return
|
|
271
|
+
if (hit('[data-move]')) return change(t, { column: hit('[data-move]').dataset.move })
|
|
272
|
+
if (hit('[data-task-open], [data-task-leave]')) return ticket(hit('[data-task-open], [data-task-leave]'), t)
|
|
273
|
+
if (hit('[data-task-more]')) {
|
|
274
|
+
return openTaskMenu(hit('[data-task-more]'), t, {
|
|
275
|
+
// The board may have been drawn again since the menu opened: find the card again.
|
|
276
|
+
edit: () => rename(el.querySelector(`.task[data-task="${CSS.escape(t.id)}"] .task-title`), t),
|
|
277
|
+
recur: () => change(t, { recurring: !t.recurring }),
|
|
278
|
+
pickup: () => change(t, { noPickup: !t.noPickup }),
|
|
279
|
+
archive: () => change(t, { archived: true }),
|
|
280
|
+
remove: () => change(t, {}, '/delete')
|
|
281
|
+
})
|
|
282
|
+
}
|
|
283
|
+
if (hit('[data-task-recur]')) return change(t, { recurring: !t.recurring })
|
|
284
|
+
if (hit('[data-task-notes]')) return notes(t)
|
|
285
|
+
if (hit('[data-task-nopickup]')) return change(t, { noPickup: false })
|
|
286
|
+
if (hit('[data-task-unarchive]')) return change(t, { archived: false })
|
|
287
|
+
if (hit('[data-task-delete]')) return change(t, {}, '/delete')
|
|
288
|
+
if (hit('[data-file-remove]')) return change(t, { files: (t.files || []).filter((f) => f !== hit('[data-file-remove]').dataset.fileRemove) })
|
|
289
|
+
if (hit('.task-title')) return rename(hit('.task-title'), t)
|
|
290
|
+
}
|
|
291
|
+
el.onsubmit = async (e) => {
|
|
292
|
+
e.preventDefault()
|
|
293
|
+
const t = taskOf(e)
|
|
294
|
+
if (e.target.id === 'task-add-form') {
|
|
295
|
+
const input = $('#task-add', el)
|
|
296
|
+
const title = input.value.trim()
|
|
297
|
+
const code = $('#pj-add-in', el)?.value || st.into
|
|
298
|
+
if (!title || !code || !b.open.some((c) => c.id === code)) return
|
|
299
|
+
const s = state.sessions.get(code)
|
|
300
|
+
input.value = ''
|
|
301
|
+
try { await save(code, '', { title, ...boardAssignment($('#task-add-assign', el)?.value || '', b.people, s?.status?.tasks || []) }); $('#task-add', el)?.focus() } catch (err) { toast(err.message); const again = $('#task-add', el); if (again) again.value = title }
|
|
302
|
+
} else if (t && e.target.matches('.task-file-form')) {
|
|
303
|
+
const f = e.target.querySelector('.task-file').value.trim()
|
|
304
|
+
if (f && !(t.files || []).includes(f)) change(t, { files: [...(t.files || []), f] })
|
|
305
|
+
} else if (t && e.target.matches('.task-cron-form')) change(t, { cron: e.target.querySelector('.task-cron').value.trim() })
|
|
306
|
+
}
|
|
307
|
+
el.onchange = (e) => {
|
|
308
|
+
if (e.target.id === 'pj-add-in') { st.into = e.target.value; return }
|
|
309
|
+
if (!e.target.matches('select.task-assign')) return
|
|
310
|
+
const t = taskOf(e)
|
|
311
|
+
if (t) change(t, boardAssignment(e.target.value, b.people, state.sessions.get(t.code)?.status?.tasks || []))
|
|
312
|
+
}
|
|
313
|
+
el.oninput = (e) => {
|
|
314
|
+
if (e.target.id === 'board-search') { st.query = e.target.value; return apply() }
|
|
315
|
+
if (e.target.id !== 'archive-filter') return
|
|
316
|
+
const q = e.target.value.trim().toLowerCase()
|
|
317
|
+
let any = false
|
|
318
|
+
for (const group of el.querySelectorAll('.archive-group')) {
|
|
319
|
+
let n = 0
|
|
320
|
+
for (const row of group.querySelectorAll('.task-archived')) { row.hidden = !!q && !row.dataset.title.includes(q); if (!row.hidden) n++ }
|
|
321
|
+
group.hidden = !n
|
|
322
|
+
group.querySelector('[data-group-count]').textContent = n
|
|
323
|
+
any = any || n > 0
|
|
324
|
+
}
|
|
325
|
+
const none = $('.board-archive-none', el)
|
|
326
|
+
if (none) none.hidden = any
|
|
327
|
+
}
|
|
328
|
+
// Drag a card to another column; dropped on a card, it goes before it.
|
|
329
|
+
el.ondragstart = (e) => { const card = e.target.closest?.('.task'); if (card) { e.dataTransfer.setData('text/plain', card.dataset.task); card.classList.add('dragging') } }
|
|
330
|
+
el.ondragover = (e) => { const col = e.target.closest('.board-col'); if (!col) return; e.preventDefault(); for (const c of el.querySelectorAll('.board-col.over')) if (c !== col) c.classList.remove('over'); col.classList.add('over') }
|
|
331
|
+
el.ondragend = () => { for (const n of el.querySelectorAll('.over, .dragging')) n.classList.remove('over', 'dragging') }
|
|
332
|
+
el.ondrop = (e) => {
|
|
333
|
+
const col = e.target.closest('.board-col')
|
|
334
|
+
const t = b.tasks.find((x) => x.id === e.dataTransfer.getData('text/plain'))
|
|
335
|
+
if (!col || !t) return
|
|
336
|
+
e.preventDefault()
|
|
337
|
+
for (const n of el.querySelectorAll('.over, .dragging')) n.classList.remove('over', 'dragging')
|
|
338
|
+
const before = b.tasks.find((x) => x.id === e.target.closest('.task')?.dataset.task)
|
|
339
|
+
change(t, { column: col.dataset.column, ...(before && before.code === t.code && before.id !== t.id ? { before: splitBoardTaskId(before.id)[1] } : {}) })
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if (live) { clearTimeout(live.later); live.ro.disconnect() }
|
|
343
|
+
const ro = new ResizeObserver(() => layout())
|
|
344
|
+
live = {
|
|
345
|
+
el,
|
|
346
|
+
ro,
|
|
347
|
+
later: null,
|
|
348
|
+
leave: () => {
|
|
349
|
+
st.scroll = [...el.querySelectorAll('.board-list')].map((l) => l.scrollTop)
|
|
350
|
+
st.draft = $('#task-add', el)?.value || ''
|
|
351
|
+
st.refocus = document.activeElement?.id === 'task-add' && el.contains(document.activeElement)
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
ro.observe(el)
|
|
355
|
+
draw()
|
|
356
|
+
if (st.refocus) $('#task-add', el)?.focus()
|
|
357
|
+
st.refocus = false
|
|
358
|
+
st.draft = ''
|
|
359
|
+
}
|