0
votes

I have a route called estates where users will see a list of estates they own and from which they can view the details of one estate.

In order to enter the estate route, I must pass an estate_id and a mode parameter. The mode is, by default, set to open

model(params) {
  return this.store.queryRecord('estate', params);
},

In some cases can return an error asking for a different mode. In that situation, the users will be prompted to choose either between "backup" or "saved" via a popup, since it must be a user's made decision. I tried the following expecting the queryParamsDidChange hook to retry the transition but it did not work since Ember has not entered yet the estate route. So how can I could I retry a transition that never resolved with modified query params?

Estate model extract:

queryParams: {
  mode: {
    refreshModel: true,
    replace: true
  }
},


actions: {
  error(reason, transition) {
    // 1. Abort the transition so that we don't default to the error page.
    transition.abort();

    // 2. Set controller's previousTransition property so that we can retry it.
    this.controllerFor('estate').set('previousTransiton', transition);

    // 3. Parse the error
    const promiseErrors = reason.errors;

    for (let e=0; e<promiseErrors.length; e++) {
      switch(promiseErrors[e].reason) {
        case 'backupOrSaved':
          this.send('showErrorOnEstateOpen');
          return;
      }
    }
  },
},

Estate controller extract:

queryParams: ['mode'],
mode: 'open',

eventBusService: Ember.inject.service('event-bus'),

_listen: function() {
  this.get('eventBusService').on('alterEstateOpenMode', this,   '_alterOpenMode');
}.on('init'),

_alterOpenMode(mod) {
  this.set('mode', mod.mode);
},
1

1 Answers

0
votes

I'm not sure this is the way to do it, but if I were in your situation, I would just go about reconstructing a new transitionTo with different query params from the old transition.

If you have no dynamic segments to your transition, you could simply do

//your transition
var transition = someSavedTransition;
var newQueryParams = {foo: "foo"};
this.transitionTo(transition.targetName, newQueryParams);

If you have dynamic segments, or you need this to be more generic, you will need to extract the transition.params and probably transitionTo.apply(route, anArrayYouBuilt) where arrayYouBuilt has the transition at index 0, all the models index 1->(n-1) and the query params at n, where n = number of dynamic segs + 1.

Lastly, the transition has queryParmas on its object so if you want to replace only one of the queryParams and keep the rest in your new transitionTo, $.extend(transition.queryParams, {keyToReplace: valueToReplace});

hope that helps