Skip to content

Instantly share code, notes, and snippets.

@sukima
Last active November 28, 2018 19:33
Show Gist options
  • Save sukima/2495cceafba548c10f0fda6f6d53c817 to your computer and use it in GitHub Desktop.
Save sukima/2495cceafba548c10f0fda6f6d53c817 to your computer and use it in GitHub Desktop.
karakalla example
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['card', 'rental-card']
});
import Ember from 'ember';
import { reads } from '@ember/object/computed';
export default Ember.Controller.extend({
queryParams: ['city'],
city: '',
rentals: reads('model')
});
export default function() {
this.get('/rentals', function(schema, request) {
let city = request.queryParams.city;
return city
? schema.rentals.where({ city })
: schema.rentals.all();
}, { timing: 3000 });
}
import { Factory } from 'ember-cli-mirage';
export default Factory.extend({
title() { return faker.company.catchPhrase(); },
owner() { return faker.name.findName(); },
city() { return faker.address.city(); },
category: faker.list.random('Estate', 'Appartment', 'Tent'),
bedrooms() { return faker.random.number(); },
image() { return faker.image.imageUrl(); },
description() { return faker.lorem.paragraph(); }
});
export default function(server) {
server.createList('rental', 10);
}
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { belongsTo, hasMany } from 'ember-data/relationships';
export default Model.extend({
title: attr('string'),
owner: attr('string'),
city: attr('string'),
category: attr('string'),
bedrooms: attr('number'),
image: attr('string'),
description: attr('string')
});
import Ember from 'ember';
export default Ember.Route.extend({
queryParams: {
city: { refreshModel: true }
},
model({ city }) {
return this.store.query('rental', { city });
}
});
<div class="hack container">
{{outlet}}
</div>
<header class="card-header">{{rental.title}} - <a href role="button" {{action chooseCity rental.city}}>{{rental.city}}</a></header>
<div class="card-content">
<div class="inner">
{{rental.description}}
</div>
</div>
<div class="alert alert-error">
{{model}}
</div>
<div class="alert alert-info">
Loading&hellip; <span class="loading"></span>
</div>
<button class="btn btn-default btn-ghost" {{action (mut city) ""}}>Clear filter</button>
<div>
{{#each rentals as |rental|}}
{{rental-card rental=rental chooseCity=(action (mut city))}}
{{/each}}
</div>
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"ENV": {
"ember-cli-mirage": {
"enabled": true
}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"hack_css": "https://cdnjs.cloudflare.com/ajax/libs/hack/0.8.0/hack.css",
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2",
"ember-cli-mirage": "latest"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment