Fix: Show API Keys disabled msg. when disabled Auth (#4723)

Co-authored-by: Frank Elsinga <frank@elsinga.de>
This commit is contained in:
Nelson Chan 2024-05-01 04:11:09 +08:00 committed by GitHub
parent 2778929f74
commit 59f10d542b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 148 additions and 132 deletions

View file

@ -1,53 +1,63 @@
<template> <template>
<div> <div>
<div class="add-btn"> <div
<button class="btn btn-primary me-2" type="button" @click="$refs.apiKeyDialog.show()"> v-if="settings.disableAuth"
<font-awesome-icon icon="plus" /> {{ $t("Add API Key") }} class="mt-5 d-flex align-items-center justify-content-center my-3"
</button> >
{{ $t("apiKeysDisabledMsg") }}
</div> </div>
<div v-else>
<div class="add-btn">
<button class="btn btn-primary me-2" type="button" @click="$refs.apiKeyDialog.show()">
<font-awesome-icon icon="plus" /> {{ $t("Add API Key") }}
</button>
</div>
<div> <div>
<span v-if="Object.keys(keyList).length === 0" class="d-flex align-items-center justify-content-center my-3"> <span
{{ $t("No API Keys") }} v-if="Object.keys(keyList).length === 0"
</span> class="d-flex align-items-center justify-content-center my-3"
>
{{ $t("No API Keys") }}
</span>
<div <div
v-for="(item, index) in keyList" v-for="(item, index) in keyList"
:key="index" :key="index"
class="item" class="item"
:class="item.status" :class="item.status"
> >
<div class="left-part"> <div class="left-part">
<div <div class="circle"></div>
class="circle" <div class="info">
></div> <div class="title">{{ item.name }}</div>
<div class="info"> <div class="status">
<div class="title">{{ item.name }}</div> {{ $t("apiKey-" + item.status) }}
<div class="status"> </div>
{{ $t("apiKey-" + item.status) }} <div class="date">
</div> {{ $t("Created") }}: {{ item.createdDate }}
<div class="date"> </div>
{{ $t("Created") }}: {{ item.createdDate }} <div class="date">
</div> {{ $t("Expires") }}:
<div class="date"> {{ item.expires || $t("Never") }}
{{ $t("Expires") }}: {{ item.expires || $t("Never") }} </div>
</div> </div>
</div> </div>
</div>
<div class="buttons"> <div class="buttons">
<div class="btn-group" role="group"> <div class="btn-group" role="group">
<button v-if="item.active" class="btn btn-normal" @click="disableDialog(item.id)"> <button v-if="item.active" class="btn btn-normal" @click="disableDialog(item.id)">
<font-awesome-icon icon="pause" /> {{ $t("Disable") }} <font-awesome-icon icon="pause" /> {{ $t("Disable") }}
</button> </button>
<button v-if="!item.active" class="btn btn-primary" @click="enableKey(item.id)"> <button v-if="!item.active" class="btn btn-primary" @click="enableKey(item.id)">
<font-awesome-icon icon="play" /> {{ $t("Enable") }} <font-awesome-icon icon="play" /> {{ $t("Enable") }}
</button> </button>
<button class="btn btn-danger" @click="deleteDialog(item.id)"> <button class="btn btn-danger" @click="deleteDialog(item.id)">
<font-awesome-icon icon="trash" /> {{ $t("Delete") }} <font-awesome-icon icon="trash" /> {{ $t("Delete") }}
</button> </button>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -90,6 +100,9 @@ export default {
let result = Object.values(this.$root.apiKeyList); let result = Object.values(this.$root.apiKeyList);
return result; return result;
}, },
settings() {
return this.$parent.$parent.$parent.settings;
},
}, },
methods: { methods: {
@ -127,9 +140,11 @@ export default {
* Pause maintenance * Pause maintenance
*/ */
disableKey() { disableKey() {
this.$root.getSocket().emit("disableAPIKey", this.selectedKeyID, (res) => { this.$root
this.$root.toastRes(res); .getSocket()
}); .emit("disableAPIKey", this.selectedKeyID, (res) => {
this.$root.toastRes(res);
});
}, },
/** /**
@ -145,113 +160,113 @@ export default {
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "../../assets/vars.scss"; @import "../../assets/vars.scss";
.mobile {
.item {
flex-direction: column;
align-items: flex-start;
margin-bottom: 20px;
}
}
.add-btn {
padding-top: 20px;
padding-bottom: 20px;
}
.mobile {
.item { .item {
display: flex; flex-direction: column;
align-items: center; align-items: flex-start;
gap: 10px; margin-bottom: 20px;
text-decoration: none; }
border-radius: 10px; }
transition: all ease-in-out 0.15s;
justify-content: space-between;
padding: 10px;
min-height: 90px;
margin-bottom: 5px;
&:hover { .add-btn {
background-color: $highlight-white; padding-top: 20px;
padding-bottom: 20px;
}
.item {
display: flex;
align-items: center;
gap: 10px;
text-decoration: none;
border-radius: 10px;
transition: all ease-in-out 0.15s;
justify-content: space-between;
padding: 10px;
min-height: 90px;
margin-bottom: 5px;
&:hover {
background-color: $highlight-white;
}
&.active {
.circle {
background-color: $primary;
} }
}
&.active { &.inactive {
.circle { .circle {
background-color: $primary; background-color: $danger;
}
}
&.inactive {
.circle {
background-color: $danger;
}
}
&.expired {
.left-part {
opacity: 0.3;
}
.circle {
background-color: $dark-font-color;
}
} }
}
&.expired {
.left-part { .left-part {
display: flex; opacity: 0.3;
gap: 12px;
align-items: center;
.circle {
width: 25px;
height: 25px;
border-radius: 50rem;
}
.info {
.title {
font-weight: bold;
font-size: 20px;
}
.status {
font-size: 14px;
}
}
} }
.buttons { .circle {
display: flex; background-color: $dark-font-color;
gap: 8px; }
flex-direction: row-reverse; }
.btn-group { .left-part {
width: 310px; display: flex;
gap: 12px;
align-items: center;
.circle {
width: 25px;
height: 25px;
border-radius: 50rem;
}
.info {
.title {
font-weight: bold;
font-size: 20px;
}
.status {
font-size: 14px;
} }
} }
} }
.date { .buttons {
margin-top: 5px; display: flex;
display: block; gap: 8px;
font-size: 14px; flex-direction: row-reverse;
background-color: rgba(255, 255, 255, 0.5);
border-radius: 20px;
padding: 0 10px;
width: fit-content;
.dark & { .btn-group {
color: white; width: 310px;
background-color: rgba(255, 255, 255, 0.1);
} }
} }
}
.dark { .date {
.item { margin-top: 5px;
&:hover { display: block;
background-color: $dark-bg2; font-size: 14px;
} background-color: rgba(255, 255, 255, 0.5);
border-radius: 20px;
padding: 0 10px;
width: fit-content;
.dark & {
color: white;
background-color: rgba(255, 255, 255, 0.1);
}
}
.dark {
.item {
&:hover {
background-color: $dark-bg2;
} }
} }
}
</style> </style>

View file

@ -820,5 +820,6 @@
"showCertificateExpiry": "Show Certificate Expiry", "showCertificateExpiry": "Show Certificate Expiry",
"noOrBadCertificate": "No/Bad Certificate", "noOrBadCertificate": "No/Bad Certificate",
"gamedigGuessPort": "Gamedig: Guess Port", "gamedigGuessPort": "Gamedig: Guess Port",
"gamedigGuessPortDescription": "The port used by Valve Server Query Protocol may be different from the client port. Try this if the monitor cannot connect to your server." "gamedigGuessPortDescription": "The port used by Valve Server Query Protocol may be different from the client port. Try this if the monitor cannot connect to your server.",
"apiKeysDisabledMsg": "API keys are disabled because authentication is disabled."
} }