From 0db7df6c144d4061059a35d68d428e14c07d7ac4 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 27 May 2021 16:29:18 +0200 Subject: [PATCH 1/2] Add keyup event listener on hour/minute inputs - To set the date (and trigger the onChange event) when the user is typing through its keyboard --- .../admin/order_cycles/order_cycles.js.erb.coffee | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/admin/order_cycles/order_cycles.js.erb.coffee b/app/assets/javascripts/admin/order_cycles/order_cycles.js.erb.coffee index 71ab6b9b18..9241517262 100644 --- a/app/assets/javascripts/admin/order_cycles/order_cycles.js.erb.coffee +++ b/app/assets/javascripts/admin/order_cycles/order_cycles.js.erb.coffee @@ -3,12 +3,18 @@ angular.module('admin.orderCycles', ['ngTagsInput', 'admin.indexUtils', 'admin.e require: "ngModel" link: (scope, element, attrs, ngModel) -> $timeout -> - flatpickr(element, Object.assign({}, + fp = flatpickr(element, Object.assign({}, window.FLATPICKR_DATETIME_DEFAULT, { onOpen: (selectedDates, dateStr, instance) -> instance.setDate(ngModel.$modelValue) instance.input.dispatchEvent(new Event('focus', { bubbles: true })); })); + fp.minuteElement.addEventListener "keyup", (e) -> + if !isNaN(event.target.value) + fp.setDate(fp.selectedDates[0].setMinutes(e.target.value), true) + fp.hourElement.addEventListener "keyup", (e) -> + if !isNaN(event.target.value) + fp.setDate(fp.selectedDates[0].setHours(e.target.value), true) .directive 'ofnOnChange', -> (scope, element, attrs) -> From 60f3ebca628f828e133c3e7eae5353803185d02a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 1 Jun 2021 12:04:14 +0200 Subject: [PATCH 2/2] Check whether the changes made by the keyboard are taken into account in datetimepicker - User can change minute directly with keyboard, and without closing the datetimepicker, the modification should be catch and then a label "You have unsaved changes" with the "Save changes" button should appear --- spec/features/admin/order_cycles/simple_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/features/admin/order_cycles/simple_spec.rb b/spec/features/admin/order_cycles/simple_spec.rb index 03dea7eae9..ee63ede2bb 100644 --- a/spec/features/admin/order_cycles/simple_spec.rb +++ b/spec/features/admin/order_cycles/simple_spec.rb @@ -604,6 +604,16 @@ feature ' end end + scenario "modify the minute of a order cycle with the keyboard, check that the modifications are taken into account" do + order_cycle = create(:simple_order_cycle, name: "Translusent Berries") + login_as_admin_and_visit admin_order_cycles_path + find("#oc#{order_cycle.id}_orders_close_at").click + datetime = Time.at(Time.zone.local(2040, 10, 17, 0o6, 0o0, 0o0)) + input = find(".flatpickr-calendar.open .flatpickr-minute") + input.send_keys datetime.strftime("%M").to_s.strip + expect(page).to have_content "You have unsaved changes" + end + scenario "deleting an order cycle" do order_cycle = create(:simple_order_cycle, name: "Translusent Berries") login_as_admin_and_visit admin_order_cycles_path