[Web] Filter tables by Domain where possible

This feature was standard in Mailcow in pre-BS5 releases

Signed-off-by: Kristian Feldsam <feldsam@gmail.com>
This commit is contained in:
Kristian Feldsam 2023-09-03 14:05:12 +02:00
parent 372b1c7bbc
commit 8e5cd90707

View File

@ -851,8 +851,9 @@ jQuery(function($){
"tr" + "tr" +
"<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
language: lang_datatables, language: lang_datatables,
initComplete: function(){ initComplete: function(settings, json){
hideTableExpandCollapseBtn('#tab-mailboxes', '#mailbox_table'); hideTableExpandCollapseBtn('#tab-mailboxes', '#mailbox_table');
filterByDomain(json, 8, table);
}, },
ajax: { ajax: {
type: "GET", type: "GET",
@ -1362,8 +1363,9 @@ jQuery(function($){
"tr" + "tr" +
"<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
language: lang_datatables, language: lang_datatables,
initComplete: function(){ initComplete: function(settings, json){
hideTableExpandCollapseBtn('#tab-resources', '#resource_table'); hideTableExpandCollapseBtn('#tab-resources', '#resource_table');
filterByDomain(json, 5, table);
}, },
ajax: { ajax: {
type: "GET", type: "GET",
@ -1509,8 +1511,9 @@ jQuery(function($){
"<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
language: lang_datatables, language: lang_datatables,
order: [[2, 'desc']], order: [[2, 'desc']],
initComplete: function(){ initComplete: function(settings, json){
hideTableExpandCollapseBtn('#collapse-tab-bcc', '#bcc_table'); hideTableExpandCollapseBtn('#collapse-tab-bcc', '#bcc_table');
filterByDomain(json, 6, table);
}, },
ajax: { ajax: {
type: "GET", type: "GET",
@ -1823,8 +1826,9 @@ jQuery(function($){
"<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
language: lang_datatables, language: lang_datatables,
order: [[2, 'desc']], order: [[2, 'desc']],
initComplete: function(){ initComplete: function(settings, json){
hideTableExpandCollapseBtn('#tab-mbox-aliases', '#alias_table'); hideTableExpandCollapseBtn('#tab-mbox-aliases', '#alias_table');
filterByDomain(json, 5, table);
}, },
ajax: { ajax: {
type: "GET", type: "GET",
@ -2329,6 +2333,40 @@ jQuery(function($){
else else
$(tab).find(".table_collapse_option").hide(); $(tab).find(".table_collapse_option").hide();
} }
function filterByDomain(json, column, table){
var tableId = $(table.table().container()).attr('id');
// Create the `select` element
var select = $('<select class="btn btn-sm btn-xs-lg btn-light text-start mx-2"><option value="">'+lang.all_domains+'</option></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($('<option>' + domain + '</option>'));
});
}
// detect element visibility changes // detect element visibility changes
function onVisible(element, callback) { function onVisible(element, callback) {