From 499666a88e1c2e1ac7d3a4374849babccd0f3e9f Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Fri, 9 Oct 2020 21:11:52 +0200 Subject: [PATCH] Fix dissappearing unparsed rules --- UI/Input/OpeningHours/OpeningHoursInput.ts | 10 +++++++--- test.ts | 18 +++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/UI/Input/OpeningHours/OpeningHoursInput.ts b/UI/Input/OpeningHours/OpeningHoursInput.ts index 254331e7c..dd83dc375 100644 --- a/UI/Input/OpeningHours/OpeningHoursInput.ts +++ b/UI/Input/OpeningHours/OpeningHoursInput.ts @@ -27,9 +27,9 @@ export default class OpeningHoursInput extends InputElement { constructor(value: UIEventSource = new UIEventSource("")) { super(); - const rulesFromOhPicker = value.map(OH.Parse); - + const leftoverRules = value.map(str => { + console.log("Leftovers?",str) if (str === undefined) { return [] } @@ -46,8 +46,11 @@ export default class OpeningHoursInput extends InputElement { } return leftOvers; }) + // NOte: MUST be bound AFTER the leftover rules! + const rulesFromOhPicker = value.map(OH.Parse); const ph = value.map(str => { + console.log("PH RULE?", ph) if (str === undefined) { return "" } @@ -62,6 +65,7 @@ export default class OpeningHoursInput extends InputElement { this._phSelector = new PublicHolidayInput(ph); function update() { + console.log("UPdating") let rules = OH.ToString(rulesFromOhPicker.data); if (leftoverRules.data.length != 0) { rules += ";" + leftoverRules.data.join(";") @@ -83,7 +87,7 @@ export default class OpeningHoursInput extends InputElement { } return new Combine([ Translations.t.general.opening_hours.not_all_rules_parsed, - new FixedUiElement(leftovers.map(r => `${r}
`).join("") ).SetClass("subtle") + new FixedUiElement(leftovers.map(r => `${r}
`).join("")).SetClass("subtle") ]).Render(); })) diff --git a/test.ts b/test.ts index 761a7a427..5cfbd67bb 100644 --- a/test.ts +++ b/test.ts @@ -1,15 +1,15 @@ //* -import OpeningHoursVisualization from "./UI/OhVisualization"; -import {UIEventSource} from "./Logic/UIEventSource"; -new OpeningHoursVisualization( new UIEventSource({ - opening_hours: "2000 Dec 21 10:00-12:00;", - _country: "be", - _lat: "51.2", - _lon: "3.2" - } -), 'opening_hours').AttachTo("maindiv") +import {UIEventSource} from "./Logic/UIEventSource"; +import OpeningHoursInput from "./UI/Input/OpeningHours/OpeningHoursInput"; + +const oh = "Sep 1-Feb 28 Mo-Th 08:00-12:00, 13:30-17:30; Mar 1-Aug 31 Mo-Fr 07:00-12:00, 13:30-17:30; PH off" + +const source = new UIEventSource("") +new OpeningHoursInput(source).AttachTo('maindiv') +console.log("SEtting ",oh) +source.setData(oh) /*/