From 9fb09067232ea4ce95fda7ebe18a5cb01184a943 Mon Sep 17 00:00:00 2001 From: Corban-Lee Jones Date: Sun, 15 Sep 2024 15:35:01 +0100 Subject: [PATCH] unique rules functional on sub modal --- CHANGELOG.md | 9 ++++++++- apps/static/js/home/subscriptions.js | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6e065f..1cfbd96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- `UniqueContentRule` model, allows the user to determine how unique RSS items are defined +- `unique_content_rules` attribute to the `Subscription` model, many-to-many relationship with the related model +- Web interface method of setting a Subscription's unique content rules, through a multi-select field +- Migrations to allow older versions to seemlessly upgrade for this change, by creating the `UniqueContentRule` instances and setting default content rules on Subscriptions + ### Fixed - Footer links pointing to older domain @@ -15,7 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Web interface now uses the full device width, rather than a smaller maximum width -- Server sidebar use more width, also displays name and guild ID, becomes smaller on small devices. +- Server sidebar use more width, also displays name and guild ID, becomes smaller on small devices - Update changelog to follow [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) ## [0.3.4] - 2024-09-12 diff --git a/apps/static/js/home/subscriptions.js b/apps/static/js/home/subscriptions.js index 4403912..ac25076 100644 --- a/apps/static/js/home/subscriptions.js +++ b/apps/static/js/home/subscriptions.js @@ -65,6 +65,24 @@ async function initSubscriptionTable() { return `${channelsCount}`; } }, + { + title: "Content Rules", + data: "unique_content_rules", + className: "text-center text-nowrap", + render: function(data, type) { + console.log(JSON.stringify(data)) + + let badges = $("
"); + + data.forEach(function(rule, idx) { + let badge = $(`${rule.name}`) + if (idx > 0) { badge.addClass("ms-2") } + badges.append(badge); + }); + + return badges.html(); + } + }, { title: "Created", data: "creation_datetime", @@ -210,6 +228,7 @@ async function showEditSubModal(subId) { $("#subTitleMutators").val("").change(); $("#subDescMutators").val("").change(); $("#subActive").prop("checked", true); + $("#subUniqueRules").val(1).change(); // GUID option selected by default $("#subEmbedColour .colour-reset").click(); $("#subArticleFetchImage").prop("checked", true); @@ -242,6 +261,9 @@ async function showEditSubModal(subId) { $("#subFilters").val("").change(); $("#subFilters").val(subscription.filters).change(); + $("#subUniqueRules").val("").change(); + $("#subUniqueRules").val(subscription.unique_content_rules.map(rule => rule.id)).change(); + updateColourInput("subEmbedColour", `#${subscription.embed_colour}`); $("#subArticleFetchImage").prop("checked", subscription.article_fetch_image); @@ -299,6 +321,11 @@ $("#subForm").on("submit", async function(event) { filter => formData.append("filters", parseInt(filter.value)) ); + // Unique Content Rules + $("#subUniqueRules option:selected").toArray().forEach( + rule => formData.append("unique_content_rules", parseInt(rule.value)) + ); + // This field is constructed differently, so needs to be specifically added formData.append("embed_colour", getColourInputVal("subEmbedColour", false));