Skip to content

Commit

Permalink
values in url separated by ~
Browse files Browse the repository at this point in the history
  • Loading branch information
programmer4web committed Jan 29, 2018
1 parent 2ca980b commit bb148c8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
16 changes: 5 additions & 11 deletions cosmoz-omnitable-column-autocomplete.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,26 +164,20 @@
if (!(Array.isArray(obj) && obj.length > 0)) {
return null;
}
return this.serialize(obj.map(item => {
return obj.map(item => {
const property = this.valueProperty;
if (!property) {
return item;
}
return this.get(property, item);
}));
}).join('~');
},

_deserializeFilter: function (obj) {
const type = this.filter && this.filter.constructor || Object;

if (type === Object && obj == null) {
return {};
}
if (type === Array && obj == null) {
return [];
if (obj == null || obj === '') {
return null;
}
const deserialized = this.deserialize(obj, type);
return deserialized.map(item => this.values.find(v => {
return obj.split('~').map(item => this.values.find(v => {
const property = this.valueProperty;
if (!property) {
const vv = typeof v === 'number' ? v.toString() : v;
Expand Down
4 changes: 2 additions & 2 deletions test/autocomplete.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
column.filter = [{ id: 'c', name: 'cc' }];

const serialized = column._serializeFilter(column.filter);
assert.equal(serialized, '["c"]', 'Expected valueProperty to be serialized');
assert.equal(serialized, 'c', 'Expected valueProperty to be serialized');

const deserialized = column._deserializeFilter(serialized);
assert.deepEqual(deserialized[0], { id: 'c', name: 'cc' });
Expand All @@ -72,7 +72,7 @@
column.filter = [{ id: 'b', name: 'bb' }, { id: 'g', name: 'gg' }];

const serialized = column._serializeFilter(column.filter);
assert.equal(serialized, '["b","g"]', 'Expected valueProperty to be serialized');
assert.equal(serialized, 'b~g', 'Expected valueProperty to be serialized');

const deserialized = column._deserializeFilter(serialized);
assert.deepEqual(deserialized[0], { id: 'b', name: 'bb' });
Expand Down
4 changes: 2 additions & 2 deletions test/hash-param.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
});

test('updates filter from url hash', function (done) {
location.hash = '#/#test-filter--id=["1"]';
location.hash = '#/#test-filter--id=1';
instantiate(function () {
assert.isArray(omnitable.columns[0].filter);
assert.lengthOf(omnitable.columns[0].filter, 1);
Expand Down Expand Up @@ -163,7 +163,7 @@
hash = omnitable._routeHash;
column.filter = [0, 1];
Polymer.Base.async(function () {
assert.equal(hash['test-filter--id'], '[0,1]');
assert.equal(hash['test-filter--id'], '0~1');
column.resetFilter();
Polymer.Base.async(function () {
assert.equal(hash['test-filter--id'], null);
Expand Down

0 comments on commit bb148c8

Please sign in to comment.