Bug 35716 - Duplicated assets in both koha-tmpl/intra-tmpl and koha-tmpl/opac-tmpl
Summary: Duplicated assets in both koha-tmpl/intra-tmpl and koha-tmpl/opac-tmpl
Status: Needs Signoff
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-01-05 17:09 UTC by Pedro Amorim
Modified: 2024-05-04 22:12 UTC (History)
10 users (show)

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


Attachments
Bug 35716: PoC (2.19 KB, patch)
2024-04-03 14:22 UTC, Pedro Amorim
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Pedro Amorim 2024-01-05 17:09:09 UTC
There are some JS assets duplicated in koha-tmpl/intra-tmpl and koha-tmpl/opac-tmpl.

100% match:
./koha-tmpl/opac-tmpl/bootstrap/js/i18n.js
./koha-tmpl/intranet-tmpl/js/i18n.js

100% match:
./koha-tmpl/opac-tmpl/bootstrap/js/Gettext.js
./koha-tmpl/intranet-tmpl/js/Gettext.js

~95% match:
./koha-tmpl/opac-tmpl/bootstrap/js/coce.js
./koha-tmpl/intranet-tmpl/js/coce.js

~95% match:
./koha-tmpl/opac-tmpl/bootstrap/js/cookieconsent.js
./koha-tmpl/intranet-tmpl/prog/js/cookieconsent.js

~80% match:
./koha-tmpl/opac-tmpl/bootstrap/js/ill-availability.js
./koha-tmpl/intranet-tmpl/prog/js/ill-availability.js

~50% match:
./koha-tmpl/opac-tmpl/bootstrap/js/basket.js
./koha-tmpl/intranet-tmpl/prog/js/basket.js

Some of the differences in the above pairs may have been due to requirements specific to only staff or to only OPAC, or it may also have been the case that they have fallen out of sync over the years with some enhancements being added to one of the pair and not the other.

I don't know what the best solution for this would be (if one is needed) but developing bug 35604 I need to have the same JS file on both intra and OPAC and feels bad to have to copy the same file to 2 different places.

I'm only looking for JS files but I know this is also the case for images, maybe some CSS and other assets.

Could we consider having a koha-tmpl/shared-tmpl directory, or have some of these overlapping assets only exist once and have them be duplicated for each interface during build, or yet another better option?
Comment 1 Pedro Amorim 2024-04-03 14:22:52 UTC
Created attachment 164381 [details] [review]
Bug 35716: PoC

**K-T-D TEST ONLY**
At /kohadevbox/koha, run the following:
- sudo cpan File::Copy::Recursive
- sudo rm -rf /usr/share/koha
- sudo perl Makefile.PL # press Enter on all prompts
- sudo make install
- find /usr/share/koha -name hello.js
Notice the output:
/usr/share/koha/opac/htdocs/opac-tmpl/js/hello.js
/usr/share/koha/intranet/htdocs/intranet-tmpl/js/hello.js

My first attemp was using the file_map that is used to PM
but I failed. Even changing the code to allow for multiple targets
in the file_map, the WriteMakefile will always only map 1 to 1
from the PM hashref. But PL_FILES allows for an array of destinations
given one source.

This patch needs more work as a SHARED_TMPL_DIR env variable
would be ideal, amongst other improvements, but this is just a proof of
concept to have others look at and see if they agree with this approach.
Comment 2 Pedro Amorim 2024-05-03 14:27:21 UTC
Changing to NSO to get more eyes on it.
Comment 3 Nick Clemens (kidclamp) 2024-05-03 14:42:07 UTC
I love the idea here - it's frustrating that we have to maintain two sets of files for the same purposes - this could go along way towards standardizing more of what we do
Comment 4 Martin Renvoize 2024-05-03 19:13:43 UTC
I love the direction here though I wonder what you mean by a SHARED_TMPL_DIR environment variable?

I wonder if we could perhaps use some symlinking for development so one doesn't have to run make to test changes to these files?.. not sure if there would be a performance implications in live running using symlinks Vs hard files either on that front.

Thanks for raising this again Pedro.. sure we must be able to resolve this age old problem by now
Comment 5 Martin Renvoize 2024-05-03 19:21:16 UTC
https://gitlab.com/koha-community/Koha/-/blob/main/C4/Templates.pm?ref_type=heads#L52

I feel like we could do something here perhaps.. so instead of make copying to two places, we have a shared directory at the top level where we look for included including translated ones after we've looked in the more localised for themes version of the same files?
Comment 6 David Nind 2024-05-04 22:12:06 UTC
I think this is a great idea! It makes no sense to me to have duplicates, and then need to remember to update in two places when changes are made.

If they only relate to the staff and OPAC templates, maybe just having a shared folder under koha-tmpl would be sufficient (as proposed in comment #1?

Bearing in mind I don't understand all the nuances (such as for translation, or custom templates) , maybe that is too simplistic...