View Mode is Working
This commit is contained in:
@@ -23,6 +23,7 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.bullercodeworks.com/brian/expds/data"
|
"git.bullercodeworks.com/brian/expds/data"
|
||||||
"git.bullercodeworks.com/brian/expds/data/models"
|
"git.bullercodeworks.com/brian/expds/data/models"
|
||||||
@@ -46,11 +47,14 @@ type ScreenHome struct {
|
|||||||
layout *w.LinearLayout
|
layout *w.LinearLayout
|
||||||
columns *w.LinearLayout
|
columns *w.LinearLayout
|
||||||
|
|
||||||
activePds *models.Pds
|
activePds *models.Pds
|
||||||
pdsListingTypes []models.EntryType
|
pdsListing *wd.SimpleListWithHelp
|
||||||
pdsListing *wd.SimpleListWithHelp
|
jsonContent *wd.JsonContent
|
||||||
pdsNSIDs []syntax.NSID
|
|
||||||
jsonContent *wd.JsonContent
|
pdsListingTypes []models.EntryType
|
||||||
|
pdsNSIDs []syntax.NSID
|
||||||
|
expandedEntries map[string]interface{}
|
||||||
|
recordIdsToNSIDs map[string]syntax.NSID
|
||||||
|
|
||||||
alert *w.Alert
|
alert *w.Alert
|
||||||
alertLayout *w.LinearLayout
|
alertLayout *w.LinearLayout
|
||||||
@@ -64,6 +68,9 @@ func (s *ScreenHome) Init(a *App) {
|
|||||||
s.a, s.r = a, a.repo
|
s.a, s.r = a, a.repo
|
||||||
s.style = a.style
|
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.menuLayout = w.NewTopMenuLayout("home.toplayout", s.style)
|
||||||
s.initMenu()
|
s.initMenu()
|
||||||
|
|
||||||
@@ -181,46 +188,58 @@ func (s *ScreenHome) cliGetPds(args ...string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
s.cli.Log("Retrieved: %s (%s)", pds.AtId, pds.Did)
|
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.activePds = pds
|
||||||
|
s.expandedEntries = make(map[string]interface{})
|
||||||
|
s.updatePdsListing()
|
||||||
|
s.updateJsonView(s.pdsListing.SelectedIndex(), s.pdsListing.GetSelectedItem())
|
||||||
return true
|
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 {
|
func (s *ScreenHome) selectPdsListingEntry(idx int, nm string) bool {
|
||||||
if len(s.pdsListingTypes) < idx {
|
if !s.updateJsonView(idx, nm) {
|
||||||
s.Log("error finding pds listing type (idx: %d >= list length: %d", idx, len(s.pdsListingTypes))
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// Update the jsonContent with the list of records
|
|
||||||
switch s.pdsListingTypes[idx] {
|
switch s.pdsListingTypes[idx] {
|
||||||
case models.TypeNSID:
|
case models.TypeNSID:
|
||||||
nsid, err := syntax.ParseNSID(nm)
|
// Expand the NSID
|
||||||
if err != nil {
|
if _, ok := s.expandedEntries[nm]; ok {
|
||||||
s.Log("error parsing NSID from %s: %w", nm, err)
|
delete(s.expandedEntries, nm)
|
||||||
return false
|
} else {
|
||||||
|
s.expandedEntries[nm] = new(interface{})
|
||||||
}
|
}
|
||||||
recordIds := s.activePds.GetRecordIdsFor(nsid)
|
s.updatePdsListing()
|
||||||
s.jsonContent.SetValue(recordIds)
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case models.TypeRecord:
|
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
|
return false
|
||||||
@@ -244,8 +263,15 @@ func (s *ScreenHome) updateJsonView(idx int, nm string) bool {
|
|||||||
return true
|
return true
|
||||||
|
|
||||||
case models.TypeRecord:
|
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
|
return false
|
||||||
|
|||||||
@@ -45,7 +45,10 @@ type JsonContent struct {
|
|||||||
focusable bool
|
focusable bool
|
||||||
keyMap *wd.KeyMap
|
keyMap *wd.KeyMap
|
||||||
|
|
||||||
value any
|
editable bool
|
||||||
|
value any
|
||||||
|
|
||||||
|
activeNode []string
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ wd.Widget = (*JsonContent)(nil)
|
var _ wd.Widget = (*JsonContent)(nil)
|
||||||
@@ -117,6 +120,8 @@ func (w *JsonContent) SetValue(v any) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *JsonContent) SetEditable(v bool) { w.editable = v }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
func (w *JsonContent) SetJsonContent(txt string) {
|
func (w *JsonContent) SetJsonContent(txt string) {
|
||||||
w.text = txt
|
w.text = txt
|
||||||
|
|||||||
Reference in New Issue
Block a user