Permalink
Browse files

feat(column): convert column values

  • Loading branch information...
VMBindraban
VMBindraban committed Jul 26, 2016
1 parent 61a05ba commit f6fa9da4ec263bd104e57d825b36a84afdc7fd2f
Showing with 158 additions and 87 deletions.
  1. +84 −80 config.js
  2. +4 −1 package.json
  3. +2 −1 src/bootstrap/datatable.html
  4. +60 −0 src/convert-manager.js
  5. +8 −5 src/datatable.js
164 config.js
@@ -14,16 +14,19 @@ System.config({
},
map: {
"aurelia-framework": "npm:aurelia-framework@1.0.0-beta.1.2.5",
"aurelia-framework": "npm:aurelia-framework@1.0.0-rc.1.0.7",
"aurelia-logging": "npm:aurelia-logging@1.0.0-rc.1.0.1",
"aurelia-orm": "npm:aurelia-orm@3.0.0-rc4",
"aurelia-pager": "npm:aurelia-pager@0.0.5",
"aurelia-polyfills": "npm:aurelia-polyfills@1.0.0-beta.2.0.0",
"aurelia-router": "npm:aurelia-router@1.0.0-beta.2.0.0",
"aurelia-polyfills": "npm:aurelia-polyfills@1.0.0-rc.1.0.0",
"aurelia-router": "npm:aurelia-router@1.0.0-rc.1.0.5",
"aurelia-templating": "npm:aurelia-templating@1.0.0-rc.1.0.2",
"aurelia-view-manager": "npm:aurelia-view-manager@0.0.4",
"babel": "npm:babel-core@5.8.38",
"babel-runtime": "npm:babel-runtime@5.8.38",
"core-js": "npm:core-js@1.2.6",
"json-statham": "npm:json-statham@1.3.0",
"core-js": "npm:core-js@1.2.7",
"json-statham": "npm:json-statham@1.4.0",
"typer": "npm:typer@1.1.0",
"github:jspm/nodelibs-assert@0.1.0": {
"assert": "npm:assert@1.4.1"
},
@@ -49,94 +52,94 @@ System.config({
"util": "npm:util@0.10.3"
},
"npm:aurelia-api@3.0.0-rc4": {
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.0.0-beta.2.0.1",
"aurelia-fetch-client": "npm:aurelia-fetch-client@1.0.0-beta.2.0.0",
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.0.0-rc.1.0.1",
"aurelia-fetch-client": "npm:aurelia-fetch-client@1.0.0-rc.1.0.1",
"extend": "npm:extend@3.0.0",
"qs": "npm:qs@6.2.0"
},
"npm:aurelia-binding@1.0.0-beta.2.0.0": {
"aurelia-logging": "npm:aurelia-logging@1.0.0-beta.2.0.0",
"aurelia-metadata": "npm:aurelia-metadata@1.0.0-beta.2.0.0",
"aurelia-pal": "npm:aurelia-pal@1.0.0-beta.1.3.0",
"aurelia-task-queue": "npm:aurelia-task-queue@1.0.0-beta.2.0.0"
},
"npm:aurelia-dependency-injection@1.0.0-beta.2.0.1": {
"aurelia-metadata": "npm:aurelia-metadata@1.0.0-beta.2.0.0",
"aurelia-pal": "npm:aurelia-pal@1.0.0-beta.1.3.0"
},
"npm:aurelia-event-aggregator@1.0.0-beta.2.0.0": {
"aurelia-logging": "npm:aurelia-logging@1.0.0-beta.2.0.0"
},
"npm:aurelia-framework@1.0.0-beta.1.2.5": {
"aurelia-binding": "npm:aurelia-binding@1.0.0-beta.2.0.0",
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.0.0-beta.2.0.1",
"aurelia-loader": "npm:aurelia-loader@1.0.0-beta.2.0.0",
"aurelia-logging": "npm:aurelia-logging@1.0.0-beta.2.0.0",
"aurelia-metadata": "npm:aurelia-metadata@1.0.0-beta.2.0.0",
"aurelia-pal": "npm:aurelia-pal@1.0.0-beta.1.3.0",
"aurelia-path": "npm:aurelia-path@1.0.0-beta.2.0.0",
"aurelia-task-queue": "npm:aurelia-task-queue@1.0.0-beta.2.0.0",
"aurelia-templating": "npm:aurelia-templating@1.0.0-beta.3.0.0"
},
"npm:aurelia-loader@1.0.0-beta.2.0.0": {
"aurelia-metadata": "npm:aurelia-metadata@1.0.0-beta.2.0.0",
"aurelia-path": "npm:aurelia-path@1.0.0-beta.2.0.0"
},
"npm:aurelia-metadata@1.0.0-beta.2.0.0": {
"aurelia-pal": "npm:aurelia-pal@1.0.0-beta.1.3.0"
"qs": "npm:qs@6.2.1"
},
"npm:aurelia-binding@1.0.0-rc.1.0.4": {
"aurelia-logging": "npm:aurelia-logging@1.0.0-rc.1.0.1",
"aurelia-metadata": "npm:aurelia-metadata@1.0.0-rc.1.0.1",
"aurelia-pal": "npm:aurelia-pal@1.0.0-rc.1.0.0",
"aurelia-task-queue": "npm:aurelia-task-queue@1.0.0-rc.1.0.0"
},
"npm:aurelia-dependency-injection@1.0.0-rc.1.0.1": {
"aurelia-metadata": "npm:aurelia-metadata@1.0.0-rc.1.0.1",
"aurelia-pal": "npm:aurelia-pal@1.0.0-rc.1.0.0"
},
"npm:aurelia-event-aggregator@1.0.0-rc.1.0.0": {
"aurelia-logging": "npm:aurelia-logging@1.0.0-rc.1.0.1"
},
"npm:aurelia-framework@1.0.0-rc.1.0.7": {
"aurelia-binding": "npm:aurelia-binding@1.0.0-rc.1.0.4",
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.0.0-rc.1.0.1",
"aurelia-loader": "npm:aurelia-loader@1.0.0-rc.1.0.0",
"aurelia-logging": "npm:aurelia-logging@1.0.0-rc.1.0.1",
"aurelia-metadata": "npm:aurelia-metadata@1.0.0-rc.1.0.1",
"aurelia-pal": "npm:aurelia-pal@1.0.0-rc.1.0.0",
"aurelia-path": "npm:aurelia-path@1.0.0-rc.1.0.0",
"aurelia-task-queue": "npm:aurelia-task-queue@1.0.0-rc.1.0.0",
"aurelia-templating": "npm:aurelia-templating@1.0.0-rc.1.0.2"
},
"npm:aurelia-loader@1.0.0-rc.1.0.0": {
"aurelia-metadata": "npm:aurelia-metadata@1.0.0-rc.1.0.1",
"aurelia-path": "npm:aurelia-path@1.0.0-rc.1.0.0"
},
"npm:aurelia-metadata@1.0.0-rc.1.0.1": {
"aurelia-pal": "npm:aurelia-pal@1.0.0-rc.1.0.0"
},
"npm:aurelia-orm@3.0.0-rc4": {
"aurelia-api": "npm:aurelia-api@3.0.0-rc4",
"aurelia-binding": "npm:aurelia-binding@1.0.0-beta.2.0.0",
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.0.0-beta.2.0.1",
"aurelia-metadata": "npm:aurelia-metadata@1.0.0-beta.2.0.0",
"aurelia-templating": "npm:aurelia-templating@1.0.0-beta.3.0.0",
"aurelia-binding": "npm:aurelia-binding@1.0.0-rc.1.0.4",
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.0.0-rc.1.0.1",
"aurelia-metadata": "npm:aurelia-metadata@1.0.0-rc.1.0.1",
"aurelia-templating": "npm:aurelia-templating@1.0.0-rc.1.0.2",
"aurelia-validation": "npm:aurelia-validation@0.6.6",
"extend": "npm:extend@3.0.0",
"typer": "npm:typer@1.1.0"
},
"npm:aurelia-pager@0.0.5": {
"aurelia-framework": "npm:aurelia-framework@1.0.0-beta.1.2.5",
"aurelia-framework": "npm:aurelia-framework@1.0.0-rc.1.0.7",
"aurelia-view-manager": "npm:aurelia-view-manager@0.0.4"
},
"npm:aurelia-polyfills@1.0.0-beta.2.0.0": {
"aurelia-pal": "npm:aurelia-pal@1.0.0-beta.1.3.0"
},
"npm:aurelia-route-recognizer@1.0.0-beta.2.0.0": {
"aurelia-path": "npm:aurelia-path@1.0.0-beta.2.0.0"
},
"npm:aurelia-router@1.0.0-beta.2.0.0": {
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.0.0-beta.2.0.1",
"aurelia-event-aggregator": "npm:aurelia-event-aggregator@1.0.0-beta.2.0.0",
"aurelia-history": "npm:aurelia-history@1.0.0-beta.2.0.0",
"aurelia-logging": "npm:aurelia-logging@1.0.0-beta.2.0.0",
"aurelia-path": "npm:aurelia-path@1.0.0-beta.2.0.0",
"aurelia-route-recognizer": "npm:aurelia-route-recognizer@1.0.0-beta.2.0.0"
},
"npm:aurelia-task-queue@1.0.0-beta.2.0.0": {
"aurelia-pal": "npm:aurelia-pal@1.0.0-beta.1.3.0"
},
"npm:aurelia-templating@1.0.0-beta.3.0.0": {
"aurelia-binding": "npm:aurelia-binding@1.0.0-beta.2.0.0",
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.0.0-beta.2.0.1",
"aurelia-loader": "npm:aurelia-loader@1.0.0-beta.2.0.0",
"aurelia-logging": "npm:aurelia-logging@1.0.0-beta.2.0.0",
"aurelia-metadata": "npm:aurelia-metadata@1.0.0-beta.2.0.0",
"aurelia-pal": "npm:aurelia-pal@1.0.0-beta.1.3.0",
"aurelia-path": "npm:aurelia-path@1.0.0-beta.2.0.0",
"aurelia-task-queue": "npm:aurelia-task-queue@1.0.0-beta.2.0.0"
"npm:aurelia-polyfills@1.0.0-rc.1.0.0": {
"aurelia-pal": "npm:aurelia-pal@1.0.0-rc.1.0.0"
},
"npm:aurelia-route-recognizer@1.0.0-rc.1.0.1": {
"aurelia-path": "npm:aurelia-path@1.0.0-rc.1.0.0"
},
"npm:aurelia-router@1.0.0-rc.1.0.5": {
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.0.0-rc.1.0.1",
"aurelia-event-aggregator": "npm:aurelia-event-aggregator@1.0.0-rc.1.0.0",
"aurelia-history": "npm:aurelia-history@1.0.0-rc.1.0.0",
"aurelia-logging": "npm:aurelia-logging@1.0.0-rc.1.0.1",
"aurelia-path": "npm:aurelia-path@1.0.0-rc.1.0.0",
"aurelia-route-recognizer": "npm:aurelia-route-recognizer@1.0.0-rc.1.0.1"
},
"npm:aurelia-task-queue@1.0.0-rc.1.0.0": {
"aurelia-pal": "npm:aurelia-pal@1.0.0-rc.1.0.0"
},
"npm:aurelia-templating@1.0.0-rc.1.0.2": {
"aurelia-binding": "npm:aurelia-binding@1.0.0-rc.1.0.4",
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.0.0-rc.1.0.1",
"aurelia-loader": "npm:aurelia-loader@1.0.0-rc.1.0.0",
"aurelia-logging": "npm:aurelia-logging@1.0.0-rc.1.0.1",
"aurelia-metadata": "npm:aurelia-metadata@1.0.0-rc.1.0.1",
"aurelia-pal": "npm:aurelia-pal@1.0.0-rc.1.0.0",
"aurelia-path": "npm:aurelia-path@1.0.0-rc.1.0.0",
"aurelia-task-queue": "npm:aurelia-task-queue@1.0.0-rc.1.0.0"
},
"npm:aurelia-validation@0.6.6": {
"aurelia-binding": "npm:aurelia-binding@1.0.0-beta.2.0.0",
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.0.0-beta.2.0.1",
"aurelia-logging": "npm:aurelia-logging@1.0.0-beta.2.0.0",
"aurelia-metadata": "npm:aurelia-metadata@1.0.0-beta.2.0.0",
"aurelia-templating": "npm:aurelia-templating@1.0.0-beta.3.0.0"
"aurelia-binding": "npm:aurelia-binding@1.0.0-rc.1.0.4",
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.0.0-rc.1.0.1",
"aurelia-logging": "npm:aurelia-logging@1.0.0-rc.1.0.1",
"aurelia-metadata": "npm:aurelia-metadata@1.0.0-rc.1.0.1",
"aurelia-templating": "npm:aurelia-templating@1.0.0-rc.1.0.2"
},
"npm:aurelia-view-manager@0.0.4": {
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.0.0-beta.2.0.1",
"aurelia-logging": "npm:aurelia-logging@1.0.0-beta.2.0.0",
"aurelia-templating": "npm:aurelia-templating@1.0.0-beta.3.0.0",
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.0.0-rc.1.0.1",
"aurelia-logging": "npm:aurelia-logging@1.0.0-rc.1.0.1",
"aurelia-templating": "npm:aurelia-templating@1.0.0-rc.1.0.2",
"extend": "npm:extend@3.0.0"
},
"npm:babel-runtime@5.8.38": {
@@ -150,7 +153,7 @@ System.config({
"isarray": "npm:isarray@1.0.0",
"process": "github:jspm/nodelibs-process@0.1.2"
},
"npm:core-js@1.2.6": {
"npm:core-js@1.2.7": {
"fs": "github:jspm/nodelibs-fs@0.1.2",
"path": "github:jspm/nodelibs-path@0.1.0",
"process": "github:jspm/nodelibs-process@0.1.2",
@@ -159,7 +162,8 @@ System.config({
"npm:inherits@2.0.1": {
"util": "github:jspm/nodelibs-util@0.1.0"
},
"npm:json-statham@1.3.0": {
"npm:json-statham@1.4.0": {
"extend": "npm:extend@3.0.0",
"fs": "github:jspm/nodelibs-fs@0.1.2",
"mkdirp": "npm:mkdirp@0.5.1",
"path": "github:jspm/nodelibs-path@0.1.0",
@@ -69,11 +69,14 @@
},
"dependencies": {
"aurelia-framework": "^1.0.0-beta.1.2.5",
"aurelia-logging": "^1.0.0-rc.1.0.1",
"aurelia-orm": "^3.0.0-rc4",
"aurelia-pager": "^0.0.5",
"aurelia-router": "^1.0.0-beta.1",
"aurelia-templating": "^1.0.0-rc.1.0.2",
"aurelia-view-manager": "^0.0.4",
"json-statham": "^1.3.0"
"json-statham": "^1.3.0",
"typer": "^1.1.0"
},
"devDependencies": {
"aurelia-polyfills": "^1.0.0-beta.1.1.0",
@@ -1,5 +1,6 @@
<template>
<require from="../columns-filter"></require>
<require from="../convert-manager"></require>
<!-- Search bar -->
<div if.bind="searchable !== null" class="row">
@@ -51,7 +52,7 @@
<!-- Columns -->
<td repeat.for="columnLabel of columnLabels">
<a click.delegate="selected(row)">${displayValue(row, columnLabel.column)}</a>
<a click.delegate="selected(row)">${displayValue(row, columnLabel.column) | convertManager: columnLabel.converter}</a>
</td>
<!-- Actions -->
@@ -0,0 +1,60 @@
import {inject} from 'aurelia-dependency-injection';
import {ViewResources} from 'aurelia-templating';
import {getLogger} from 'aurelia-logging';
import typer from 'typer';
@inject(ViewResources)
export class ConvertManagerValueConverter {
constructor(viewResources) {
this.viewResources = viewResources;
this.logger = getLogger('aurelia-datatable');
}
runConverter (value, converter, convertParams) {
let valueConverter = this.viewResources.getValueConverter(converter);
if (valueConverter) {
return valueConverter.toView(value, convertParams);
}
this.logger.error('No ValueConverter named "' + converter + '" was found!');
return value;
}
toView (value, converters) {
if (!converters) {
return value;
}
for (let converter of converters.split(' | ')) {
let index = converter.indexOf(':');
if (index < 0) {
value = this.runConverter(value, converter);
continue;
}
let name = converter.slice(0, index);
let param = this.parseParams(converter.slice(index + 1).trim())
value = this.runConverter(value, name, param);
}
return value;
}
parseParams (str) {
if (!str) {
return null;
}
if (typer.detect(str) === 'string' && str[0] !== '{') {
return str.substr(1, str.length -2);
}
return typer.cast(str);
}
}
@@ -17,6 +17,7 @@ export class DataTable {
@bindable limit = 30;
@bindable columns = '';
@bindable searchColumn = 'name';
@bindable actions = [];
@bindable searchable = null; // Show the search field? (Optional attribute).
@bindable sortable = null; // Columns can be sorted? (Optional attribute).
@bindable edit = null; // Rows are editable? (Optional attribute).
@@ -29,7 +30,6 @@ export class DataTable {
@bindable data;
@bindable route;
@bindable pages;
@bindable actions = [];
constructor(Router, element, entityManager) {
this.router = Router;
@@ -185,18 +185,21 @@ export class DataTable {
return;
}
let aliased = label.split(' as ');
let converter = label.split(' | ');
let aliased = converter[0].split(' as ');
let cleanedColumn = clean(aliased[0]);
if (columnsArray.indexOf(cleanedColumn) === -1) {
columnsArray.push(cleanedColumn);
}
labels.push({
nested: cleanedColumn.indexOf('.') !== -1,
column: cleanedColumn,
label : ucfirst(clean(aliased[1] || aliased[0]))
nested : cleanedColumn.indexOf('.') !== -1,
column : cleanedColumn,
label : ucfirst(clean(aliased[1] || aliased[0])),
converter: (converter.length > 1) ? converter.slice(1).join(' | ') : false
});
});
return labels;

0 comments on commit f6fa9da

Please sign in to comment.