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

Commit

Permalink
fix(components): update criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
doktordirk committed Jul 25, 2016
1 parent d741a0c commit 37fe2d9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
40 changes: 35 additions & 5 deletions src/component/association-select.js
Expand Up @@ -8,7 +8,7 @@ import {EntityManager, Entity, OrmMetadata} from '../aurelia-orm';
@customElement('association-select')
@inject(BindingEngine, EntityManager, Element)
export class AssociationSelect {
@bindable criteria = null;
@bindable criteria;

@bindable repository;

Expand All @@ -24,7 +24,7 @@ export class AssociationSelect {

@bindable manyAssociation;

@bindable({defaultBindingMode: bindingMode.twoWay}) value;
@bindable({defaultBindingMode: bindingMode.twoWay}) value ;

@bindable({defaultBindingMode: bindingMode.twoWay}) error;

Expand Down Expand Up @@ -104,7 +104,7 @@ export class AssociationSelect {
return {};
}

return JSON.parse(JSON.stringify(this.criteria));
return JSON.parse(JSON.stringify(this.criteria || {}));
}

/**
Expand Down Expand Up @@ -189,9 +189,22 @@ export class AssociationSelect {
}

/**
* Change resource
* @param {string resource New resource value
* Check if the value is changed
*
* @param {string|{}} newVal New value
* @param {[string|{}]} oldVal Old value
* @return {Boolean} Whenever the value is changed
*/
isChanged(property, newVal, oldVal) {
return !this[property] || !newVal || (newVal === oldVal);
}

/**
* Change resource
*
* @param {{}} newVal New criteria value
* @param {{}} oldVal Old criteria value
*/
resourceChanged(resource) {
if (!resource) {
logger.error(`resource is ${typeof resource}. It should be a string or a reference`);
Expand All @@ -200,6 +213,23 @@ export class AssociationSelect {
this.repository = this.entityManager.getRepository(resource);
}

/**
* Change criteria
*
* @param {{}} newVal New criteria value
* @param {{}} oldVal Old criteria value
*/
criteriaChanged(newVal, oldVal) {
if (this.isChanged('criteria', newVal, oldVal)) {
return;
}

if (this.value) {
this.load(this.value);
}
}


/**
* When attached to the DOM, initialize the component.
*/
Expand Down
24 changes: 20 additions & 4 deletions src/component/paged.js
Expand Up @@ -43,8 +43,8 @@ export class Paged {
* @param {[string|{}]} oldVal Old value
* @return {Boolean} Whenever the value is changed
*/
isChanged(newVal, oldVal) {
return !this.resource || !newVal || (newVal === oldVal);
isChanged(property, newVal, oldVal) {
return !this[property] || !newVal || (newVal === oldVal);
}

/**
Expand All @@ -54,21 +54,37 @@ export class Paged {
* @param {integer} oldVal Old page value
*/
pageChanged(newVal, oldVal) {
if (this.isChanged(newVal, oldVal)) {
if (this.isChanged('resource', newVal, oldVal)
|| this.isChanged('criteria', newVal, oldVal)) {
return;
}

this.reloadData();
}

/**
* Change resource
*
* @param {{}} newVal New resource value
* @param {{}} oldVal Old resource value
*/
resourceChanged(newVal, oldVal) {
if (this.isChanged('resource', newVal, oldVal)) {
return;
}

this.reloadData();
}


/**
* Change criteria
*
* @param {{}} newVal New criteria value
* @param {{}} oldVal Old criteria value
*/
criteriaChanged(newVal, oldVal) {
if (this.isChanged(newVal, oldVal)) {
if (this.isChanged('criteria', newVal, oldVal)) {
return;
}

Expand Down

0 comments on commit 37fe2d9

Please sign in to comment.