moding-il / bizdoc.core

Developer framework for designing organization forms
Other
2 stars 2 forks source link

Documents chaining #11

Open zehavibarak opened 3 years ago

zehavibarak commented 3 years ago

In some scenarious, documents may be linked to other documents.

When documents are created using DocumentFactory service, it may receive a parentId argument.

  await _documentFactory.CreateAsync("myForm", new MyModel {}, parentId);

You can access the parent id from DocumentContext service.

public class MyForm : FormBase<MyModel> {
  public override async Task FlowResumeAsync([NotNull] MyFormModel model)
  {
    var parentId = _documentContext.Document.ParentId;
    // retrieve chained documents
    var children = from document in _store.Documents where document.ParentId == parentId select document;
  }
}

In the form Angular component, you can then retrieve the document chain.

  onBind(data: RecipientModel) { 
    // retrieve children
    data.children.forEach(c=> …);

    // retrieve parent recursively
    let parent = data.parent;
    while (parent) {
        parent = parent.parent;
    }
  }

  /***
  * get full document info
  */
  onChainExpand(id: number) {
    this._ documentInfo.get(id).subscribe((d: DocumentModel) => …);
  }