Last active
January 10, 2018 12:40
-
-
Save BillyRayPreachersSon/1d2349b2f97b88ea20618ec5f764ec99 to your computer and use it in GitHub Desktop.
Changeset test
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 changeset = this.get('model'); | |
console.log( | |
'Widget name:[%s] props.foo:[%s] props.bar:[%s]', | |
changeset.get('name'), | |
changeset.get('props.foo'), | |
changeset.get('props.bar'), | |
); | |
changeset.validate().then(() => { | |
if (changeset.get('isValid')) { | |
console.log('Changeset is valid. Saving...'); | |
changeset.save().then(() => { | |
console.log('Changeset successfully saved'); | |
this.transitionToRoute('index'); | |
}).catch((err) => { | |
console.log('Error while saving changeset:', err); | |
}); | |
} else { | |
console.log('Changeset is not valid. Not saving'); | |
console.log('Changeset error:', changeset.get('error')); | |
console.log('Changeset errors:', changeset.get('errors')); | |
} | |
}); | |
} | |
} | |
}); |
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' }), | |
props: attr('widget-props') | |
}); |
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 lookupValidator from 'ember-changeset-validations'; | |
import WidgetValidations from '../validations/widget'; | |
export default Ember.Route.extend({ | |
model() { | |
let newWidget = this.get('store').createRecord('widget', { | |
props: { | |
foo: 'Foo', | |
bar: 'Bar' | |
} | |
}); | |
return new Changeset(newWidget, lookupValidator(WidgetValidations), WidgetValidations); | |
} | |
}); |
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({ | |
}); |
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
import DS from 'ember-data'; | |
export default DS.Transform.extend({ | |
deserialize(serialised) { | |
return { | |
aDifferentFoo: serialised.foo, | |
aDifferentBar: serialised.bar | |
} | |
}, | |
serialize(deserialised) { | |
return { | |
foo: deserialised.aDifferentFoo, | |
bar: deserialised.aDifferentBar | |
} | |
} | |
}); |
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", | |
"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-template-compiler": "2.16.2", | |
"ember-testing": "2.16.2" | |
}, | |
"addons": { | |
"ember-changeset": "1.4.2-beta.0", | |
"ember-changeset-validations": "1.2.4", | |
"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 validateWidgetProps from '../validators/widget-props'; | |
export default { | |
props: validateWidgetProps() | |
}; |
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
export default function validateWidgetProps() { | |
return (key, response) => { | |
return true; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment