Mutators front-end
This commit is contained in:
parent
fd5749c33c
commit
5b68c15659
@ -137,3 +137,9 @@ async function deleteTrackedContent(guid) {
|
|||||||
const encodedGuid = encodeURIComponent(guid);
|
const encodedGuid = encodeURIComponent(guid);
|
||||||
return await ajaxRequest(`/api/tracked-content/${encodedGuid}/`, "DELETE");
|
return await ajaxRequest(`/api/tracked-content/${encodedGuid}/`, "DELETE");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mutators
|
||||||
|
|
||||||
|
async function getMutators() {
|
||||||
|
return await ajaxRequest("/api/article-mutator/?page_size=25", "GET");
|
||||||
|
}
|
@ -29,6 +29,7 @@ function initContentTable() {
|
|||||||
return '<input type="checkbox" class="form-check-input table-select-row" />'
|
return '<input type="checkbox" class="form-check-input table-select-row" />'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{ data: "id", visible: false },
|
||||||
{ title: "GUID", data: "guid", visible: false },
|
{ title: "GUID", data: "guid", visible: false },
|
||||||
{
|
{
|
||||||
title: "Name",
|
title: "Name",
|
||||||
@ -72,8 +73,8 @@ $("#deleteSelectedContentBtn").on("click", async function() {
|
|||||||
|
|
||||||
var rows = contentTable.rows(".selected").data();
|
var rows = contentTable.rows(".selected").data();
|
||||||
$.each(rows, async function() {
|
$.each(rows, async function() {
|
||||||
await deleteTrackedContent(this.guid);
|
await deleteTrackedContent(this.id);
|
||||||
showToast("danger", "Deleted Tracked Content", "It can now appear be sent again. Content GUID: " + this.guid);
|
showToast("danger", "Deleted Tracked Content", "It can now appear be sent again. Content ID: " + this.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
|
@ -149,7 +149,7 @@ async function showEditSubModal(subId) {
|
|||||||
$("#subFormModal .form-edit").hide();
|
$("#subFormModal .form-edit").hide();
|
||||||
$("#subChannels").val("").change();
|
$("#subChannels").val("").change();
|
||||||
$("#subFilters").val("").change();
|
$("#subFilters").val("").change();
|
||||||
$("#subUwu").prop("checked", false);
|
$("#subMutators").val("").change();
|
||||||
$("#subActive").prop("checked", true);
|
$("#subActive").prop("checked", true);
|
||||||
$("#subImagePreview img").attr("src", "").hide();
|
$("#subImagePreview img").attr("src", "").hide();
|
||||||
$("#subImagePreview small").show();
|
$("#subImagePreview small").show();
|
||||||
@ -162,11 +162,13 @@ async function showEditSubModal(subId) {
|
|||||||
$("#subName").val(subscription.name);
|
$("#subName").val(subscription.name);
|
||||||
$("#subUrl").val(subscription.url);
|
$("#subUrl").val(subscription.url);
|
||||||
$("#subExtraNotes").val(subscription.extra_notes);
|
$("#subExtraNotes").val(subscription.extra_notes);
|
||||||
$("#subUwu").prop("checked", subscription.uwuify);
|
|
||||||
$("#subActive").prop("checked", subscription.active);
|
$("#subActive").prop("checked", subscription.active);
|
||||||
$("#subFormModal .form-create").hide();
|
$("#subFormModal .form-create").hide();
|
||||||
$("#subFormModal .form-edit").show();
|
$("#subFormModal .form-edit").show();
|
||||||
|
|
||||||
|
$("#subMutators").val("").change();
|
||||||
|
$("#subMutators").val(subscription.mutators.map(mutator => mutator.id)).change();
|
||||||
|
|
||||||
const channels = await getSubChannels(subscription.id);
|
const channels = await getSubChannels(subscription.id);
|
||||||
$("#subChannels").val("").change();
|
$("#subChannels").val("").change();
|
||||||
$("#subChannels").val(channels.results.map(channel => channel.channel_id)).change();
|
$("#subChannels").val(channels.results.map(channel => channel.channel_id)).change();
|
||||||
@ -190,11 +192,10 @@ $("#subForm").on("submit", async function(event) {
|
|||||||
uwuify = $("#subUwu").prop("checked");
|
uwuify = $("#subUwu").prop("checked");
|
||||||
subChannels = $("#subChannels option:selected").toArray().map(channel => channel.value);
|
subChannels = $("#subChannels option:selected").toArray().map(channel => channel.value);
|
||||||
subFilters = $("#subFilters option:selected").toArray().map(filter => parseInt(filter.value));
|
subFilters = $("#subFilters option:selected").toArray().map(filter => parseInt(filter.value));
|
||||||
active = $("#subActive").prop("checked");
|
subMutators = $("#subMutators option:selected").toArray().map(mutator => parseInt(mutator.value));
|
||||||
|
active = true;
|
||||||
|
|
||||||
// alert(JSON.stringify(subFilters, null, 4));
|
var subPrimaryKey = await saveSubscription(id, name, url, guildId, extraNotes, uwuify, subFilters, subMutators, active);
|
||||||
|
|
||||||
var subPrimaryKey = await saveSubscription(id, name, url, guildId, extraNotes, uwuify, subFilters, active);
|
|
||||||
|
|
||||||
await deleteSubChannels(subPrimaryKey);
|
await deleteSubChannels(subPrimaryKey);
|
||||||
subChannels.forEach(async channelId => {
|
subChannels.forEach(async channelId => {
|
||||||
@ -208,7 +209,7 @@ $("#subForm").on("submit", async function(event) {
|
|||||||
$("#subFormModal").modal("hide");
|
$("#subFormModal").modal("hide");
|
||||||
});
|
});
|
||||||
|
|
||||||
async function saveSubscription(id, name, url, guildId, extraNotes, uwuify, filters, active, handleErrorMsg=true) {
|
async function saveSubscription(id, name, url, guildId, extraNotes, uwuify, filters, mutators, active, handleErrorMsg=true) {
|
||||||
var formData = new FormData();
|
var formData = new FormData();
|
||||||
formData.append("name", name);
|
formData.append("name", name);
|
||||||
formData.append("url", url);
|
formData.append("url", url);
|
||||||
@ -216,6 +217,7 @@ async function saveSubscription(id, name, url, guildId, extraNotes, uwuify, filt
|
|||||||
formData.append("extra_notes", extraNotes);
|
formData.append("extra_notes", extraNotes);
|
||||||
formData.append("uwuify", uwuify)
|
formData.append("uwuify", uwuify)
|
||||||
filters.forEach(filter => formData.append("filters", filter));
|
filters.forEach(filter => formData.append("filters", filter));
|
||||||
|
mutators.forEach(mutator => formData.append("mutators", mutator));
|
||||||
formData.append("active", active);
|
formData.append("active", active);
|
||||||
|
|
||||||
var response;
|
var response;
|
||||||
@ -353,6 +355,7 @@ $(document).on("selectedServerChange", async function() {
|
|||||||
await loadSubscriptions(activeServer.guild_id);
|
await loadSubscriptions(activeServer.guild_id);
|
||||||
await loadChannelOptions(activeServer.guild_id);
|
await loadChannelOptions(activeServer.guild_id);
|
||||||
await loadFilterOptions(activeServer.guild_id);
|
await loadFilterOptions(activeServer.guild_id);
|
||||||
|
await loadMutatorOptions();
|
||||||
})
|
})
|
||||||
|
|
||||||
// Dev button (to be removed)
|
// Dev button (to be removed)
|
||||||
@ -483,39 +486,74 @@ async function loadChannelOptions(guildId) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function loadMutatorOptions() {
|
||||||
|
|
||||||
|
// Disable input while options are loading
|
||||||
|
$("#subMutators").prop("disabled", true);
|
||||||
|
|
||||||
|
// Delete existing options
|
||||||
|
$("#subMutators option").each(function() {
|
||||||
|
if ($(this).val())
|
||||||
|
$(this).remove();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Clear select2 input
|
||||||
|
$("#subMutators").val("").change();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const mutators = await getMutators();
|
||||||
|
console.log(JSON.stringify(mutators));
|
||||||
|
|
||||||
|
mutators.results.forEach(filter => {
|
||||||
|
$("#subMutators").append($("<option>", {
|
||||||
|
text: filter.name,
|
||||||
|
value: filter.id
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch(error) {
|
||||||
|
console.error(error);
|
||||||
|
showToast("danger", "Error loading sub mutators", error, 18000);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
// Re-enable the input
|
||||||
|
$("#subMutators").prop("disabled", false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function loadFilterOptions(guildId) {
|
async function loadFilterOptions(guildId) {
|
||||||
|
|
||||||
// Disable input while options are loading
|
// Disable input while options are loading
|
||||||
$("#subFilters").prop("disabled", true);
|
$("#subFilters").prop("disabled", true);
|
||||||
|
|
||||||
// Delete existing options
|
// Delete existing options
|
||||||
$("#subFilters option").each(function() {
|
$("#subFilters option").each(function() {
|
||||||
if ($(this).val())
|
if ($(this).val())
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Clear select2 input
|
||||||
|
$("#subFilters").val("").change();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const filters = await getFilters(guildId);
|
||||||
|
console.log(JSON.stringify(filters));
|
||||||
|
|
||||||
|
filters.results.forEach(filter => {
|
||||||
|
$("#subFilters").append($("<option>", {
|
||||||
|
text: filter.name,
|
||||||
|
value: filter.id
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
}
|
||||||
// Clear select2 input
|
catch(error) {
|
||||||
$("#subFilters").val("").change();
|
console.error(error);
|
||||||
|
showToast("danger", "Error loading sub filters", error, 18000);
|
||||||
try {
|
}
|
||||||
const filters = await getFilters(guildId);
|
finally {
|
||||||
console.log(JSON.stringify(filters));
|
// Re-enable the input
|
||||||
|
$("#subFilters").prop("disabled", false);
|
||||||
filters.results.forEach(filter => {
|
}
|
||||||
$("#subFilters").append($("<option>", {
|
|
||||||
text: filter.name,
|
|
||||||
value: filter.id
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch(error) {
|
|
||||||
console.error(error);
|
|
||||||
showToast("danger", "Error loading sub filters", error, 18000);
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
// Re-enable the input
|
|
||||||
$("#subFilters").prop("disabled", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,20 +39,18 @@
|
|||||||
<select name="subFilters" id="subFilters" class="select-2" multiple data-dropdownparent="#subFormModal" tabindex="4"></select>
|
<select name="subFilters" id="subFilters" class="select-2" multiple data-dropdownparent="#subFormModal" tabindex="4"></select>
|
||||||
<div class="form-text">Filters to apply to this subscription's content.</div>
|
<div class="form-text">Filters to apply to this subscription's content.</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-switch mb-4 ps-0">
|
<div>
|
||||||
|
<label for="subMutators" class="form-label">Article Mutators</label>
|
||||||
|
<select name="subMutators" id="subMutators" class="select-2" multiple data-dropdownparent="#subFormModal" tabindex="6"></select>
|
||||||
|
<div class="form-text">Apply mutators to subscription articles.</div>
|
||||||
|
</div>
|
||||||
|
<!-- <div class="form-switch mb-4 ps-0">
|
||||||
<label for="subActive" class="form-check-label mb-2">Active</label>
|
<label for="subActive" class="form-check-label mb-2">Active</label>
|
||||||
<br>
|
<br>
|
||||||
<input type="checkbox" id="subActive" name="subActive" class="form-check-input ms-0 mt-0" tabindex="6">
|
<input type="checkbox" id="subActive" name="subActive" class="form-check-input ms-0 mt-0" tabindex="6">
|
||||||
<br>
|
<br>
|
||||||
<div class="form-text">Inactive subscriptions wont be processed.</div>
|
<div class="form-text">Inactive subscriptions wont be processed.</div>
|
||||||
</div>
|
</div> -->
|
||||||
<div class="form-switch ps-0">
|
|
||||||
<label for="subUwu" class="form-check-label mb-2">Uwu</label>
|
|
||||||
<br>
|
|
||||||
<input type="checkbox" id="subUwu" name="subUwu" class="form-check-input ms-0 mt-0" tabindex="6">
|
|
||||||
<br>
|
|
||||||
<div class="form-text">Uwu?</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user