modals rewrite

This commit is contained in:
Corban-Lee Jones 2024-09-27 12:22:10 +01:00
parent bc3a88e159
commit 66e41ab53d
10 changed files with 160 additions and 232 deletions

View File

@ -110,9 +110,11 @@ class MessageStyle(models.Model):
"""
id = models.AutoField(primary_key=True)
server = models.ForeignKey(to=Server, on_delete=models.CASCADE)
server = models.ForeignKey(to=Server, on_delete=models.CASCADE, null=True, blank=False)
is_embed = models.BooleanField()
colour = models.CharField(max_length=6)
is_embed = models.BooleanField(default=True)
is_hyperlinked = models.BooleanField() # title only
show_author = models.BooleanField()
show_timestamp = models.BooleanField()

View File

@ -154,13 +154,21 @@ $(document).on("selectedServerChange", function() {
// #region Load Servers
async function loadServers() {
$(".server-loading-item").show();
try {
let response = await generateServers();
$(".server-loading-item").hide();
if (response.hasOwnProperty("retry_after")) {
$(".server-rate-limit").show();
return;
}
response.forEach(server => {
addToLoadedServers(server, false);
});
}
catch (error) {
logError(error);

View File

@ -13,7 +13,7 @@ function initSubscriptionsModule() {
className: "text-truncate",
render: function(data, type, row) {
const name = sanitise(data);
return `<button type="button" class="btn btn-link text-start text-decoration-none">${name}</button>`;
return `<button type="button" class="btn btn-link text-start text-decoration-none edit-modal">${name}</button>`;
}
},
{
@ -118,3 +118,45 @@ $(subTableId).on("change", ".sub-toggle-active", async function() {
let formData = objectToFormData(sub);
await ajaxRequest(`/api/subscriptions/${id}/`, "PUT", formData);
});
// region New/Edit Modal
$(subTableId).closest('.js-tableBody').siblings('.js-tableFilters').on("click", ".table-new-btn", async function() {
await openSubModal(-1);
});
$(subTableId).on("click", ".edit-modal", async function() {
let id = $(subTableId).DataTable().row($(this).closest("tr")).data().id;
await openSubModal(id)
})
async function openSubModal(id) {
$modal = $("#subFormModal");
if (parseInt(id) === -1) {
$modal.find(".form-create").show();
$modal.find(".form-edit").hide();
}
else {
$modal.find(".form-create").hide();
$modal.find(".form-edit").show();
let data = await ajaxRequest(`/api/subscriptions/${id}/`, "GET");
$modal.find("[data-field]").each(function() {
let key = $(this).attr("data-field");
let value = data[key];
if (typeof value === "boolean") {
$(this).prop("checked", value);
}
else {
$(this).val(value);
}
});
}
$modal.modal("show");
}

View File

@ -1,30 +0,0 @@
<form id="serverSettingsForm" novalidate>
<div class="row my-3 px-3">
<div class="col-12 text-end">
<button type="submit" id="saveSettings" class="btn btn-primary rounded-1">Save Changes</button>
<button type="button" class="btn btn-outline-danger rounded-1 ms-3">Reset All</button>
</div>
</div>
<div class="row my-3 px-3">
<div class="col-lg-4">
<div class="mb-4">
<div class="colour-input"
data-id="defaultEmbedColour"
data-label="Default Embed Colour"
data-helptext="Default colour of each embed in Discord."
data-defaultcolour="#3498db">
</div>
</div>
</div>
<div class="col-lg-8"></div>
<div class="col-lg-4">
<div class="form-switch ps-0">
<label for="serverActive" class="form-check-label mb-2">Server Active?</label>
<br>
<input type="checkbox" name="serverActive" id="serverActive" class="form-check-input ms-0 mt-0">
<br>
<div class="form-text">Is this server active?</div>
</div>
</div>
</div>
</form>

View File

@ -1,192 +0,0 @@
<div id="subFormModal" class="modal modal-lg fade" data-bs-backdrop="static" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content rounded-1">
<form id="subForm" class="mb-0" novalidate>
<div class="modal-header">
<h5 class="modal-title ms-2">
<span class="form-create">Add</span>
<span class="form-edit">Edit</span>
Subscription
</h5>
</div>
<div class="modal-body p-4">
<input type="hidden" id="subId" name="subId" data-role="is-id">
<div class="row">
<div class="col-lg-6 pe-lg-4">
<div class="mb-4">
<label for="subName" class="form-label">Name</label>
<input type="text" id="subName" name="subName" class="form-control rounded-1" placeholder="My News Feed" required data-field="name" tabindex="1">
<div class="form-text">Use a unique name to refer to this subscription.</div>
</div>
</div>
<div class="col-lg-6 ps-lg-4">
<div class="mb-4">
<label for="subUrl" class="form-label">URL</label>
<input type="url" id="subUrl" name="subUrl" class="form-control rounded-1" placeholder="http://example.com/rss.xml" required data-field="url" tabindex="2">
<div class="form-text">Must point to a valid <a href="https://en.wikipedia.org/wiki/RSS" class="text-decoration-none" target="_blank">RSS</a> feed.</div>
</div>
</div>
<div class="col-lg-6 pe-lg-4">
<div class="mb-4">
<label for="subChannels" class="form-label">Channels</label>
<select name="subChannels" id="subChannels" class="select-2" multiple data-dropdownparent="#subFormModal" tabindex="3"></select>
<div class="form-text">Subscription content will be sent to these channels.</div>
</div>
</div>
<div class="col-lg-6 ps-lg-4">
<div class="mb-4">
<label for="subFilters" class="form-label">Filters</label>
<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>
</div>
<div class="col-lg-6 pe-lg-4">
<div class="mb-4 mb-lg-0">
<label for="subExtraNotes" class="form-label">Extra Notes</label>
<textarea id="subExtraNotes" name="subExtraNotes" class="form-control rounded-1" placeholder="" data-field="extra_notes" tabindex="5" style="resize: none; height: 7rem"></textarea>
</div>
</div>
<div class="col-lg-6 ps-lg-4">
<div class="form-check form-switch">
<label for="subActive" class="form-check-label">Enabled</label>
<input type="checkbox" id="subActive" name="subActive" class="form-check-input" data-field="active" tabindex="6">
<div class="form-text">Disabled Subscriptions are ignored.</div>
</div>
</div>
</div>
</div>
<div class="modal-footer px-4">
<!-- form-create -->
<button type="button" id="devGenerateSub" class="btn btn-outline-info rounded-1 me-3 ms-0 d-none" tabindex="7">&#40;Dev&#41; Generate</button>
<button type="button" id="deleteEditSub" class="btn btn-danger rounded-1 me-3 ms-0 form-edit" tabindex="8">Delete</button>
<button type="button" class="btn btn-outline-primary rounded-1 me-auto ms-0" data-bs-toggle="modal" data-bs-target="#subAdvancedModal" tabindex="9">Advanced</button>
<button type="submit" class="btn btn-primary rounded-1 me-0" tabindex="9">
<span class="form-create">Create</span>
<span class="form-edit">Confirm Edit</span>
</button>
<button type="button" class="btn btn-secondary rounded-1 me-0 ms-3" data-bs-dismiss="modal" tabindex="10">Cancel</button>
</div>
</form>
</div>
</div>
</div>
<div id="subAdvancedModal" class="modal modal-lg fade" data-bs-backdrop="static" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content rounded-1">
<form id="subAdvancedForm" class="mb-0" novalidate>
<div class="modal-header">
<h5 class="modal-title ms-2">
<span class="form-create">Add</span>
<span class="form-edit">Edit</span>
Subscription · Advanced
</h5>
</div>
<div class="modal-body p-4">
<div class="row">
<div class="col-lg-6 pe-lg-4 d-none">
<div class="mb-4">
<label for="" class="form-label">Article Fetch Limit</label>
<input type="number" id="subFetchLimit" class="form-control rounded-1" max="10" min="1" tabindex="3">
<div class="form-text">Limit the number of articles fetched every cycle.</div>
</div>
</div>
<div class="col-lg-6 ps-lg-4 d-none">
<div class="form-switch ps-0 mb-4">
<label for="subResetFetchLimit" class="form-check-label mb-2">Max Fetch Limit after the First Cycle</label>
<br>
<input type="checkbox" id="subResetFetchLimit" name="subResetFetchLimit" class="form-check-input ms-0 mt-0" tabindex="4">
<br>
<div class="form-text">Sets the Fetch Limit to 10 after the first cycle. Helps with initial spam.</div>
</div>
</div>
<div class="col-lg-6 pe-lg-4">
<div class="mb-4">
<label for="subPubThreshold" class="form-label">Publish Datetime Threshold</label>
<input type="datetime-local" name="subPubThreshold" id="subPubThreshold" class="form-control rounded-1" required data-field="published_threshold" tabindex="9">
<div class="form-text">RSS content older than this datetime will be skipped.</div>
</div>
</div>
<div class="col-lg-6 ps-lg-4">
<div>
<label for="subUniqueRules">Unique Content Rules</label>
<select name="subUniqueRules" id="subUniqueRules" class="select-2" multiple data-dropdownparent="#subAdvancedModal" required data-field="unique_content_rules" tabindex="10"></select>
<div class="form-text">Prevent duplicate articles, by identifying articles matched by these selected fields.</div>
</div>
</div>
<div class="col-lg-6 ps-lg-4 d-none">
<div class="form-check form-switch">
<label for="subArticleFetchImage" class="form-check-label">Show Images</label>
<input type="checkbox" id="subArticleFetchImage" name="subArticleFetchImage" class="form-check-input" data-field="article_fetch_image" tabindex="11">
<div class="form-text">Show images on the Discord embed?</div>
</div>
</div>
<div class="col-12">
<hr class="mb-4">
</div>
<div class="col-12">
<h5 class="mb-4">Discord Embed Style</h5>
</div>
<div class="col-lg-6 pe-lg-4">
<div class="form-check form-switch mb-4">
<label for="" class="form-check-label">Hyperlink Title</label>
<input type="checkbox" class="form-check-input">
<div class="form-text">Hyperlinked title using the content's URL.</div>
</div>
</div>
<div class="col-lg-6 ps-lg-4">
<div class="form-check form-switch mb-4">
<label for="" class="form-check-label">Show Author</label>
<input type="checkbox" class="form-check-input">
<div class="form-text">Show the content author if possible.</div>
</div>
</div>
<div class="col-lg-6 pe-lg-4">
<div class="form-check form-switch mb-4">
<label for="" class="form-check-label">Show Timestamp</label>
<input type="checkbox" class="form-check-input">
<div class="form-text">Show the content timestamp if possible.</div>
</div>
</div>
<div class="col-lg-6 ps-lg-4">
<div class="form-check form-switch mb-4">
<label for="" class="form-check-label">Show Images</label>
<input type="checkbox" class="form-check-input">
<div class="form-text">Show any images if possible.</div>
</div>
</div>
<div class="col-lg-6 pe-lg-4">
<div class="mb-4">
<label for="subTitleMutators" class="form-label">Title Mutators</label>
<select name="subTitleMutators" id="subTitleMutators" class="select-2 sub-mutators-field" multiple data-dropdownparent="#subAdvancedModal" tabindex="1"></select>
<div class="form-text">Apply mutators to article titles.</div>
</div>
</div>
<div class="col-lg-6 ps-lg-4">
<div class="mb-4">
<label for="subDescMutators" class="form-label">Description Mutators</label>
<select name="subDescMutators" id="subDescMutators" class="select-2 sub-mutators-field" multiple data-dropdownparent="#subAdvancedModal" tabindex="2"></select>
<div class="form-text">Apply mutators to article descriptions.</div>
</div>
</div>
<!-- mb-4 mb-lg-0 -->
<div class="col-lg-6 pe-lg-4">
<div class="">
<div class="colour-input"
data-id="subEmbedColour"
data-label="Colour"
data-helptext="Colour of each embed in Discord."
data-tabindex="5">
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer px-4">
<button type="button" class="btn btn-primary rounded-1 me-0 ms-3" data-bs-toggle="modal" data-bs-target="#subFormModal" tabindex="12">Back</button>
</div>
</form>
</div>
</div>
</div>

View File

@ -22,8 +22,8 @@
<div class="rounded-1 placeholder" style="min-width: 45px !important; min-height: 45px !important;"></div>
<div class="text-start ps-2 w-100 flex-shrink-1 placeholder-wave">
{% if forloop.counter0|divisibleby:2 %}
<div class="placeholder rounded-1 w-50"></div>
<div class="placeholder rounded-1 w-75"></div>
<div class="placeholder rounded-1 w-100"></div>
{% else %}
<div class="placeholder rounded-1 w-75"></div>
<div class="placeholder rounded-1 w-50"></div>
@ -33,6 +33,12 @@
</div>
</li>
{% endfor %}
<li class="nav-item server-rate-limit" style="display: none;">
<div class="alert alert-warning text-start" role="alert">
<p class="small">You are being rate limited.</p>
<p class="small mb-0">Refresh the page to try again.</p>
</div>
</li>
</ul>
<ul class="d-flex flex-lg-row flex-column list-unstyled text-center flex-nowrap mb-0 px-lg-4 px-2 align-items-center text-body-secondary">
<li>
@ -45,10 +51,10 @@
<i class="bi bi-question-lg fs-6"></i>
</a>
</li>
<li class="ms-3 d-none d-lg-inline">
<li class="mx-auto d-none d-lg-inline">
<div class="vr"></div>
</li>
<li class="ms-3 d-none d-lg-inline text-nowrap text-reset small">
<li class="d-none d-lg-inline text-nowrap text-reset small">
&copy; 2024 PYRSS
</li>
</ul>
@ -154,10 +160,10 @@
</div>
</div>
</div>
{% include "home/includes/submodal.html" %}
{% include "home/includes/filtermodal.html" %}
{% include "home/includes/deletemodal.html" %}
{% include "home/includes/settingsmodal.html" %}
{% include "home/modals/editSub.html" %}
{% include "home/modals/editFilter.html" %}
{% include "home/modals/editServer.html" %}
{% include "home/modals/confirm.html" %}
{% endblock content %}
{% block javascript %}

View File

@ -0,0 +1,92 @@
<div id="subFormModal" class="modal modal-lg fade" data-bs-backdrop="static" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content rounded-1">
<form id="subForm" class="mb-0" novalidate>
<div class="modal-header">
<h5 class="modal-title ms-2">
<span class="form-create">Add</span>
<span class="form-edit">Edit</span>
Subscription
</h5>
</div>
<div class="modal-body p-4">
<input type="hidden" id="subId" name="subId" data-role="is-id">
<div class="row">
<div class="col-lg-6 pe-lg-4">
<div class="mb-4">
<label for="subName" class="form-label">Name</label>
<input type="text" id="subName" name="subName" class="form-control rounded-1" required data-field="name" tabindex="1">
<div class="form-text"></div>
</div>
</div>
<div class="col-lg-6 ps-lg-4">
<div class="mb-4">
<label for="subUrl" class="form-label">URL</label>
<input type="url" id="subUrl" name="subUrl" class="form-control rounded-1" required data-field="url" tabindex="2">
<div class="form-text">Source of <a href="https://en.wikipedia.org/wiki/RSS" class="text-decoration-none" target="_blank">RSS</a> content.</div>
</div>
</div>
<div class="col-lg-6 pe-lg-4">
<div class="mb-4">
<label for="" class="form-label">Message Style</label>
<select name="" id="" class="select-2" data-dropdownparent="#subFormModal" data-field="message_style" tabindex="3">
</select>
<div class="form-text">Appearance of delivered content.</div>
</div>
</div>
<div class="col-lg-6 ps-lg-4">
<div class="mb-4">
<label for="subPubThreshold" class="form-label">Publish Threshold</label>
<input type="datetime-local" name="subPubThreshold" id="subPubThreshold" class="form-control rounded-1" required data-field="published_threshold" tabindex="4">
<div class="form-text">Age limit of processed content.</div>
</div>
</div>
<div class="col-lg-6 pe-lg-4">
<div class="mb-4">
<label for="subChannels" class="form-label">Channels</label>
<select name="subChannels" id="subChannels" class="select-2" multiple data-dropdownparent="#subFormModal" data-field="" tabindex="5"></select>
<div class="form-text">Send content to these channels.</div>
</div>
</div>
<div class="col-lg-6 ps-lg-4">
<div class="mb-4">
<label for="subFilters" class="form-label">Filters</label>
<select name="subFilters" id="subFilters" class="select-2" multiple data-dropdownparent="#subFormModal" data-field="filters" tabindex="6"></select>
<div class="form-text">Filter out unwanted content.</div>
</div>
</div>
<div class="col-lg-6 pe-lg-4">
<div>
<label for="subUniqueRules" class="form-label">Uniqueness Rules</label>
<select name="subUniqueRules" id="subUniqueRules" class="select-2" multiple data-dropdownparent="#subFormModal" required data-field="unique_rules" tabindex="7"></select>
<div class="form-text">Rules on telling content apart.</div>
</div>
</div>
<div class="col-lg-6 ps-lg-4">
<div class="form-check form-switch">
<label for="subActive" class="form-check-label">Enabled</label>
<input type="checkbox" id="subActive" name="subActive" class="form-check-input" data-field="active" tabindex="8">
<div class="form-text d-none">Disabled Subscriptions are ignored.</div>
</div>
</div>
</div>
</div>
<div class="modal-footer px-4">
<button type="button" id="devGenerateSub" class="btn btn-outline-info rounded-1 me-3 ms-0 d-none" tabindex="10">
&#40;Dev&#41; Generate
</button>
<button type="button" id="deleteEditSub" class="btn btn-danger rounded-1 me-auto ms-0 form-edit" tabindex="11">
Delete
</button>
<button type="submit" class="btn btn-primary rounded-1 me-0" tabindex="12">
<span class="form-create">Create</span>
<span class="form-edit">Confirm Edit</span>
</button>
<button type="button" class="btn btn-secondary rounded-1 me-0 ms-3" data-bs-dismiss="modal" tabindex="13">
Cancel
</button>
</div>
</form>
</div>
</div>
</div>