jeudi 28 janvier 2016

Ember retry transition from a failed promise with new query params

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);
},




Aucun commentaire:

Enregistrer un commentaire