From bb315ba57a2d8e6fafa6e2b8d01cd9d91317ce01 Mon Sep 17 00:00:00 2001 From: CJ Lynce Date: Tue, 13 Aug 2024 20:52:34 +0000 Subject: [PATCH] Bug 36594: Library hours display issues The following issues existing when displays library hours in koha/admin/branches.pl -For newly created or edited libraries, 'null' is displayed when that time is undefined. -Time is displayed with seconds, which are not necessary. -The system preference CalendarFirstDayOfWeek is not respected when viewing a specific library with hours defined. This patch corrects these issues: -Undefined values are properly handled. All open & close times are undefined, the library is considered as not having hours set. -If open and close times for a day are both undefined, the library is considered closed. -Time is now displayed in the format HH:MM -CalendarFirstDayOfWeek is respected when viewing a library with defined hours. To Test: 1. Login to staff interface 2. Go to Koha administration > Basic parameters > Libraries 3. Edit any library or create a new library. Do not set hours. Save. 4. On the library list, in the hours column, all days are displayed with null. 5. Edit or create a 2nd library, set some hours, leaving at least one day without hours. Save. 6. In the library list, in the hours column, defined times are in the format HH:MM:SS. 7. Edit the system preference CalendarFirstDayOfWeek to set a day other than Sunday as the first day of the week. 8. Return to Go to Koha administration > Basic parameters > Libraries 9. Click on the name of a specific library with hours to view details. 10. The order of the calendar week still starts with Sunday. 11. Apply Patch. 12. Return to Go to Koha administration > Basic parameters > Libraries 13. Check that your library with all undefined times shows "Library hours not set". 14. Check that your library with defined hours is showing times in HH:MM format, and days without defined hours are "Closed". 15. Click on the name of a library with hours to view details. Verify that the calendar week starts respects CalendarFirstDayOfWeek. 16. Click on the name of another library without hours to view details. Verify these libraries show as "No opening hours have been set" in the branch detail view. Sponsored-by: Westlake Porter Public Library Signed-off-by: David Nind --- .../prog/en/modules/admin/branches.tt | 49 +++++++++++++++---- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt index d4bd388f27..bcb107297e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt @@ -556,7 +556,16 @@
  • Opening hours: - [% IF library.library_hours.count > 0 # Existing library %] + [% SET CalendarFirstDayOfWeek = Koha.Preference("CalendarFirstDayOfWeek") %] + [% SET set_hours = 0 %] + [% IF library.library_hours.count > 0 %] + [% FOR i IN [0..6] %] + [% IF library.library_hours.as_list.$i.open_time != null || library.library_hours.as_list.$i.close_time != null %] + [% set_hours = 1 %] + [% END %] + [% END %] + [% END %] + [% IF set_hours > 0 # Existing library %] [% SET library_hours = library.library_hours.as_list %] @@ -574,12 +583,18 @@ - - + [% IF hr.open_time == null && hr.close_time == null %] + + [% ELSE %] + + + [% END %] [% END %] @@ -757,7 +772,15 @@ { "data": function( row, type, val, meta ) { let result = ''; + let set_hours = 0; if ( row.library_hours.length > 0 ) { + for (let check_counter = 0; check_counter < 7; check_counter++) { + if ( row.library_hours[check_counter].open_time != null || row.library_hours[check_counter].close_time != null ) { + set_hours = 1; + } + } + } + if ( set_hours > 0 ) { const daysOfWeek = [ _("Sunday"), _("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday") ]; result = '
    [% PROCESS dayname day=d %] - [% hr.open_time | html %] - - [% hr.close_time | html %] - + Closed + + [% IF hr.open_time != null %][% hr.open_time.substr(0,5) | html %][% END %] + + [% IF hr.close_time != null %][% hr.close_time.substr(0,5) | html %][% END %] +
    '; @@ -766,8 +789,16 @@ const day = i % 7; // Wrap around the day using modulo operator result += ''; result += ''; - result += ''; - result += ''; + if ( row.library_hours[day].open_time == null && row.library_hours[day].close_time == null ) { + result += ''; + } else { + result += ''; + result += ''; + } result += ''; counter++; } -- 2.39.2
    DayOpen timeClose time
    '+daysOfWeek[day]+''+row.library_hours[day].open_time+''+row.library_hours[day].close_time+'Closed'; + result += row.library_hours[day].open_time != null ? row.library_hours[day].open_time.substr(0,5) : ''; + result += ''; + result += row.library_hours[day].close_time != null ? row.library_hours[day].close_time.substr(0,5) : ''; + result += '