feat(awards): a reference's number can be corrected in the editor

The one field the editor would not let you touch, and the one that was wrong on
WAJA. Every other property of a reference — its name, pattern, entity list,
validity window — was editable; the code was rendered readOnly, so correcting a
number meant deleting all 47 references and importing a new list, throwing away
anything the operator had adjusted in it.

A rename in the store, not a delete plus an insert: everything the reference
carries travels with it, which is the whole point of correcting a number rather
than replacing an entry. A number already in use is refused — REPLACE INTO would
have let one reference silently swallow another, discovered much later as a
prefecture quietly missing from the list.

The typed code is held apart from the selection. The list and every field patch
key off the selected code, so editing it in place made the editor lose the
reference mid-edit.

SaveAwardReference now recomputes the log like Delete and Replace already did. A
reference's name is what the award column SHOWS for awards displaying by name,
and its pattern is part of what matches at all — so editing one changes rows,
and the grid was left showing the old label until something else happened to
trigger a pass.

Changelog: the three TCI-sharing lines are merged into one. The server and the
two fixes made to it while building are one unreleased feature, and an operator
only ever meets the finished thing. The TCI-client PTT line stays separate — it
is OpsLog driving a SunSDR, the other direction entirely.
This commit is contained in:
2026-08-17 10:26:13 +02:00
parent 2941121f4b
commit 21a0d560de
8 changed files with 236 additions and 15 deletions
+31
View File
@@ -5240,6 +5240,37 @@ func (a *App) SaveAwardReference(code string, ref awardref.Ref) error {
}
a.markAwardEdited(code)
a.mirrorAwards()
// A reference's name is what the award column SHOWS for awards displaying by
// name, and its pattern is part of what matches at all — so editing one
// changes rows in the log, exactly as deleting or replacing the list does.
// Those already recomputed; this did not, and left the grid showing the old
// label until something else happened to trigger a pass.
a.recomputeAwardRefsAsync()
return nil
}
// RenameAwardReference changes a reference's code on an award the operator
// already runs.
//
// The one field the editor could not touch, and the one that was wrong: WAJA
// shipped numbered by the Japanese state rather than by the JARL. Correcting it
// meant deleting the whole list and importing another — throwing away anything
// the operator had adjusted in it.
func (a *App) RenameAwardReference(code, oldRef, newRef string) error {
if a.awardRefs == nil {
return fmt.Errorf("db not initialized")
}
if err := a.awardRefs.Rename(a.ctx, code, oldRef, newRef); err != nil {
return err
}
a.markAwardEdited(code)
a.mirrorAwards()
// The materialised award columns hold a LABEL computed from the definition —
// the reference code for most awards, the name for those displaying by name.
// A renumbered reference changes the first kind, so the log is recomputed
// exactly as it is for every other reference-list change.
a.recomputeAwardRefsAsync()
applog.Printf("awards: %s reference %s renumbered to %s", code, oldRef, newRef)
return nil
}
+8 -10
View File
@@ -4,21 +4,19 @@
"date": "",
"en": [
"An entity that is a single island group now fills the IOTA reference on its own — no callbook subscription needed.",
"CAT sharing can now speak TCI instead of Hamlib, so a TCI-only program reaches whatever radio OpsLog is on.",
"CAT sharing can now speak TCI instead of Hamlib, split included, so a TCI-only program reaches whatever radio you are on.",
"Lookup cache: a TTL of 0 switches it off, so a callbook record you are correcting is re-read every time.",
"TCI: when the radio forbids transmitting, PTT now says so instead of doing nothing silently.",
"TCI sharing: the server now announces transmit permission, without which a client such as MSHV never keys at all.",
"TCI sharing: split is armed on the frequency the client asked for, whichever order it sent the two commands in.",
"WAJA carried Japans civil prefecture numbers instead of the JARLs: 35 of the 47 references are renumbered."
"TCI radios: when the rig forbids transmitting, PTT says so instead of doing nothing silently.",
"WAJA carried Japans civil prefecture numbers instead of the JARLs: 35 of the 47 references are renumbered.",
"Award references can be renumbered in the editor — the number was the one field it would not let you correct."
],
"fr": [
"Une entité qui est un seul groupe d’îles remplit désormais la référence IOTA toute seule, sans abonnement callbook.",
"Le partage CAT peut désormais parler TCI au lieu de Hamlib : un logiciel TCI atteint la radio, quelle quelle soit.",
"Le partage CAT peut désormais parler TCI au lieu de Hamlib, split compris : un logiciel TCI atteint la radio, quelle quelle soit.",
"Cache des recherches : un TTL à 0 le désactive, pour relire à chaque fois une fiche callbook en cours de correction.",
"TCI : quand la radio interdit l’émission, le PTT le dit désormais au lieu de ne rien faire en silence.",
"Partage TCI : le serveur annonce désormais lautorisation d’émettre, sans laquelle un client comme MSHV ne passe jamais en émission.",
"Partage TCI : le split sarme sur la fréquence demandée par le logiciel, quel que soit lordre de ses deux commandes.",
"WAJA portait les numéros civils des préfectures japonaises et non ceux de la JARL : 35 des 47 références sont renumérotées."
"Radios TCI : quand la radio interdit l’émission, le PTT le dit au lieu de ne rien faire en silence.",
"WAJA portait les numéros civils des préfectures japonaises et non ceux de la JARL : 35 des 47 références sont renumérotées.",
"Les références dun diplôme se renumérotent dans l’éditeur : le numéro était le seul champ quil refusait de corriger."
]
},
{
+35 -3
View File
@@ -14,7 +14,7 @@ import { useI18n } from '@/lib/i18n';
import {
GetAwardDefs, SaveAwardDefs, ResetAwardDefs, AwardFields,
GetAwardReferenceMeta, UpdateAwardReferenceList,
ListAwardReferences, SearchAwardReferences, SaveAwardReference, DeleteAwardReference,
ListAwardReferences, SearchAwardReferences, SaveAwardReference, DeleteAwardReference, RenameAwardReference,
ImportAwardReferencesText, GetAwardPresets, ApplyAwardPreset,
ListCountries, DXCCForCountry, DXCCName,
PopulateBuiltinReferences, HasBuiltinReferences,
@@ -915,6 +915,10 @@ function ReferencesPanel({ code, presets, meta, awardValidFrom, awardValidTo, on
const [refs, setRefs] = useState<AwardRef[]>([]);
const [q, setQ] = useState('');
const [selCode, setSelCode] = useState<string | null>(null);
// The code as TYPED. The list and every patch key off selCode, so editing the
// code in place would make the editor lose the reference mid-edit; the draft
// is applied as a rename when the operator saves.
const [codeDraft, setCodeDraft] = useState('');
const [busy, setBusy] = useState(false);
const [bulk, setBulk] = useState('');
const [showBulk, setShowBulk] = useState(false);
@@ -952,6 +956,7 @@ function ReferencesPanel({ code, presets, meta, awardValidFrom, awardValidTo, on
}
const sel = refs.find((r) => r.code === selCode) || null;
useEffect(() => { setCodeDraft(selCode ?? ''); }, [selCode]);
// Large lists are already filtered by the server; small lists filter locally.
const filtered = useMemo(() => {
if (large) return refs;
@@ -965,6 +970,27 @@ function ReferencesPanel({ code, presets, meta, awardValidFrom, awardValidTo, on
try { await SaveAwardReference(code, r as any); load(); onChanged(); }
catch (e: any) { setErr(String(e?.message ?? e)); }
}
// Save the selected reference, renumbering it first when the code was edited.
//
// The rename has to come first and has to be a rename: saving under the new
// code would simply create a second reference and leave the old one behind,
// which is how a list quietly grows duplicates.
async function saveSelected(r: AwardRef) {
const next = codeDraft.trim().toUpperCase();
if (!next) { setErr(t('awed.refCodeEmpty')); return; }
if (next !== r.code) {
try {
await RenameAwardReference(code, r.code, next);
} catch (e: any) {
// Most often the number is already taken by another reference. Said
// here rather than swallowed: the save has NOT happened.
setErr(String(e?.message ?? e));
return;
}
setSelCode(next);
}
await saveRef({ ...r, code: next });
}
async function addRef() {
const c = prompt(t('awed.newRefCodePrompt'))?.trim().toUpperCase();
if (!c) return;
@@ -1046,7 +1072,13 @@ function ReferencesPanel({ code, presets, meta, awardValidFrom, awardValidTo, on
) : (
<div className="space-y-2">
<div className="flex items-center gap-2">
<Input className="h-8 w-28 font-mono font-semibold" value={sel.code} readOnly />
{/* Editable, because a shipped list can be wrong about it: WAJA
went out carrying Japan's civil prefecture numbers instead of
the JARL's, and correcting that meant deleting all 47
references and importing a new list. */}
<Input className="h-8 w-28 font-mono font-semibold" value={codeDraft}
title={t('awed.refCodeTip')}
onChange={(e) => setCodeDraft(e.target.value)} />
<label className="flex items-center gap-1.5 text-xs cursor-pointer"><Checkbox checked={sel.valid} onCheckedChange={(c) => patchSel({ valid: !!c })} /> {t('awed.valid')}</label>
<div className="flex-1" />
<button className="text-muted-foreground hover:text-destructive" onClick={() => delRef(sel.code)}><Trash2 className="size-4" /></button>
@@ -1084,7 +1116,7 @@ function ReferencesPanel({ code, presets, meta, awardValidFrom, awardValidTo, on
? t('awed.refValidHintAward', { from: openEnded(awardValidFrom), to: openEnded(awardValidTo) })
: t('awed.refValidHint')}
</p>
<div className="flex justify-end pt-1"><Button size="sm" className="h-7" onClick={() => sel && saveRef(sel)}><Save className="size-3.5 mr-1" /> {t('awed.saveReference')}</Button></div>
<div className="flex justify-end pt-1"><Button size="sm" className="h-7" onClick={() => sel && saveSelected(sel)}><Save className="size-3.5 mr-1" /> {t('awed.saveReference')}</Button></div>
</div>
)}
</div>
File diff suppressed because one or more lines are too long
+2
View File
@@ -861,6 +861,8 @@ export function ReloadUDPIntegrations():Promise<Array<string>>;
export function RemovePassphrase(arg1:string):Promise<void>;
export function RenameAwardReference(arg1:string,arg2:string,arg3:string):Promise<void>;
export function RenameDatabase(arg1:string):Promise<void>;
export function RenameLogbook(arg1:string):Promise<void>;
+4
View File
@@ -1662,6 +1662,10 @@ export function RemovePassphrase(arg1) {
return window['go']['main']['App']['RemovePassphrase'](arg1);
}
export function RenameAwardReference(arg1, arg2, arg3) {
return window['go']['main']['App']['RenameAwardReference'](arg1, arg2, arg3);
}
export function RenameDatabase(arg1) {
return window['go']['main']['App']['RenameDatabase'](arg1);
}
+42
View File
@@ -266,6 +266,48 @@ func (r *Repo) Upsert(ctx context.Context, awardCode string, ref Ref) error {
return err
}
// Rename changes a reference's CODE, keeping everything else about it.
//
// Wanted because a shipped list can simply be wrong: WAJA went out numbered by
// the Japanese state instead of by the JARL, and the only way to correct it was
// to delete all 47 references and import a new list — losing anything the
// operator had adjusted. The number is the one field an editor could not touch.
//
// A rename, not a delete plus an insert: everything the reference carries — its
// pattern, its DXCC list, its validity window — travels with it, which is the
// whole point of correcting a number rather than replacing an entry.
func (r *Repo) Rename(ctx context.Context, awardCode, oldCode, newCode string) error {
ac := strings.ToUpper(strings.TrimSpace(awardCode))
from := strings.ToUpper(strings.TrimSpace(oldCode))
to := strings.ToUpper(strings.TrimSpace(newCode))
if ac == "" || from == "" || to == "" {
return fmt.Errorf("empty award or reference code")
}
if from == to {
return nil
}
// A collision would REPLACE the other reference and take its name, pattern
// and dates with it — one silently swallowing another, discovered much later
// as a reference that has quietly gone missing.
var n int
if err := r.db.QueryRowContext(ctx,
`SELECT COUNT(*) FROM award_references WHERE award_code = ? AND ref_code = ?`, ac, to).Scan(&n); err != nil {
return err
}
if n > 0 {
return fmt.Errorf("%s already has a reference %s", ac, to)
}
res, err := r.db.ExecContext(ctx,
`UPDATE award_references SET ref_code = ? WHERE award_code = ? AND ref_code = ?`, to, ac, from)
if err != nil {
return err
}
if rows, _ := res.RowsAffected(); rows == 0 {
return fmt.Errorf("%s has no reference %s", ac, from)
}
return nil
}
// Delete removes one reference from an award.
func (r *Repo) Delete(ctx context.Context, awardCode, refCode string) error {
_, err := r.db.ExecContext(ctx,
+112
View File
@@ -0,0 +1,112 @@
package awardref
import (
"context"
"path/filepath"
"testing"
"hamlog/internal/db"
)
func renameRepo(t *testing.T) *Repo {
t.Helper()
conn, err := db.Open(filepath.Join(t.TempDir(), "a.db"))
if err != nil {
t.Fatalf("open: %v", err)
}
t.Cleanup(func() { conn.Close() })
return NewRepo(conn)
}
// Correcting a reference's number must keep the reference.
//
// WAJA shipped numbered by the Japanese state instead of by the JARL, and until
// now the only way to fix that was to delete all 47 references and import a new
// list — losing anything the operator had adjusted. A rename keeps the pattern,
// the entity list and the validity window, because a wrong NUMBER is all that
// was wrong.
func TestRenameKeepsEverythingButTheCode(t *testing.T) {
r := renameRepo(t)
ctx := context.Background()
if err := r.Upsert(ctx, "WAJA", Ref{
Code: "13", Name: "Tokyo", Pattern: `\bTok[iy]o\b`, Valid: true,
DXCCList: []int{339}, ValidFrom: "1970-01-01",
}); err != nil {
t.Fatalf("seed: %v", err)
}
if err := r.Rename(ctx, "WAJA", "13", "10"); err != nil {
t.Fatalf("rename: %v", err)
}
refs, err := r.List(ctx, "WAJA")
if err != nil {
t.Fatalf("list: %v", err)
}
if len(refs) != 1 {
t.Fatalf("WAJA holds %d references after a rename, want 1 — it was copied, not renamed", len(refs))
}
got := refs[0]
if got.Code != "10" {
t.Errorf("code = %q, want 10", got.Code)
}
if got.Name != "Tokyo" || got.Pattern != `\bTok[iy]o\b` {
t.Errorf("the reference lost what it carried: name=%q pattern=%q", got.Name, got.Pattern)
}
if len(got.DXCCList) != 1 || got.DXCCList[0] != 339 || got.ValidFrom != "1970-01-01" {
t.Errorf("the reference lost its entity list or dates: %+v", got)
}
}
// A number already in use must be refused. Left to REPLACE, the rename would
// take the other reference's name, pattern and dates with it — one entry
// silently swallowing another, found much later as a prefecture that has
// quietly gone missing from the list.
func TestRenameRefusesANumberAlreadyTaken(t *testing.T) {
r := renameRepo(t)
ctx := context.Background()
if err := r.Upsert(ctx, "WAJA", Ref{Code: "10", Name: "Gunma", Valid: true}); err != nil {
t.Fatalf("seed: %v", err)
}
if err := r.Upsert(ctx, "WAJA", Ref{Code: "13", Name: "Tokyo", Valid: true}); err != nil {
t.Fatalf("seed: %v", err)
}
if err := r.Rename(ctx, "WAJA", "13", "10"); err == nil {
t.Fatal("renaming onto an existing number was accepted — one reference would have eaten the other")
}
refs, _ := r.List(ctx, "WAJA")
if len(refs) != 2 {
t.Fatalf("WAJA holds %d references, want both still there", len(refs))
}
}
// Renaming something that is not there is an error, not a silent no-op: it
// means the editor and the store disagree about what the award holds.
func TestRenameAnUnknownReferenceFails(t *testing.T) {
r := renameRepo(t)
if err := r.Rename(context.Background(), "WAJA", "99", "10"); err == nil {
t.Error("renaming a reference the award does not have was accepted")
}
}
// Codes are stored upper-cased, so a rename must compare the same way — else
// "eu-048" onto "EU-048" looks like a move and is really the same reference,
// which the collision check has to catch.
func TestRenameIsCaseInsensitive(t *testing.T) {
r := renameRepo(t)
ctx := context.Background()
if err := r.Upsert(ctx, "IOTA", Ref{Code: "EU-048", Name: "Belle-Ile", Valid: true}); err != nil {
t.Fatalf("seed: %v", err)
}
if err := r.Rename(ctx, "iota", "eu-048", "eu-048"); err != nil {
t.Errorf("renaming a reference to itself in another case failed: %v", err)
}
if err := r.Rename(ctx, "IOTA", "eu-048", "eu-049"); err != nil {
t.Fatalf("rename: %v", err)
}
refs, _ := r.List(ctx, "IOTA")
if len(refs) != 1 || refs[0].Code != "EU-049" {
t.Errorf("references = %+v, want the one renamed to EU-049 and upper-cased", refs)
}
}