Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
fix(paged): change content to slot, allow resource+repository, enable…
Browse files Browse the repository at this point in the history
… error feedback

BREAKING CHANGE: resource appropiately renamed to respository
  • Loading branch information
doktordirk committed Jul 25, 2016
1 parent a3a6d45 commit 5027799
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/component/paged.html
@@ -1,3 +1,3 @@
<template>
<content></content>
<slot></slot>
</template>
28 changes: 23 additions & 5 deletions src/component/paged.js
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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.