feat: added colonns for awards in recent qso
This commit is contained in:
@@ -2718,6 +2718,64 @@ func (a *App) ComputeQSOAwardRefs(q qso.QSO) ([]QSOAwardRef, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// AwardRefsForQSOs returns, per QSO id, a map of award code → the reference(s)
|
||||
// that QSO contributes to (joined when several). Powers the per-award columns in
|
||||
// the Recent QSOs / Worked-before grids. The reference metadata is computed ONCE
|
||||
// for the whole batch so a page of QSOs stays cheap.
|
||||
func (a *App) AwardRefsForQSOs(ids []int64) (map[int64]map[string]string, error) {
|
||||
out := map[int64]map[string]string{}
|
||||
if a.qso == nil || len(ids) == 0 {
|
||||
return out, nil
|
||||
}
|
||||
defs := a.awardDefs()
|
||||
metas := a.awardRefMetas(defs)
|
||||
fieldByCode := map[string]string{}
|
||||
for _, d := range defs {
|
||||
fieldByCode[strings.ToUpper(d.Code)] = strings.ToLower(strings.TrimSpace(d.Field))
|
||||
}
|
||||
nameOf := func(field, ref string) string {
|
||||
switch field {
|
||||
case "dxcc":
|
||||
if n, err := strconv.Atoi(ref); err == nil {
|
||||
return dxcc.NameForDXCC(n)
|
||||
}
|
||||
case "cont":
|
||||
return continentName(ref)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
err := a.qso.IterateByIDs(a.ctx, ids, func(q qso.QSO) error {
|
||||
a.enrichQSOForAwards(&q)
|
||||
results := award.Compute(defs, []qso.QSO{q}, metas, nameOf)
|
||||
m := map[string]string{}
|
||||
for i := range results {
|
||||
r := &results[i]
|
||||
code := strings.ToUpper(r.Code)
|
||||
dxccField := fieldByCode[code] == "dxcc"
|
||||
var refs []string
|
||||
for _, rf := range r.Refs {
|
||||
if !rf.Worked {
|
||||
continue
|
||||
}
|
||||
// DXCC's ref is a number → show the country name instead.
|
||||
label := rf.Ref
|
||||
if dxccField && rf.Name != "" {
|
||||
label = rf.Name
|
||||
}
|
||||
refs = append(refs, label)
|
||||
}
|
||||
if len(refs) > 0 {
|
||||
m[code] = strings.Join(refs, ", ")
|
||||
}
|
||||
}
|
||||
if len(m) > 0 {
|
||||
out[q.ID] = m
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return out, err
|
||||
}
|
||||
|
||||
// AwardRefMeta describes a reference list's state for the UI.
|
||||
type AwardRefMeta struct {
|
||||
Code string `json:"code"`
|
||||
|
||||
Reference in New Issue
Block a user