Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update paged-remote-array.js #143

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions addon/components/page-numbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import Ember from 'ember';
import Util from 'ember-cli-pagination/util';
import PageItems from 'ember-cli-pagination/lib/page-items';
import Validate from 'ember-cli-pagination/validate';

export default Ember.Component.extend({
currentPageBinding: "content.page",
totalPagesBinding: "content.totalPages",

hasPages: Ember.computed.gt('totalPages', 1),

watchInvalidPage: function() {
var me = this;
var c = this.get('content');
if (c && c.on) {
c.on('invalidPage', function(e) {
me.sendAction('invalidPageAction',e);
});
}
}.observes("content"),

truncatePages: true,
numPagesToShow: 10,

validate: function() {
if (Util.isBlank(this.get('currentPage'))) {
Validate.internalError("no currentPage for page-numbers");
}
if (Util.isBlank(this.get('totalPages'))) {
Validate.internalError('no totalPages for page-numbers');
}
},

pageItemsObj: function() {
return PageItems.create({
parent: this,
currentPageBinding: "parent.currentPage",
totalPagesBinding: "parent.totalPages",
truncatePagesBinding: "parent.truncatePages",
numPagesToShowBinding: "parent.numPagesToShow",
showFLBinding: "parent.showFL"
});
}.property(),

//pageItemsBinding: "pageItemsObj.pageItems",

pageItems: function() {
this.validate();
return this.get("pageItemsObj.pageItems");
}.property("pageItemsObj.pageItems","pageItemsObj"),

canStepForward: (function() {
var page = Number(this.get("currentPage"));
var totalPages = Number(this.get("totalPages"));
return page < totalPages;
}).property("currentPage", "totalPages"),

canStepBackward: (function() {
var page = Number(this.get("currentPage"));
return page > 1;
}).property("currentPage"),

actions: {
pageClicked: function(number) {
Util.log("PageNumbers#pageClicked number " + number);
this.set("currentPage", number);
this.sendAction('action',number);
},
incrementPage: function(num) {
var currentPage = Number(this.get("currentPage")),
totalPages = Number(this.get("totalPages"));

if(currentPage === totalPages && num === 1) { return false; }
if(currentPage <= 1 && num === -1) { return false; }
this.incrementProperty('currentPage', num);

var newPage = this.get('currentPage');
this.sendAction('action',newPage);
}
}
});
6 changes: 3 additions & 3 deletions addon/remote/paged-remote-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ export default Ember.ArrayProxy.extend(PageMixin, Ember.Evented, ArrayProxyPromi
}

try {
this.get('promise');
return this.get('promise');
}
catch (e) {
this.set('promise', this.fetchContent());
return this.set('promise', this.fetchContent());
}
},

Expand Down Expand Up @@ -134,4 +134,4 @@ export default Ember.ArrayProxy.extend(PageMixin, Ember.Evented, ArrayProxyPromi
this.incrementProperty('paramsForBackendCounter');
Ember.run.once(this,"pageChanged");
}
});
});
82 changes: 2 additions & 80 deletions app/components/page-numbers.js
Original file line number Diff line number Diff line change
@@ -1,81 +1,3 @@
import Ember from 'ember';
import Util from 'ember-cli-pagination/util';
import PageItems from 'ember-cli-pagination/lib/page-items';
import Validate from 'ember-cli-pagination/validate';
import PageNumbers from 'ember-cli-pagination/components/page-numbers';

export default Ember.Component.extend({
currentPageBinding: "content.page",
totalPagesBinding: "content.totalPages",

hasPages: Ember.computed.gt('totalPages', 1),

watchInvalidPage: function() {
var me = this;
var c = this.get('content');
if (c && c.on) {
c.on('invalidPage', function(e) {
me.sendAction('invalidPageAction',e);
});
}
}.observes("content"),

truncatePages: true,
numPagesToShow: 10,

validate: function() {
if (Util.isBlank(this.get('currentPage'))) {
Validate.internalError("no currentPage for page-numbers");
}
if (Util.isBlank(this.get('totalPages'))) {
Validate.internalError('no totalPages for page-numbers');
}
},

pageItemsObj: function() {
return PageItems.create({
parent: this,
currentPageBinding: "parent.currentPage",
totalPagesBinding: "parent.totalPages",
truncatePagesBinding: "parent.truncatePages",
numPagesToShowBinding: "parent.numPagesToShow",
showFLBinding: "parent.showFL"
});
}.property(),

//pageItemsBinding: "pageItemsObj.pageItems",

pageItems: function() {
this.validate();
return this.get("pageItemsObj.pageItems");
}.property("pageItemsObj.pageItems","pageItemsObj"),

canStepForward: (function() {
var page = Number(this.get("currentPage"));
var totalPages = Number(this.get("totalPages"));
return page < totalPages;
}).property("currentPage", "totalPages"),

canStepBackward: (function() {
var page = Number(this.get("currentPage"));
return page > 1;
}).property("currentPage"),

actions: {
pageClicked: function(number) {
Util.log("PageNumbers#pageClicked number " + number);
this.set("currentPage", number);
this.sendAction('action',number);
},
incrementPage: function(num) {
var currentPage = Number(this.get("currentPage")),
totalPages = Number(this.get("totalPages"));

if(currentPage === totalPages && num === 1) { return false; }
if(currentPage <= 1 && num === -1) { return false; }
this.incrementProperty('currentPage', num);

var newPage = this.get('currentPage');
this.sendAction('action',newPage);
}
}
});
export default PageNumbers;