mirror of
https://github.com/narrrl/narl-workspace.git
synced 2026-11-19 10:45:03 +01:00
boards: a card can come back once it is done
`:repeat weekly` gives a card a rule: daily, weekly, monthly, yearly, or every +Nd, +Nw, +Nm, +Ny. Finishing it, by a move into the last list or by the API's done, leaves a copy at the bottom of the inbox with the same title, notes, document and rule, due on the next date. The finished card gives its rule up in the same transaction, so reopening it and finishing it again makes no second copy. The next date is counted on the calendar in WORKSPACE_TIMEZONE, so noon stays noon across a change of the clocks, and months are counted from the old due date rather than step by step, so a card due on the 31st comes back on the 31st wherever a month has one. A card finished late skips the dates already past; one without a date counts from the moment it was finished. A move and an edit answer with `again`, the copy, so the status line can say when the card comes back. The board and the agenda show the rule as `↻ weekly`, the rail has a button for it, and `:` in the agenda now opens the line with the agenda kept up, so `:repeat` knows which card. The rule travels in `.workspace.json` without a format bump: an older build ignores the field and imports the card as one that does not repeat. An import drops a rule it cannot read.
This commit is contained in:
1 parent
824f2bb945
commit
6673298cb2
16 files changed
+657
-51
No files matched your search
@@ -327,6 +327,11 @@
|
||||
cmdline = ':due '
|
||||
}
|
||||
return true
|
||||
case ':':
|
||||
// And so does `:repeat`, and any other command that asks for it.
|
||||
cmdGlobal = false
|
||||
cmdline = ':'
|
||||
return true
|
||||
case 'H':
|
||||
case 'L':
|
||||
if (card) void workspace.guard(() => workspace.sendAgendaCard(card, event.key === 'H' ? -1 : 1))
|
||||
|
||||
@@ -68,6 +68,9 @@
|
||||
>
|
||||
<span class="text">{card.title}</span>
|
||||
<span class="where">{card.space_slug}/{card.list_name}</span>
|
||||
{#if card.repeat !== null}
|
||||
<span class="due" title="comes back in the inbox once done">↻ {card.repeat}</span>
|
||||
{/if}
|
||||
{#if card.due_at !== null}
|
||||
<span class="due">{formatWeekday(card.due_at)} {formatDay(card.due_at).slice(5)}</span>
|
||||
{/if}
|
||||
|
||||
@@ -85,11 +85,14 @@
|
||||
<span class="tick" class:ticked={card.done_at !== null}></span>
|
||||
<span class="text">{card.title}</span>
|
||||
</span>
|
||||
{#if card.due_at !== null || card.node_id !== null}
|
||||
{#if card.due_at !== null || card.node_id !== null || card.repeat !== null}
|
||||
<span class="meta">
|
||||
{#if card.due_at !== null}
|
||||
<span class={urgency(card)}>due {formatDay(card.due_at)}</span>
|
||||
{/if}
|
||||
{#if card.repeat !== null}
|
||||
<span title="comes back in the inbox once done">↻ {card.repeat}</span>
|
||||
{/if}
|
||||
{#if card.node_id !== null}
|
||||
<span class="doc">→ {card.node_name ?? `#${card.node_id}`}</span>
|
||||
{/if}
|
||||
|
||||
@@ -79,6 +79,7 @@
|
||||
['Enter', 'to the card, on its own board — or to the entry'],
|
||||
['Space', 'done, where it stands'],
|
||||
['D', 'due date: fri, tm, +3d … — :due on the line'],
|
||||
[':', 'the line, with the agenda kept up — :repeat weekly acts on the card'],
|
||||
['H / L', 'to the list left / right on its board'],
|
||||
['T', "today's diary entry"],
|
||||
['t · q · Esc', 'close the agenda'],
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
down: ['M12 5v14', 'M6 13l6 6 6-6'],
|
||||
drop: ['M12 4v11', 'M7 10l5 5 5-5', 'M5 20h14'],
|
||||
rename: ['M4 20h4L19 9l-4-4L4 16z', 'M13 7l4 4'],
|
||||
repeat: ['M17 3l3 3-3 3', 'M4 11V9a3 3 0 0 1 3-3h13', 'M7 21l-3-3 3-3', 'M20 13v2a3 3 0 0 1-3 3H4'],
|
||||
trash: ['M4 7h16', 'M9 7V4h6v3', 'M6 7l1 13h10l1-13'],
|
||||
more: ['M5 12h.01', 'M12 12h.01', 'M19 12h.01'],
|
||||
} satisfies Record<string, string[]>
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
{ icon: 'check', label: 'Done, or back to the inbox', keys: ['Space'], run: () => workspace.guard(() => workspace.toggleDone()), dim: !card },
|
||||
{ icon: 'right', label: 'Send the card right', keys: ['L'], run: () => workspace.guard(() => workspace.sendCard(1)), dim: !card },
|
||||
{ icon: 'calendar', label: 'Due date', keys: ['D'], run: () => hooks.openCommandLine(':due '), dim: !card },
|
||||
{ icon: 'repeat', label: 'Repeat once done', keys: [':repeat'], run: () => hooks.openCommandLine(':repeat '), dim: !card },
|
||||
{ icon: 'doc', label: "The card's notes", keys: ['Enter'], run: () => workspace.guard(() => workspace.openCard()), dim: !card },
|
||||
],
|
||||
[
|
||||
|
||||
+10
-2
@@ -166,11 +166,18 @@ export interface Card {
|
||||
node_name: string | null
|
||||
due_at: number | null
|
||||
done_at: number | null
|
||||
/** `daily`, `weekly`, `monthly`, `yearly`, `+3d`, `+2w`, `+6m` — or none. */
|
||||
repeat: string | null
|
||||
position: number
|
||||
created_at: number
|
||||
updated_at: number
|
||||
}
|
||||
|
||||
/** A card after a move or an edit, and the copy a repeating card it finished left in the inbox. */
|
||||
export interface Moved extends Card {
|
||||
again: Card | null
|
||||
}
|
||||
|
||||
/** An open card as the agenda lists it, with the board it lives on. */
|
||||
export interface AgendaCard extends Card {
|
||||
space_id: number
|
||||
@@ -551,14 +558,15 @@ export const api = {
|
||||
body?: string
|
||||
node_id?: number | null
|
||||
due_at?: number | null
|
||||
repeat?: string | null
|
||||
done?: boolean
|
||||
},
|
||||
) => request<Card>(`/cards/${id}`, { method: 'PUT', body: body(patch) }),
|
||||
) => request<Moved>(`/cards/${id}`, { method: 'PUT', body: body(patch) }),
|
||||
|
||||
deleteCard: (id: number) => request<{ ok: true }>(`/cards/${id}`, { method: 'DELETE' }),
|
||||
|
||||
moveCard: (id: number, list_id: number, position?: number) =>
|
||||
request<Card>(`/cards/${id}/move`, { method: 'POST', body: body({ list_id, position }) }),
|
||||
request<Moved>(`/cards/${id}/move`, { method: 'POST', body: body({ list_id, position }) }),
|
||||
|
||||
listMedia: () => pages((limit, offset) => request<MediaFile[]>(`/media?limit=${limit}&offset=${offset}`)),
|
||||
|
||||
|
||||
+19
-1
@@ -466,7 +466,7 @@ export const commands: CommandSpec[] = [
|
||||
const agenda = workspace.overlay === 'agenda'
|
||||
if (workspace.view !== 'board' && !agenda) return workspace.say('no board open — :board', 'error')
|
||||
const set = (due_at: number | null) =>
|
||||
agenda ? workspace.dueAgendaCard(due_at) : workspace.patchCard({ due_at })
|
||||
agenda ? workspace.patchAgendaCard({ due_at }) : workspace.patchCard({ due_at })
|
||||
const target = arg.trim()
|
||||
if (target === '-' || target === '') return workspace.guard(() => set(null))
|
||||
const at = parseDue(target)
|
||||
@@ -475,6 +475,24 @@ export const commands: CommandSpec[] = [
|
||||
workspace.say(`due ${formatDay(at)}`)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'repeat',
|
||||
args: '<rule|->',
|
||||
group: 'board',
|
||||
help: 'once the card is done, a copy comes back in the inbox: daily, weekly, monthly, yearly, +3d, +2w, +6m — - stops it',
|
||||
complete: () => ['daily', 'weekly', 'monthly', 'yearly', '+2w', '-'],
|
||||
run: async (arg) => {
|
||||
const agenda = workspace.overlay === 'agenda'
|
||||
if (workspace.view !== 'board' && !agenda) return workspace.say('no board open — :board', 'error')
|
||||
const rule = arg.trim()
|
||||
const repeat = rule === '-' || rule === '' ? null : rule
|
||||
await workspace.guard(async () => {
|
||||
const card = await (agenda ? workspace.patchAgendaCard({ repeat }) : workspace.patchCard({ repeat }))
|
||||
// The server's spelling of the rule: `+14d` is kept as `+2w`.
|
||||
if (card) workspace.say(card.repeat === null ? 'repeats no more' : `repeats ${card.repeat} once done`)
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'done',
|
||||
group: 'board',
|
||||
|
||||
+20
-11
@@ -12,6 +12,7 @@ import {
|
||||
type DiaryEntry,
|
||||
type WorkspaceNode,
|
||||
type MediaFile,
|
||||
type Moved,
|
||||
type NodeSummary,
|
||||
type Revision,
|
||||
type RevisionSummary,
|
||||
@@ -19,7 +20,7 @@ import {
|
||||
type TrashItem,
|
||||
type VaultStatus,
|
||||
} from './api'
|
||||
import { formatBytes, formatDay, formatStamp, isTouchDevice, parseDay, sealedNote, type Heading } from './util'
|
||||
import { formatBytes, formatDay, formatStamp, formatWeekday, isTouchDevice, parseDay, sealedNote, type Heading } from './util'
|
||||
|
||||
export type Pane = 'list' | 'document'
|
||||
/** The tree of documents, or the board of the space being browsed. */
|
||||
@@ -41,6 +42,12 @@ type Spot = {
|
||||
|
||||
export type Draft = { name: string; body: string; created_at: number }
|
||||
|
||||
/** `done: x`, and when a repeating card comes back. */
|
||||
function doneSaid(moved: Moved): string {
|
||||
const again = moved.again?.due_at
|
||||
return again == null ? `done: ${moved.title}` : `done: ${moved.title} — again ${formatWeekday(again)} ${formatDay(again)}`
|
||||
}
|
||||
|
||||
let tiles = 0
|
||||
|
||||
/**
|
||||
@@ -1369,22 +1376,23 @@ class Workspace {
|
||||
async finishCard(card: AgendaCard) {
|
||||
const done = (await api.board(card.space_id)).lists.at(-1)
|
||||
if (!done) return
|
||||
await api.moveCard(card.id, done.id, done.cards.length)
|
||||
const moved = await api.moveCard(card.id, done.id, done.cards.length)
|
||||
await this.loadAgenda()
|
||||
if (this.view === 'board' && this.spaceId === card.space_id) await this.reloadBoard()
|
||||
this.say(`done: ${card.title}`)
|
||||
this.say(doneSaid(moved))
|
||||
}
|
||||
|
||||
/** `:due` with the agenda up: the highlighted card's date, on its own board. */
|
||||
async dueAgendaCard(due_at: number | null) {
|
||||
/** `:due` or `:repeat` with the agenda up: the highlighted card, on its own board. */
|
||||
async patchAgendaCard(patch: Parameters<typeof api.updateCard>[1]) {
|
||||
const card = this.agendaCards[this.agendaCursor]
|
||||
if (!card) return this.say('no card highlighted', 'error')
|
||||
await api.updateCard(card.id, { due_at })
|
||||
const updated = await api.updateCard(card.id, patch)
|
||||
await this.loadAgenda()
|
||||
// It may have changed group; the cursor goes with it.
|
||||
const at = this.agendaCards.findIndex((c) => c.id === card.id)
|
||||
if (at >= 0) this.agendaCursor = at
|
||||
if (this.view === 'board' && this.spaceId === card.space_id) await this.reloadBoard()
|
||||
return updated
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1396,12 +1404,12 @@ class Workspace {
|
||||
const from = lists.findIndex((list) => list.id === card.list_id)
|
||||
const target = lists[from + delta]
|
||||
if (from < 0 || !target) return this.say(`${card.title} is already in the ${delta < 0 ? 'first' : 'last'} list`, 'error')
|
||||
await api.moveCard(card.id, target.id, target.cards.length)
|
||||
const moved = await api.moveCard(card.id, target.id, target.cards.length)
|
||||
await this.loadAgenda()
|
||||
const at = this.agendaCards.findIndex((c) => c.id === card.id)
|
||||
if (at >= 0) this.agendaCursor = at
|
||||
if (this.view === 'board' && this.spaceId === card.space_id) await this.reloadBoard()
|
||||
this.say(from + delta === lists.length - 1 ? `done: ${card.title}` : `"${card.title}" → ${target.name}`)
|
||||
this.say(from + delta === lists.length - 1 ? doneSaid(moved) : `"${card.title}" → ${target.name}`)
|
||||
}
|
||||
|
||||
async loadOverview() {
|
||||
@@ -1563,9 +1571,9 @@ class Workspace {
|
||||
const lists = this.board?.lists ?? []
|
||||
const target = lists[index]
|
||||
if (!card || !target || index === this.listCursor) return
|
||||
await api.moveCard(card.id, target.id, target.cards.length)
|
||||
const moved = await api.moveCard(card.id, target.id, target.cards.length)
|
||||
await this.reloadBoard(this.spaceId, card.id)
|
||||
this.say(index === lists.length - 1 ? `done: ${card.title}` : `"${card.title}" → ${target.name}`)
|
||||
this.say(index === lists.length - 1 ? doneSaid(moved) : `"${card.title}" → ${target.name}`)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1595,8 +1603,9 @@ class Workspace {
|
||||
async patchCard(patch: Parameters<typeof api.updateCard>[1]) {
|
||||
const card = this.card
|
||||
if (!card) return this.say('no card selected', 'error')
|
||||
await api.updateCard(card.id, patch)
|
||||
const updated = await api.updateCard(card.id, patch)
|
||||
await this.reloadBoard(this.spaceId, card.id)
|
||||
return updated
|
||||
}
|
||||
|
||||
/** Space: into the done list, or back out of it to the inbox. */
|
||||
|
||||
Reference in new issue
Block a user