claim settings
This commit is contained in:
parent
cc8470f30d
commit
636270bee7
20
app/http/endpoints/api/claimsettings.go
Normal file
20
app/http/endpoints/api/claimsettings.go
Normal file
@ -0,0 +1,20 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/TicketsBot/GoPanel/database"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func GetClaimSettings(ctx *gin.Context) {
|
||||
guildId := ctx.Keys["guildid"].(uint64)
|
||||
|
||||
settings, err := database.Client.ClaimSettings.Get(guildId); if err != nil {
|
||||
ctx.AbortWithStatusJSON(500, gin.H{
|
||||
"success": false,
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, settings)
|
||||
}
|
@ -21,7 +21,6 @@ type Settings struct {
|
||||
|
||||
func GetSettingsHandler(ctx *gin.Context) {
|
||||
guildId := ctx.Keys["guildid"].(uint64)
|
||||
ctx.Done()
|
||||
var prefix, welcomeMessage string
|
||||
var ticketLimit uint8
|
||||
var category, archiveChannel uint64
|
||||
|
40
app/http/endpoints/api/updateclaimsettings.go
Normal file
40
app/http/endpoints/api/updateclaimsettings.go
Normal file
@ -0,0 +1,40 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
dbclient "github.com/TicketsBot/GoPanel/database"
|
||||
"github.com/TicketsBot/database"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func PostClaimSettings(ctx *gin.Context) {
|
||||
guildId := ctx.Keys["guildid"].(uint64)
|
||||
|
||||
var settings database.ClaimSettings
|
||||
if err := ctx.BindJSON(&settings); err != nil {
|
||||
ctx.AbortWithStatusJSON(400, gin.H{
|
||||
"success": false,
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if settings.SupportCanType && !settings.SupportCanView {
|
||||
ctx.AbortWithStatusJSON(400, gin.H{
|
||||
"success": false,
|
||||
"error": "Must be able to view channel to type",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if err := dbclient.Client.ClaimSettings.Set(guildId, settings); err != nil {
|
||||
ctx.AbortWithStatusJSON(500, gin.H{
|
||||
"success": false,
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, gin.H{
|
||||
"success": true,
|
||||
})
|
||||
}
|
@ -100,6 +100,9 @@ func StartServer() {
|
||||
guildAuthApi.GET("/:id/tags", api.TagsListHandler)
|
||||
guildAuthApi.PUT("/:id/tags", api.CreateTag)
|
||||
guildAuthApi.DELETE("/:id/tags/:tag", api.DeleteTag)
|
||||
|
||||
guildAuthApi.GET("/:id/claimsettings", api.GetClaimSettings)
|
||||
guildAuthApi.POST("/:id/claimsettings", api.PostClaimSettings)
|
||||
}
|
||||
|
||||
userGroup := router.Group("/user", middleware.AuthenticateToken)
|
||||
|
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.14
|
||||
require (
|
||||
github.com/BurntSushi/toml v0.3.1
|
||||
github.com/TicketsBot/archiverclient v0.0.0-20200425115930-0ca198cc8306
|
||||
github.com/TicketsBot/database v0.0.0-20200513210802-2adabede3591
|
||||
github.com/TicketsBot/database v0.0.0-20200514140316-5fc42f69495c
|
||||
github.com/apex/log v1.1.2
|
||||
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||
|
@ -6,9 +6,6 @@
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4 class="card-title">Settings</h4>
|
||||
{{if .empty}}
|
||||
<p class="card-category">Select a server to manage below</p>
|
||||
{{end}}
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form onsubmit="updateSettings(); return false;">
|
||||
@ -102,6 +99,49 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Claim settings -->
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4 class="card-title">Claim Settings</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form onsubmit="updateClaimSettings(); return false;">
|
||||
<div class="row">
|
||||
<div class="col-md-2 pr-1">
|
||||
<div class="form-group">
|
||||
<label>Support Reps Can View Claimed Tickets</label>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="can_view" value="on" id="can_view" style="width:30px;height:30px;" onclick="canViewChanged();">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-2 pr-1">
|
||||
<div class="form-group">
|
||||
<label>Support Reps Can Type In Claimed Tickets</label>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="can_type" value="on" id="can_type" style="width:30px;height:30px;">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row" style="padding-top: 20px">
|
||||
<div class="col-md-2 pr-1">
|
||||
<div class="form-group">
|
||||
<button class="btn btn-primary btn-fill" type="submit"><i class="fas fa-paper-plane"></i>
|
||||
Submit
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div aria-live="polite" aria-atomic="true" style="position: relative;">
|
||||
@ -175,6 +215,45 @@
|
||||
loadData();
|
||||
</script>
|
||||
|
||||
<script>
|
||||
async function getClaimSettings() {
|
||||
const res = await axios.get('/api/{{.guildId}}/claimsettings');
|
||||
return res.data;
|
||||
}
|
||||
|
||||
async function loadClaimSettings() {
|
||||
const settings = await getClaimSettings();
|
||||
document.getElementById('can_view').checked = settings.support_can_view;
|
||||
document.getElementById('can_type').checked = settings.support_can_type;
|
||||
}
|
||||
|
||||
loadClaimSettings();
|
||||
|
||||
async function updateClaimSettings() {
|
||||
const data = {
|
||||
support_can_view: document.getElementById('can_view').checked,
|
||||
support_can_type: document.getElementById('can_type').checked
|
||||
};
|
||||
|
||||
const res = await axios.post('/api/{{.guildId}}/claimsettings', data);
|
||||
if (res.status === 200 && res.data.success) {
|
||||
showToast("Success", "Your settings have been saved.");
|
||||
} else {
|
||||
showToast("Error", res.data.error);
|
||||
}
|
||||
}
|
||||
|
||||
function canViewChanged() {
|
||||
const isChecked = document.getElementById('can_view').checked;
|
||||
if (isChecked) {
|
||||
document.getElementById('can_type').disabled = false;
|
||||
} else {
|
||||
document.getElementById('can_type').disabled = true;
|
||||
document.getElementById('can_type').checked = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
async function updateSettings() {
|
||||
const data = {
|
||||
@ -192,7 +271,7 @@
|
||||
if (res.status === 200) {
|
||||
const success = showValidations(res.data);
|
||||
if (success) {
|
||||
showToast("Success", "Your settings have been saved.")
|
||||
showToast("Success", "Your settings have been saved.");
|
||||
}
|
||||
} else {
|
||||
showToast("Error", "A severe error occurred. Please check your console for more information.");
|
||||
|
Loading…
x
Reference in New Issue
Block a user