Permalink
Browse files

fix(paged): change content to slot, allow resource+repository, enable…

… error feedback

BREAKING CHANGE: resource appropiately renamed to respository
  • Loading branch information...
doktordirk committed Jul 24, 2016
1 parent a3a6d45 commit 5027799d3fb95255e986f4bdb5a8708b221eded1
Showing with 24 additions and 6 deletions.
  1. +1 −1 src/component/paged.html
  2. +23 −5 src/component/paged.js
@@ -1,3 +1,3 @@
<template>
<content></content>
<slot></slot>
</template>
@@ -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;
});
}
}

0 comments on commit 5027799

Please sign in to comment.