Last active
February 24, 2017 16:41
-
-
Save jelhan/faf43bdb207b6594ddaecf7fd44cd936 to your computer and use it in GitHub Desktop.
ember-changeset
This file contains hidden or 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'; | |
const { computed, inject } = Ember; | |
export default Ember.Component.extend({ | |
actions: { | |
cancel() { | |
this.get('model').rollback(); | |
}, | |
save() { | |
this.sendAction('save', this.get('model')); | |
} | |
}, | |
availableProfessions: computed(function() { | |
return this.get('store').findAll('profession'); | |
}), | |
store: inject.service() | |
}); |
This file contains hidden or 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 PersonValidations from '../validations/person'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
PersonValidations | |
}); |
This file contains hidden or 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() { | |
this.resource('people'); | |
this.resource('professions'); | |
}; |
This file contains hidden or 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, belongsTo } from 'ember-cli-mirage'; | |
export default Model.extend({ | |
profession: belongsTo('profession') | |
}); |
This file contains hidden or 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, hasMany } from 'ember-cli-mirage'; | |
export default Model.extend({ | |
persons: hasMany('person') | |
}); |
This file contains hidden or 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(server) { | |
let dentist = server.create('profession', { | |
name: 'dentist' | |
}); | |
server.create('profession', { name: 'student' }); | |
server.create('profession', { name: 'teacher' }); | |
server.create('person', { | |
age: 28, | |
firstName: 'Max', | |
lastName: 'Mustermann', | |
profession: dentist | |
}); | |
}; |
This file contains hidden or 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({ | |
age: attr('number'), | |
firstName: attr('string'), | |
lastName: attr('string'), | |
profession: belongsTo() | |
}); |
This file contains hidden or 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'), | |
persons: hasMany('person') | |
}); |
This file contains hidden or 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({ | |
actions: { | |
create(changeset) { | |
this.store.createRecord('person', changeset.get('change')).save(); | |
}, | |
save(changeset) { | |
changeset.save(); | |
} | |
}, | |
model() { | |
return this.store.findAll('person'); | |
} | |
}); |
This file contains hidden or 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.11.0", | |
"EmberENV": { | |
"EXTEND_PROTOTYPES": { | |
"Date": false | |
}, | |
"FEATURES": {} | |
}, | |
"ENV": { | |
"ember-cli-mirage": { | |
"enabled": true | |
} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.6.2", | |
"ember-data": "2.6.2", | |
"ember-template-compiler": "2.6.2", | |
"ember-testing": "2.6.2" | |
}, | |
"addons": { | |
"ember-bootstrap": "1.0.0-alpha.4", | |
"ember-bootstrap-changeset-validations": "1.0.0-alpha", | |
"ember-changeset": "1.2.2", | |
"ember-changeset-validations": "1.2.5", | |
"ember-cli-mirage": "*", | |
"ember-power-select-with-create": "*", | |
"ember-route-action-helper": "2.0.2" | |
} | |
} |
This file contains hidden or 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, | |
validateNumber | |
} from 'ember-changeset-validations/validators'; | |
export default { | |
age: validateNumber({ gte: 18 }), | |
firstName: validatePresence(true), | |
lastName: validatePresence(true), | |
profession: validatePresence(true) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment