Some work, I guess
This commit is contained in:
@@ -108,12 +108,12 @@ func (bd *BoltDB) GetPairFromPath(path []string) (*BoltPair, error) {
|
||||
return p, err
|
||||
}
|
||||
|
||||
func (bd *BoltDB) GetVisibleItemCount(path []string) (int, error) {
|
||||
func (bd *BoltDB) GetVisibleItemCount(path []string, search string) (int, error) {
|
||||
vis := 0
|
||||
var retErr error
|
||||
if len(path) == 0 {
|
||||
for i := range bd.buckets {
|
||||
n, err := bd.GetVisibleItemCount(bd.buckets[i].GetPath())
|
||||
n, err := bd.GetVisibleItemCount(bd.buckets[i].GetPath(), search)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -126,13 +126,13 @@ func (bd *BoltDB) GetVisibleItemCount(path []string) (int, error) {
|
||||
}
|
||||
// 1 for the bucket
|
||||
vis++
|
||||
if b.expanded {
|
||||
// This bucket is expanded, add up it's children
|
||||
if b.expanded || search != "" {
|
||||
// This bucket is expanded (or we're searching), add up it's children
|
||||
// * 1 for each pair
|
||||
vis += len(b.pairs)
|
||||
// * recurse for buckets
|
||||
for i := range b.buckets {
|
||||
n, err := bd.GetVisibleItemCount(b.buckets[i].GetPath())
|
||||
n, err := bd.GetVisibleItemCount(b.buckets[i].GetPath(), search)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -143,12 +143,12 @@ func (bd *BoltDB) GetVisibleItemCount(path []string) (int, error) {
|
||||
return vis, retErr
|
||||
}
|
||||
|
||||
func (bd *BoltDB) BuildVisiblePathSlice(filter string) ([][]string, error) {
|
||||
func (bd *BoltDB) BuildVisiblePathSlice(search string) ([][]string, error) {
|
||||
var retSlice [][]string
|
||||
var retErr error
|
||||
// The root path, recurse for root buckets
|
||||
for i := range bd.buckets {
|
||||
bktS, bktErr := bd.buckets[i].BuildVisiblePathSlice([]string{}, filter)
|
||||
bktS, bktErr := bd.buckets[i].BuildVisiblePathSlice([]string{}, search)
|
||||
if bktErr == nil {
|
||||
retSlice = append(retSlice, bktS...)
|
||||
} else {
|
||||
@@ -159,8 +159,8 @@ func (bd *BoltDB) BuildVisiblePathSlice(filter string) ([][]string, error) {
|
||||
return retSlice, retErr
|
||||
}
|
||||
|
||||
func (bd *BoltDB) IsVisiblePath(path []string, filter string) bool {
|
||||
visPaths, err := bd.BuildVisiblePathSlice(filter)
|
||||
func (bd *BoltDB) IsVisiblePath(path []string, search string) bool {
|
||||
visPaths, err := bd.BuildVisiblePathSlice(search)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
@@ -181,8 +181,8 @@ func (bd *BoltDB) IsVisiblePath(path []string, filter string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
func (bd *BoltDB) GetPrevVisiblePath(path []string, filter string) []string {
|
||||
visPaths, err := bd.BuildVisiblePathSlice(filter)
|
||||
func (bd *BoltDB) GetPrevVisiblePath(path []string, search string) []string {
|
||||
visPaths, err := bd.BuildVisiblePathSlice(search)
|
||||
if path == nil {
|
||||
if len(visPaths) > 0 {
|
||||
return visPaths[len(visPaths)-1]
|
||||
@@ -205,8 +205,8 @@ func (bd *BoltDB) GetPrevVisiblePath(path []string, filter string) []string {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (bd *BoltDB) GetNextVisiblePath(path []string, filter string) []string {
|
||||
visPaths, err := bd.BuildVisiblePathSlice(filter)
|
||||
func (bd *BoltDB) GetNextVisiblePath(path []string, search string) []string {
|
||||
visPaths, err := bd.BuildVisiblePathSlice(search)
|
||||
if path == nil {
|
||||
if len(visPaths) > 0 {
|
||||
return visPaths[0]
|
||||
|
@@ -38,14 +38,16 @@ func (b *BoltBucket) GetPath() []string {
|
||||
buildVisiblePathSlice builds a slice of string slices containing all visible paths in this bucket
|
||||
The passed prefix is the path leading to the current bucket
|
||||
*/
|
||||
func (b *BoltBucket) BuildVisiblePathSlice(prefix []string, filter string) ([][]string, error) {
|
||||
func (b *BoltBucket) BuildVisiblePathSlice(prefix []string, search string) ([][]string, error) {
|
||||
var retSlice [][]string
|
||||
var retErr error
|
||||
retSlice = append(retSlice, append(prefix, b.name))
|
||||
if b.expanded {
|
||||
if search == "" || strings.Contains(b.name, search) {
|
||||
retSlice = append(retSlice, append(prefix, b.name))
|
||||
}
|
||||
if b.expanded || search != "" {
|
||||
// Add subbuckets
|
||||
for i := range b.buckets {
|
||||
bktS, bktErr := b.buckets[i].BuildVisiblePathSlice(append(prefix, b.name), filter)
|
||||
bktS, bktErr := b.buckets[i].BuildVisiblePathSlice(append(prefix, b.name), search)
|
||||
if bktErr != nil {
|
||||
return retSlice, bktErr
|
||||
}
|
||||
@@ -53,7 +55,7 @@ func (b *BoltBucket) BuildVisiblePathSlice(prefix []string, filter string) ([][]
|
||||
}
|
||||
// Add pairs
|
||||
for i := range b.pairs {
|
||||
if filter != "" && !strings.Contains(b.pairs[i].key, filter) {
|
||||
if search != "" && !strings.Contains(b.pairs[i].key, search) {
|
||||
continue
|
||||
}
|
||||
retSlice = append(retSlice, append(append(prefix, b.name), b.pairs[i].key))
|
||||
|
Reference in New Issue
Block a user