diff --git a/frontend/src/assets/rule-proposals.css b/frontend/src/assets/rule-proposals.css index 1877d1d7..72f5f239 100644 --- a/frontend/src/assets/rule-proposals.css +++ b/frontend/src/assets/rule-proposals.css @@ -3,6 +3,7 @@ Loaded scoped by each, so these class names stay local to the panels. */ .proposals { display: flex; flex-direction: column; gap: var(--fs-space-2); } .sub-title { margin: 0; font-size: 0.95rem; color: var(--fs-text-primary); } +.proposals-bar { display: flex; justify-content: flex-end; } .proposal-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--fs-space-2); } .proposal-rule { padding: var(--fs-space-3); diff --git a/frontend/src/components/WeightProposals.vue b/frontend/src/components/WeightProposals.vue index 037fdd9c..f207c5c7 100644 --- a/frontend/src/components/WeightProposals.vue +++ b/frontend/src/components/WeightProposals.vue @@ -7,22 +7,41 @@ import type { import type { RuleTrigger } from "@/api/rulebooks"; import { apiErrorMessage } from "@/api/client"; import { useToastStore } from "@/stores/toast"; +import ConfirmDialog from "@/components/ConfirmDialog.vue"; /** * Suggestions for how strongly a rule arrives and what reaches it, waiting on * a person. A pass read each rule beside what happened when it reached * sessions, and proposed its enforcement (inform, hold, enforce), its salience, * or a typed trigger. Nothing changes until "Apply" is pressed; "Not this" - * keeps the value from being proposed again. The same judgment - * `judge_rule_weights` makes in a session, through the same service. + * keeps the value from being proposed again. "Apply all" confirms every + * listed suggestion at once, after a dialog that counts what changes. The + * same judgment `judge_rule_weights` makes in a session, through the same + * service. */ const toast = useToastStore(); const data = ref(null); const failed = ref(false); const busy = ref(null); +const confirmingAll = ref(false); const rules = computed(() => data.value?.rules ?? []); +const proposalCount = computed(() => rules.value.reduce((n, r) => n + r.proposals.length, 0)); + +// The dialog names how many rules would start stopping work, since a hold or +// an enforce is the change a person notices in their next session. +const allSummary = computed(() => { + const stopping = rules.value.filter((r) => r.proposals.some( + (p) => p.field === "enforcement" && p.value !== "inform", + )).length; + const changes = `${proposalCount.value} change${proposalCount.value === 1 ? "" : "s"}`; + const across = `${rules.value.length} rule${rules.value.length === 1 ? "" : "s"}`; + const stops = stopping + ? ` ${stopping} of them will hold or refuse the acts they govern.` + : ""; + return `${changes} across ${across} take effect at once.${stops}`; +}); // What each enforcement does when the rule arrives — said beside the change, // since "hold" and "enforce" stop work and the person applying one should @@ -84,6 +103,31 @@ async function decide(rule: RuleWeightProposals, p: WeightProposal, verdict: Ver } } +async function applyAll() { + confirmingAll.value = false; + busy.value = "all"; + try { + const out = await judgeWeightProposals(rules.value.flatMap((rule) => rule.proposals.map((p) => ({ + rule_id: rule.id, field: p.field, value: p.trigger ?? p.value, + verdict: "confirm" as Verdict, note: "Applied with Apply all in Settings.", + })))); + if (out.refused.length) { + const first = out.refused[0]; + toast.show( + `${out.judged.length} applied; ${out.refused.length} refused — #${first.rule_id}: ${first.error}`, + "error", + ); + } else { + toast.show(`${out.judged.length} applied.`, "success"); + } + await load(); + } catch (e) { + toast.show(apiErrorMessage(e, "Could not apply the suggestions"), "error"); + } finally { + busy.value = null; + } +} + onMounted(load); @@ -102,6 +146,13 @@ onMounted(load); rule exactly, by the tool, path, command or word the act carries; a rule with triggers holds or refuses only the acts they match, and elsewhere it is a line.

+
+ +
  • @@ -147,6 +198,15 @@ onMounted(load);
+