refactor for server changes
This commit is contained in:
parent
a70079d635
commit
57dc57786c
@ -68,10 +68,12 @@ class GuildsView(View):
|
||||
await self.delete_member(user, data["id"])
|
||||
return
|
||||
|
||||
server = await Server.objects.aget_or_create(
|
||||
server = await Server.objects.aupdate_or_create(
|
||||
id=data["id"],
|
||||
name=data["name"],
|
||||
icon_hash=data["icon"]
|
||||
defaults={
|
||||
"name": data["name"],
|
||||
"icon_hash": data["icon"]
|
||||
}
|
||||
)
|
||||
|
||||
await ServerMember.objects.aupdate_or_create(
|
||||
|
@ -182,27 +182,27 @@ async function getServers() {
|
||||
|
||||
async function getSubscriptions(filters, sort) {
|
||||
let querystring = makeQuerystring(filters, sort);
|
||||
return await ajaxRequest(`/api/r_subscriptions/${querystring}`, "GET");
|
||||
return await ajaxRequest(`/api/subscriptions/${querystring}`, "GET");
|
||||
}
|
||||
|
||||
async function getSubscription(id) {
|
||||
return await ajaxRequest(`/api/r_subscriptions/${id}/`, "GET");
|
||||
async function getSubscription(serverId, subId) {
|
||||
return await ajaxRequest(`/api/${serverId}/subscriptions/${subId}/`, "GET");
|
||||
}
|
||||
|
||||
async function newSubscription(formData) {
|
||||
return await ajaxRequest("/api/r_subscriptions/", "POST", formData);
|
||||
async function newSubscription(serverId, formData) {
|
||||
return await ajaxRequest(`/api/servers/${serverId}/subscriptions/`, "POST", formData);
|
||||
}
|
||||
|
||||
async function deleteSubscription(id) {
|
||||
return await ajaxRequest(`/api/r_subscriptions/${id}/`, "DELETE");
|
||||
async function deleteSubscription(serverId, subId) {
|
||||
return await ajaxRequest(`/api/servers/${serverId}/subscriptions/${subId}/`, "DELETE");
|
||||
}
|
||||
|
||||
async function editSubscription(id, formData) {
|
||||
return await ajaxRequest(`/api/r_subscriptions/${id}/`, "PUT", formData);
|
||||
async function editSubscription(serverId, subId, formData) {
|
||||
return await ajaxRequest(`/api/servers/${serverId}/subscriptions/${subId}/`, "PUT", formData);
|
||||
}
|
||||
|
||||
async function getSubscriptionOptions() {
|
||||
return await ajaxRequest("/api/r_subscriptions/", "OPTIONS")
|
||||
async function getSubscriptionOptions(serverId) {
|
||||
return await ajaxRequest(`/api/${serverId}/subscriptions/`, "OPTIONS")
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
@ -126,7 +126,7 @@ function restartResolveChannelNamesTask() {
|
||||
}
|
||||
|
||||
function startResolveChannelNamesTask() {
|
||||
const guildId = getCurrentlyActiveServer().guild_id;
|
||||
const guildId = selectedServer.id;
|
||||
channelResolveInterval = setInterval(function() {
|
||||
if (resolveChannelNames(guildId))
|
||||
clearInterval(channelResolveInterval);
|
||||
@ -190,7 +190,7 @@ async function deleteSelectedContent() {
|
||||
|
||||
// Multi-deletion can take time, this timeout ensures the refresh is accurate
|
||||
setTimeout(async () => {
|
||||
await loadContent(getCurrentlyActiveServer().guild_id);
|
||||
await loadContent(selectedServer.id);
|
||||
}, 600);
|
||||
},
|
||||
null
|
||||
@ -206,7 +206,7 @@ function clearExistingContentRows() {
|
||||
}
|
||||
|
||||
$("#contentTabPane").on("click", ".table-refresh-btn", async function() {
|
||||
await loadContent(getCurrentlyActiveServer().guild_id);
|
||||
await loadContent(selectedServer.id);
|
||||
});
|
||||
|
||||
|
||||
@ -248,8 +248,7 @@ async function loadContent(guildId) {
|
||||
}
|
||||
|
||||
$(document).on("selectedServerChange", async function() {
|
||||
const activeServer = getCurrentlyActiveServer();
|
||||
await loadContent(activeServer.guild_id);
|
||||
await loadContent(selectedServer.id);
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
@ -129,7 +129,7 @@ $("#filterForm").on("submit", async function(event) {
|
||||
match = $("#filterMatch").val();
|
||||
isWhitelist = $("#filterWhitelist").prop("checked");
|
||||
isInsensitive = $("#filterInsensitive").prop("checked");
|
||||
guildId = getCurrentlyActiveServer().guild_id;
|
||||
guildId = selectedServer.id;
|
||||
|
||||
var filterPrimaryKey = await saveFilter(id, name, algorithm, match, isWhitelist, isInsensitive, guildId);
|
||||
|
||||
@ -171,7 +171,7 @@ function clearExistingFilterRows() {
|
||||
}
|
||||
|
||||
$("#filtersTabPane").on("click", ".table-refresh-btn", async function() {
|
||||
loadFilters(getCurrentlyActiveServer().guild_id);
|
||||
loadFilters(selectedServer.id);
|
||||
});
|
||||
|
||||
async function loadFilters(guildId) {
|
||||
@ -244,8 +244,7 @@ async function loadMatchingAlgorithms() {
|
||||
};
|
||||
|
||||
$(document).on("selectedServerChange", async function() {
|
||||
const activeServer = getCurrentlyActiveServer();
|
||||
await loadFilters(activeServer.guild_id);
|
||||
await loadFilters(selectedServer.id);
|
||||
});
|
||||
|
||||
// #region Delete Filters
|
||||
@ -263,7 +262,7 @@ $("#deleteEditFilter").on("click", async function() {
|
||||
"danger",
|
||||
async () => {
|
||||
await deleteFilter(filterId);
|
||||
await loadFilters(getCurrentlyActiveServer().guild_id);
|
||||
await loadFilters(selectedServer.id);
|
||||
|
||||
showToast(
|
||||
"danger",
|
||||
@ -300,7 +299,7 @@ async function deleteSelectedFilters() {
|
||||
|
||||
// Multi-deletion can take time, this timeout ensures the refresh is accurate
|
||||
setTimeout(async () => {
|
||||
await loadFilters(getCurrentlyActiveServer().guild_id);
|
||||
await loadFilters(selectedServer.id);
|
||||
}, 600);
|
||||
},
|
||||
null
|
||||
|
@ -1,10 +1,9 @@
|
||||
$(document).ready(async function() {
|
||||
// await initSubscriptionTable();
|
||||
// await initFiltersTable();
|
||||
// await initContentTable();
|
||||
|
||||
await loadServers();
|
||||
|
||||
await initSubscriptionTable();
|
||||
await initFiltersTable();
|
||||
await initContentTable();
|
||||
|
||||
$("#subscriptionsTab").click();
|
||||
});
|
||||
|
||||
|
@ -82,7 +82,8 @@ function removeSelectButton(id) {
|
||||
$("#backToSelectServer").on("click", function() {
|
||||
$("#noSelectedServer").show();
|
||||
$("#selectedServerContainer").hide();
|
||||
selectServer = null;
|
||||
$("#serverList .server-item > .server-item-selector.active").removeClass("active");
|
||||
selectedServer = null;
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
@ -4,7 +4,7 @@ $("#serverSettingsBtn").on("click", async function() {
|
||||
});
|
||||
|
||||
async function showServerSettingsModal() {
|
||||
const server = getCurrentlyActiveServer();
|
||||
const server = selectedServer;
|
||||
var guildSettings;
|
||||
|
||||
try { guildSettings = (await getGuildSettings(server.guild_id)).results[0] }
|
||||
|
@ -5,8 +5,8 @@ var subTable = null;
|
||||
|
||||
// Create subscription table
|
||||
async function initSubscriptionTable() {
|
||||
subOptions = await getSubscriptionOptions();
|
||||
await initTable("#subscriptionsTabPane", "subTable", loadSubscriptions, showEditSubModal, deleteSelectedSubscriptions, subOptions);
|
||||
// subOptions = await getSubscriptionOptions();
|
||||
await initTable("#subscriptionsTabPane", "subTable", loadSubscriptions, showEditSubModal, deleteSelectedSubscriptions);
|
||||
|
||||
subTable = $("#subTable").DataTable({
|
||||
info: false,
|
||||
@ -301,7 +301,7 @@ $("#subForm").on("submit", async function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
let subId = $("#subId").val();
|
||||
let guildId = getCurrentlyActiveServer().guild_id;
|
||||
let guildId = selectedServer.id;
|
||||
|
||||
// TODO: move this into a function, so I can fix the active toggle switches which are broken due to this change
|
||||
|
||||
@ -425,7 +425,7 @@ function clearExistingSubRows() {
|
||||
}
|
||||
|
||||
$("#subscriptionsTabPane").on("click", ".table-refresh-btn", async function() {
|
||||
loadSubscriptions(getCurrentlyActiveServer().guild_id);
|
||||
loadSubscriptions(selectedServer.id);
|
||||
});
|
||||
|
||||
async function loadSubscriptions(guildId) {
|
||||
@ -465,10 +465,9 @@ async function loadSubscriptions(guildId) {
|
||||
// #region Server Change Event Handler
|
||||
|
||||
$(document).on("selectedServerChange", async function() {
|
||||
let server = getCurrentlyActiveServer();
|
||||
guildId = server.guild_id;
|
||||
let guildId = selectedServer.id;
|
||||
|
||||
await updateDefaultSubEmbedColour();
|
||||
// await updateDefaultSubEmbedColour();
|
||||
|
||||
await loadSubscriptions(guildId);
|
||||
await loadChannelOptions(guildId);
|
||||
@ -479,7 +478,7 @@ $(document).on("selectedServerChange", async function() {
|
||||
|
||||
async function updateDefaultSubEmbedColour(settings=null) {
|
||||
if (!settings){
|
||||
settings = (await getGuildSettings(guildId)).results[0]
|
||||
settings = (await getGuildSettings(selectedServer.id)).results[0]
|
||||
}
|
||||
$("#subEmbedColour .colour-reset").attr("data-defaultcolour", "#" + settings.default_embed_colour);
|
||||
}
|
||||
@ -503,7 +502,7 @@ $("#deleteEditSub").on("click", async function() {
|
||||
"danger",
|
||||
async () => {
|
||||
await deleteSubscription(subId);
|
||||
await loadSubscriptions(getCurrentlyActiveServer().guild_id);
|
||||
await loadSubscriptions(selectedServer.id);
|
||||
|
||||
showToast(
|
||||
"danger",
|
||||
@ -540,7 +539,7 @@ async function deleteSelectedSubscriptions() {
|
||||
|
||||
// Multi-deletion can take time, this timeout ensures the refresh is accurate
|
||||
setTimeout(async () => {
|
||||
await loadSubscriptions(getCurrentlyActiveServer().guild_id);
|
||||
await loadSubscriptions(selectedServer.id);
|
||||
}, 600);
|
||||
},
|
||||
null
|
||||
@ -582,7 +581,7 @@ async function loadChannelOptions(guildId) {
|
||||
|
||||
// Also check that the user hasn't changed the currently active guild, otherwise
|
||||
// the alert will show under the wrong server.
|
||||
if (getCurrentlyActiveServer().guild_id === guildId)
|
||||
if (selectedServer.id === guildId)
|
||||
$("#serverJoinAlert").show();
|
||||
|
||||
// Warning icon on sidebar server select
|
||||
|
0
apps/static/js/home/tabs/subscriptions.js
Normal file
0
apps/static/js/home/tabs/subscriptions.js
Normal file
@ -81,7 +81,7 @@ function createSearchRow(containingSelector, searchId, sortDropdownId, filterDro
|
||||
}
|
||||
|
||||
// Show the sort dropdown
|
||||
if (options.sort && options.actions.GET) {
|
||||
if (options && options.sort && options.actions.GET) {
|
||||
$(`${containingSelector} .table-search-row .table-search-buttons`).append(`
|
||||
<div class="d-inline-block">
|
||||
<div id="${sortDropdownId}" class="dropdown table-sort-dropdown">
|
||||
@ -98,7 +98,7 @@ function createSearchRow(containingSelector, searchId, sortDropdownId, filterDro
|
||||
}
|
||||
|
||||
// Show the filters dropdown
|
||||
if (options.filter && options.actions.GET) {
|
||||
if (options && options.filter && options.actions.GET) {
|
||||
$(`${containingSelector} .table-search-row .table-search-buttons`).append(`
|
||||
<div class="d-inline-block">
|
||||
<div id="${filterDropdownId}" class="dropdown table-filter-dropdown">
|
||||
@ -273,7 +273,7 @@ async function bindSearchBar(tableId, searchBarSelector, loadDataFunc) {
|
||||
var searchString = $(this).val();
|
||||
setTableFilter(tableId, "search", searchString);
|
||||
timeouts[searchBarSelector] = setTimeout(async function() {
|
||||
await loadDataFunc(getCurrentlyActiveServer().guild_id);
|
||||
await loadDataFunc(selectedServer.id);
|
||||
}, 300);
|
||||
});
|
||||
}
|
||||
@ -282,7 +282,7 @@ async function bindFilterDropdown(tableId, filterDropdownId, loadDataFunc) {
|
||||
$(`#${filterDropdownId} .dropdown-menu`).on("change", "input", async function() {
|
||||
setTableFilter(tableId, $(this).attr("data-key"), $(this).data("state"));
|
||||
setTableFilter(tableId, "page", "1");
|
||||
await loadDataFunc(getCurrentlyActiveServer().guild_id);
|
||||
await loadDataFunc(selectedServer.id);
|
||||
});
|
||||
}
|
||||
|
||||
@ -304,7 +304,7 @@ async function bindSortDropdown(tableId, sortDropdownId, loadDataFunc) {
|
||||
}
|
||||
|
||||
setTableSorts(tableId, sortKey);
|
||||
await loadDataFunc(getCurrentlyActiveServer().guild_id);
|
||||
await loadDataFunc(selectedServer.id);
|
||||
});
|
||||
}
|
||||
|
||||
@ -467,7 +467,7 @@ async function bindTablePagination(tableId, pageControlsId, dataLoadFunc) {
|
||||
wantedPage = $(this).attr("data-page");
|
||||
|
||||
setTableFilter(tableId, "page", wantedPage);
|
||||
await dataLoadFunc(getCurrentlyActiveServer().guild_id)
|
||||
await dataLoadFunc(selectedServer.id)
|
||||
});
|
||||
}
|
||||
|
||||
@ -477,7 +477,7 @@ async function bindTablePaginationResizer(tableId, resizerControlId, dataLoadFun
|
||||
setTableFilter(tableId, "page", "1");
|
||||
setTableFilter(tableId, "page_size", $(this).val());
|
||||
|
||||
await dataLoadFunc(getCurrentlyActiveServer().guild_id);
|
||||
await dataLoadFunc(selectedServer.id);
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user