diff --git a/apps/api/serializers.py b/apps/api/serializers.py index 2e2338b..fc8193a 100644 --- a/apps/api/serializers.py +++ b/apps/api/serializers.py @@ -172,7 +172,7 @@ class SavedGuildSerializer(DynamicModelSerializer): class Meta: model = SavedGuilds - fields = ("id", "guild_id", "name", "icon", "added_by", "permissions", "owner") + fields = ("id", "guild_id", "name", "icon", "added_by", "permissions", "default_embed_colour", "owner") class TrackedContentSerializer_GET(DynamicModelSerializer): diff --git a/apps/home/migrations/0019_savedguilds_default_embed_colour.py b/apps/home/migrations/0019_savedguilds_default_embed_colour.py new file mode 100644 index 0000000..50c68df --- /dev/null +++ b/apps/home/migrations/0019_savedguilds_default_embed_colour.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.4 on 2024-07-23 14:28 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0018_subchannel_channel_name'), + ] + + operations = [ + migrations.AddField( + model_name='savedguilds', + name='default_embed_colour', + field=models.CharField(blank=True, default='3498db', max_length=6), + ), + ] diff --git a/apps/home/models.py b/apps/home/models.py index 4ca2f96..2df91d4 100644 --- a/apps/home/models.py +++ b/apps/home/models.py @@ -56,6 +56,12 @@ class SavedGuilds(models.Model): help_text=_("Does the 'added by' user own this guild?") ) + default_embed_colour = models.CharField( + max_length=6, + default="3498db", + blank=True + ) + class Meta: """ Metadata for the SavedGuilds Model. diff --git a/apps/static/css/home/index.css b/apps/static/css/home/index.css index c2b6902..43ae859 100644 --- a/apps/static/css/home/index.css +++ b/apps/static/css/home/index.css @@ -70,3 +70,7 @@ td { height: 100%; } } + +#serverTabs .nav-link { + border-radius: 0; +} \ No newline at end of file diff --git a/apps/static/js/home/index.js b/apps/static/js/home/index.js index 7f16f3c..f8adeda 100644 --- a/apps/static/js/home/index.js +++ b/apps/static/js/home/index.js @@ -11,11 +11,11 @@ $(document).ready(async function() { handleDiscordChannelNames(); }); -$('#serverTabs [data-bs-toggle="tab"]').on("show.bs.tab", function(event) { - const activeTab = $(event.target); - $(".tab-pane-buttons .tab-pane-buttons-item").hide(); - $(`.tab-pane-buttons .tab-pane-buttons-item[data-tab="${activeTab.attr("id")}"]`).show(); -}); +// $('#serverTabs [data-bs-toggle="tab"]').on("show.bs.tab", function(event) { +// const activeTab = $(event.target); +// $(".tab-pane-buttons .tab-pane-buttons-item").hide(); +// $(`.tab-pane-buttons .tab-pane-buttons-item[data-tab="${activeTab.attr("id")}"]`).show(); +// }); $(document).on("selectedServerChange", function() { $("#subscriptionsTab").click(); @@ -63,4 +63,63 @@ function genHexString(len) { output += (Math.floor(Math.random() * 16)).toString(16); } return output; -} \ No newline at end of file +} + +// #region Colour Controls +$(".colour-control-picker").on("change", function() { + $(this).closest(".colour-control-group").find(".colour-control-text").val($(this).val()); +}); + +$(".colour-control-text").on("change", function() { + $(this).closest(".colour-control-group").find(".colour-control-picker").val($(this).val()); +}); + +function updateColourInput(id, hexString) { + hexString = hexString.toUpperCase(); + $(`#${id} .colour-picker`).val(hexString); + $(`#${id} .colour-text`).val(hexString); +} + +$(document).ready(function() { + $(".colour-input").each(function() { + let id = $(this).attr("data-id") + label = $(this).attr("data-label"); + helpText = $(this).attr("data-helptext"); + defaultColour = $(this).attr("data-defaultcolour"); + defaultColour = defaultColour ? defaultColour : "#3498db" + + $(this).replaceWith(` + +
+ + + + +
+
${helpText}
+ `); + + $(`#${id} .colour-picker`).on("change", function() { + updateColourInput(id, $(this).val()); + }); + + $(`#${id} .colour-text`).on("change", function() { + updateColourInput(id, $(this).val()); + }); + + $(`#${id} .colour-reset`).on("click", function() { + updateColourInput(id, $(this).attr("data-defaultcolour")); + }); + + $(`#${id} .colour-random`).on("click", function() { + updateColourInput(id, "#" + genHexString(6)); + }); + + updateColourInput(id, defaultColour) + $(`#${id} [data-bs-toggle="tooltip"]`).tooltip(); + }); +}); \ No newline at end of file diff --git a/apps/static/js/home/subscriptions.js b/apps/static/js/home/subscriptions.js index aef3463..ec4218b 100644 --- a/apps/static/js/home/subscriptions.js +++ b/apps/static/js/home/subscriptions.js @@ -200,7 +200,7 @@ async function showEditSubModal(subId) { $("#subDescMutators").val("").change(); $("#subActive").prop("checked", true); - $("#subResetEmbedColour").click(); + $("#subEmbedColour .colour-reset").click(); $("#subArticleFetchImage").prop("checked", true); $("#subPubThreshold").val(getCurrentDateTime()); @@ -231,7 +231,7 @@ async function showEditSubModal(subId) { $("#subFilters").val("").change(); $("#subFilters").val(subscription.filters).change(); - subSetHexColour(`#${subscription.embed_colour}`); + updateColourInput("subEmbedColour", `#${subscription.embed_colour}`); $("#subArticleFetchImage").prop("checked", subscription.article_fetch_image); $("#subPubThreshold").val(subscription.published_threshold.split('+')[0]); @@ -255,7 +255,7 @@ $("#subForm").on("submit", async function(event) { title: $("#subTitleMutators option:selected").toArray().map(mutator => parseInt(mutator.value)), desc: $("#subDescMutators option:selected").toArray().map(mutator => parseInt(mutator.value)) } - subEmbedColour = $("#subEmbedColour").val().split("#")[1]; + subEmbedColour = $("#subEmbedColour .colour-text").val().split("#")[1]; articleFetchImage = $("#subArticleFetchImage").prop("checked") publishedThreshold = $("#subPubThreshold").val(); active = $("#subActive").prop("checked"); @@ -382,6 +382,9 @@ $(document).on("selectedServerChange", async function() { updateBotInviteLink(); const activeServer = getCurrentlyActiveServer(); + + $("#subEmbedColour .colour-reset").attr("data-defaultcolour", "#" + activeServer.default_embed_colour); + await loadSubscriptions(activeServer.guild_id); await loadChannelOptions(activeServer.guild_id); await loadFilterOptions(activeServer.guild_id); @@ -622,31 +625,3 @@ function updateBotInviteLink() { $("#invitePyrssToServerBtn").attr("href", inviteUrl); } - -// #region Colour Controls -$("#subEmbedColour").on("change", function() { - $("#subEmbedColourText").val($(this).val()); -}); - -$("#subEmbedColourText").on("change", function() { - $("#subEmbedColour").val($(this).val()); -}); - -function subSetHexColour(hexString) { - hexString = hexString.toUpperCase(); - $("#subEmbedColour").val(hexString); - $("#subEmbedColourText").val(hexString); -} - -$(document).ready(async () => {$("#subResetEmbedColour").click() }); - // let options = await getSubscriptionOptions(); - // console.log(JSON.stringify(options.actions.GET.creation_datetime)); - -$("#subResetEmbedColour").on("click", function() { - subSetHexColour("#3498db"); -}); - -$("#subRandomEmbedColour").on("click", function() { - subSetHexColour(`#${genHexString(6)}`); -}); -// #endregion \ No newline at end of file diff --git a/apps/templates/home/includes/settingstab.html b/apps/templates/home/includes/settingstab.html new file mode 100644 index 0000000..2b44f90 --- /dev/null +++ b/apps/templates/home/includes/settingstab.html @@ -0,0 +1,12 @@ +
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/apps/templates/home/includes/submodal.html b/apps/templates/home/includes/submodal.html index aabf3dc..4537c56 100644 --- a/apps/templates/home/includes/submodal.html +++ b/apps/templates/home/includes/submodal.html @@ -118,18 +118,11 @@
- -
- - - - +
-
Colour of each embed in Discord.
diff --git a/apps/templates/home/index.html b/apps/templates/home/index.html index 790a39f..5ec6eec 100644 --- a/apps/templates/home/index.html +++ b/apps/templates/home/index.html @@ -56,34 +56,29 @@
-
-
- -
-
-
-
-
-
-
-
-
+
+
+
-
+
+
{% include "home/includes/settingstab.html" %}