mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-12-13 05:50:27 +00:00
Merge pull request #98 from chekoopa/tree-view-fix
Fix ghost siblings and orphaned subhyphae view
This commit is contained in:
commit
d2a1c9d151
54
tree/tree.go
54
tree/tree.go
@ -12,11 +12,27 @@ import (
|
||||
)
|
||||
|
||||
func findSiblingsAndDescendants(hyphaName string) ([]*sibling, map[string]bool) {
|
||||
hyphaDir := ""
|
||||
if hyphaRawDir := path.Dir(hyphaName); hyphaRawDir != "." {
|
||||
hyphaDir = hyphaRawDir
|
||||
}
|
||||
var (
|
||||
siblings = []*sibling{&sibling{hyphaName, 0, 0}}
|
||||
siblingsMap = make(map[string]bool)
|
||||
siblingCheck = func(h *hyphae.Hypha) hyphae.CheckResult {
|
||||
if path.Dir(hyphaName) == path.Dir(h.Name) && h.Name != hyphaName {
|
||||
siblings = append(siblings, &sibling{h.Name, 0, 0})
|
||||
// I don't like this double comparison, but it is only the way to circumvent some flickups
|
||||
if strings.HasPrefix(h.Name, hyphaDir) && h.Name != hyphaDir && h.Name != hyphaName {
|
||||
var (
|
||||
rawSubPath = strings.TrimPrefix(h.Name, hyphaDir)[1:]
|
||||
slashIdx = strings.IndexRune(rawSubPath, '/')
|
||||
)
|
||||
if slashIdx > -1 {
|
||||
var sibPath = h.Name[:slashIdx+len(hyphaDir)+1]
|
||||
if _, exists := siblingsMap[sibPath]; !exists {
|
||||
siblingsMap[sibPath] = false
|
||||
}
|
||||
} else { // it is a straight sibling
|
||||
siblingsMap[h.Name] = true
|
||||
}
|
||||
}
|
||||
return hyphae.CheckContinue
|
||||
}
|
||||
@ -31,9 +47,18 @@ func findSiblingsAndDescendants(hyphaName string) ([]*sibling, map[string]bool)
|
||||
|
||||
i7n = hyphae.NewIteration()
|
||||
)
|
||||
siblingsMap[hyphaName] = true
|
||||
|
||||
i7n.AddCheck(siblingCheck)
|
||||
i7n.AddCheck(descendantCheck)
|
||||
i7n.Ignite()
|
||||
|
||||
siblings := make([]*sibling, len(siblingsMap))
|
||||
sibIdx := 0
|
||||
for sibName, exists := range siblingsMap {
|
||||
siblings[sibIdx] = &sibling{sibName, 0, 0, exists}
|
||||
sibIdx++
|
||||
}
|
||||
sort.Slice(siblings, func(i, j int) bool {
|
||||
return siblings[i].name < siblings[j].name
|
||||
})
|
||||
@ -79,7 +104,7 @@ func Tree(hyphaName string) (siblingsHTML, childrenHTML, prev, next string) {
|
||||
wg.Done()
|
||||
}()
|
||||
go func() {
|
||||
children = figureOutChildren(hyphaName, descendantsPool).children
|
||||
children = figureOutChildren(hyphaName, descendantsPool, true).children
|
||||
wg.Done()
|
||||
}()
|
||||
wg.Wait()
|
||||
@ -103,10 +128,11 @@ func Tree(hyphaName string) (siblingsHTML, childrenHTML, prev, next string) {
|
||||
|
||||
type child struct {
|
||||
name string
|
||||
exists bool
|
||||
children []child
|
||||
}
|
||||
|
||||
func figureOutChildren(hyphaName string, subhyphaePool map[string]bool) child {
|
||||
func figureOutChildren(hyphaName string, subhyphaePool map[string]bool, exists bool) child {
|
||||
var (
|
||||
nestLevel = strings.Count(hyphaName, "/")
|
||||
adopted = make([]child, 0)
|
||||
@ -115,16 +141,30 @@ func figureOutChildren(hyphaName string, subhyphaePool map[string]bool) child {
|
||||
subnestLevel := strings.Count(subhyphaName, "/")
|
||||
if subnestLevel-1 == nestLevel && path.Dir(subhyphaName) == hyphaName {
|
||||
delete(subhyphaePool, subhyphaName)
|
||||
adopted = append(adopted, figureOutChildren(subhyphaName, subhyphaePool))
|
||||
adopted = append(adopted, figureOutChildren(subhyphaName, subhyphaePool, true))
|
||||
}
|
||||
}
|
||||
return child{hyphaName, adopted}
|
||||
for descName, _ := range subhyphaePool {
|
||||
if strings.HasPrefix(descName, hyphaName) {
|
||||
var (
|
||||
rawSubPath = strings.TrimPrefix(descName, hyphaName)[1:]
|
||||
slashIdx = strings.IndexRune(rawSubPath, '/')
|
||||
)
|
||||
if slashIdx > -1 {
|
||||
var sibPath = descName[:slashIdx+len(hyphaName)+1]
|
||||
adopted = append(adopted, figureOutChildren(sibPath, subhyphaePool, false))
|
||||
} // `else` never happens?
|
||||
}
|
||||
}
|
||||
|
||||
return child{hyphaName, exists, adopted}
|
||||
}
|
||||
|
||||
type sibling struct {
|
||||
name string
|
||||
directSubhyphaeCount int
|
||||
indirectSubhyphaeCount int
|
||||
exists bool
|
||||
}
|
||||
|
||||
func subhyphaeMatrix(children []child) (html string) {
|
||||
|
@ -20,7 +20,7 @@ pseudographics:
|
||||
})
|
||||
%}
|
||||
<li class="subhyphae__entry">
|
||||
<a class="subhyphae__link" href="/hypha/{%s c.name %}">
|
||||
<a class="subhyphae__link {% if !c.exists %}wikilink_new{% endif %}" href="/hypha/{%s c.name %}">
|
||||
{%s util.BeautifulName(path.Base(c.name)) %}
|
||||
</a>
|
||||
{% if len(c.children) > 0 %}
|
||||
@ -36,7 +36,7 @@ pseudographics:
|
||||
|
||||
{% func siblingHTML(s *sibling) %}
|
||||
<li class="sibling-hyphae__entry">
|
||||
<a class="sibling-hyphae__link" href="/hypha/{%s s.name %}">
|
||||
<a class="sibling-hyphae__link {% if !s.exists %}wikilink_new{% endif %}" href="/hypha/{%s s.name %}">
|
||||
{%s util.BeautifulName(path.Base(s.name)) %}
|
||||
<span class="sibling-hyphae__count">
|
||||
{% if s.directSubhyphaeCount > 0 %}
|
||||
|
@ -82,7 +82,15 @@ func streamchildHTML(qw422016 *qt422016.Writer, c *child) {
|
||||
//line tree/view.qtpl:21
|
||||
qw422016.N().S(`
|
||||
<li class="subhyphae__entry">
|
||||
<a class="subhyphae__link" href="/hypha/`)
|
||||
<a class="subhyphae__link `)
|
||||
//line tree/view.qtpl:23
|
||||
if !c.exists {
|
||||
//line tree/view.qtpl:23
|
||||
qw422016.N().S(`wikilink_new`)
|
||||
//line tree/view.qtpl:23
|
||||
}
|
||||
//line tree/view.qtpl:23
|
||||
qw422016.N().S(`" href="/hypha/`)
|
||||
//line tree/view.qtpl:23
|
||||
qw422016.E().S(c.name)
|
||||
//line tree/view.qtpl:23
|
||||
@ -156,7 +164,15 @@ func streamsiblingHTML(qw422016 *qt422016.Writer, s *sibling) {
|
||||
//line tree/view.qtpl:37
|
||||
qw422016.N().S(`
|
||||
<li class="sibling-hyphae__entry">
|
||||
<a class="sibling-hyphae__link" href="/hypha/`)
|
||||
<a class="sibling-hyphae__link `)
|
||||
//line tree/view.qtpl:39
|
||||
if !s.exists {
|
||||
//line tree/view.qtpl:39
|
||||
qw422016.N().S(`wikilink_new`)
|
||||
//line tree/view.qtpl:39
|
||||
}
|
||||
//line tree/view.qtpl:39
|
||||
qw422016.N().S(`" href="/hypha/`)
|
||||
//line tree/view.qtpl:39
|
||||
qw422016.E().S(s.name)
|
||||
//line tree/view.qtpl:39
|
||||
|
Loading…
Reference in New Issue
Block a user