Browse Source

DoRecursive can be stopped, now

Dmitry Yu Okunev 5 years ago
parent
commit
577c697b8b
1 changed files with 16 additions and 4 deletions
  1. 16 4
      unit.go

+ 16 - 4
unit.go

@@ -97,6 +97,10 @@ func (u Unit) View_readTag(fieldName string, parent interface{}, args []interfac
 	return template.HTML(fmt.Sprintf(`<a href="/asu/unitsByID/%v?fullscreen=true">%v — %v</a>`, u.Id, u.Code, name))
 }
 
+func (unit Unit) IsChildrenReady() bool {
+	return unit.childrenReady
+}
+
 type Units []Unit
 
 func (units Units) ToMap() map[int]*Unit {
@@ -140,18 +144,26 @@ func (units Units) CalculateTree() Units {
 	return units
 }
 
-func (unit *Unit) DoRecursive(f func(*Unit, interface{}), arg interface{}) {
-	f(unit, arg)
+func (unit *Unit) DoRecursive(f func(*Unit, interface{}) bool, arg interface{}) bool {
+	if !f(unit, arg) {
+		return false
+	}
 
 	for _, child := range unit.GetChildrenPtrs() {
-		child.DoRecursive(f, arg)
+		if !child.DoRecursive(f, arg) {
+			return false
+		}
 	}
+
+	return true
 }
 
-func (units Units) DoRecursive(f func(*Unit, interface{}), arg interface{}) {
+func (units Units) DoRecursive(f func(*Unit, interface{}) bool, arg interface{}) bool {
 	for _, unit := range units {
 		unit.DoRecursive(f, arg)
 	}
+
+	return true
 }
 
 func (u Unit) GetChildrenPtrs() []*Unit {