Forked from vigneshrajarr/controllers.application.js
Last active
January 15, 2019 04:46
-
-
Save BenjaminBeck/4a907b966d0c071ba214ab0fe1e679f6 to your computer and use it in GitHub Desktop.
demo ember-models-table async filter/sort
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.RESTAdapter.extend({ | |
//namespace: 'api', | |
host: 'https://jsonplaceholder.typicode.com', | |
//coalesceFindRequests: true | |
handleResponse: function handleResponse(status, headers, payload, requestData) { | |
let result = this._super(...arguments); | |
result = {album: result} | |
return result; | |
}, | |
}); |
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.RESTAdapter.extend({ | |
//namespace: 'api', | |
host: 'https://jsonplaceholder.typicode.com', | |
//coalesceFindRequests: true | |
handleResponse: function handleResponse(status, headers, payload, requestData) { | |
let result = this._super(...arguments); | |
console.log(result); | |
return result; | |
}, | |
}); |
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.RESTAdapter.extend({ | |
//namespace: 'api', | |
host: 'https://jsonplaceholder.typicode.com', | |
//coalesceFindRequests: true | |
handleResponse: function handleResponse(status, headers, payload, requestData) { | |
let result = this._super(...arguments); | |
for(let i=0; i<result.length; i++){ | |
result[i]["album"] = { | |
id: Math.floor(Math.random() * 100) + 1, | |
//id: result[i]["albumId"], | |
type: 'album' | |
} | |
} | |
result = {photo: result} | |
return result; | |
}, | |
}); |
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({ | |
store: Ember.inject.service(), | |
columns: [ | |
{propertyName: 'id', title: 'id as string', className:'small-col'}, | |
{propertyName: 'idSortable', title: 'is as integer', className:'small-col'}, | |
{propertyName: 'title'}, | |
{propertyName: 'numberOfPhotos', title:'Number of Photos (1)'}, | |
{propertyName: 'numberOfPhotos', title:'Number of Photos (2)', component:'table/cell-number-of-photos', sortedBy:'numberOfPhotos'} | |
], | |
photos: Ember.computed(function(){ | |
let result = this.store.findAll('photo'); | |
console.log('photos', result); | |
return result; | |
}) | |
}); |
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.Model.extend({ | |
title: DS.attr('string'), | |
photos: DS.hasMany('photos'), | |
idSortable: Ember.computed('id', function(){ | |
let id = this.get('id'); | |
return parseInt(id); | |
}), | |
numberOfPhotos: Ember.computed('photos.[]', async function(){ | |
let photos = await this.get('photos'); | |
return photos.length; | |
}) | |
}); |
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.Model.extend({ | |
title: DS.attr('string'), | |
url: DS.attr('string'), | |
thumbnailUrl: DS.attr('string'), | |
album: DS.belongsTo('album') | |
}); |
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 DS from "ember-data"; | |
export default Ember.Route.extend({ | |
model: async function() { | |
let photos = this.store.findAll('photo'); | |
let result = await this.store.findAll('album'); | |
console.log(result); | |
return result; | |
} | |
}); |
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.RESTSerializer.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
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
table, tr, th, td | |
{ | |
border:1px solid #000; | |
} | |
th | |
{ | |
cursor:pointer; | |
} |
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.14.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"lodash": "https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.js", | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "2.18.2", | |
"ember-template-compiler": "2.18.2", | |
"jquery-mockjax": "https://cdn.jsdelivr.net/gh/jakerella/jquery-mockjax/dist/jquery.mockjax.js" | |
}, | |
"addons": { | |
"ember-promise-helpers": "1.0.5", | |
"ember-data": "2.18.5", | |
"ember-models-table": "2.9.0-beta.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment