From 2a76068ab693cc72f510ffde5f5295f1aaeac458 Mon Sep 17 00:00:00 2001 From: Peter Nijssen Date: Wed, 15 May 2019 14:51:18 +0200 Subject: [PATCH] resolve an issue when not all types are activated --- postnl-card.js | 64 +++++++++++++++++++++++++++----------------------- tracker.json | 4 ++-- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/postnl-card.js b/postnl-card.js index 23479bd..52487a8 100755 --- a/postnl-card.js +++ b/postnl-card.js @@ -231,46 +231,52 @@ class PostNL extends LitElement { this.distribution_delivered = [] // Format letters - Object.entries(this.letterObject.attributes.letters).sort((a, b) => new Date(b[1].delivery_date) - new Date(a[1].delivery_date)).map(([key, letter]) => { - if (window.moment) { - if (moment(letter.delivery_date).isBefore(moment().subtract(this.past_days, 'days').startOf('day'))) { - return; + if (this.letterObject) { + Object.entries(this.letterObject.attributes.letters).sort((a, b) => new Date(b[1].delivery_date) - new Date(a[1].delivery_date)).map(([key, letter]) => { + if (window.moment) { + if (moment(letter.delivery_date).isBefore(moment().subtract(this.past_days, 'days').startOf('day'))) { + return; + } } - } - this.letters.push(letter); - }); + this.letters.push(letter); + }); + } // Format deliveries - Object.entries(this.deliveryObject.attributes.enroute).sort((a, b) => new Date(b[1].planned_date) - new Date(a[1].planned_date)).map(([key, shipment]) => { - this.delivery_enroute.push(shipment); - }); - - Object.entries(this.deliveryObject.attributes.delivered).sort((a, b) => new Date(b[1].delivery_date) - new Date(a[1].delivery_date)).map(([key, shipment]) => { - if (window.moment) { - if (shipment.delivery_date != null && moment(shipment.delivery_date).isBefore(moment().subtract(this.past_days, 'days').startOf('day'))) { - return; + if (this.deliveryObject) { + Object.entries(this.deliveryObject.attributes.enroute).sort((a, b) => new Date(b[1].planned_date) - new Date(a[1].planned_date)).map(([key, shipment]) => { + this.delivery_enroute.push(shipment); + }); + + Object.entries(this.deliveryObject.attributes.delivered).sort((a, b) => new Date(b[1].delivery_date) - new Date(a[1].delivery_date)).map(([key, shipment]) => { + if (window.moment) { + if (shipment.delivery_date != null && moment(shipment.delivery_date).isBefore(moment().subtract(this.past_days, 'days').startOf('day'))) { + return; + } } - } - this.delivery_delivered.push(shipment); - }); + this.delivery_delivered.push(shipment); + }); + } // Format distribution - Object.entries(this.distributionObject.attributes.enroute).sort((a, b) => new Date(b[1].planned_date) - new Date(a[1].planned_date)).map(([key, shipment]) => { - this.distribution_enroute.push(shipment); - }); - - Object.entries(this.distributionObject.attributes.delivered).sort((a, b) => new Date(b[1].delivery_date) - new Date(a[1].delivery_date)).map(([key, shipment]) => { - if (window.moment) { - if (shipment.delivery_date != null && moment(shipment.delivery_date).isBefore(moment().subtract(this.past_days, 'days').startOf('day'))) { - return; + if (this.distributionObject) { + Object.entries(this.distributionObject.attributes.enroute).sort((a, b) => new Date(b[1].planned_date) - new Date(a[1].planned_date)).map(([key, shipment]) => { + this.distribution_enroute.push(shipment); + }); + + Object.entries(this.distributionObject.attributes.delivered).sort((a, b) => new Date(b[1].delivery_date) - new Date(a[1].delivery_date)).map(([key, shipment]) => { + if (window.moment) { + if (shipment.delivery_date != null && moment(shipment.delivery_date).isBefore(moment().subtract(this.past_days, 'days').startOf('day'))) { + return; + } } - } - this.distribution_delivered.push(shipment); - }); + this.distribution_delivered.push(shipment); + }); + } } render({ _hass, _hide, _values, config, delivery, distribution, letters } = this) { diff --git a/tracker.json b/tracker.json index f032b8d..4fe97c6 100644 --- a/tracker.json +++ b/tracker.json @@ -1,9 +1,9 @@ { "postnl-card": { - "version": "0.9.1", + "version": "0.9.2", "updated_at": "2019-05-15", "visit_repo": "https://github.com/peternijssen/lovelace-postnl", - "remote_location": "https://github.com/peternijssen/lovelace-postnl/releases/download/0.9.1/postnl-card.js", + "remote_location": "https://github.com/peternijssen/lovelace-postnl/releases/download/0.9.2/postnl-card.js", "changelog": "https://github.com/peternijssen/lovelace-postnl/releases/latest" } }