Bug 36716 - Need a better way of looping through smart-rules ( circ table ) columns
Summary: Need a better way of looping through smart-rules ( circ table ) columns
Status: RESOLVED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Circulation (show other bugs)
Version: Main
Hardware: All All
: P5 - low minor
Assignee: Emily Lamancusa (emlam)
QA Contact: Martin Renvoize (ashimema)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-04-29 15:43 UTC by Lucas Gass (lukeg)
Modified: 2024-11-18 21:47 UTC (History)
4 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
24.11.00
Circulation function:


Attachments
Bug 36716: Do special processing based on input id, not column index (6.27 KB, patch)
2024-08-09 18:27 UTC, Emily Lamancusa (emlam)
Details | Diff | Splinter Review
Bug 36716: Do special processing based on input id, not column index (6.32 KB, patch)
2024-08-12 15:47 UTC, Lucas Gass (lukeg)
Details | Diff | Splinter Review
Bug 36716: Do special processing based on input id, not column index (6.39 KB, patch)
2024-08-21 08:25 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Lucas Gass (lukeg) 2024-04-29 15:43:15 UTC
When a user clicks "Edit" ( .editrule ) we use JavaScript to loop through each of the columns in the table. This is done based on the column index like so:

if ( i == 3 ) 

or 

} else if ( i == 5 || i == 6 || i == 26 || i == 27 || i == 28 || current_input_id === "holds_pickup_period" ) {

This leads to problems like Bug 36708. 

We could probably give the columns names/classes so we don't have to rely on the index, which may vary between Koha versions.
Comment 1 Emily Lamancusa (emlam) 2024-08-09 17:03:23 UTC
+1 for this!

Commit c654932f0c376b2b619c9bd4550aab0adf9acdab from bug 8367 did something like that for the holds pickup period - checking the input id rather than the index. Taking a stab at this using that method...

I'm also changing this to a bug rather than an enhancement, because similar bugs keep cropping up (I'm seeing at least one, with no automatic renewal after (hard limit) again, in main currently).
Comment 2 Emily Lamancusa (emlam) 2024-08-09 18:27:11 UTC
Created attachment 170214 [details] [review]
Bug 36716: Do special processing based on input id, not column index

When a user clicks "Edit" ( .editrule ) we use JavaScript to loop
through each of the columns in the table to copy the appropriate values
into the input fields. Fields that need special processing are
identified by the column index, which can lead to problems when the
index varies between Koha versions or columns are shown/hidden based
on syspref settings.

In the current main, there is at least one such bug causing the
value for "no automatic renewal before" not to propagate, but to get
silently saved in the "no automatic renewal before (hard limit)" field
instead.

Identifying fields for special processing based on input id rather than
index should fix the above issue and avoid similar regressions.

To test:
1. Create a circulation rule that has:
    a) a value (such as 30) in the column "No automatic renewal after"
    b) no value in the column "No automatic renewal after (hard limit)"
2. Click the button to edit the circulation rule from step 1
--> The text field for "No automatic renewal after" is blank
3. Save the rule without making any changes
--> "No automatic renewal after" is now blank for this rule, but "No
    automatic renewal after (hard limit)" has a date in it
4. Apply patch
5. Repeat steps 1-3
--> "No automatic renewal after" and "No automatic renewal after (hard
     limit)" now preserve their values correctly
6. Create a circulation rule that has a non-default value in every field
7. Edit the circulation rule from step 6
--> Confirm that all values are copied to the edit fields correctly
8. Save the rule without making any changes
--> Confirm that the rule saved correctly
9. Create a circulation rule, leaving the following columns blank:
    "Current checkouts allowed"
    "Current on-site checkouts allowed"
    "Holds allowed (total)"
    "Holds allowed (daily)"
    "Holds per record (count)"
--> The above columns should display as "Unlimited"
10. Edit the rule from step 9
--> The input fields for the above columns should be blank
11. Save the rule without making any changes
--> The above fields should still display as "Unlimited"
Comment 3 Lucas Gass (lukeg) 2024-08-12 15:47:57 UTC
Created attachment 170233 [details] [review]
Bug 36716: Do special processing based on input id, not column index

When a user clicks "Edit" ( .editrule ) we use JavaScript to loop
through each of the columns in the table to copy the appropriate values
into the input fields. Fields that need special processing are
identified by the column index, which can lead to problems when the
index varies between Koha versions or columns are shown/hidden based
on syspref settings.

In the current main, there is at least one such bug causing the
value for "no automatic renewal before" not to propagate, but to get
silently saved in the "no automatic renewal before (hard limit)" field
instead.

Identifying fields for special processing based on input id rather than
index should fix the above issue and avoid similar regressions.

To test:
1. Create a circulation rule that has:
    a) a value (such as 30) in the column "No automatic renewal after"
    b) no value in the column "No automatic renewal after (hard limit)"
2. Click the button to edit the circulation rule from step 1
--> The text field for "No automatic renewal after" is blank
3. Save the rule without making any changes
--> "No automatic renewal after" is now blank for this rule, but "No
    automatic renewal after (hard limit)" has a date in it
4. Apply patch
5. Repeat steps 1-3
--> "No automatic renewal after" and "No automatic renewal after (hard
     limit)" now preserve their values correctly
6. Create a circulation rule that has a non-default value in every field
7. Edit the circulation rule from step 6
--> Confirm that all values are copied to the edit fields correctly
8. Save the rule without making any changes
--> Confirm that the rule saved correctly
9. Create a circulation rule, leaving the following columns blank:
    "Current checkouts allowed"
    "Current on-site checkouts allowed"
    "Holds allowed (total)"
    "Holds allowed (daily)"
    "Holds per record (count)"
--> The above columns should display as "Unlimited"
10. Edit the rule from step 9
--> The input fields for the above columns should be blank
11. Save the rule without making any changes
--> The above fields should still display as "Unlimited"

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 4 Lucas Gass (lukeg) 2024-08-12 15:48:23 UTC
Thanks, Emily!
Comment 5 Martin Renvoize (ashimema) 2024-08-21 08:25:27 UTC
Created attachment 170533 [details] [review]
Bug 36716: Do special processing based on input id, not column index

When a user clicks "Edit" ( .editrule ) we use JavaScript to loop
through each of the columns in the table to copy the appropriate values
into the input fields. Fields that need special processing are
identified by the column index, which can lead to problems when the
index varies between Koha versions or columns are shown/hidden based
on syspref settings.

In the current main, there is at least one such bug causing the
value for "no automatic renewal before" not to propagate, but to get
silently saved in the "no automatic renewal before (hard limit)" field
instead.

Identifying fields for special processing based on input id rather than
index should fix the above issue and avoid similar regressions.

To test:
1. Create a circulation rule that has:
    a) a value (such as 30) in the column "No automatic renewal after"
    b) no value in the column "No automatic renewal after (hard limit)"
2. Click the button to edit the circulation rule from step 1
--> The text field for "No automatic renewal after" is blank
3. Save the rule without making any changes
--> "No automatic renewal after" is now blank for this rule, but "No
    automatic renewal after (hard limit)" has a date in it
4. Apply patch
5. Repeat steps 1-3
--> "No automatic renewal after" and "No automatic renewal after (hard
     limit)" now preserve their values correctly
6. Create a circulation rule that has a non-default value in every field
7. Edit the circulation rule from step 6
--> Confirm that all values are copied to the edit fields correctly
8. Save the rule without making any changes
--> Confirm that the rule saved correctly
9. Create a circulation rule, leaving the following columns blank:
    "Current checkouts allowed"
    "Current on-site checkouts allowed"
    "Holds allowed (total)"
    "Holds allowed (daily)"
    "Holds per record (count)"
--> The above columns should display as "Unlimited"
10. Edit the rule from step 9
--> The input fields for the above columns should be blank
11. Save the rule without making any changes
--> The above fields should still display as "Unlimited"

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 6 Martin Renvoize (ashimema) 2024-08-21 08:26:04 UTC
Massive Dev quality of life improvement here.. thanks Lucas.. no idea why we haven't done this before now!
Comment 7 Katrin Fischer 2024-08-23 15:33:55 UTC
(In reply to Martin Renvoize from comment #6)
> Massive Dev quality of life improvement here.. thanks Lucas.. no idea why we
> haven't done this before now!

I agree!
Comment 8 Katrin Fischer 2024-08-23 15:36:07 UTC
One question, why not update these? (visible above one of the deleted lines in the patch):

 if ( i == 0 || i == 1 ) {
Comment 9 Katrin Fischer 2024-08-23 16:22:24 UTC
Pushed for 24.11!

Well done everyone, thank you!
Comment 10 Katrin Fischer 2024-11-14 15:22:35 UTC
(In reply to Katrin Fischer from comment #8)
> One question, why not update these? (visible above one of the deleted lines
> in the patch):
> 
>  if ( i == 0 || i == 1 ) {

Never got a reply. Dropping.