From 5027799d3fb95255e986f4bdb5a8708b221eded1 Mon Sep 17 00:00:00 2001 From: doktordirk Date: Sun, 24 Jul 2016 17:42:50 +0200 Subject: [PATCH] fix(paged): change content to slot, allow resource+repository, enable error feedback BREAKING CHANGE: resource appropiately renamed to respository --- src/component/paged.html | 2 +- src/component/paged.js | 28 +++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/component/paged.html b/src/component/paged.html index 7b07f6c2..1d343592 100644 --- a/src/component/paged.html +++ b/src/component/paged.html @@ -1,3 +1,3 @@ diff --git a/src/component/paged.js b/src/component/paged.js index bc120ed9..921c62f6 100644 --- a/src/component/paged.js +++ b/src/component/paged.js @@ -8,8 +8,10 @@ export class Paged { // https://github.com/aurelia/templating/issues/73, you still had to set `data` on .two-way when global @bindable({defaultBindingMode: bindingMode.twoWay}) data = []; @bindable({defaultBindingMode: bindingMode.twoWay}) page = 1; - @bindable criteria = {}; - @bindable resource = null; + @bindable({defaultBindingMode: bindingMode.twoWay}) error; + @bindable criteria + @bindable repository = null; + @bindable resource @bindable limit = 30; /** @@ -73,17 +75,33 @@ export class Paged { this.reloadData(); } + /** + * Change resource + * @param {string resource New resource value + */ + resourceChanged(resource) { + if (!resource) { + logger.error(`resource is ${typeof resource}. It should be a string or a reference`); + } + + this.repository = this.entityManager.getRepository(resource); + } + /** * Get data from repository */ getData() { - this.criteria.skip = this.page * this.limit - this.limit; - this.criteria.limit = this.limit; + let criteria = JSON.parse(JSON.stringify(this.criteria)); + criteria.skip = this.page * this.limit - this.limit; + criteria.limit = this.limit; + this.error = null; - this.resource.find(this.criteria, true).then(result => { + this.repository.find(criteria, true).then(result => { this.data = result; }).catch(error => { logger.error('Something went wrong.', error); + + this.error = error; }); } }