From bb148c8fdca7b4e675143a4d61a29a29e471cdb3 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 29 Jan 2018 14:55:24 +0200 Subject: [PATCH] values in url separated by ~ --- cosmoz-omnitable-column-autocomplete.html | 16 +++++----------- test/autocomplete.html | 4 ++-- test/hash-param.html | 4 ++-- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/cosmoz-omnitable-column-autocomplete.html b/cosmoz-omnitable-column-autocomplete.html index 56befe04..5e80a387 100644 --- a/cosmoz-omnitable-column-autocomplete.html +++ b/cosmoz-omnitable-column-autocomplete.html @@ -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; diff --git a/test/autocomplete.html b/test/autocomplete.html index 87278bd0..920b5e02 100644 --- a/test/autocomplete.html +++ b/test/autocomplete.html @@ -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' }); @@ -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' }); diff --git a/test/hash-param.html b/test/hash-param.html index 483cc37f..ab6ceb10 100644 --- a/test/hash-param.html +++ b/test/hash-param.html @@ -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); @@ -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);