From 8864ac9cc03fa25579d0f87c48bd32877c791613 Mon Sep 17 00:00:00 2001 From: Corban-Lee Date: Wed, 26 Jun 2024 15:58:04 +0100 Subject: [PATCH] embed colour, and filter table abstract functions --- apps/api/serializers.py | 4 +- apps/api/views.py | 2 +- .../0009_subscription_embed_colour.py | 18 ++++ apps/home/models.py | 6 ++ apps/static/css/home/index.css | 23 ++++ apps/static/js/home/content.js | 88 +++++---------- apps/static/js/home/filters.js | 37 ++++--- apps/static/js/home/index.js | 53 +++++++++ apps/static/js/home/subscriptions.js | 101 +++++++++++++++--- apps/templates/home/includes/submodal.html | 33 ++++-- apps/templates/home/index.html | 45 ++++++-- 11 files changed, 296 insertions(+), 114 deletions(-) create mode 100644 apps/home/migrations/0009_subscription_embed_colour.py diff --git a/apps/api/serializers.py b/apps/api/serializers.py index eb03902..63d72c2 100644 --- a/apps/api/serializers.py +++ b/apps/api/serializers.py @@ -147,7 +147,7 @@ class SubscriptionSerializer_GET(DynamicModelSerializer): model = Subscription fields = ( "id", "name", "url", "guild_id", "channels_count", "creation_datetime", "extra_notes", - "filters", "article_title_mutators", "article_desc_mutators", "active" + "filters", "article_title_mutators", "article_desc_mutators", "embed_colour", "active" ) @@ -160,7 +160,7 @@ class SubscriptionSerializer_POST(DynamicModelSerializer): model = Subscription fields = ( "id", "name", "url", "guild_id", "channels_count", "creation_datetime", "extra_notes", - "filters", "article_title_mutators", "article_desc_mutators", "active" + "filters", "article_title_mutators", "article_desc_mutators", "embed_colour", "active" ) diff --git a/apps/api/views.py b/apps/api/views.py index ca4d40e..649cfb0 100644 --- a/apps/api/views.py +++ b/apps/api/views.py @@ -189,7 +189,7 @@ class Subscription_ListView(generics.ListCreateAPIView): filter_backends = [filters.SearchFilter, rest_filters.DjangoFilterBackend, filters.OrderingFilter] filterset_fields = [ "id", "name", "url", "guild_id", "creation_datetime", "extra_notes", "filters", - "article_title_mutators", "article_desc_mutators", "active" + "article_title_mutators", "article_desc_mutators", "embed_colour", "active" ] search_fields = ["name", "extra_notes"] ordering_fields = ["creation_datetime", "guild_id"] diff --git a/apps/home/migrations/0009_subscription_embed_colour.py b/apps/home/migrations/0009_subscription_embed_colour.py new file mode 100644 index 0000000..14f6008 --- /dev/null +++ b/apps/home/migrations/0009_subscription_embed_colour.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.4 on 2024-06-26 13:12 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0008_subscription_article_fetch_limit_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='subscription', + name='embed_colour', + field=models.CharField(default='3498db', max_length=6), + ), + ] diff --git a/apps/home/models.py b/apps/home/models.py index 7b1886b..fa169a9 100644 --- a/apps/home/models.py +++ b/apps/home/models.py @@ -224,6 +224,12 @@ class Subscription(models.Model): reset_article_fetch_limit = models.BooleanField(default=False) + embed_colour = models.CharField( + max_length=6, + default="3498db", + blank=True + ) + active = models.BooleanField(default=True) class Meta: diff --git a/apps/static/css/home/index.css b/apps/static/css/home/index.css index c8d0128..c226b62 100644 --- a/apps/static/css/home/index.css +++ b/apps/static/css/home/index.css @@ -30,6 +30,18 @@ transition: border-radius .15s ease-in; } +/* widths */ + +.mw-10rem { + max-width: 10rem; +} + +.col-switch-width { + width: 3.5rem; + min-width: 3.5rem; + max-width: 3.5rem; +} + /* tables */ .table { @@ -43,4 +55,15 @@ .table.dataTable > tbody > tr.selected a { color: var(--bs-link-color) !important; +} + +/* Fuck ugly height fix */ +td { + height: 1px; +} + +@-moz-document url-prefix() { + .fix_height { + height: 100%; + } } \ No newline at end of file diff --git a/apps/static/js/home/content.js b/apps/static/js/home/content.js index db9da15..be92bc9 100644 --- a/apps/static/js/home/content.js +++ b/apps/static/js/home/content.js @@ -24,13 +24,17 @@ function initContentTable() { title: '', data: null, orderable: false, - className: "text-center col-1", + className: "text-center col-switch-width", render: function() { return '' } }, { data: "id", visible: false }, - { title: "GUID", data: "guid", visible: false }, + { + title: "GUID", + data: "guid", + className: "text-truncate mw-10rem", + }, { title: "Name", data: "title", @@ -60,9 +64,25 @@ function initContentTable() { data: "creation_datetime", className: "text-nowrap", render: function(data, type) { - return `${new Date(data).toISOString().replace('T', ' · ').replace(/\.\d+Z$/, '')}`; + // return new Date(data).toISOString().split("T")[0]; + let dateTime = new Date(data); + let dateTimeString = formatDate(dateTime); + return $(` + + ${dateTime.toISOString().split("T")[0]} + + `).popover()[0]; } }, + { + orderable: false, + className: "p-0", + render: function(data, type, row) { + return `
 
` + } + } ] }); } @@ -108,7 +128,10 @@ async function loadContent(guildId, page=1, pageSize=null) { try { const content = await getTrackedContent(guildId, null, page, pageSize); contentTable.rows.add(content.results).draw(false); - handleContentPagination(page, pageSize, content.count, content.next, content.previous); + + updateTablePagination("#contentPagination", page, pageSize, content.count, content.next, content.previous); + updateTablePaginationInfo("#contentTablePageInfo", content.results.length, content.count); + $("#contentTable thead .table-select-all").prop("disabled", content.results.length === 0); } catch (err) { @@ -121,60 +144,3 @@ $(document).on("selectedServerChange", async function() { const activeServer = getCurrentlyActiveServer(); await loadContent(activeServer.guild_id); }); - -$("#contentTablePageSize").on("change", async function() { - const page = 1; // reset to page 1 to ensure the page exists. - const pageSize = $(this).val(); - - loadContent(getCurrentlyActiveServer().guild_id, page, pageSize); -}); - -function handleContentPagination(currentPage, pageSize, totalItems, nextExists, prevExists) { - - $("#contentPagination").attr("data-page", currentPage); - - // Remove existing page-specific buttons - $("#contentPagination .page-pick").remove(); - - // Determine states of 'previous page' and 'next page' buttons - $("#contentPagination .page-prev").toggleClass("disabled", !prevExists).attr("tabindex", prevExists ? "" : "-1"); - $("#contentPagination .page-next").toggleClass("disabled", !nextExists).attr("tabindex", nextExists ? "" : "-1"); - - // Calculate amount of pages to account for - const pages = Math.max(Math.ceil(totalItems / pageSize), 1); - - // Create a button for each page - for (let i = 1; i < pages + 1; i++) { - let pageItem = $("
  • ").addClass("page-item"); - let pageLink = $(" + + +
    Colour of each article's embed in Discord.
    + +
    -
    +
    +
    + +
    + showing  +  of  +
    +
    + + +
    +
    -
    +
    -
    +
    -
    +
    + showing  +  of  +
    +