Created
October 13, 2016 09:24
-
-
Save cbroeren/d79349695dd4da6f7247f5f3874b7574 to your computer and use it in GitHub Desktop.
JSON to data model
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 Controller from 'ember-controller'; | |
| import service from 'ember-service/inject'; | |
| import computed from 'ember-computed'; | |
| import get from 'ember-metal/get'; | |
| import RESULT from '../fixture/ajax-result'; | |
| export default Controller.extend({ | |
| appName: 'JSON to model', | |
| store: service(), | |
| list: computed(function() { | |
| let store = get(this, 'store'); | |
| return RESULT.data.assets.map((asset) => { | |
| asset.old.data.type = 'asset'; | |
| let oldAsset = store.push(asset.old); | |
| let newAsset = store.createRecord('asset', asset.new); | |
| return { | |
| old: oldAsset, | |
| new: newAsset | |
| }; | |
| }); | |
| }) | |
| }); |
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 { | |
| data: { | |
| assets: [ | |
| { | |
| new: { asset_nr: 9991, weight: 14840, capacity_remark: 'foo' }, | |
| old: { | |
| data: { | |
| id: 1, | |
| type: 'assets', | |
| attributes: { | |
| 'asset-nr': 9991, | |
| 'weight': 14000, | |
| 'capacity-remark': 'foo 9991' | |
| } | |
| } | |
| } | |
| }, | |
| { | |
| new: { asset_nr: 9992, weight: undefined, capacity_remark: 'bar' }, | |
| old: { | |
| data: { | |
| id: 2, | |
| type: 'assets', | |
| attributes: { | |
| 'asset-nr': 9992, | |
| 'weight': 12000, | |
| 'capacity-remark': 'bar 9992' | |
| } | |
| } | |
| } | |
| } | |
| ] | |
| } | |
| }; |
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({ | |
| assetNr: attr('string'), | |
| weight: attr('number'), | |
| capacity: attr('number'), | |
| capacityRemark: attr('string') | |
| }); |
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
| body { | |
| margin: 12px 16px; | |
| font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
| font-size: 12pt; | |
| } | |
| table { | |
| border-spacing: 0; | |
| border-collapse: collapse; | |
| } | |
| th { | |
| text-align: left; | |
| } | |
| tr:nth-child(even) { | |
| border-bottom: 1px solid lightgrey; | |
| } | |
| tr:nth-child(odd) { | |
| border-bottom: 1px solid black; | |
| } |
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.10.5", | |
| "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.8.0", | |
| "ember-data": "2.8.0", | |
| "ember-template-compiler": "2.8.0", | |
| "ember-testing": "2.8.0" | |
| }, | |
| "addons": {} | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment