Last active
August 11, 2017 13:18
-
-
Save angelomachado/c0655d0dfeadb649c082321ab29b6a4c to your computer and use it in GitHub Desktop.
Controle de estoque
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.Component.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
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Controle de estoque' | |
}); |
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() { | |
window.server = this; | |
this.resource('products'); | |
this.resource('stocks'); | |
}; |
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'), | |
stocks: hasMany() | |
}); |
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({ | |
quantidade: attr('number'), | |
product: belongsTo() | |
}); |
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 JSONAPISerializer from 'ember-data/serializers/json-api'; | |
export default JSONAPISerializer.extend({ | |
serializeHasMany(snapshot, json, relationship) { | |
this._super(...arguments); | |
const key = relationship.key; | |
const hasMany = snapshot.hasMany(key); | |
if (!hasMany || !hasMany.length) { | |
return; | |
} | |
const payloadKey = this.keyForRelationship(key, 'hasMany', 'serialize'); | |
const data = new Array(hasMany.length); | |
for (let i = 0; i < hasMany.length; i++) { | |
const item = hasMany[i]; | |
data[i] = item.serialize({ includeId: true }).data; | |
} | |
json.relationships = json.relationships || {}; | |
json.relationships[payloadKey] = { data }; | |
}, | |
updateRecord(json, store) { | |
// if (!json.attributes) { | |
// // return non-attribute (id/type only) JSON intact | |
// return json; | |
// } | |
console.log('normalized json: ', json); | |
// const record = store.peekAll(json.type) | |
// .filterBy('currentState.stateName', "root.loaded.created.uncommitted") | |
// .findBy('_internalModel.' + Ember.GUID_KEY, json.attributes.__id__); | |
// if (record) { | |
// record.set('id', json.id); | |
// record._internalModel.flushChangedAttributes(); | |
// record._internalModel.adapterWillCommit(); | |
// store.didSaveRecord(record._internalModel); | |
// } | |
return json; | |
}, | |
// normalizeSaveResponse(store, modelName, obj) { | |
// const rels = obj.data.relationships || []; | |
// Object.keys(rels).forEach(rel => { | |
// // guard against potential `null` relationship, allowed by JSON API | |
// if (!rels[rel]) { | |
// return; | |
// } | |
// let relationshipData = rels[rel].data; | |
// if (Array.isArray(relationshipData)) { | |
// // hasMany | |
// relationshipData = relationshipData.map(json => { | |
// json.type = Ember.String.singularize(json.type); | |
// this.updateRecord(json, store); | |
// }); | |
// } | |
// }); | |
// return this._super(store, modelName, obj); | |
// } | |
}); |
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.12.1", | |
"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.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
}, | |
"addons": { | |
"ember-data": "2.12.1", | |
"ember-cli-mirage": "0.3.4", | |
"ember-one-way-controls": "2.0.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment