Last active
January 10, 2018 11:41
-
-
Save BillyRayPreachersSon/c6c7cca561f5bb57bba90bbad1b1eccd to your computer and use it in GitHub Desktop.
Changeset test (with Mirage)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
actions: { | |
save() { | |
let model = this.get('model'); | |
console.log( | |
'Saving model: [%s] [%s] [%s]', | |
model.get('name'), | |
model.get('blurb1'), | |
model.get('blurb2'), | |
); | |
model.save().then(() => { | |
this.transitionToRoute('index'); | |
}); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//import Collection from 'ember-cli-mirage/orm/collection'; | |
export default function() { | |
//window.server = this; | |
this.get('/widgets', function (schema, request) { | |
if (schema.widgets.all().models.length === 0) { | |
// Bootstrap some widget data if none already exists | |
schema.db.widgets.insert([ | |
{ name:'Widget 1', blurb1:'Lorum', blurb2:'ipsum' }, | |
{ name:'Widget 2', blurb1:'dolor', blurb2:'sit amet' } | |
]); | |
} | |
let widgets = schema.widgets.all(); | |
return widgets.models; | |
}); | |
this.post('/widgets', function(schema, request) { | |
const requestBodyData = JSON.parse(request.requestBody); | |
return schema.widgets.create(requestBodyData.data.attributes); | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
name: attr('string', { defaultValue: 'New widget' }), | |
blurb1: attr('string', { defaultValue: 'Foo' }), | |
blurb2: attr('string', { defaultValue: 'Bar' }) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import config from './config/environment'; | |
const Router = Ember.Router.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('create'); | |
}); | |
export default Router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import Changeset from 'ember-changeset'; | |
import WidgetValidations from '../validations/widget'; | |
export default Ember.Route.extend({ | |
model() { | |
let newWidget = this.get('store').createRecord('widget'); | |
return new Changeset(newWidget); | |
//return newWidget; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model() { | |
return $.get('/widgets'); | |
//return this.get('store').findAll('widget'); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* { | |
box-sizing: border-box; | |
} | |
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
nav { | |
border-top: 1px solid black; | |
border-bottom: 1px solid black; | |
margin-bottom: 2em; | |
padding: 10px 0px 14px 0px; | |
} | |
li { | |
margin-bottom: 1em; | |
} | |
li > div { | |
margin-bottom: 0.25em; | |
} | |
form > div.row { | |
margin-bottom: 1.5em; | |
background-color: #eeeeee; | |
padding: 10px; | |
} | |
form > div.row > label { | |
display: block; | |
margin-bottom: 8px; | |
} | |
form > div.row > input[type="text"] { | |
font-size: 1em; | |
width: 100%; | |
padding: 2px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.13.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.16.2", | |
"ember-changeset-validations": "1.2.8", | |
"ember-template-compiler": "2.16.2", | |
"ember-testing": "2.16.2" | |
}, | |
"addons": { | |
"ember-changeset": "1.3.0", | |
"ember-cli-mirage": "0.4.1", | |
"ember-data": "2.16.3" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
validatePresence, | |
validateLength | |
} from 'ember-changeset-validations/validators'; | |
export default { | |
name: [ | |
validatePresence(true), | |
validateLength({ min: 8 }) | |
] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment