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