SPB Git

Repository Public

TakeoffLedger.tsx 9.8 KB 121 lines tsx

1/**2 * =============================================================================3 *                  SP BOUCHER | ACADEMIC RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * PROJECT METADATA8 * -----------------------------------------------------------------------------9 * Project          : UQO Éval10 * File             : src/components/metre/TakeoffLedger.tsx11 * Module           : components12 * Repository       : https://git.spboucher.ai/uqo-eval13 * Project Website  : https://www.uqo-eval.app14 * Created          : 2026-10-2815 * Last Modified    : 2026-10-2816 *17 * =============================================================================18 * SOFTWARE MAINTAINER & AFFILIATION19 * =============================================================================20 *21 * Maintainer       : Simon-Pierre Boucher22 * Position         : Professor of Finance23 * Institution      : Université du Québec en Outaouais (UQO)24 * Department       : Département des sciences administratives25 * Website          : https://spboucher.ai26 * Git              : https://git.spboucher.ai27 *28 * Research Contact : research@spboucher.ai29 * Direct Contact   : simon@spboucher.ai30 * Security/Admin   : admin@spboucher.ai31 *32 * The affiliation is descriptive. It is not an institutional endorsement,33 * a license grant or a determination of ownership.34 *35 * =============================================================================36 * COPYRIGHT, AUTHORSHIP & DATA37 * =============================================================================38 *39 * Copyright (c) the author(s) of this work.40 * Ownership is not asserted by this notice; see the repository records.41 *42 * This header identifies the maintainer of the software. Scientific43 * authorship of any associated paper is stated in the paper itself and44 * is not changed by this notice. Datasets and third-party materials45 * remain the property of their respective owners and licensors.46 *47 * This file is governed by the applicable project license, copyright48 * notices, institutional agreements and relevant law.49 *50 * =============================================================================51 * LICENSE & MAINTENANCE52 * =============================================================================53 *54 * License          : None specified (no license file in this repository)55 * Classification   : Public56 *57 * =============================================================================58 * END OF SP BOUCHER SOURCE HEADER59 * =============================================================================60 */6162// UQO Éval — Métré : registre de métré — mesures (formule, entrées, valeur, unité, calibration, périmée, vérification), saisie manuelle, recalcul.63"use client";64import { useState } from "react";65import type { WorkspaceData } from "./ProjectWorkspace";66import { api, Block, Btn, dt, Err, Field, Input, Select, num } from "./ui";67import { unitLabel } from "@/lib/metre/units";6869export default function TakeoffLedger({ d, fr, lang, canWrite, reload }: { d: WorkspaceData; fr: boolean; lang: string; canWrite: boolean; reload: () => Promise<void> }) {70  const [err, setErr] = useState<string | null>(null);71  const [m, setM] = useState({ name: "", value: "", unit: d.project.unitSystem === "imperial" ? "ft2" : "m2", confidence: "assumed", note: "" });72  const [open, setOpen] = useState<string | null>(null);73  const stale = d.measurements.filter((x) => x.stale).length;74  const call = async (fn: () => Promise<unknown>) => { setErr(null); try { await fn(); await reload(); } catch (e) { setErr((e as Error).message); } };75  return (76    <div className="space-y-12">77      <Block num="01" title={fr ? "Registre de mesures" : "Measurement ledger"} aside={canWrite && stale > 0 && <Btn small tone="accent" onClick={() => call(() => api(`/projects/${d.project.id}/measurements`, { method: "POST", json: { action: "recompute" } }))}>{fr ? `Recalculer ${stale} mesure(s) périmée(s)` : `Recompute ${stale} stale measurement(s)`}</Btn>}>78        <p className="text-[13.5px] text-ink-2">{fr ? "Chaque mesure conserve sa formule, ses entrées, l'objet et la page source, la révision de calibration, l'horodatage et le vérificateur. Une mesure périmée (recalibration ou géométrie modifiée) doit être recalculée avant d'être vérifiée ou figée dans une révision." : "Each measurement keeps its formula, inputs, source object and page, calibration revision, timestamp and verifier. A stale measurement (recalibration or edited geometry) must be recomputed before being verified or frozen in a revision."}</p>79        {!d.measurements.length ? <p className="text-[13.5px] text-ink-2">{fr ? "Aucune mesure : dessinez des objets dans le Plan Studio et cliquez « Mesurer », ou saisissez une quantité manuelle." : "No measurement yet: draw objects in Plan Studio and click “Measure”, or enter a manual quantity."}</p> : (80          <div className="src-wrap"><table className="src-table"><thead><tr><th>{fr ? "Mesure" : "Measurement"}</th><th>{fr ? "Formule" : "Formula"}</th><th className="text-right">{fr ? "Valeur" : "Value"}</th><th>{fr ? "Unité" : "Unit"}</th><th>{fr ? "Confiance" : "Confidence"}</th><th>{fr ? "Cal." : "Cal."}</th><th>{fr ? "État" : "Status"}</th><th>{fr ? "Vérification" : "Verification"}</th><th></th></tr></thead><tbody>81            {d.measurements.map((x) => (<FragmentRow key={x.id} x={x} fr={fr} lang={lang} canWrite={canWrite} open={open === x.id} toggle={() => setOpen(open === x.id ? null : x.id)} onVerify={(v) => call(() => api(`/measurements/${x.id}`, { method: "PATCH", json: { verified: v } }))} onDelete={() => call(() => api(`/measurements/${x.id}`, { method: "DELETE" }))} />))}82          </tbody></table></div>83        )}84        <Err msg={err} />85      </Block>86      {canWrite && (87        <Block num="02" title={fr ? "Quantité saisie manuellement" : "Manually entered quantity"}>88          <p className="text-[13.5px] text-ink-2">{fr ? "Pour un élément non dessiné (ex. nombre d'appareils, longueur relevée sur place). Toujours étiquetée « estimée » ou « supposée », jamais « mesurée »." : "For an element not drawn (e.g. fixture count, length surveyed on site). Always labelled “estimated” or “assumed”, never “measured”."}</p>89          <div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-5">90            <Field label={fr ? "Nom" : "Name"}><Input value={m.name} onChange={(e) => setM({ ...m, name: e.target.value })} /></Field>91            <Field label={fr ? "Valeur" : "Value"}><Input type="number" step="0.001" min={0} value={m.value} onChange={(e) => setM({ ...m, value: e.target.value })} className="vp-mono" /></Field>92            <Field label={fr ? "Unité" : "Unit"}><Select value={m.unit} onChange={(e) => setM({ ...m, unit: e.target.value })}>{["m", "ft", "m2", "ft2", "m3", "ft3", "yd3", "unit", "h", "lump"].map((u) => <option key={u} value={u}>{unitLabel(u, fr)}</option>)}</Select></Field>93            <Field label={fr ? "Confiance" : "Confidence"}><Select value={m.confidence} onChange={(e) => setM({ ...m, confidence: e.target.value })}><option value="estimated">{fr ? "estimée (relevé)" : "estimated (survey)"}</option><option value="assumed">{fr ? "supposée" : "assumed"}</option></Select></Field>94            <Field label={fr ? "Note / justification" : "Note / rationale"}><Input value={m.note} onChange={(e) => setM({ ...m, note: e.target.value })} /></Field>95          </div>96          <Btn small tone="primary" disabled={!m.name || !m.value} onClick={() => call(async () => { await api(`/projects/${d.project.id}/measurements`, { method: "POST", json: { ...m, value: Number(m.value) } }); setM({ ...m, name: "", value: "", note: "" }); })}>{fr ? "Ajouter au registre" : "Add to ledger"}</Btn>97        </Block>98      )}99    </div>100  );101}102103function FragmentRow({ x, fr, lang, canWrite, open, toggle, onVerify, onDelete }: { x: WorkspaceData["measurements"][number]; fr: boolean; lang: string; canWrite: boolean; open: boolean; toggle: () => void; onVerify: (v: boolean) => void; onDelete: () => void }) {104  return (105    <>106      <tr>107        <td><button type="button" className="text-left font-semibold text-accent-deep hover:underline" onClick={toggle}>{x.name}</button><div className="vp-mono text-[10px] text-ink-3">{x.objectId ? `${fr ? "objet" : "object"} ${x.objectId.slice(0, 8)}` : fr ? "saisie" : "manual"}</div></td>108        <td className="vp-mono text-[11.5px]">{x.formulaText}</td>109        <td className="vp-mono text-right"><b>{num(x.value, lang, 3)}</b></td>110        <td className="vp-mono">{unitLabel(x.unit, fr)}</td>111        <td className="vp-mono text-[11px] uppercase">{x.confidence}</td>112        <td className="vp-mono text-[11px]">{x.calibrationRevision ?? "—"}</td>113        <td>{x.stale ? <span className="pill pill-conf-C">{fr ? "périmée" : "stale"}</span> : <span className="pill pill-conf-B">{fr ? "à jour" : "current"}</span>}</td>114        <td className="text-[12px]">{x.verifiedAt ? <span className="text-accent">✓ {dt(x.verifiedAt, lang)}</span> : <span className="text-ink-3">{fr ? "non vérifiée" : "unverified"}</span>}</td>115        <td className="whitespace-nowrap">{canWrite && (<>{x.verifiedAt ? <Btn small onClick={() => onVerify(false)}>{fr ? "Annuler" : "Unverify"}</Btn> : <Btn small tone="accent" disabled={x.stale} onClick={() => onVerify(true)}>{fr ? "Vérifier" : "Verify"}</Btn>} <Btn small onClick={onDelete}>✕</Btn></>)}</td>116      </tr>117      {open && <tr><td colSpan={9} className="bg-surface-2"><div className="vp-mono text-[11px] text-ink-2"><div>{fr ? "entrées" : "inputs"} : {Object.entries(x.inputs).map(([k, v]) => `${k} = ${v}`).join(" · ") || "—"}</div><div>{fr ? "lignage" : "lineage"} : {x.lineage.join(" → ") || "—"} · {fr ? "calculée" : "computed"} {dt(x.computedAt, lang)} · {fr ? "page" : "page"} {x.pageId?.slice(0, 8) ?? "—"}</div></div></td></tr>}118    </>119  );120}121
Files main
Menu

Theme