Skip to content

Instantly share code, notes, and snippets.

@gmarquet
Created February 20, 2017 16:03
Show Gist options
  • Save gmarquet/7e600a351c3281bb4897d5bd901e7cf0 to your computer and use it in GitHub Desktop.
Save gmarquet/7e600a351c3281bb4897d5bd901e7cf0 to your computer and use it in GitHub Desktop.
Edit mode without component
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
content: attr(),
post: belongsTo('post'),
});
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(),
comments: hasMany('comment'),
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('post', {path: '/'}, function(){
this.route('edit');
this.route('index', {path: '/'}, function(){
this.route('comments', {path: '/'});
});
});
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
model() {
this.store.push({
data: [{
id: 1,
type: 'post',
attributes: {
title: 'First Post',
},
relationships: {
comments: {
data : [
{id: 1, type: "comment"},
{id: 2, type: "comment"},
{id: 3, type: "comment"},
]
}
}
}],
included: [
{
id: 1,
type: 'comment',
attributes: {
content: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit',
},
relationships: {
post: { data : { id: 1, type: "post"}}
}
},
{
id: 2,
type: 'comment',
attributes: {
content: 'Duis aute irure dolor in reprehenderit in voluptate velit essecillum dolore eu',
},
relationships: {
post: { data : { id: 1, type: "post"}}
}
},
{
id: 3,
type: 'comment',
attributes: {
content: ' Excepteur sint occaecat',
},
relationships: {
post: { data : { id: 1, type: "post"}}
}
},
]
});
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model(){
return this.store.peekRecord('post', 1);
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model(){
return this.store.peekRecord('post', 1).get('comments');
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model(){
return this.store.peekRecord('post', 1);
}
});
{{#link-to 'post.index'}}Post{{/link-to}} |
{{#link-to 'post.edit'}}Edit{{/link-to}} |
{{#link-to 'post.index.comments'}}comments{{/link-to}}
<hr>
{{outlet}}
<br>
<br>
{{input value=model.title}}<br>
{{#link-to 'post.index'}}Cancel{{/link-to}}
<hr>
{{outlet}}
<strong>Comments</strong> <br>
{{#each model as |comment|}}
{{comment.content}} <br>
{{/each}}
Post title: {{model.title}}<br>
{{#link-to 'post.edit'}}Edit post{{/link-to}}
<hr>
{{outlet}}
import Ember from 'ember';
export default function destroyApp(application) {
Ember.run(application, 'destroy');
}
import Resolver from '../../resolver';
import config from '../../config/environment';
const resolver = Resolver.create();
resolver.namespace = {
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix
};
export default resolver;
import Ember from 'ember';
import Application from '../../app';
import config from '../../config/environment';
const { run } = Ember;
const assign = Ember.assign || Ember.merge;
export default function startApp(attrs) {
let application;
let attributes = assign({rootElement: "#test-root"}, config.APP);
attributes = assign(attributes, attrs); // use defaults, but you can override;
run(() => {
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
return application;
}
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
setResolver(resolver);
{
"version": "0.11.0",
"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.10.2",
"ember-data": "2.11.0",
"ember-template-compiler": "2.10.2",
"ember-testing": "2.10.2"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment