From 8e5cd907072a75cee8116367b234362e97616c53 Mon Sep 17 00:00:00 2001 From: Kristian Feldsam Date: Sun, 3 Sep 2023 14:05:12 +0200 Subject: [PATCH] [Web] Filter tables by Domain where possible This feature was standard in Mailcow in pre-BS5 releases Signed-off-by: Kristian Feldsam --- data/web/js/site/mailbox.js | 46 +++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/data/web/js/site/mailbox.js b/data/web/js/site/mailbox.js index 3ddeea94..8381ab4d 100644 --- a/data/web/js/site/mailbox.js +++ b/data/web/js/site/mailbox.js @@ -851,8 +851,9 @@ jQuery(function($){ "tr" + "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", language: lang_datatables, - initComplete: function(){ + initComplete: function(settings, json){ hideTableExpandCollapseBtn('#tab-mailboxes', '#mailbox_table'); + filterByDomain(json, 8, table); }, ajax: { type: "GET", @@ -1362,8 +1363,9 @@ jQuery(function($){ "tr" + "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", language: lang_datatables, - initComplete: function(){ + initComplete: function(settings, json){ hideTableExpandCollapseBtn('#tab-resources', '#resource_table'); + filterByDomain(json, 5, table); }, ajax: { type: "GET", @@ -1509,8 +1511,9 @@ jQuery(function($){ "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", language: lang_datatables, order: [[2, 'desc']], - initComplete: function(){ + initComplete: function(settings, json){ hideTableExpandCollapseBtn('#collapse-tab-bcc', '#bcc_table'); + filterByDomain(json, 6, table); }, ajax: { type: "GET", @@ -1823,8 +1826,9 @@ jQuery(function($){ "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", language: lang_datatables, order: [[2, 'desc']], - initComplete: function(){ + initComplete: function(settings, json){ hideTableExpandCollapseBtn('#tab-mbox-aliases', '#alias_table'); + filterByDomain(json, 5, table); }, ajax: { type: "GET", @@ -2329,6 +2333,40 @@ jQuery(function($){ else $(tab).find(".table_collapse_option").hide(); } + + function filterByDomain(json, column, table){ + var tableId = $(table.table().container()).attr('id'); + // Create the `select` element + var select = $('') + .insertBefore( + $('#'+tableId+' .dataTables_filter > label > input') + ) + .on( 'change', function(){ + table.column(column) + .search($(this).val()) + .draw(); + }); + + // get all domains + var domains = []; + json.forEach(obj => { + Object.entries(obj).forEach(([key, value]) => { + if(key === 'domain') { + domains.push(value) + } + }); + }); + + // get unique domain list + domains = domains.filter(function(value, index, array) { + return array.indexOf(value) === index; + }); + + // add domains to select + domains.forEach(function(domain) { + select.append($('')); + }); + } // detect element visibility changes function onVisible(element, callback) {