Last active
December 29, 2017 11:52
-
-
Save onechiporenko/a671b54d9519da5f68c21cfc194232d6 to your computer and use it in GitHub Desktop.
Server paginated table usage (v2.3.0)
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 DS from 'ember-data'; | |
export default DS.JSONAPIAdapter.extend({ | |
host: 'https://www.googleapis.com', | |
namespace: 'books/v1/volumes' | |
}); |
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 ApplicationAdapter from './application'; | |
export default ApplicationAdapter.extend({ | |
query(store, type, {page = 1, maxResults = 10}) { | |
const url = `${this.get('host')}/${this.get('namespace')}`; | |
const startIndex = (page - 1) * maxResults; | |
return this.ajax(url, 'GET', {data: {q: 'javascript', startIndex, maxResults}}); | |
} | |
}); |
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 SemanticUiTheme from 'app/themes/semanticui'; | |
import ModelsTableServerPaginated from './models-table-server-paginated'; | |
import layout from 'app/templates/components/my-table'; | |
export default ModelsTableServerPaginated.extend({ | |
layout, | |
useFilteringByColumns: false, | |
expandedRowComponent: 'book-details', | |
themeInstance: SemanticUiTheme.create(), | |
filterQueryParameters: { | |
page: 'page', | |
pageSize: 'maxResults' | |
}, | |
pageSizeValues: [10, 20, 40], | |
columns: [ | |
{component: 'toggle-expand', mayBeHidden: false}, | |
{propertyName: 'id', useSorting: false}, | |
{propertyName: 'title', useSorting: false}, | |
{propertyName: 'authors', useSorting: false}, | |
{propertyName: 'pageCount', useSorting: false}, | |
{propertyName: 'maturityRating', useSorting: false}, | |
{propertyName: 'contentVersion', useSorting: false}, | |
{propertyName: 'language', useSorting: false}, | |
{propertyName: 'price', useSorting: false} | |
] | |
}); |
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.Component.extend({ | |
actions: { | |
collapseRow(index, record) { | |
this.get('collapseRow')(index, record); | |
}, | |
expandRow(index, record) { | |
this.get('expandRow')(index, record); | |
} | |
} | |
}); |
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.Controller.extend({ | |
appName: 'Server paginated table usage' | |
}); |
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 SemanticUiTheme from '../themes/semanticui'; | |
export default Ember.Controller.extend({ | |
expandedRowComponent: 'book-details', | |
themeInstance: SemanticUiTheme.create({ | |
'expand-row': 'icon plus', | |
'collapse-row': 'icon minus', | |
}), | |
filterQueryParameters: { | |
page: 'page', | |
pageSize: 'maxResults' | |
}, | |
pageSizeValues: [10, 20, 40], | |
columns: [ | |
{component: 'toggle-expand', mayBeHidden: false}, | |
{propertyName: 'id', useSorting: false}, | |
{propertyName: 'title', useSorting: false}, | |
{propertyName: 'authors', useSorting: false}, | |
{propertyName: 'pageCount', useSorting: false}, | |
{propertyName: 'maturityRating', useSorting: false}, | |
{propertyName: 'contentVersion', useSorting: false}, | |
{propertyName: 'language', useSorting: false}, | |
{propertyName: 'price', useSorting: false} | |
] | |
}); |
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 Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
pageCount: attr('number'), | |
title: attr('string'), | |
publishedDate: attr('date'), | |
maturityRating: attr('string'), | |
contentVersion: attr('string'), | |
language: attr('string'), | |
thumb: attr('string'), | |
authors: attr('string'), | |
categories: attr('string'), | |
description: attr('string'), | |
publisher: attr('string'), | |
currencyCode: attr('string'), | |
amount: attr('number'), | |
price: Ember.computed('amount', 'currencyCode', function () { | |
const amount = this.get('amount') || 'n/a'; | |
const currencyCode = this.get('currencyCode') || ''; | |
return `${amount} ${currencyCode}`; | |
}) | |
}); |
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({ | |
model() { | |
return this.get('store').query('book', {}); | |
} | |
}); |
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 DS from 'ember-data'; | |
export default DS.JSONAPISerializer.extend({ | |
}); |
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 ApplicationSerializer from './application'; | |
export default ApplicationSerializer.extend({ | |
normalizeQueryResponse(a, b, payload) { | |
payload.totalItems = payload.totalItems > 120 ? 120 : payload.totalItems; // use only first 120 items | |
payload.data = payload.items.map(item => { | |
const dataItem = { | |
id: item.id, | |
type: 'book', | |
attributes: item.volumeInfo | |
}; | |
dataItem.attributes.authors = (dataItem.attributes.authors || []).join(', '); | |
dataItem.attributes.categories = (dataItem.attributes.categories || []).join(', '); | |
dataItem.attributes.thumb = (dataItem.attributes.imageLinks || {}).thumbnail; | |
dataItem.attributes.amount = Ember.get(item, 'saleInfo.listPrice.amount'); | |
dataItem.attributes.currencyCode = Ember.get(item, 'saleInfo.listPrice.currencyCode'); | |
return dataItem; | |
}); | |
payload.meta = { | |
pagesCount: Math.round(payload.totalItems / payload.data.length), | |
itemsCount: payload.totalItems | |
}; | |
return payload; | |
} | |
}); |
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.12.1", | |
"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-models-table": "2.3.0", | |
"semantic-ui-ember": "2.0.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment