File

src/app/shared/widgets/select-tree/tree-base.component.ts

Index

Widget inputs
Widget outputs
Properties
Methods

Properties

Protected allRequestsFinished
allRequestsFinished:
Default value : new Subject()

Methods

Protected expandNode
expandNode(currentPath: string[], fullPath: string[], selectOnFinish: boolean)
Parameters :
Name Type Optional
currentPath string[] no
fullPath string[] no
selectOnFinish boolean no
Returns : void
Protected expandPath
expandPath(category: string[], selectOnFinish: )
Parameters :
Name Type Optional Default value
category string[] no
selectOnFinish no true
Returns : void
Protected getTree
getTree()
Returns : TreeComponent
import { flatCopyArray } from "../../components/util";
import { first } from "rxjs/operators";
import { Subject } from "rxjs";
import { TreeComponent } from "angular-tree-component";

export abstract class TreeBaseComponent {
  protected allRequestsFinished = new Subject();

  protected abstract getTree(): TreeComponent;
  protected expandPath(category: string[], selectOnFinish = true) {
    const tree = this.getTree().treeModel;

    let node = tree.getNodeByPath(flatCopyArray(category));
    if (node) {
      node.ensureVisible();
      if (selectOnFinish) {
        node.setIsActive(true);
      }
      return;
    }
    const path = [];
    while (path.length <= category.length) {
      path.push(category[path.length]);
      const processingNode = tree.getNodeByPath(flatCopyArray(path));
      if (!processingNode) {
        this.expandNode(path, category, selectOnFinish);
        break;
      }
    }
  }

  protected expandNode(
    currentPath: string[],
    fullPath: string[],
    selectOnFinish: boolean
  ) {
    const path = currentPath.slice(0, currentPath.length - 1);
    const parent = this.getTree().treeModel.getNodeByPath(flatCopyArray(path));
    if (!parent) {
      console.warn("Cant find parent for path ", path);
      return;
    }
    this.allRequestsFinished.pipe(first()).subscribe(() => {
      if (currentPath.length === fullPath.length) {
        const node = this.getTree().treeModel.getNodeByPath(fullPath);
        node.ensureVisible();
        if (selectOnFinish) {
          node.setIsActive(true);
        }

        return;
      }
      currentPath.push(fullPath[currentPath.length]);
      this.expandNode(currentPath, fullPath, selectOnFinish);
    });

    parent.expand();
  }
}

results matching ""

    No results matching ""