docsa
5/20/2017 - 9:52 PM

add-on et mirage

add-on et mirage

{
  "version": "0.11.0",
  "ENV": {
    "ember-cli-mirage": {
      "enabled": true
    },
    "emberx-select": {
      "enabled": true
    }
  },
  "EmberENV": {
    "FEATURES": {}
  },
  "options": {
    "use_pods": false,
    "enable-testing": false
  },
  "dependencies": {
    "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
    "ember": "2.12.0",
    "ember-data": "2.11.0",
    "ember-template-compiler": "2.12.0",
    "ember-testing": "2.12.0"
  },
  "addons": {
    "emberx-select": "3.0.0",
    "ember-cli-mirage": "0.2.5"
  }
}
<h1>Welcome to {{appName}}</h1>
<a href="https://github.com/thefrontside/emberx-select/issues/180">Doesn't work with RSVP hash #180</a>
<br>
<br>

<b>Residential Complexes</b>
<ul>
{{#each model.residentialComplexes as |complex|}}
	<li>{{complex.name}}</li>
{{/each}}
</ul>

<b>{{model.realEstate.name}} is part of</b>
{{#x-select 
	value=model.realEstate.residentialComplexId
  action=(action (mut model.realEstate.residentialComplexId)) as |xs|}}
>
  <option value="" disabled>Select a residential complex</option>
  {{#each model.residentialComplexes as |option|}}
    {{#xs.option value=option.id}}{{option.name}}{{/xs.option}}
  {{/each}}
{{/x-select}}

<pre>
model.realEstate.residentialComplexId = {{model.realEstate.residentialComplexId}}
</pre>
import Ember from 'ember';

export default Ember.Route.extend({
	model(params){
    const realEstate = this.store.findRecord('realEstate', '1', { reload: true });
    const residentialComplexes = this.store.findAll('residential-complex');
    return Ember.RSVP.hash({
      realEstate: realEstate,
      residentialComplexes: residentialComplexes,
    });
  },
});
import Model from "ember-data/model";
import attr from "ember-data/attr";

export default Model.extend({
  name: attr('string'),
});
import Model from "ember-data/model";
import attr from "ember-data/attr";

export default Model.extend({
  name: attr('string'),
  residentialComplexId: attr('string'),
});
import { JSONAPISerializer } from 'ember-cli-mirage';

export default JSONAPISerializer.extend({});
export default function(server) {
  const complexes = ['A', 'B', 'C', 'D'];
  complexes.forEach((complexName) => {
    server.create('residential-complex', {
      id: complexName,
      name: `Residential Complex ${complexName}`,
    });
  });
  
  server.create('real-estate', {
    id: '1',
    name: 'Real Estate 1',
    residentialComplexId: 'B',
  });
}
import { Model, belongsTo } from 'ember-cli-mirage';

export default Model.extend({});
import { Model, belongsTo } from 'ember-cli-mirage';

export default Model.extend({});
import Mirage from 'ember-cli-mirage';

export default function() {
  window.server = this;

  this.get('real-estates/');
  this.get('real-estates/:id');
  this.post('real-estates/');
  this.patch('real-estates/:id');
  this.delete('real-estates/:id');
  
  this.get('residential-complexes/');
  this.get('residential-complexes/:id');
  this.post('residential-complexes');
  this.patch('residential-complexes/:id');
  this.delete('residential-complexes/:id');
};
import Ember from 'ember';

export default Ember.Controller.extend({
  appName: 'Ember Twiddle'
});