Created
June 20, 2016 16:35
-
-
Save timmyomahony/e26ab2cf0ee1df839cfbea5877c4fa62 to your computer and use it in GitHub Desktop.
New Twiddle
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({ | |
tagName: "section", | |
page: 1, | |
paginateBy: 10, | |
paginatedItems: Ember.computed('amenities', 'page', function(){ | |
var i = (parseInt(this.get('page')) - 1) * parseInt(this.get('paginateBy')); | |
var j = i + parseInt(this.get('paginateBy')); | |
return this.get('items').slice(i, j); | |
}), | |
numberOfPages: Ember.computed('page', function(){ | |
var n = this.get('items.length'); | |
var c = parseInt(this.get('paginateBy')); | |
var r = Math.floor(n/c); | |
if(n % c > 0) { | |
r += 1; | |
} | |
return r; | |
}), | |
pageNumbers: Ember.computed('numberOfPages', function(){ | |
var n = Array(this.get('numberOfPages')); | |
for(var i = 0;i < n.length;i++) { | |
n[i] = i + 1; | |
} | |
return n; | |
}), | |
showNext: Ember.computed('page', function(){ | |
return (this.get('page') < this.get('numberOfPages')); | |
}), | |
showPrevious: Ember.computed('page', function(){ | |
return (this.get('page') > 1); | |
}), | |
nextText: 'Next page', | |
previousText: 'Previous page', | |
actions: { | |
nextClicked() { | |
if(this.get('page') + 1 <= this.get('numberOfPages')) { | |
this.set('page', this.get('page') + 1); | |
} | |
}, | |
previousClicked() { | |
if(this.get('page') > 0) { | |
this.set('page', this.get('page') - 1); | |
} | |
}, | |
pageClicked(pageNumber){ | |
this.set('page', pageNumber); | |
} | |
} | |
}); |
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({ | |
tagName: "li" | |
}); |
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({ | |
tagName: "ul" | |
}); |
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({ | |
paginateBy: 6 | |
}); |
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'; | |
let teams = [{ | |
id: 1, | |
name: "Albania" | |
}, | |
{ | |
id: 2, | |
name: "Austria" | |
}, | |
{ | |
id: 3, | |
name: "Belgium" | |
}, | |
{ | |
id: 4, | |
name: "Croatia" | |
}, | |
{ | |
id: 5, | |
name: "Czech Republic" | |
}, | |
{ | |
id: 6, | |
name: "England" | |
}, | |
{ | |
id: 7, | |
name: "France" | |
}, | |
{ | |
id: 8, | |
name: "Germany" | |
}, | |
{ | |
id: 9, | |
name: "Hungary" | |
}, | |
{ | |
id: 10, | |
name: "Iceland" | |
}, | |
{ | |
id: 11, | |
name: "Italy" | |
}, | |
{ | |
id: 12, | |
name: "Northern Ireland" | |
}, | |
{ | |
id: 13, | |
name: "Poland" | |
}, | |
{ | |
id: 14, | |
name: "Portugal" | |
}, | |
{ | |
id: 15, | |
name: "Republic of Ireland" | |
}, | |
{ | |
id: 16, | |
name: "Romania" | |
}, | |
{ | |
id: 17, | |
name: "Russia" | |
}, | |
{ | |
id: 18, | |
name: "Slovakia" | |
}, | |
{ | |
id: 19, | |
name: "Spain" | |
}, | |
{ | |
id: 20, | |
name: "Sweden" | |
}, | |
{ | |
id: 21, | |
name: "Switzerland" | |
}, | |
{ | |
id: 22, | |
name: "Turkey" | |
}, | |
{ | |
id: 23, | |
name: "Ukraine" | |
}, | |
{ | |
id: 24, | |
name: "Wales" | |
} | |
] | |
export default Ember.Route.extend({ | |
model() { | |
return teams; | |
} | |
}); |
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.9.3", | |
"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.6.0", | |
"ember-data": "2.6.1", | |
"ember-template-compiler": "2.6.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment