From 1b28600c395455853f2b3093ac8826e160ee89fe Mon Sep 17 00:00:00 2001 From: Corban-Lee Jones Date: Fri, 27 Sep 2024 17:42:42 +0100 Subject: [PATCH] message styles table --- apps/home/static/home/js/index.js | 23 ++++++- apps/home/static/home/js/tabs/styles.js | 68 +++++++++++++++++++ apps/home/templates/home/tabs/styles.html | 80 ++++++++++++++++++++++- 3 files changed, 168 insertions(+), 3 deletions(-) diff --git a/apps/home/static/home/js/index.js b/apps/home/static/home/js/index.js index 53651ba..d97e185 100644 --- a/apps/home/static/home/js/index.js +++ b/apps/home/static/home/js/index.js @@ -4,6 +4,7 @@ $(document).ready(async function() { // await initContentTable(); initSubscriptionsModule(); + initMessageStylesModule(); await loadServers(); $("#subscriptionsTab").click(); @@ -13,6 +14,9 @@ $(document).on("selectedServerChange", function() { $("#subscriptionsTab").click(); }); + +// region Hex Strings + function genHexString(len=6) { let output = ''; for (let i = 0; i < len; ++i) { @@ -21,6 +25,14 @@ function genHexString(len=6) { return output; } + +// region DateTime + +function isISODateTimeString(value) { + const isoDatePattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+([+-]\d{2}:\d{2}|Z)$/; + return typeof value === 'string' && isoDatePattern.test(value); +} + // my clone of python's datetime.strftime function formatStringDate(date, format) { const padZero = (num, len) => String(num).padStart(len, "0"); @@ -76,7 +88,8 @@ function formatStringDate(date, format) { return format.replace(/%[a-zA-Z%-]/g, match => formatters[match] ? formatters[match](date) : match); } -// #region Colour Controls + +// region Colour Controls $(".colour-control-picker").on("change", function() { $(this).closest(".colour-control-group").find(".colour-control-text").val($(this).val()); }); @@ -155,8 +168,11 @@ $(document).ready(function() { }); }); + +// region Confirm Modal + async function confirmationModal(title, bodyText, style, acceptFunc, declineFunc) { - let $modal = $("#confirmationModal"); + let $modal = $("#confirmModal"); // Ensure valid style and apply it to the confirm button if (!["danger", "success", "warning", "info", "primary", "secondary"].includes(style)) { @@ -191,6 +207,9 @@ function arrayToHtmlList(array, bold=false) { return $ul; } + +// region Log Error + function logError(error) { if (error instanceof Error) { // Logs typical error properties like message and stack diff --git a/apps/home/static/home/js/tabs/styles.js b/apps/home/static/home/js/tabs/styles.js index e69de29..be64ca8 100644 --- a/apps/home/static/home/js/tabs/styles.js +++ b/apps/home/static/home/js/tabs/styles.js @@ -0,0 +1,68 @@ +const styleTableId = "#styleTable"; + + +// region Init Module + +function initMessageStylesModule() { + initializeDataTable( + styleTableId, + [ + { + title: "Name", + data: "name" + }, + { + title: "Is Embed?", + data: "is_embed" + }, + { + title: "Is Hyperlinked?", + data: "is_hyperlinked" + }, + { + title: "Show Author?", + data: "show_author" + }, + { + title: "Show Timestamp?", + data: "show_timestamp" + }, + { + title: "Show Images?", + data: "show_images" + }, + { + title: "Fetch Images?", + data: "fetch_images" + }, + { + title: "Title Mutator", + data: "title_mutator" + }, + { + title: "Description Mutator", + data: "description_mutator" + } + ] + ); +}; + + +// region Load Data + +$(document).on("selectedServerChange", async function() { + await loadMessageStyleData(); +}); + +$(document).on("doDataLoad", async function() { + await loadMessageStyleData(); +}); + +async function loadMessageStyleData() { + if (!selectedServer) { + return; + } + + setTableFilter(styleTableId, "server", selectedServer.id); + await loadTableData(styleTableId, "/api/message-styles/", "GET"); +} diff --git a/apps/home/templates/home/tabs/styles.html b/apps/home/templates/home/tabs/styles.html index 97b1e63..0507299 100644 --- a/apps/home/templates/home/tabs/styles.html +++ b/apps/home/templates/home/tabs/styles.html @@ -1 +1,79 @@ -styles \ No newline at end of file +
+
+
+ + + + +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+
+
+ +
+
+ + + of  + 10 +
+
\ No newline at end of file