Browse Source

Non-recursive children prepare

Dmitry Yu Okunev 5 years ago
parent
commit
61c2a38e63
2 changed files with 19 additions and 2 deletions
  1. 1 0
      formular.go
  2. 18 2
      unit.go

+ 1 - 0
formular.go

@@ -63,6 +63,7 @@ func (f *Formular) AfterFind() error {
 	if f.UnitShortName != nil {
 		*f.UnitShortName = strings.Trim(*f.UnitShortName, " ")
 	}
+	f.UnitName = strings.Trim(f.UnitName, " ")
 	return nil
 }
 

+ 18 - 2
unit.go

@@ -256,7 +256,7 @@ func (u Unit) IsActive() bool {
 	return u.isActive
 }
 
-func (u *Unit) PrepareChildrenTree() *Unit {
+func (u *Unit) prepareChildrenTree(recursive bool) *Unit {
 	if u.childrenReady {
 		return u
 	}
@@ -272,7 +272,9 @@ func (u *Unit) PrepareChildrenTree() *Unit {
 
 	for idx, _ := range children {
 		child := &children[idx]
-		child.PrepareChildrenTree()
+		if recursive {
+			child.PrepareChildrenTree()
+		}
 
 		u.children = append(u.children, child)
 	}
@@ -281,6 +283,13 @@ func (u *Unit) PrepareChildrenTree() *Unit {
 
 	return u
 }
+func (u *Unit) PrepareChildrenTree() *Unit {
+	return u.prepareChildrenTree(true)
+}
+func (u *Unit) PrepareChildren() *Unit {
+	return u.prepareChildrenTree(false)
+}
+
 func (units Units) PrepareChildrenTree() Units {
 	for idx, _ := range units {
 		units[idx].PrepareChildrenTree()
@@ -288,6 +297,13 @@ func (units Units) PrepareChildrenTree() Units {
 
 	return units
 }
+func (units Units) PrepareChildren() Units {
+	for idx, _ := range units {
+		units[idx].PrepareChildren()
+	}
+
+	return units
+}
 
 func GetUnitsHeadedBy(empGUID int) (units Units) {
 	var formulars Formulars