Bugzilla – Attachment 134133 Details for
Bug 29648
Make KohaTable tables 'default length' and 'default sort' configurable
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29648: Improve existing code
Bug-29648-Improve-existing-code.patch (text/plain), 6.64 KB, created by
Katrin Fischer
on 2022-04-27 16:36:34 UTC
(
hide
)
Description:
Bug 29648: Improve existing code
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2022-04-27 16:36:34 UTC
Size:
6.64 KB
patch
obsolete
>From 0f13b3994f27907a17c4dd9d0e32be621ef2f6c7 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 16 Dec 2021 11:34:02 +0100 >Subject: [PATCH] Bug 29648: Improve existing code > >We already have 2 tables that are configurable, on acqui/basket and >reports/orders_by_budget. >This patch is modifying a bit the existing code to transfer the >responsability/logic to the KohaTable constructor instead of the >template that is creating the object. > >Signed-off-by: Owen Leonard <oleonard@myacpl.org> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> > >Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> >--- > C4/Utils/DataTables/TablesSettings.pm | 8 +++++++- > Koha/Template/Plugin/TablesSettings.pm | 3 +++ > .../prog/en/includes/columns_settings.inc | 11 ++++++++++- > .../intranet-tmpl/prog/en/modules/acqui/basket.tt | 13 +++++-------- > .../prog/en/modules/reports/orders_by_budget.tt | 7 ++----- > 5 files changed, 27 insertions(+), 15 deletions(-) > >diff --git a/C4/Utils/DataTables/TablesSettings.pm b/C4/Utils/DataTables/TablesSettings.pm >index 79c9417569..13157a71a3 100644 >--- a/C4/Utils/DataTables/TablesSettings.pm >+++ b/C4/Utils/DataTables/TablesSettings.pm >@@ -88,7 +88,13 @@ sub get_table_settings { > tablename => $tablename, > } > )->next; >- return $rs ? $rs : $list->{modules}{$module}{$page}{$tablename}; >+ >+ return { >+ default_display_length => $rs ? $rs->default_display_length >+ : $list->{modules}{$module}{$page}{$tablename}{default_display_length}, >+ default_sort_order => $rs ? $rs->default_sort_order >+ : $list->{modules}{$module}{$page}{$tablename}{default_sort_order} >+ }; > } > > sub get_modules { >diff --git a/Koha/Template/Plugin/TablesSettings.pm b/Koha/Template/Plugin/TablesSettings.pm >index 25df84e0ae..720b67445a 100644 >--- a/Koha/Template/Plugin/TablesSettings.pm >+++ b/Koha/Template/Plugin/TablesSettings.pm >@@ -132,6 +132,9 @@ sub GetTableSettings { > $format //= q{}; > > my $settings = C4::Utils::DataTables::TablesSettings::get_table_settings( $module, $page, $table ); >+ my $columns = C4::Utils::DataTables::TablesSettings::get_columns( $module, $page, $table ); >+ >+ $settings->{columns} = $columns; > > return $format eq 'json' > ? to_json( $settings || {} ) >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc >index 42d4fb09bc..4d61b10534 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc >@@ -3,12 +3,14 @@ > <!-- columns_settings.inc --> > > <script> >-function KohaTable(id_selector, dt_parameters, columns_settings, add_filters) { >+function KohaTable(id_selector, dt_parameters, table_settings, add_filters) { > var counter = 0; > var hidden_ids = []; > var included_ids = []; > var selector = '#' + id_selector; > >+ var columns_settings = table_settings['columns']; >+ > $(columns_settings).each( function() { > var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index( selector + ' th' ); > var used_id = dt_parameters.bKohaColumnsUseNames ? named_id : counter; >@@ -182,6 +184,13 @@ function KohaTable(id_selector, dt_parameters, columns_settings, add_filters) { > }); > } > >+ if ( table_settings.hasOwnProperty('default_display_length') ) { >+ new_parameters["pageLength"] = table_settings['default_display_length']; >+ } >+ if ( table_settings.hasOwnProperty('default_sort_order') ) { >+ new_parameters["order"] = [[ table_settings['default_sort_order'], 'asc' ]]; >+ } >+ > table.dataTable(new_parameters); > table.DataTable().on("column-visibility.dt", function(){ > if( typeof columnsInit == 'function' ){ >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt >index a716d459ae..e1ae56b631 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt >@@ -982,19 +982,16 @@ > [% END %] > [% END %] > <script> >- var columns_settings = [% TablesSettings.GetColumns( 'acqui', 'basket', 'orders', 'json' ) | $raw %]; >- [% IF !(Koha.Preference('EDIFACT') && ediaccount) %] >- columns_settings.splice(13,1); >- [% END %] >- [% SET table_settings = TablesSettings.GetTableSettings( 'acqui', 'basket', 'orders' ) %]; > $(document).ready(function() { >+ var table_settings = [% TablesSettings.GetTableSettings( 'acqui', 'basket', 'orders', 'json' ) | $raw %]; >+ [% IF !(Koha.Preference('EDIFACT') && ediaccount) %] >+ table_settings['columns'].splice(13, 1); >+ [% END %] > KohaTable("orders", { > "sPaginationType": "full", > "autoWidth": false, > "exportColumns": [0,1,2,3,4,5,6,7,8,9,10,11,12,13], >- "iDisplayLength": [% table_settings.default_display_length | html %], >- "order": [[ [% table_settings.default_sort_order | html %], 'asc']], >- }, columns_settings); >+ }, table_settings); > > var cancelledorderst = $("#cancelledorderst").dataTable($.extend(true, {}, dataTablesDefaults, { > "sPaginationType": "full" >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/orders_by_budget.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/orders_by_budget.tt >index 96edad15e2..5055f29776 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/orders_by_budget.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/orders_by_budget.tt >@@ -171,14 +171,11 @@ > [% INCLUDE 'datatables.inc' %] > [% INCLUDE 'columns_settings.inc' %] > <script> >- var columns_settings = [% TablesSettings.GetColumns( 'reports', 'orders_by_fund', 'funds-table', 'json' ) | $raw %]; >- [% SET table_settings = TablesSettings.GetTableSettings( 'reports', 'orders_by_fund', 'funds-table' ) %]; >+ var table_settings = [% TablesSettings.GetTableSettings( 'reports', 'orders_by_fund', 'funds-table', 'json' ) %]; > $(document).ready( function () { > var funds_table = KohaTable("funds", { >- "pageLength": [% table_settings.default_display_length | html %], >- "order": [[ [% table_settings.default_sort_order | html %], 'asc']], > 'autoWidth': false, >- }, columns_settings ); >+ }, table_settings ); > > showallbudgets = $('#budgetfilter').html(); > $('#budgetfilter .b_inactive').remove(); >-- >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 29648
:
128592
|
128593
|
128594
|
128595
|
128596
|
128597
|
128598
|
128599
|
128600
|
128601
|
128602
|
128603
|
128604
|
128605
|
128606
|
128607
|
128608
|
128609
|
128610
|
128611
|
128612
|
128613
|
128614
|
128615
|
128616
|
128617
|
128618
|
128619
|
128620
|
128621
|
128622
|
128623
|
128624
|
128625
|
128626
|
129084
|
129085
|
129089
|
129352
|
129685
|
129686
|
129770
|
129771
|
129772
|
129773
|
129774
|
129775
|
129776
|
129777
|
129778
|
129779
|
129780
|
129781
|
129782
|
129783
|
129784
|
129785
|
129786
|
129787
|
129788
|
129789
|
129790
|
129791
|
129792
|
129793
|
129794
|
129795
|
129796
|
129797
|
129798
|
129799
|
129800
|
129801
|
129802
|
129803
|
129804
|
129805
|
129806
|
131703
|
131875
|
131876
|
133001
|
133002
|
133003
|
133004
|
133005
|
133006
|
133007
|
133008
|
133009
|
133010
|
133011
|
133012
|
133013
|
133014
|
133015
|
133016
|
133017
|
133018
|
133019
|
133020
|
133021
|
133022
|
133023
|
133024
|
133025
|
133026
|
133027
|
134018
|
134019
|
134020
|
134021
|
134022
|
134023
|
134024
|
134025
|
134026
|
134027
|
134028
|
134029
|
134030
|
134031
|
134032
|
134033
|
134034
|
134035
|
134036
|
134037
|
134038
|
134039
|
134040
|
134041
|
134042
|
134043
|
134044
|
134045
|
134046
|
134047
|
134048
|
134049
|
134050
|
134051
|
134052
|
134053
|
134054
|
134086
|
134087
|
134088
|
134089
|
134090
|
134091
|
134092
|
134093
|
134094
|
134095
|
134096
|
134097
|
134098
|
134099
|
134100
|
134101
|
134102
|
134103
|
134104
|
134105
|
134106
|
134107
|
134108
|
134109
|
134110
|
134111
|
134112
|
134113
|
134114
|
134115
|
134116
|
134117
|
134118
|
134119
|
134120
|
134121
|
134122
|
134123
| 134133 |
134134
|
134135
|
134136
|
134137
|
134138
|
134139
|
134140
|
134141
|
134142
|
134143
|
134144
|
134145
|
134146
|
134147
|
134148
|
134149
|
134150
|
134151
|
134152
|
134153
|
134154
|
134155
|
134156
|
134157
|
134158
|
134159
|
134160
|
134161
|
134162
|
134163
|
134164
|
134165
|
134166
|
134167
|
134168
|
134169
|
134170
|
134171
|
134194