Add quantitative tasks with checklist controls to the planner
This commit is contained in:
parent
29fcb50fcd
commit
c08452d5a4
22 changed files with 434 additions and 33 deletions
|
|
@ -2,11 +2,13 @@
|
|||
import { Icon } from "../../../components/Icon.jsx";
|
||||
import { useInlineEdit } from "../../../hooks/useInlineEdit.js";
|
||||
import { MissingPrerequisitesTooltip, TaskPlannerItemDetails } from "./TaskPlannerItemPanels.jsx";
|
||||
import { TaskPlannerQuantity } from "./TaskPlannerQuantity.jsx";
|
||||
import {
|
||||
TASK_TYPES,
|
||||
getTaskCategoryDataset,
|
||||
getTaskTypeLabel,
|
||||
isTaskResetSoon
|
||||
isTaskResetSoon,
|
||||
updateTaskQuantity
|
||||
} from "./taskPlannerUtils.js";
|
||||
|
||||
export function TaskPlannerItem({
|
||||
|
|
@ -51,14 +53,9 @@ export function TaskPlannerItem({
|
|||
onCommit: (title) => onUpdateTask(task.id, (current) => ({ ...current, title }))
|
||||
});
|
||||
|
||||
function updateChecked(event) {
|
||||
const checked = event.target.checked;
|
||||
if (checked && missingPrerequisites.length > 0) onPrerequisiteNotice(task.id);
|
||||
onUpdateTask(task.id, (current) => ({
|
||||
...current,
|
||||
checked,
|
||||
checkedAt: checked ? Date.now() : 0
|
||||
}));
|
||||
function updateQuantity(value) {
|
||||
if (Number(value) >= (task.qtyTarget || 1) && !task.checked && missingPrerequisites.length > 0) onPrerequisiteNotice(task.id);
|
||||
onUpdateTask(task.id, (current) => updateTaskQuantity(current, value));
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
@ -75,14 +72,18 @@ export function TaskPlannerItem({
|
|||
>
|
||||
<Icon name="drag" />
|
||||
</button>
|
||||
<input
|
||||
className="nds-checkbox"
|
||||
data-size="sm"
|
||||
type="checkbox"
|
||||
checked={task.checked}
|
||||
onChange={updateChecked}
|
||||
aria-label={`${task.checked ? textContent.uncheckTitle || "Marquer non effectué" : textContent.checkTitle || "Marquer effectué"} ${task.title}`}
|
||||
/>
|
||||
{task.qtyTarget > 1 ? (
|
||||
<TaskPlannerQuantity task={task} textContent={textContent} onChange={updateQuantity} />
|
||||
) : (
|
||||
<input
|
||||
className="nds-checkbox"
|
||||
data-size="sm"
|
||||
type="checkbox"
|
||||
checked={task.checked}
|
||||
onChange={(event) => updateQuantity(event.target.checked ? 1 : 0)}
|
||||
aria-label={`${task.checked ? textContent.uncheckTitle || "Marquer non effectué" : textContent.checkTitle || "Marquer effectué"} ${task.title}`}
|
||||
/>
|
||||
)}
|
||||
<input
|
||||
{...titleEdit.getInputProps({
|
||||
className: "tool-split-entry-label task-planner-title-input nds-inline-input",
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { Icon } from "../../../components/Icon.jsx";
|
|||
import { InlineNotice } from "../../../components/AppOverlays.jsx";
|
||||
import { Tooltip } from "../../../components/Tooltip.jsx";
|
||||
import { useInlineEdit } from "../../../hooks/useInlineEdit.js";
|
||||
import { TaskPlannerQuantityTarget } from "./TaskPlannerQuantity.jsx";
|
||||
import {
|
||||
WEEK_DAYS,
|
||||
getEffectiveTaskCategory,
|
||||
|
|
@ -65,7 +66,10 @@ export function TaskPlannerItemDetails({
|
|||
)}
|
||||
{settingsOpen && (
|
||||
<div className="task-planner-task-settings">
|
||||
<TaskResetSettings task={task} data={data} textContent={textContent} onUpdateTask={onUpdateTask} />
|
||||
<div className="task-planner-task-fields">
|
||||
<TaskPlannerQuantityTarget task={task} textContent={textContent} onUpdateTask={onUpdateTask} />
|
||||
<TaskResetSettings task={task} data={data} textContent={textContent} onUpdateTask={onUpdateTask} />
|
||||
</div>
|
||||
<LinksEditor
|
||||
label={textContent.linksLabel || "Parent"}
|
||||
relations={relations}
|
||||
|
|
|
|||
|
|
@ -9,14 +9,15 @@ import { TaskPlannerTopbar } from "./TaskPlannerTopbar.jsx";
|
|||
import { TextExchangeActions } from "./TextExchangeActions.jsx";
|
||||
import {
|
||||
applyDueResets,
|
||||
getTaskParentMap
|
||||
getTaskParentMap,
|
||||
updateTaskQuantityTarget
|
||||
} from "./taskPlannerUtils.js";
|
||||
import { useTaskPlannerReorder } from "./useTaskPlannerReorder.js";
|
||||
|
||||
export function TaskPlannerModule({ toolboxId, moduleId, context, editing, configurationTarget }) {
|
||||
const data = context.normalizeTaskPlannerData(context.getModuleData(toolboxId, moduleId, { tasks: [] }));
|
||||
const textContent = context.moduleText?.taskPlanner || {};
|
||||
const taskDraft = useDraftForm({ title: "", type: "daily", category: "" });
|
||||
const taskDraft = useDraftForm({ title: "", type: "daily", category: "", qtyTarget: "1" });
|
||||
const categoryOptions = useMemo(() => [
|
||||
...data.categoryOrder,
|
||||
...data.tasks.map((task) => task.category).filter(Boolean).filter((category) => !data.categoryOrder.includes(category))
|
||||
|
|
@ -63,7 +64,7 @@ export function TaskPlannerModule({ toolboxId, moduleId, context, editing, confi
|
|||
if (category) task.category = category;
|
||||
save({
|
||||
...data,
|
||||
tasks: [...data.tasks, task],
|
||||
tasks: [...data.tasks, updateTaskQuantityTarget(task, draft.qtyTarget)],
|
||||
categoryOrder: category && !data.categoryOrder.includes(category) ? [...data.categoryOrder, category] : data.categoryOrder
|
||||
});
|
||||
reset();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
// Rôle : affiche la progression quantitative et l'édition de la cible d'une tâche.
|
||||
import { useInlineEdit } from "../../../hooks/useInlineEdit.js";
|
||||
import { updateTaskQuantityTarget } from "./taskPlannerUtils.js";
|
||||
import { parsePositiveInt } from "../storage/modules/shared.js";
|
||||
|
||||
export function TaskPlannerQuantity({ task, textContent, onChange }) {
|
||||
return (
|
||||
<div className="task-planner-quantity nds-quantity-stepper" data-size="md">
|
||||
<button type="button" onClick={() => onChange(task.qtyCurrent - 1)} aria-label={`${textContent.decrementLabel} ${task.title}`}>-</button>
|
||||
<label className="nds-quantity-stepper-value">
|
||||
<input
|
||||
className="nds-quantity-stepper-input"
|
||||
type="number"
|
||||
max={task.qtyTarget}
|
||||
step="1"
|
||||
value={task.qtyCurrent}
|
||||
style={{ "--qty-current-digits": String(task.qtyCurrent).length }}
|
||||
onChange={(event) => onChange(event.target.value)}
|
||||
aria-label={`${textContent.currentQuantityLabel} ${task.title}`}
|
||||
/>
|
||||
<span>/ {task.qtyTarget}</span>
|
||||
</label>
|
||||
<button type="button" onClick={() => onChange(task.qtyCurrent + 1)} aria-label={`${textContent.incrementLabel} ${task.title}`}>+</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function TaskPlannerQuantityTarget({ task, textContent, onUpdateTask }) {
|
||||
const targetEdit = useInlineEdit({
|
||||
value: task.qtyTarget || 1,
|
||||
transform: (value) => parsePositiveInt(value, 1),
|
||||
onCommit: (value) => onUpdateTask(task.id, (current) => updateTaskQuantityTarget(current, value))
|
||||
});
|
||||
return (
|
||||
<label className="task-planner-reset-override">
|
||||
<span>{textContent.quantityLabel}</span>
|
||||
<input {...targetEdit.getInputProps({ className: "nds-input", "data-size": "sm", type: "number", min: 1, step: 1, "aria-label": `${textContent.quantityLabel} ${task.title}` })} />
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
|
@ -39,6 +39,7 @@ export function TaskPlannerTopbar({
|
|||
<select {...taskDraft.getFieldProps("type", { className: "nds-select", "data-size": "sm", "aria-label": textContent.typeLabel || "Type" })}>
|
||||
{TASK_TYPES.map((taskType) => <option key={taskType} value={taskType}>{getTaskTypeLabel(taskType, textContent)}</option>)}
|
||||
</select>
|
||||
<input {...taskDraft.getFieldProps("qtyTarget", { className: "task-planner-quantity-target nds-input", "data-size": "sm", type: "number", min: 1, step: 1, "aria-label": textContent.quantityLabel, title: textContent.quantityLabel })} />
|
||||
<button className="nds-button" data-size="sm" data-variant="primary">{textContent.addButton || "Ajouter"}</button>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,36 @@
|
|||
// Rôle : regroupe les constantes et helpers purs de l'outil task planner.
|
||||
import { getLatestDailyReset, getLatestWeeklyReset, parseResetTime } from "./resetUtils.js";
|
||||
import { clampQty } from "../storage/modules/checklist.js";
|
||||
import { parsePositiveInt } from "../storage/modules/shared.js";
|
||||
|
||||
export const TASK_TYPES = ["daily", "weekly", "unique"];
|
||||
const DAILY_RESET_SOON_MS = 6 * 60 * 60 * 1000;
|
||||
const WEEKLY_RESET_SOON_MS = 48 * 60 * 60 * 1000;
|
||||
|
||||
export function updateTaskQuantity(task, value, now = Date.now()) {
|
||||
const qtyCurrent = clampQty(value, task.qtyTarget || 1);
|
||||
const checked = qtyCurrent >= (task.qtyTarget || 1);
|
||||
const next = { ...task, checked, checkedAt: checked ? now : 0 };
|
||||
if (task.qtyTarget > 1) {
|
||||
next.qtyCurrent = qtyCurrent;
|
||||
next.progressAt = qtyCurrent !== 0 ? now : 0;
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
export function updateTaskQuantityTarget(task, value, now = Date.now()) {
|
||||
const qtyTarget = parsePositiveInt(value, 1);
|
||||
if (qtyTarget === (task.qtyTarget || 1)) return task;
|
||||
const qtyCurrent = task.qtyTarget > 1 ? task.qtyCurrent : task.checked ? 1 : 0;
|
||||
const next = updateTaskQuantity({ ...task, qtyTarget }, qtyCurrent, now);
|
||||
if (qtyTarget === 1) {
|
||||
delete next.qtyTarget;
|
||||
delete next.qtyCurrent;
|
||||
delete next.progressAt;
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
export const WEEK_DAYS = [
|
||||
{ value: 1, label: "Lundi" },
|
||||
{ value: 2, label: "Mardi" },
|
||||
|
|
@ -63,9 +89,10 @@ export function applyDueResets(data, now = Date.now()) {
|
|||
? getLatestDailyReset(now, task.dailyResetTime || data.resetTime)
|
||||
: getLatestWeeklyReset(now, data.resetTime, task.weeklyResetDay ?? data.weeklyResetDay);
|
||||
latestResetAt = Math.max(latestResetAt, resetAt);
|
||||
if (!task.checked || resetAt <= (task.checkedAt || data.lastResetAt)) return task;
|
||||
const hasProgress = task.checked || (task.qtyTarget > 1 && task.qtyCurrent !== 0);
|
||||
if (!hasProgress || resetAt <= (task.progressAt || task.checkedAt || data.lastResetAt)) return task;
|
||||
changed = true;
|
||||
return { ...task, checked: false, checkedAt: 0 };
|
||||
return updateTaskQuantity(task, 0, now);
|
||||
});
|
||||
|
||||
if (latestResetAt > data.lastResetAt) changed = true;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ export function exportTaskPlannerText(data) {
|
|||
function writeTask(task, depth = 0) {
|
||||
const prefix = " ".repeat(depth);
|
||||
lines.push(`${prefix}- ${task.type || "unique"} ${task.title}`);
|
||||
if (task.qtyTarget > 1) lines.push(`${prefix} @qtyTarget: ${task.qtyTarget}`);
|
||||
if (task.description) lines.push(`${prefix} @description: ${task.description.replace(/\n/g, "\\n")}`);
|
||||
if (task.dailyResetTime) lines.push(`${prefix} @dailyResetTime: ${task.dailyResetTime}`);
|
||||
if (task.weeklyResetDay !== undefined) lines.push(`${prefix} @weeklyResetDay: ${task.weeklyResetDay}`);
|
||||
|
|
@ -61,6 +62,11 @@ export function importTaskPlannerText(text, context) {
|
|||
if (meta) {
|
||||
const task = stack[Math.max(0, depth - 1)];
|
||||
if (!task) throw lineError(index, `meta de tâche sans tâche: ${cleanLine}`);
|
||||
if (meta.key === "qtyTarget") {
|
||||
const target = Number(meta.value);
|
||||
if (!Number.isSafeInteger(target) || target < 1) throw lineError(index, "quantité cible invalide.");
|
||||
task.qtyTarget = target;
|
||||
}
|
||||
if (meta.key === "description") task.description = meta.value.replace(/\\n/g, "\n");
|
||||
if (meta.key === "dailyResetTime") task.dailyResetTime = meta.value;
|
||||
if (meta.key === "weeklyResetDay") task.weeklyResetDay = parseInteger(meta.value, 1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue