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

Commit

Permalink
refactor(project): remove event aggre, make criteria two-way bindable
Browse files Browse the repository at this point in the history
  • Loading branch information
VMBindraban committed May 31, 2016
1 parent efb7740 commit 04f0a32
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@
"dist": "dist/amd"
},
"dependencies": {
"aurelia-event-aggregator": "^1.0.0-beta.1.2.1"
"aurelia-framework": "^1.0.0-beta.1.0.5",
"json-statham": "^1.3.0",
"aurelia-router": "^1.0.0-beta.1"
},
"devDependencies": {
"aurelia-framework": "^1.0.0-beta.1.0.5",
"aurelia-orm": "^3.0.0-rc2",
"aurelia-polyfills": "^1.0.0-beta.1.1.0",
"aurelia-router": "^1.0.0-beta.1",
"babel": "babel-core@^5.8.24",
"babel-runtime": "^5.8.24",
"core-js": "^1.1.4",
"json-statham": "^1.3.0"
"core-js": "^1.1.4"
}
}
}
32 changes: 13 additions & 19 deletions src/data-table.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {bindable, inject, computedFrom, customElement} from 'aurelia-framework';
import {EventAggregator} from 'aurelia-event-aggregator';
import {bindable, inject, computedFrom, customElement, bindingMode} from 'aurelia-framework';
import {Router} from 'aurelia-router';
import {Statham} from 'json-statham';

@customElement('data-table')
@inject(Router, Element, EventAggregator)
@inject(Router, Element)
export class DataTable {
@bindable({defaultBindingMode: bindingMode.twoWay}) criteria;
// search criteria
@bindable repository;
// String representing the column names
@bindable columns = '';
Expand All @@ -28,33 +29,26 @@ export class DataTable {
count = 0;
columnsArray = [];
sortingCriteria = {};
searchCriteria = {};
searchCriteria = {}
constructor(Router, element, eventAggregator) {
this.router = Router;
this.element = element;
this.ea = eventAggregator;
}
attached() {
this.ea.subscribe('publishData', response => {
this.data = response.data;
});
this.load();
}
load() {
let criteria = this.buildCriteria();
this.ea.publish('updateCriteria', criteria);
this.criteria = this.buildCriteria();
if (!this.repository) {
this.showActions = false;
return;
}
this.repository.find(criteria, true).then(result => {
this.repository.find(this.criteria, true).then(result => {
this.data = result;
})
.catch(error => {
Expand All @@ -63,25 +57,25 @@ export class DataTable {
}

buildCriteria() {
let criteria = {};
let crit = {};

if (this.searchable !== null && Object.keys(this.searchCriteria).length ) {
let propertyName = Object.keys(this.searchCriteria)[0];
if (this.searchCriteria[propertyName]) {
criteria['where'] = {};
criteria['where'][propertyName] = {};
criteria['where'][propertyName]['contains'] = this.searchCriteria[propertyName];
crit['where'] = {};
crit['where'][propertyName] = {};
crit['where'][propertyName]['contains'] = this.searchCriteria[propertyName];
}
}

if (this.sortable !== null && Object.keys(this.sortingCriteria).length ) {
let propertyName = Object.keys(this.sortingCriteria)[0];
if (this.sortingCriteria[propertyName]) {
criteria['sort'] = propertyName + ' ' + this.sortingCriteria[propertyName];
crit['sort'] = propertyName + ' ' + this.sortingCriteria[propertyName];
}
}

return criteria;
return crit;
}

populate (row) {
Expand Down

0 comments on commit 04f0a32

Please sign in to comment.