View Mode is Working
This commit is contained in:
@@ -23,6 +23,7 @@ package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.bullercodeworks.com/brian/expds/data"
|
||||
"git.bullercodeworks.com/brian/expds/data/models"
|
||||
@@ -46,11 +47,14 @@ type ScreenHome struct {
|
||||
layout *w.LinearLayout
|
||||
columns *w.LinearLayout
|
||||
|
||||
activePds *models.Pds
|
||||
pdsListingTypes []models.EntryType
|
||||
pdsListing *wd.SimpleListWithHelp
|
||||
pdsNSIDs []syntax.NSID
|
||||
jsonContent *wd.JsonContent
|
||||
activePds *models.Pds
|
||||
pdsListing *wd.SimpleListWithHelp
|
||||
jsonContent *wd.JsonContent
|
||||
|
||||
pdsListingTypes []models.EntryType
|
||||
pdsNSIDs []syntax.NSID
|
||||
expandedEntries map[string]interface{}
|
||||
recordIdsToNSIDs map[string]syntax.NSID
|
||||
|
||||
alert *w.Alert
|
||||
alertLayout *w.LinearLayout
|
||||
@@ -64,6 +68,9 @@ func (s *ScreenHome) Init(a *App) {
|
||||
s.a, s.r = a, a.repo
|
||||
s.style = a.style
|
||||
|
||||
s.expandedEntries = make(map[string]interface{})
|
||||
s.recordIdsToNSIDs = make(map[string]syntax.NSID)
|
||||
|
||||
s.menuLayout = w.NewTopMenuLayout("home.toplayout", s.style)
|
||||
s.initMenu()
|
||||
|
||||
@@ -181,46 +188,58 @@ func (s *ScreenHome) cliGetPds(args ...string) bool {
|
||||
return true
|
||||
}
|
||||
s.cli.Log("Retrieved: %s (%s)", pds.AtId, pds.Did)
|
||||
/*
|
||||
vals, err := pds.List()
|
||||
if err != nil {
|
||||
s.cli.Log(err.Error())
|
||||
return true
|
||||
}
|
||||
*/
|
||||
s.pdsListing.SetTitle(fmt.Sprintf("%s (%s)", pds.AtId.String(), pds.Did.String()))
|
||||
|
||||
// When we first get the pds, all entries are models.TypeNSID
|
||||
s.pdsListingTypes = []models.EntryType{}
|
||||
nsidList := pds.NSIDStringList()
|
||||
for i := 0; i < len(nsidList); i++ {
|
||||
s.pdsListingTypes = append(s.pdsListingTypes, models.TypeNSID)
|
||||
}
|
||||
s.pdsListing.SetList(nsidList)
|
||||
s.hideCli()
|
||||
s.activePds = pds
|
||||
s.expandedEntries = make(map[string]interface{})
|
||||
s.updatePdsListing()
|
||||
s.updateJsonView(s.pdsListing.SelectedIndex(), s.pdsListing.GetSelectedItem())
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *ScreenHome) updatePdsListing() {
|
||||
s.pdsListing.SetTitle(fmt.Sprintf("%s (%s)", s.activePds.AtId.String(), s.activePds.Did.String()))
|
||||
// When we first get the pds, all entries are models.TypeNSID
|
||||
s.pdsListingTypes = []models.EntryType{}
|
||||
s.recordIdsToNSIDs = make(map[string]syntax.NSID)
|
||||
var wrk []string
|
||||
nsidList := s.activePds.NSIDStringList()
|
||||
for i, v := range nsidList {
|
||||
wrk = append(wrk, v)
|
||||
s.pdsListingTypes = append(s.pdsListingTypes, models.TypeNSID)
|
||||
if _, ok := s.expandedEntries[v]; ok {
|
||||
nsid := s.activePds.NSIDs[i]
|
||||
rIds := s.activePds.GetRecordIdsFor(nsid)
|
||||
for j := range rIds {
|
||||
wrk = append(wrk, fmt.Sprintf("• %s", rIds[j]))
|
||||
s.pdsListingTypes = append(s.pdsListingTypes, models.TypeRecord)
|
||||
s.recordIdsToNSIDs[rIds[j]] = nsid
|
||||
}
|
||||
}
|
||||
}
|
||||
s.pdsListing.SetList(wrk)
|
||||
s.hideCli()
|
||||
}
|
||||
|
||||
func (s *ScreenHome) selectPdsListingEntry(idx int, nm string) bool {
|
||||
if len(s.pdsListingTypes) < idx {
|
||||
s.Log("error finding pds listing type (idx: %d >= list length: %d", idx, len(s.pdsListingTypes))
|
||||
if !s.updateJsonView(idx, nm) {
|
||||
return false
|
||||
}
|
||||
// Update the jsonContent with the list of records
|
||||
|
||||
switch s.pdsListingTypes[idx] {
|
||||
case models.TypeNSID:
|
||||
nsid, err := syntax.ParseNSID(nm)
|
||||
if err != nil {
|
||||
s.Log("error parsing NSID from %s: %w", nm, err)
|
||||
return false
|
||||
// Expand the NSID
|
||||
if _, ok := s.expandedEntries[nm]; ok {
|
||||
delete(s.expandedEntries, nm)
|
||||
} else {
|
||||
s.expandedEntries[nm] = new(interface{})
|
||||
}
|
||||
recordIds := s.activePds.GetRecordIdsFor(nsid)
|
||||
s.jsonContent.SetValue(recordIds)
|
||||
s.updatePdsListing()
|
||||
return true
|
||||
|
||||
case models.TypeRecord:
|
||||
|
||||
// If signed in and we can edit this, activate jsonContent in 'editable' mode
|
||||
s.jsonContent.SetEditable(true)
|
||||
s.columns.ActivateWidget(s.jsonContent)
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
@@ -244,8 +263,15 @@ func (s *ScreenHome) updateJsonView(idx int, nm string) bool {
|
||||
return true
|
||||
|
||||
case models.TypeRecord:
|
||||
//s.jsonContent.SetValue(s.activePds.Records[
|
||||
|
||||
var nsid syntax.NSID
|
||||
var ok bool
|
||||
nm, _ := strings.CutPrefix(nm, "• ")
|
||||
if nsid, ok = s.recordIdsToNSIDs[nm]; !ok {
|
||||
s.Log("error finding NSID for record %s", nm)
|
||||
}
|
||||
rId := fmt.Sprintf("%s/%s", nsid.String(), nm)
|
||||
s.jsonContent.SetValue(s.activePds.Records[rId])
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
@@ -45,7 +45,10 @@ type JsonContent struct {
|
||||
focusable bool
|
||||
keyMap *wd.KeyMap
|
||||
|
||||
value any
|
||||
editable bool
|
||||
value any
|
||||
|
||||
activeNode []string
|
||||
}
|
||||
|
||||
var _ wd.Widget = (*JsonContent)(nil)
|
||||
@@ -117,6 +120,8 @@ func (w *JsonContent) SetValue(v any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *JsonContent) SetEditable(v bool) { w.editable = v }
|
||||
|
||||
/*
|
||||
func (w *JsonContent) SetJsonContent(txt string) {
|
||||
w.text = txt
|
||||
|
||||
Reference in New Issue
Block a user