Panel fixes
This commit is contained in:
parent
8993b31a0b
commit
7336d50d62
@ -174,7 +174,7 @@ func CreatePanel(ctx *gin.Context) {
|
|||||||
|
|
||||||
ctx.JSON(200, gin.H{
|
ctx.JSON(200, gin.H{
|
||||||
"success": true,
|
"success": true,
|
||||||
"panel_id": strconv.Itoa(panelId),
|
"panel_id": panelId,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ func DeletePanel(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
panelId, err := strconv.Atoi(ctx.Param("id"))
|
panelId, err := strconv.Atoi(ctx.Param("panelid"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.AbortWithStatusJSON(400, gin.H{
|
ctx.AbortWithStatusJSON(400, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
|
@ -33,7 +33,7 @@ func UpdatePanel(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
panelId, err := strconv.Atoi(ctx.Param("id"))
|
panelId, err := strconv.Atoi(ctx.Param("panelid"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.AbortWithStatusJSON(400, utils.ErrorJson(err))
|
ctx.AbortWithStatusJSON(400, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -122,14 +122,8 @@ func UpdatePanel(ctx *gin.Context) {
|
|||||||
newMessageId := existing.MessageId
|
newMessageId := existing.MessageId
|
||||||
|
|
||||||
if shouldUpdateMessage {
|
if shouldUpdateMessage {
|
||||||
// delete old message
|
// delete old message, ignoring error
|
||||||
if err := rest.DeleteMessage(botContext.Token, botContext.RateLimiter, existing.ChannelId, existing.MessageId); err != nil {
|
_ = rest.DeleteMessage(botContext.Token, botContext.RateLimiter, existing.ChannelId, existing.MessageId)
|
||||||
ctx.AbortWithStatusJSON(500, gin.H{
|
|
||||||
"success": false,
|
|
||||||
"error": err.Error(),
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
premiumTier := rpc.PremiumClient.GetTierByGuildId(guildId, true, botContext.Token, botContext.RateLimiter)
|
premiumTier := rpc.PremiumClient.GetTierByGuildId(guildId, true, botContext.Token, botContext.RateLimiter)
|
||||||
newMessageId, err = data.sendEmbed(&botContext, existing.Title, existing.CustomId, existing.ReactionEmote, premiumTier > premium.None)
|
newMessageId, err = data.sendEmbed(&botContext, existing.Title, existing.CustomId, existing.ReactionEmote, premiumTier > premium.None)
|
||||||
@ -147,22 +141,6 @@ func UpdatePanel(ctx *gin.Context) {
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add reaction
|
|
||||||
if err = rest.CreateReaction(botContext.Token, botContext.RateLimiter, data.ChannelId, newMessageId, emoji); err != nil {
|
|
||||||
var unwrapped request.RestError
|
|
||||||
if errors.As(err, &unwrapped) && unwrapped.StatusCode == 403 {
|
|
||||||
ctx.AbortWithStatusJSON(500, gin.H{
|
|
||||||
"success": false,
|
|
||||||
"error": "I do not have permission to add reactions in the specified channel",
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
// TODO: Most appropriate error?
|
|
||||||
ctx.AbortWithStatusJSON(500, utils.ErrorJson(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store in DB
|
// Store in DB
|
||||||
@ -178,6 +156,7 @@ func UpdatePanel(ctx *gin.Context) {
|
|||||||
ReactionEmote: emoji,
|
ReactionEmote: emoji,
|
||||||
WelcomeMessage: data.WelcomeMessage,
|
WelcomeMessage: data.WelcomeMessage,
|
||||||
WithDefaultTeam: utils.ContainsString(data.Teams, "default"),
|
WithDefaultTeam: utils.ContainsString(data.Teams, "default"),
|
||||||
|
CustomId: existing.CustomId,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = dbclient.Client.Panel.Update(panel); err != nil {
|
if err = dbclient.Client.Panel.Update(panel); err != nil {
|
||||||
|
@ -101,8 +101,8 @@ func StartServer() {
|
|||||||
|
|
||||||
guildAuthApiAdmin.GET("/panels", api_panels.ListPanels)
|
guildAuthApiAdmin.GET("/panels", api_panels.ListPanels)
|
||||||
guildAuthApiAdmin.PUT("/panels", api_panels.CreatePanel)
|
guildAuthApiAdmin.PUT("/panels", api_panels.CreatePanel)
|
||||||
guildAuthApiAdmin.PUT("/panels/:id", api_panels.UpdatePanel)
|
guildAuthApiAdmin.PUT("/panels/:panelid", api_panels.UpdatePanel)
|
||||||
guildAuthApiAdmin.DELETE("/panels/:id", api_panels.DeletePanel)
|
guildAuthApiAdmin.DELETE("/panels/:panelid", api_panels.DeletePanel)
|
||||||
|
|
||||||
guildAuthApiAdmin.GET("/multipanels", api_panels.MultiPanelList)
|
guildAuthApiAdmin.GET("/multipanels", api_panels.MultiPanelList)
|
||||||
guildAuthApiAdmin.POST("/multipanels", api_panels.MultiPanelCreate)
|
guildAuthApiAdmin.POST("/multipanels", api_panels.MultiPanelCreate)
|
||||||
|
@ -98,7 +98,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input type="hidden" id="edit-message-id">
|
<input type="hidden" id="edit-panel-id">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -114,14 +114,14 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
function resetEditModal() {
|
function resetEditModal() {
|
||||||
clear('edit-title', 'edit-content', 'edit-message-id', 'edit-reaction', 'edit-welcome-message');
|
clear('edit-title', 'edit-content', 'edit-panel-id', 'edit-reaction', 'edit-welcome-message');
|
||||||
$('#edit-mentions').selectpicker('deselectAll');
|
$('#edit-mentions').selectpicker('deselectAll');
|
||||||
}
|
}
|
||||||
|
|
||||||
registerHideListener('editmodal');
|
registerHideListener('editmodal');
|
||||||
$('#editmodal').on('hidden.bs.modal', resetEditModal);
|
$('#editmodal').on('hidden.bs.modal', resetEditModal);
|
||||||
|
|
||||||
async function openEditModal(messageId) {
|
async function openEditModal(panelId) {
|
||||||
resetEditModal();
|
resetEditModal();
|
||||||
|
|
||||||
const res = await axios.get('/api/{{.guildId}}/panels');
|
const res = await axios.get('/api/{{.guildId}}/panels');
|
||||||
@ -130,7 +130,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const panel = res.data.find(panel => panel.message_id === messageId);
|
const panel = res.data.find(panel => panel.panel_id == panelId);
|
||||||
if (panel === undefined) {
|
if (panel === undefined) {
|
||||||
showToast('Error', 'Panel not found');
|
showToast('Error', 'Panel not found');
|
||||||
return;
|
return;
|
||||||
@ -143,7 +143,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function fillEditData(panel) {
|
async function fillEditData(panel) {
|
||||||
document.getElementById('edit-message-id').value = panel.message_id;
|
document.getElementById('edit-panel-id').value = panel.panel_id;
|
||||||
document.getElementById('edit-title').value = panel.title;
|
document.getElementById('edit-title').value = panel.title;
|
||||||
document.getElementById('edit-content').value = panel.content;
|
document.getElementById('edit-content').value = panel.content;
|
||||||
document.getElementById('edit-colour').value = `#${panel.colour.toString(16)}`;
|
document.getElementById('edit-colour').value = `#${panel.colour.toString(16)}`;
|
||||||
@ -192,19 +192,18 @@
|
|||||||
values.push(...panel.teams.map((t) => t.id));
|
values.push(...panel.teams.map((t) => t.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$('#edit-teams').selectpicker('val', values);
|
$('#edit-teams').selectpicker('val', values);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updatePanel() {
|
async function updatePanel() {
|
||||||
const messageId = document.getElementById('edit-message-id').value;
|
const panelId = document.getElementById('edit-panel-id').value;
|
||||||
const title = document.getElementById('edit-title').value;
|
const title = document.getElementById('edit-title').value;
|
||||||
const content = document.getElementById('edit-content').value;
|
const content = document.getElementById('edit-content').value;
|
||||||
const emote = document.getElementById('edit-reaction').value.replace(':', '');
|
const emote = document.getElementById('edit-reaction').value.replace(':', '');
|
||||||
const welcomeMessage = document.getElementById('edit-welcome-message').value;
|
const welcomeMessage = document.getElementById('edit-welcome-message').value;
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
message_id: messageId,
|
panel_id: panelId,
|
||||||
title: title === '' ? 'Open a ticket!' : title,
|
title: title === '' ? 'Open a ticket!' : title,
|
||||||
content: content === '' ? 'By reacting to this ticket, a message will be opened for you.' : content,
|
content: content === '' ? 'By reacting to this ticket, a message will be opened for you.' : content,
|
||||||
emote: emote === '' ? 'envelope_with_arrow' : emote,
|
emote: emote === '' ? 'envelope_with_arrow' : emote,
|
||||||
@ -216,7 +215,7 @@
|
|||||||
teams: $('#edit-teams').val()
|
teams: $('#edit-teams').val()
|
||||||
};
|
};
|
||||||
|
|
||||||
const res = await axios.put('/api/{{.guildId}}/panels/' + messageId, data);
|
const res = await axios.put('/api/{{.guildId}}/panels/' + panelId, data);
|
||||||
if (res.status === 200 && res.data.success) {
|
if (res.status === 200 && res.data.success) {
|
||||||
showToast('Success', 'Panel updated successfully')
|
showToast('Success', 'Panel updated successfully')
|
||||||
$('#editmodal').modal('hide');
|
$('#editmodal').modal('hide');
|
||||||
@ -224,10 +223,9 @@
|
|||||||
|
|
||||||
// remove old data
|
// remove old data
|
||||||
// TODO: Don't remove just update, looks cleaner
|
// TODO: Don't remove just update, looks cleaner
|
||||||
const el = document.getElementById(messageId);
|
const el = document.getElementById(panelId);
|
||||||
el.parentNode.removeChild(el);
|
el.parentNode.removeChild(el);
|
||||||
|
|
||||||
data.message_id = res.data.message_id;
|
|
||||||
appendPanel(data, await getChannels());
|
appendPanel(data, await getChannels());
|
||||||
} else {
|
} else {
|
||||||
showToast('Error', res.data.error);
|
showToast('Error', res.data.error);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user