Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,120 +18,10 @@
*/
"use strict";

const messageCategoryList = '#message-category-list';
const messagePriorityList = '#message-priority-list';
const messageHtmlTable = '#messagesTable';
const messagePriorities = ['High', 'Info'];

var dataTableRef;

/**
* Updates the list of message priorities
*/
function updateMessagePriorities() {
var priorityList = $(messagePriorityList);
$.each(messagePriorities, function (index, pri) {
var switchId = "msg-pri-switch-" + pri;
var switchElement = "#" + switchId;
var savedValue = localStorage.getItem(switchId + "-state");

if ($(switchElement).length) {
// update it
if (savedValue === null || savedValue === 'true') {
$(switchElement).prop('checked', true);
} else {
$(switchElement).prop('checked', false);
}
} else {
// create it
var div = $(document.createElement("div"));
div.addClass("form-check form-switch");

var input = $(document.createElement("input"));
input.addClass("form-check-input");
input.attr("type", "checkbox");
input.attr("role", "switch");
input.attr("id", switchId);

if (savedValue === null || savedValue === 'true') {
input.prop('checked', true);
} else {
input.prop('checked', false);
}

input.on("change", function () {
localStorage.setItem("msg-pri-switch-" + pri + "-state", $(this).is(':checked'));
refresh();
});
div.append(input);

var label = $(document.createElement("label"));
label.addClass("form-check-label fs-6");
label.attr("for", switchId);
label.text(pri);
div.append(label);

priorityList.append(div);
}
});

}

/**
* Updates the list of message categories
*/
function updateMessageCategories() {

var categories = getStoredArray(MESSAGE_CATEGORIES);

var categoryList = $(messageCategoryList);
$.each(categories, function (index, cat) {

var switchId = "msg-cat-switch-" + cat;
var switchElement = "#" + switchId;
var savedValue = localStorage.getItem(switchId + "-state");

if ($(switchElement).length) {
// update it
if (savedValue === null || savedValue === 'true') {
$(switchElement).prop('checked', true);
} else {
$(switchElement).prop('checked', false);
}
} else {
// create it
var div = $(document.createElement("div"));
div.addClass("form-check form-check-inline form-switch");

var input = $(document.createElement("input"));
input.addClass("form-check-input");
input.attr("type", "checkbox");
input.attr("role", "switch");
input.attr("id", switchId);

if (savedValue === null || savedValue === 'true') {
input.prop('checked', true);
} else {
input.prop('checked', false);
}

input.on("change", function () {
localStorage.setItem("msg-cat-switch-" + cat + "-state", $(this).is(':checked'));
refresh();
});
div.append(input);

var label = $(document.createElement("label"));
label.addClass("form-check-label fs-6");
label.attr("for", switchId);
label.text(cat);
div.append(label);

categoryList.append(div);
}
});

}
var categories;

function fetchTableData() {

Expand Down Expand Up @@ -170,15 +60,19 @@ function getTableData() {
}

function loadMessagesPageData() {
return getMessageCategories().then(function () {

categories = getStoredArray(MESSAGE_CATEGORIES);
if (categories.length === 0) {
return getMessageCategories().then(function () {
return fetchTableData();
});
} else {
return fetchTableData();
});
}
}

function refresh() {
return loadMessagesPageData().then(function () {
updateMessagePriorities();
updateMessageCategories();
if (dataTableRef) {
ajaxReloadTable(dataTableRef);
}
Expand Down Expand Up @@ -214,8 +108,6 @@ function createDataTable() {

$(function () {
loadMessagesPageData().then(function () {
updateMessagePriorities();
updateMessageCategories();
createDataTable();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ const NAVBAR_COMPONENTS = [{
countId: 'compactorStatusCount'
}];

var categories;

/**
* Remove other bootstrap color classes and add the given class to the given element
* @param {string} elementId the element id to update
Expand Down Expand Up @@ -148,7 +150,17 @@ function updateServerNotifications(statusData) {
$(function () {
setTheme();
updateDarkThemeSwitch();
updateMessagePriorities();
refreshSidebar();

categories = getStoredArray(MESSAGE_CATEGORIES);
if (categories.length === 0) {
getMessageCategories().then(function () {
updateMessageCategories();
});
} else {
updateMessageCategories();
}
});

/**
Expand Down Expand Up @@ -220,3 +232,93 @@ function updateDarkThemeSwitch() {
document.documentElement.setAttribute('data-bs-theme', enableDarkTheme ? 'dark' : 'light');
});
}

/**
* Update the High and Info Message Category Switches
*/
function updateMessagePriorities() {
var messagePriorities = ['High', 'Info'];
$.each(messagePriorities, function (index, pri) {
var switchId = "msg-pri-switch-" + pri;
var switchElement = "#" + switchId;
var savedValue = localStorage.getItem(switchId + "-state");

// update it
if (savedValue === null || savedValue === 'true') {
$(switchElement).prop('checked', true);
} else {
$(switchElement).prop('checked', false);
}

$(switchElement).on("change", function () {
localStorage.setItem("msg-pri-switch-" + pri + "-state", $(this).is(':checked'));
if (window.location.pathname == '/messages') {
refresh();
}
});
});
}

/**
* Update the High and Info Message Category Switches
*/
function updateMessageCategories() {
const messageCategoryList = '#categories-list';

var categoryList = $(messageCategoryList);
$.each(categories, function (index, cat) {

var switchId = "msg-cat-switch-" + cat;
var switchElement = "#" + switchId;
var savedValue = localStorage.getItem(switchId + "-state");

if ($(switchElement).length) {
// update it
if (savedValue === null || savedValue === 'true') {
$(switchElement).prop('checked', true);
} else {
$(switchElement).prop('checked', false);
}
} else {
// create it
var li = $(document.createElement("li"));

var outerDiv = $(document.createElement("div"));
outerDiv.addClass("dropdown-item d-flex justify-content-between align-items-center");

var div = $(document.createElement("div"));
div.addClass("form-check form-switch mb-0 ms-3");

var input = $(document.createElement("input"));
input.addClass("form-check-input mt-0");
input.attr("type", "checkbox");
input.attr("role", "switch");
input.attr("id", switchId);

if (savedValue === null || savedValue === 'true') {
input.prop('checked', true);
} else {
input.prop('checked', false);
}

input.on("change", function () {
localStorage.setItem("msg-cat-switch-" + cat + "-state", $(this).is(':checked'));
if (window.location.pathname == '/messages') {
refresh();
}
});
div.append(input);

var label = $(document.createElement("label"));
label.addClass("mb-0");
label.attr("for", switchId);
label.text(cat);

outerDiv.append(label);
outerDiv.append(div);
li.append(outerDiv);
categoryList.append(li);
}
});

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@
-->
<br />
<div class="col-xs-12" id="messages">
<h5>Message Priority Filters <small>(critical messages are always shown)</small></h5>
<div id="message-priority-list"></div>
<br />
<h5>Message Category Filters</h5>
<div id="message-category-list"></div>
<br />
<h5>Messages</h5>
<table id="messagesTable"
class="table table-bordered table-striped table-condensed" style="width: 100%;">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@
<li class="dropdown">
<a class="nav-link" href="#" id="navbarDropdown"
role="button" data-bs-toggle="dropdown" aria-expanded="false">
<span style="font-size: 1.2em;" class="bi bi-three-dots-vertical"></span>
<span style="font-size: 1.2em;" class="bi bi-gear"></span>
</a>
<ul class="dropdown-menu dropdown-menu-end">
<li><h6 class="dropdown-header">General Preferences</h6></li>
<li><hr class="dropdown-divider"></li>
<li>
<div class="dropdown-item d-flex justify-content-between align-items-center">
<label class="mb-0" for="darkThemeSwitch">Dark Theme</label>
Expand All @@ -95,6 +97,31 @@
</div>
</div>
</li>
<li><hr class="dropdown-divider"></li>
<li><h6 class="dropdown-header">Message Priorities</h6></li>
<li><hr class="dropdown-divider"></li>
<li>
<div class="dropdown-item d-flex justify-content-between align-items-center">
<label class="mb-0" for="msg-pri-switch-High">High</label>
<div class="form-check form-switch mb-0 ms-3">
<input id="msg-pri-switch-High" class="form-check-input mt-0" type="checkbox" role="switch">
</div>
</div>
</li>
<li>
<div class="dropdown-item d-flex justify-content-between align-items-center">
<label class="mb-0" for="msg-pri-switch-Info">Info</label>
<div class="form-check form-switch mb-0 ms-3">
<input id="msg-pri-switch-Info" class="form-check-input mt-0" type="checkbox" role="switch">
</div>
</div>
</li>
<li><hr class="dropdown-divider"></li>
<li><h6 class="dropdown-header">Message Categories</h6></li>
<li><hr class="dropdown-divider"></li>
<div id="categories-list">
</div>
<li><hr class="dropdown-divider"></li>
<li><a class="link-body-emphasis dropdown-item" data-bs-toggle="modal" href="#aboutModal">About</a></li>
</ul>
</li>
Expand Down