Skip to content

Instantly share code, notes, and snippets.

@tamebadger
Created May 15, 2016 13:41
Show Gist options
  • Save tamebadger/f87e57b183074129fb6573e9c6c96138 to your computer and use it in GitHub Desktop.
Save tamebadger/f87e57b183074129fb6573e9c6c96138 to your computer and use it in GitHub Desktop.
Simple Example
import Ember from 'ember';
export default Ember.Controller.extend({
})
import Ember from 'ember';
export default Ember.Controller.extend({
currentlyOpen: null,
actions: {
open(title){
const typeHash = this.get(title)
this.set('currentlyOpen',typeHash)
}
}
});
import Ember from 'ember';
export function eq(params) {
return params[0] === params[1];
}
export default Ember.Helper.helper(eq);
export default function() {
window.server = this;
this.get('users')
this.get('todos')
};
export default [
{id:1,title:'First Todo',creator:1,editor:2},
{id:2,title:'Second Todo'},
]
export default [
{id:1,name:'User 1'},
{id:2,name:'User 2'},
]
import { Model, belongsTo } from 'ember-cli-mirage';
export default Model.extend({
//creator: belongsTo(),
//editor: belongsTo()
});
import { Model } from 'ember-cli-mirage';
export default Model.extend({
});
export default function(server) {
window.server = server;
server.create('todo');
server.create('user');
}
import Model from 'ember-data/model'
import attr from 'ember-data/attr'
import { belongsTo } from 'ember-data/relationships'
export default Model.extend({
title: attr('string'),
done: attr('boolean'),
editor: belongsTo('user'),
creator: belongsTo('user'),
createdAt: attr('date'),
modifiedAt: attr('date')
})
import Model from 'ember-data/model'
import attr from 'ember-data/attr'
export default Model.extend({
name: attr('string')
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none'
});
Router.map(function() {
this.route('todos')
this.route('new')
this.route('edit', { path: 'edit/:todo_id' })
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return Ember.RSVP.hash({
todo: this.store.findRecord('todo',params.todo_id),
users: this.store.findAll('user')
})
},
setupController(controller, model){
this._super(controller,model)
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return Ember.RSVP.hash({
todo: this.store.createRecord('todo'),
users: this.store.findAll('user')
})
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return this.store.findAll('todo')
}
});
{{link-to 'All Todos' 'todos'}}|{{link-to 'New Todo' 'new'}}<br>
{{outlet}}
Edit Todo:<br/>
{{input value=model.title}}<br/>
Task Completed:{{input type='checkbox' checked=model.todo.done}}<br/>
Select Creator:
<select onchange={{action (mut model.todo.creator) value="target.value"}}>
{{#each model.users as |userChoice|}}
<option value={{userChoice.name}} selected={{eq user userChoice}}>{{userChoice.name}}</option>
{{/each}}
</select>
Select Editor:
<select onchange={{action (mut model.todo.editor) value="target.value"}}>
{{#each model.users as |userChoice|}}
<option value={{userChoice.name}} selected={{eq user userChoice}}>{{userChoice.name}}</option>
{{/each}}
</select>
New Todo:<br/>
{{input value=model.todo.title}}<br/>
Select Creator:
<select onchange={{action (mut model.todo.creator) value="target.value"}}>
{{#each model.users as |userChoice|}}
<option value={{userChoice.name}} selected={{eq user userChoice}}>{{userChoice.name}}</option>
{{/each}}
</select>
Select Editor:
<select onchange={{action (mut model.todo.editor) value="target.value"}}>
{{#each model.users as |userChoice|}}
<option value={{userChoice.name}} selected={{eq user userChoice}}>{{userChoice.name}}</option>
{{/each}}
</select>
Todos:
<hr/>
<ul>
{{#each model as |todo|}}
<li>
{{input type='checkbox' checked=todo.done}}
{{todo.title}}
{{#link-to 'edit' todo}}
Edit
{{/link-to}}
Editor:{{todo.editor.name}}
</li>
{{/each}}
</ul>
{
"version": "0.8.0",
"ENV": {
"ember-cli-mirage": {
"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.5.1",
"ember-data": "2.5.2",
"ember-template-compiler": "2.5.1"
},
"addons": {
"ember-cli-mirage": "0.2.0-beta.8"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment