3

I am developing an aurelia app. I have a component (which is a full-page component and is navigable) and also in another page, I want to use this component as a prompt to let user choose from that page. So I have written the code below to open it as intended:

selectTaskFromTree(callbackOrSuccess, failure) {
    const dialog = this.dialogService
      .open({ viewModel: PLATFORM.moduleName('features/view/tree/tree'), model: {}, lock: false });

    if (callbackOrSuccess) {
      if (failure) {
        dialog.whenClosed(response => {
          if (!response.wasCancelled) {
            callbackOrSuccess(response.output);
          } else {
            failure(response);
          }
        });
      }
      else{
        dialog.whenClosed(callbackOrSuccess);
      }
      return;
    }
    else{
      return dialog;
    }
  }

So the component Tree is now successfully loaded and shown. The problem is now how to determine if the TreeComponent is opened as a dialog or not.

The way I am thinking about is to pass an arbitrary param to it and if the param is true, the status is dialog and otherwise not dialog:

  const dialog = this.dialogService
      .open({ viewModel: PLATFORM.moduleName('features/view/tree/tree'), model: {isDialog: true}, lock: false });

But I think maybe there is also a better way to do this. For example to ask from DialogService if I am a dialog or not. So what are the other solutions and which one is better?

ConductedClever
  • 4,175
  • 2
  • 35
  • 69
  • 2
    I think that the solution of sending this data as a parameter (to the model) is a very good choice. you can leverage the same method to pass along all kind of data in this clean way. – avrahamcool Jan 01 '20 at 19:54

2 Answers2

1

To determine whether or not you have an open (or active) dialog you can ask DialogService for the relevant fields:

this.dialogService.hasOpenDialog
this.dialogService.hasActiveDialog

Sadly, this cannot tell you which dialog is open. I would argue that your idea of passing a param to the model is an equally valid way of doing it.

Henrik Erstad
  • 681
  • 3
  • 11
  • 21
1

I have thought about different solutions and I was seeking for keeping coupling low and preventing define of new param. So I wrote the below code where I want to know if this component is opened as a dialog or not:

  attached() {
    this._isDialog = Boolean(this.dialogController.settings);
  }
ConductedClever
  • 4,175
  • 2
  • 35
  • 69