From dd8c3e58366905388837e528e48197db81bfa30d Mon Sep 17 00:00:00 2001
From: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Date: Wed, 7 Feb 2024 16:45:48 +0000
Subject: [PATCH] Bug 32693: Proof of concept

This is a PoC for discussion.
Now, only the tab being viewed is processed and loaded.
---
 about.pl                                      | 62 ++++++++++++-----
 .../prog/en/includes/html_helpers.inc         | 12 ++++
 .../intranet-tmpl/prog/en/modules/about.tt    | 67 ++++++++++---------
 3 files changed, 90 insertions(+), 51 deletions(-)

diff --git a/about.pl b/about.pl
index 218c384b389..62df3d93bbb 100755
--- a/about.pl
+++ b/about.pl
@@ -61,6 +61,8 @@ use Koha::Filter::MARC::ViewPolicy;
 use C4::Members::Statistics;
 
 my $query = CGI->new;
+my $params = $query->Vars();
+
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {
         template_name   => "about.tt",
@@ -70,6 +72,26 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     }
 );
 
+my $tab = $params->{tab} || 'about';
+
+$template->param(
+    tab => $tab,
+);
+
+my $docdir;
+if ( defined C4::Context->config('docdir') ) {
+    $docdir = C4::Context->config('docdir');
+} else {
+
+    # if no <docdir> is defined in koha-conf.xml, use the default location
+    # this is a work-around to stop breakage on upgraded Kohas, bug 8911
+    $docdir = C4::Context->config('intranetdir') . '/docs';
+}
+
+my %versions = C4::Context::get_versions();
+
+if ( $tab eq 'about' ) {
+
 my $config_timezone = C4::Context->config('timezone') // '';
 my $config_invalid  = !DateTime::TimeZone->is_valid_name( $config_timezone );
 my $env_timezone    = $ENV{TZ} // '';
@@ -162,9 +184,21 @@ $template->param(
     memcached_namespace => $memcached_namespace,
     is_memcached_still_active => $is_memcached_still_active,
     where_is_memcached_config => $where_is_memcached_config,
+    perlPath      => $perl_path,
+    zebraVersion  => $zebraVersion,
+    kohaVersion   => $versions{'kohaVersion'},
+    osVersion     => $versions{'osVersion'},
+    perlVersion   => $versions{'perlVersion'},
+    perlIncPath   => [ map { perlinc => $_ }, @INC ],
+    mysqlVersion  => $versions{'mysqlVersion'},
+    apacheVersion => $versions{'apacheVersion'},
     memcached_running   => Koha::Caches->get_instance->memcached_cache,
 );
 
+}
+
+if($tab eq 'sysinfo') {
+    
 # Additional system information for warnings
 
 my $warnStatisticsFieldsError;
@@ -654,17 +688,7 @@ $template->param( 'bad_yaml_prefs' => \@bad_yaml_prefs ) if @bad_yaml_prefs;
     $template->param( warnDbRowFormat => C4::Installer->has_non_dynamic_row_format );
 }
 
-my %versions = C4::Context::get_versions();
-
 $template->param(
-    kohaVersion   => $versions{'kohaVersion'},
-    osVersion     => $versions{'osVersion'},
-    perlPath      => $perl_path,
-    perlVersion   => $versions{'perlVersion'},
-    perlIncPath   => [ map { perlinc => $_ }, @INC ],
-    mysqlVersion  => $versions{'mysqlVersion'},
-    apacheVersion => $versions{'apacheVersion'},
-    zebraVersion  => $zebraVersion,
     prefRequireChoosingExistingAuthority => $prefRequireChoosingExistingAuthority,
     prefAutoCreateAuthorities => $prefAutoCreateAuthorities,
     warnPrefRequireChoosingExistingAuthority => $warnPrefRequireChoosingExistingAuthority,
@@ -682,6 +706,9 @@ $template->param(
     xml_config_warnings => \@xml_config_warnings,
     warnStatisticsFieldsError => $warnStatisticsFieldsError,
 );
+}
+
+if ( $tab eq 'perl' ) {
 
 my @components = ();
 
@@ -734,17 +761,12 @@ if (scalar(@$row) > 0) {
 
 $template->param( table => $table );
 
+}
+
+if ( $tab eq 'team' ) {
 
 ## ------------------------------------------
 ## Koha contributions
-my $docdir;
-if ( defined C4::Context->config('docdir') ) {
-    $docdir = C4::Context->config('docdir');
-} else {
-    # if no <docdir> is defined in koha-conf.xml, use the default location
-    # this is a work-around to stop breakage on upgraded Kohas, bug 8911
-    $docdir = C4::Context->config('intranetdir') . '/docs';
-}
 
 ## Release teams
 my $teams =
@@ -840,6 +862,9 @@ $template->param( contributors => \@people );
 $template->param( maintenance_team => $teams->{team}->{$dev_team} );
 $template->param( release_team => $teams->{team}->{$short_version} );
 
+}
+if ( $tab eq 'history' ) {
+
 ## Timeline
 if ( open( my $file, "<:encoding(UTF-8)", "$docdir" . "/history.txt" ) ) {
 
@@ -879,5 +904,6 @@ if ( open( my $file, "<:encoding(UTF-8)", "$docdir" . "/history.txt" ) ) {
 } else {
     $template->param( timeline_read_error => 1 );
 }
+}
 
 output_html_with_http_headers $query, $cookie, $template->output;
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc
index 535cbca2c91..f1a1d69e55c 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc
@@ -387,6 +387,18 @@
     </ul>
 [% END %]
 
+[% BLOCK tab_item_link %]
+    [% IF ( bt_active ) %]
+        <li role="presentation" class="active">
+    [% ELSE %]
+        <li role="presentation">
+    [% END %]
+        <a href="?tab=[% link | url %]" id="[% tabname | uri %]-tab">
+            [% content | $raw %]
+        </a>
+    </li>
+[% END %]
+
 [% BLOCK tab_item %]
     [% IF ( bt_active ) %]
         <li role="presentation" class="active">
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt
index 4e916f75a3d..997863f2e66 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt
@@ -33,18 +33,19 @@
 
             [% WRAPPER tabs id= "abouttabs" %]
                 [% WRAPPER tabs_nav %]
-                    [% WRAPPER tab_item tabname= "about" bt_active= 1 %] <span>Server information</span> [% END %]
-                    [% WRAPPER tab_item tabname= "perl" %] <span>Perl modules</span> [% END %]
-                    [% WRAPPER tab_item tabname= "sysinfo" %] <span>System information</span> [% END %]
-                    [% WRAPPER tab_item tabname= "team" %] <span>Koha team</span> [% END %]
-                    [% WRAPPER tab_item tabname= "licenses" %] <span>Licenses</span> [% END %]
-                    [% WRAPPER tab_item tabname= "translations" %] <span>Translations</span> [% END %]
-                    [% WRAPPER tab_item tabname= "history" %] <span>Timeline</span> [% END %]
-                    [% WRAPPER tab_item tabname= "dedications" %] <span>Dedications</span> [% END %]
+                    [% WRAPPER tab_item_link link = "about" bt_active = tab == "about" %] <span>Server information</span> [% END %]
+                    [% WRAPPER tab_item_link link = "perl" bt_active = tab == "perl" %] <span>Perl modules</span> [% END %]
+                    [% WRAPPER tab_item_link link = "sysinfo" bt_active = tab == "sysinfo" %] <span>System information</span> [% END %]
+                    [% WRAPPER tab_item_link link = "team" bt_active = tab == "team" %] <span>Koha team</span> [% END %]
+                    [% WRAPPER tab_item_link link = "licenses" bt_active = tab == "licenses" %] <span>Licenses</span> [% END %]
+                    [% WRAPPER tab_item_link link = "translations" bt_active = tab == "translations" %] <span>Translations</span> [% END %]
+                    [% WRAPPER tab_item_link link = "history" bt_active = tab == "history" %] <span>Timeline</span> [% END %]
+                    [% WRAPPER tab_item_link link = "dedications" bt_active = tab == "dedications" %] <span>Dedications</span> [% END %]
                 [% END %]
 
                 [% WRAPPER tab_panels %]
-                    [% WRAPPER tab_panel tabname= "about" bt_active= 1 %]
+                    [% IF tab == 'about' %]
+                        [% WRAPPER tab_panel tabname= "about" bt_active= 1 %]
                         <table>
                             <caption>Server information</caption>
                             <tr>
@@ -218,9 +219,12 @@
                                 </td>
                             </tr>
                         </table>
-                    [% END # /WRAPPER tab_item about %]
+                    [% END # tab=about %]
+                    [% END # tab=about %]
+
+                    [% #WRAPPER tab_panel tabname= "perl" %]
+                    [% IF tab == 'perl' %]
 
-                    [% WRAPPER tab_panel tabname= "perl" %]
                         <table style="cursor:pointer">
                             <caption>Perl modules</caption>
                             [% FOREACH tabl IN table %]
@@ -268,12 +272,13 @@
                                 </tr>
                             [% END # /FOREACH tabl %]
                         </table>
-                    [% END # /WRAPPER tab_item perl %]
+                    [% END # tab=perl %]
 
+                    [% IF tab == 'sysinfo' %]
                     [% IF Asset.css("css/staff-global.css") == "" || Asset.js("js/vue/dist/erm.js") == "" %]
                         [% SET warnMissingCompiledFiles = 1 %]
                     [% END %]
-                    [% WRAPPER tab_panel tabname= "sysinfo" %]
+                    [% #WRAPPER tab_panel tabname= "sysinfo" %]
                         [% IF weasyprint_missing || warnPrefRequireChoosingExistingAuthority || warnPrefEasyAnalyticalRecords || warnPrefAnonymousPatronOPACPrivacy || warnPrefAnonymousPatronAnonSuggestions || warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist || warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist || warnPrefKohaAdminEmailAddress || warnPrefOpacHiddenItems || warnPrefPatronSelfRegistrationDefaultCategory || invalid_yesno.count || warnNoActiveCurrency || warnIsRootUser || xml_config_warnings.size || warnI18nMissing || AutoSelfCheckPatronDoesNotHaveSelfCheckPerm || AutoSelfCheckPatronHasTooManyPerm || warnStatisticsFieldsError || warnNoTemplateCaching || warnILLConfiguration || has_ai_issues || oauth2_missing_deps || bad_yaml_prefs || warnRelationships || log4perl_errors || config_bcrypt_settings_no_set || warnHiddenBiblionumbers.size || warnConnectBroker || elasticsearch_has_missing || warnMissingCompiledFiles || warnDbRowFormat %]
                             [% IF ( warnDbRowFormat ) %]
                                 <h2>Database row format incorrect</h2>
@@ -754,9 +759,10 @@
                         [% ELSE %]
                             <p>No warnings.</p>
                         [% END # /IF warnRequireChoosingExistingAuthority... %]
-                    [% END # /WRAPPER tab_item sysinfo %]
+                    [% END # tab=sysinfo %]
 
-                    [% WRAPPER tab_panel tabname= "team" %]
+                    [% IF tab == 'team' %]
+                    [% #WRAPPER tab_panel tabname= "team" %]
                         <h2>Special thanks to the following organizations</h2>
                         <ul>
                             <li>
@@ -965,9 +971,10 @@
                             <li>Nicholas Rosasco (Documentation Compiler)</li>
                             <li>Regula Sebastiao</li>
                         </ul>
-                    [% END # /WRAPPER tab_item team %]
+                    [% END # tab=team %]
 
-                    [% WRAPPER tab_panel tabname= "licenses" %]
+                    [% IF tab == 'licenses' %]
+                    [% #WRAPPER tab_panel tabname= "licenses" %]
                         <h2>Koha</h2>
                         <p>
                             This program is free software: you can redistribute it and/or modify it under the terms of the <a rel="license" href="https://www.gnu.org/licenses/gpl-3.0.html">GNU General Public License</a> as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
@@ -1212,9 +1219,10 @@
                             <a href="https://mottie.github.io/Keyboard/index.html">Virtual Keyboard v1.30.1</a>: <a href="https://github.com/Mottie/Keyboard/blob/v1.30.1/LICENSE">MIT Licence</a>
                         </p>
 
-                    [% END # /WRAPPER tab_item licenses %]
+                    [% END # tab=licenses %]
 
-                    [% WRAPPER tab_panel tabname= "translations" %]
+                    [% IF tab == 'translations' %]
+                    [% #WRAPPER tab_panel tabname= "translations" %]
                         <h2>Translation</h2>
                         <ul>
                             <li>العربية (Arabic) Version 3.2 to 3.4, 3.16 & 3.18 by KnowledgeWare Technologies; Versions 3.6 to 3.14 by Arabic Koha support team: Karam Qubsi, Kouider Bounama, Sham Bajaa, Ghofran Alshami, Chrestian Aboud, Fatema Salem and Duaa Bazzazi.
@@ -1263,9 +1271,10 @@
                             <li>&#1575;&#1585;&#1583;&#1608;(Urdu) Ata ur Rehman</li>
                             <li>&#1059;&#1082;&#1088;&#1072;&#1111;&#1085;&#1089;&#1100;&#1082;&#1072; (Ukrainian) Victor Titarchuk and Serhij Dubyk</li>
                         </ul>
-                    [% END # /WRAPPER tab_item translations %]
+                    [% END #tab=translations %]
 
-                    [% WRAPPER tab_panel tabname= "history" %]
+                    [% IF tab == 'history' %]
+                    [% #WRAPPER tab_panel tabname= "history" %]
                         <h2>Koha history timeline</h2>
                         [% IF ! timeline_read_error %]
                             <table style="cursor:pointer">
@@ -1289,9 +1298,10 @@
                                 Could not read the history.txt file. Please make sure &lt;docdir&gt; is correctly defined in koha-conf.xml.
                             </div>
                         [% END %]
-                    [% END # /WRAPPER tab_item history %]
+                    [% END # tab=history %]
 
-                    [% WRAPPER tab_panel tabname= "dedications" %]
+                    [% IF tab == 'dedications' %]
+                    [% #WRAPPER tab_panel tabname= "dedications" %]
                         <h2>22.11</h2>
                         <p>
                             The Koha Community would like to dedicate the release of Koha 22.11 to Rosalie Blake.
@@ -1306,19 +1316,10 @@
                             She was also a practicing Justice of the Peace, a stalwart of the Levin Pottery Club and much loved
                             mother of Simon and Jeremy, and grandmother of Ben, Toby, Anna, Charlotte and Billy.
                         </p>
-                    [% END # /WRAPPER tab_item dedications %]
+                    [% END # tab=dedications %]
                 [% END %]
             [% END # /WRAPPER abouttabs %]
         </div> <!-- /.col-md-12 -->
     </div> <!-- /.row -->
-
-[% MACRO jsinclude BLOCK %]
-    <script>
-        $(document).ready(function(){
-            selectBsTabByHash( "abouttabs" );
-        });
-    </script>
-[% END %]
-
 <!-- the main div is closed in intranet-bottom.inc -->
 [% INCLUDE 'intranet-bottom.inc' %]
-- 
2.30.2