Bugzilla – Attachment 138337 Details for
Bug 30650
Add a curbside pickup module
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30650: Be more flexible with opening slots
Bug-30650-Be-more-flexible-with-opening-slots.patch (text/plain), 14.43 KB, created by
Katrin Fischer
on 2022-07-29 16:18:29 UTC
(
hide
)
Description:
Bug 30650: Be more flexible with opening slots
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2022-07-29 16:18:29 UTC
Size:
14.43 KB
patch
obsolete
>From e02932ef4e01b2e8034928c2899ca2f09ab9e02b Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 2 May 2022 15:21:27 +0200 >Subject: [PATCH] Bug 30650: Be more flexible with opening slots > >Sponsored-by: Association KohaLa - https://koha-fr.org/ > >Signed-off-by: Koha Team University Lyon 3 <koha@univ-lyon3.fr> > >Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de> >--- > Koha/CurbsidePickupOpeningSlot.pm | 44 +++++++++ > Koha/CurbsidePickupOpeningSlots.pm | 50 ++++++++++ > Koha/CurbsidePickupPolicy.pm | 28 ++++++ > admin/curbside_pickup.pl | 28 ++---- > .../prog/en/modules/admin/curbside_pickup.tt | 98 ++++++++----------- > 5 files changed, 170 insertions(+), 78 deletions(-) > create mode 100644 Koha/CurbsidePickupOpeningSlot.pm > create mode 100644 Koha/CurbsidePickupOpeningSlots.pm > >diff --git a/Koha/CurbsidePickupOpeningSlot.pm b/Koha/CurbsidePickupOpeningSlot.pm >new file mode 100644 >index 0000000000..9e42e3bd6c >--- /dev/null >+++ b/Koha/CurbsidePickupOpeningSlot.pm >@@ -0,0 +1,44 @@ >+package Koha::CurbsidePickupOpeningSlot; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Carp; >+ >+use Koha::Database; >+ >+use base qw(Koha::Object); >+ >+=head1 NAME >+ >+CurbsidePickupOpeningSlot - Koha Curbside Pickup Slot Object class >+ >+=head1 API >+ >+=head2 Class methods >+ >+=head2 Internal methods >+ >+=head3 _type >+ >+=cut >+ >+sub _type { >+ return 'CurbsidePickupOpeningSlot'; >+} >+ >+1; >diff --git a/Koha/CurbsidePickupOpeningSlots.pm b/Koha/CurbsidePickupOpeningSlots.pm >new file mode 100644 >index 0000000000..41aec26f78 >--- /dev/null >+++ b/Koha/CurbsidePickupOpeningSlots.pm >@@ -0,0 +1,50 @@ >+package Koha::CurbsidePickupOpeningSlots; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Carp; >+ >+use Koha::Database; >+ >+use Koha::CurbsidePickupOpeningSlot; >+ >+use base qw(Koha::Objects); >+ >+=head1 NAME >+ >+Koha::CurbsidePickupOpeningSlots - Koha Curbside Pickup Opening Slots Object set class >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=cut >+ >+=head3 type >+ >+=cut >+ >+sub _type { >+ return 'CurbsidePickupOpeningSlot'; >+} >+ >+sub object_class { >+ return 'Koha::CurbsidePickupOpeningSlot'; >+} >+ >+1; >diff --git a/Koha/CurbsidePickupPolicy.pm b/Koha/CurbsidePickupPolicy.pm >index ce66f4c7ee..c974dc406a 100644 >--- a/Koha/CurbsidePickupPolicy.pm >+++ b/Koha/CurbsidePickupPolicy.pm >@@ -20,6 +20,8 @@ use Modern::Perl; > use Carp; > > use Koha::Database; >+use Koha::Library; >+use Koha::CurbsidePickupOpeningSlots; > > use base qw(Koha::Object); > >@@ -44,6 +46,32 @@ sub library { > return Koha::Library->_new_from_dbic( $rs ); > } > >+sub opening_slots { >+ my ( $self ) = @_; >+ my $rs = $self->_result->curbside_pickup_opening_slots; >+ return unless $rs; >+ return Koha::CurbsidePickupOpeningSlots->_new_from_dbic( $rs ); >+} >+ >+sub add_opening_slot { >+ my ( $self, $slot ) = @_; >+ >+ my ( $day, $start, $end ) = split '-', $slot; >+ my ( $start_hour, $start_minute ) = split ':', $start; >+ my ( $end_hour, $end_minute ) = split ':', $end; >+ >+ return Koha::CurbsidePickupOpeningSlot->new( >+ { >+ curbside_pickup_policy_id => $self->id, >+ day => $day, >+ start_hour => $start_hour, >+ start_minute => $start_minute, >+ end_hour => $end_hour, >+ end_minute => $end_minute, >+ } >+ )->store; >+} >+ > =head2 Internal methods > > =head3 _type >diff --git a/admin/curbside_pickup.pl b/admin/curbside_pickup.pl >index e90c3bfc15..21992c00f7 100755 >--- a/admin/curbside_pickup.pl >+++ b/admin/curbside_pickup.pl >@@ -43,7 +43,6 @@ if ( $op eq 'save' ) { > my $branchcode = $library->branchcode; > > my $params = { >- > branchcode => $branchcode, > enabled => scalar $input->param("enable-$branchcode") || 0, > pickup_interval => scalar $input->param("interval-$branchcode"), >@@ -51,28 +50,15 @@ if ( $op eq 'save' ) { > patron_scheduled_pickup => scalar $input->param("patron-scheduled-$branchcode") || 0, > }; > >- for my $day ( >- qw( sunday monday tuesday wednesday thursday friday saturday )) >- { >- for my $start_end (qw( start end )) { >- for my $hour_min (qw( hour minute )) { >- >- my $value = $input->param( >- "pickup-$start_end-$hour_min-$day-$branchcode"); >- $value = undef if $value eq q{}; >- >- my $key = $day . '_' . $start_end . '_' . $hour_min; >+ my $policy = >+ Koha::CurbsidePickupPolicies->find_or_create( { branchcode => $branchcode } ); >+ $policy->update($params); > >- $params->{$key} = $value; >- } >- } >+ $policy->opening_slots->delete; >+ my @pickup_slots = $input->multi_param("pickup-slot-" . $branchcode); >+ for my $pickup_slot ( @pickup_slots ) { >+ $policy->add_opening_slot($pickup_slot); > } >- >- my $CurbsidePickupPolicy = >- Koha::CurbsidePickupPolicies->find( { branchcode => $branchcode } ); >- $CurbsidePickupPolicy->delete if $CurbsidePickupPolicy; >- >- Koha::CurbsidePickupPolicy->new($params)->store(); > } > $op = 'list'; > } >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/curbside_pickup.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/curbside_pickup.tt >index 61ac77589f..df73577402 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/curbside_pickup.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/curbside_pickup.tt >@@ -9,8 +9,9 @@ > [% INCLUDE 'doc-head-close.inc' %] > <style> > .pickup-slot { >- border: solid; >- padding: 1em; >+ border: 2px solid #b9d8d9; >+ padding: 0 .1em; >+ margin: 0 .1em; > } > </style> > </head> >@@ -117,31 +118,9 @@ > <fieldset class="rows" style="float: none;"> > <legend>Curbside pickup hours</legend> > >- <em>Times should be in 24-hour format ( 00:00 to 23:59 ).</em> >- >- <ol class="pickup_hours"> >- [% BLOCK pickup_hours_day %] >- [% SET day_start_hour = d _ '_start_hour' %] >- [% SET day_start_minute = d _ '_start_minute' %] >- [% SET day_end_hour = d _ '_end_hour' %] >- [% SET day_end_minute = d _ '_end_minute' %] >- [% SET p = policies.$branchcode %] >- [% IF p.$day_start_hour && p.$day_start_minute && p.$day_end_hour && p.$day_end_minute %] >- <li> >- <span class="slot"> >- <input type="hidden" class="pickup-slot" name="pickup-slot-[% l.branchcode | html %]" value="[% d | html %]-[% p.$day_start_hour %]:[% p.$day_start_minute %]-[% p.$day_end_hour %]:[% p.$day_end_minute %]" /> >- </span> >- </li> >- [% END %] >- [% END %] >- [% PROCESS pickup_hours_day d => 'sunday' %] >- [% PROCESS pickup_hours_day d => 'monday' %] >- [% PROCESS pickup_hours_day d => 'tuesday' %] >- [% PROCESS pickup_hours_day d => 'wednesday' %] >- [% PROCESS pickup_hours_day d => 'thursday' %] >- [% PROCESS pickup_hours_day d => 'friday' %] >- [% PROCESS pickup_hours_day d => 'saturday' %] >- </ol> >+ <em>Times should be in 24-hour format (00:00 to 23:59).</em> >+ >+ <ol class="pickup_hours"></ol> > > <ol> > <li> >@@ -161,6 +140,7 @@ > </span> > </select> > <input type="button" class="add-new-slot" data-branchcode="[% l.branchcode | html %]" value="Add" /> >+ <span id="invalid_slot_warning" style="display:none;">Invalid format for this new slot, must be '00:00 to 23:59'.</span> > </div> > </li> > >@@ -210,32 +190,41 @@ > return String(hh).padStart(2, '0') + ':' + String(mm).padStart(2, '0'); > } > function format_slot(slot){ >- let start = slot[0]; >- let end = slot[1]; >+ let day, start, end; >+ [ day, start, end ] = slot.split("-"); > return format_hhmm(start) + _(" to ") + format_hhmm(end); > } >+ function delete_slot(node, branchcode){ >+ let slot = $(node).find('.pickup-slot').val(); >+ let splitted = slot.split("-"); >+ let day = splitted[0]; >+ let start = splitted[1]; >+ let end = splitted[2]; >+ opening_slots[branchcode].splice($.inArray(start+'-'+end, opening_slots), 1); >+ refresh_pickup_hours(branchcode); >+ } > function refresh_pickup_hours(branchcode) { >- let slots = {}; >- $("#conf-"+branchcode).find("input.pickup-slot").each(function(){ >- let splitted = $(this).val().split("-"); >- let day = splitted[0]; >- let start = splitted[1]; >- let end = splitted[2]; >- >- if(!slots[day]) slots[day] = []; >- >- slots[day].push([start, end]); >+ let slots_per_day = {}; >+ opening_slots[branchcode].forEach(function(slot){ >+ let day, start, end; >+ [ day, start, end ] = slot.split("-"); >+ if(!slots_per_day[day]) slots_per_day[day] = []; >+ slots_per_day[day].push(slot); > }); > >- let new_slot_node = $("<span class='slot'><input type='hidden' class='pickup-slot' name='pickup-slot-"+branchcode+"' value='"+day+"-"+start+"-"+end+"'/></span>"); >- $("#conf-"+branchcode).find(".pickup_hours").append(new_slot_node); >- > $("#conf-"+branchcode).find(".pickup_hours li").remove(); > >- Object.keys(slots).forEach(function(day){ >+ Object.keys(slots_per_day).forEach(function(day){ > let li_node = $('<li><label>'+get_day_lib(day)+'<label></li>'); >- slots[day].forEach(function(slot) { >- li_node.append('<span>'+format_slot(slot)+'</span>'); >+ slots_per_day[day].forEach(function(slot) { >+ let span_node = $('<span class="pickup-slot"></span>'); >+ span_node.append('<input type="hidden" class="pickup-slot" name="pickup-slot-'+branchcode+'" value="'+slot+'"/>'); >+ span_node.append('<span>'+format_slot(slot)+'</span>'); >+ >+ let delete_link = $('<a href="#" on><i class="fa fa-trash" aria-hidden="true"></i>').on('click', function(e){ e.preventDefault; delete_slot($(this).closest('li'), branchcode); }); >+ span_node.append(delete_link); >+ >+ span_node.appendTo(li_node); > }); > li_node.appendTo($("#conf-"+branchcode).find(".pickup_hours")); > }); >@@ -243,35 +232,31 @@ > function get_day_lib(day){ > let lib; > switch(day){ >- case 'sunday': >+ case '0': > lib = _("Sunday"); > break; >- case 'monday': >+ case '1': > lib = _("Monday"); > break; >- case 'tuesday': >+ case '2': > lib = _("Tuesday"); > break; >- case 'wednesday': >+ case '3': > lib = _("Wednesday"); > break; >- case 'thursday': >+ case '4': > lib = _("Thursday"); > break; >- case 'friday': >+ case '5': > lib = _("Friday"); > break; >- case 'saturday': >+ case '6': > lib = _("Saturday"); > break; > } > return lib; > } > >- let opening_slots = {}; >- [% FOR l IN libraries %] >- opening_slots["[% l.branchcode | html %]"] = []; >- [% END %] > $(document).ready(function(){ > [% FOR l IN libraries %] > refresh_pickup_hours("[% l.branchcode | html %]"); >@@ -282,7 +267,6 @@ > let day = $("#day-" + branchcode).val(); > let start = $("#new-start-" + branchcode).val(); > let end = $("#new-end-" + branchcode).val(); >- // FIXME confirm selection > > let start_hour, start_minute, end_hour, end_minute; > [ start_hour, start_minute ] = start.split(":"); >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 30650
:
136584
|
136585
|
136586
|
136587
|
136588
|
136589
|
136590
|
136591
|
136592
|
136593
|
136594
|
136595
|
136596
|
136597
|
136598
|
136599
|
136600
|
136601
|
136602
|
136603
|
136604
|
136605
|
136606
|
136607
|
136608
|
136609
|
136610
|
137095
|
137100
|
137199
|
137211
|
137212
|
137277
|
137278
|
137279
|
137280
|
137281
|
137282
|
137283
|
137284
|
137285
|
137286
|
137287
|
137288
|
137289
|
137290
|
137291
|
137292
|
137293
|
137294
|
137295
|
137296
|
137297
|
137298
|
137299
|
137300
|
137301
|
137302
|
137303
|
137304
|
137305
|
137306
|
137307
|
138261
|
138262
|
138263
|
138264
|
138265
|
138266
|
138267
|
138268
|
138269
|
138270
|
138271
|
138272
|
138273
|
138274
|
138275
|
138276
|
138277
|
138278
|
138279
|
138280
|
138281
|
138282
|
138283
|
138284
|
138285
|
138286
|
138287
|
138288
|
138289
|
138290
|
138291
|
138292
|
138319
|
138320
|
138321
|
138322
|
138323
|
138324
|
138325
|
138330
|
138331
|
138332
|
138333
|
138334
|
138335
|
138336
| 138337 |
138338
|
138339
|
138340
|
138341
|
138342
|
138343
|
138344
|
138345
|
138346
|
138347
|
138348
|
138349
|
138350
|
138351
|
138352
|
138353
|
138354
|
138355
|
138356
|
138357
|
138358
|
138359
|
138360
|
138361
|
138362
|
138363
|
138364
|
138365
|
138366
|
138367
|
138368
|
138369
|
138375
|
138401
|
138610