chore(client): tweak admin/roles page

This commit is contained in:
syuilo 2023-03-13 20:02:53 +09:00
parent 5d1ccb9bdc
commit 1a62ca52a0

View file

@ -7,7 +7,11 @@
<MkFolder> <MkFolder>
<template #label>{{ i18n.ts._role.baseRole }}</template> <template #label>{{ i18n.ts._role.baseRole }}</template>
<div class="_gaps_s"> <div class="_gaps_s">
<MkFolder> <MkInput v-model="baseRoleQ" type="search">
<template #prefix><i class="ti ti-search"></i></template>
</MkInput>
<MkFolder v-if="matchQuery([i18n.ts._role._options.rateLimitFactor, 'rateLimitFactor'])">
<template #label>{{ i18n.ts._role._options.rateLimitFactor }}</template> <template #label>{{ i18n.ts._role._options.rateLimitFactor }}</template>
<template #suffix>{{ Math.floor(policies.rateLimitFactor * 100) }}%</template> <template #suffix>{{ Math.floor(policies.rateLimitFactor * 100) }}%</template>
<MkRange :model-value="policies.rateLimitFactor * 100" :min="30" :max="300" :step="10" :text-converter="(v) => `${v}%`" @update:model-value="v => policies.rateLimitFactor = (v / 100)"> <MkRange :model-value="policies.rateLimitFactor * 100" :min="30" :max="300" :step="10" :text-converter="(v) => `${v}%`" @update:model-value="v => policies.rateLimitFactor = (v / 100)">
@ -15,7 +19,7 @@
</MkRange> </MkRange>
</MkFolder> </MkFolder>
<MkFolder> <MkFolder v-if="matchQuery([i18n.ts._role._options.gtlAvailable, 'gtlAvailable'])">
<template #label>{{ i18n.ts._role._options.gtlAvailable }}</template> <template #label>{{ i18n.ts._role._options.gtlAvailable }}</template>
<template #suffix>{{ policies.gtlAvailable ? i18n.ts.yes : i18n.ts.no }}</template> <template #suffix>{{ policies.gtlAvailable ? i18n.ts.yes : i18n.ts.no }}</template>
<MkSwitch v-model="policies.gtlAvailable"> <MkSwitch v-model="policies.gtlAvailable">
@ -23,7 +27,7 @@
</MkSwitch> </MkSwitch>
</MkFolder> </MkFolder>
<MkFolder> <MkFolder v-if="matchQuery([i18n.ts._role._options.ltlAvailable, 'ltlAvailable'])">
<template #label>{{ i18n.ts._role._options.ltlAvailable }}</template> <template #label>{{ i18n.ts._role._options.ltlAvailable }}</template>
<template #suffix>{{ policies.ltlAvailable ? i18n.ts.yes : i18n.ts.no }}</template> <template #suffix>{{ policies.ltlAvailable ? i18n.ts.yes : i18n.ts.no }}</template>
<MkSwitch v-model="policies.ltlAvailable"> <MkSwitch v-model="policies.ltlAvailable">
@ -31,7 +35,7 @@
</MkSwitch> </MkSwitch>
</MkFolder> </MkFolder>
<MkFolder> <MkFolder v-if="matchQuery([i18n.ts._role._options.canPublicNote, 'canPublicNote'])">
<template #label>{{ i18n.ts._role._options.canPublicNote }}</template> <template #label>{{ i18n.ts._role._options.canPublicNote }}</template>
<template #suffix>{{ policies.canPublicNote ? i18n.ts.yes : i18n.ts.no }}</template> <template #suffix>{{ policies.canPublicNote ? i18n.ts.yes : i18n.ts.no }}</template>
<MkSwitch v-model="policies.canPublicNote"> <MkSwitch v-model="policies.canPublicNote">
@ -39,7 +43,7 @@
</MkSwitch> </MkSwitch>
</MkFolder> </MkFolder>
<MkFolder> <MkFolder v-if="matchQuery([i18n.ts._role._options.canInvite, 'canInvite'])">
<template #label>{{ i18n.ts._role._options.canInvite }}</template> <template #label>{{ i18n.ts._role._options.canInvite }}</template>
<template #suffix>{{ policies.canInvite ? i18n.ts.yes : i18n.ts.no }}</template> <template #suffix>{{ policies.canInvite ? i18n.ts.yes : i18n.ts.no }}</template>
<MkSwitch v-model="policies.canInvite"> <MkSwitch v-model="policies.canInvite">
@ -47,7 +51,7 @@
</MkSwitch> </MkSwitch>
</MkFolder> </MkFolder>
<MkFolder> <MkFolder v-if="matchQuery([i18n.ts._role._options.canManageCustomEmojis, 'canManageCustomEmojis'])">
<template #label>{{ i18n.ts._role._options.canManageCustomEmojis }}</template> <template #label>{{ i18n.ts._role._options.canManageCustomEmojis }}</template>
<template #suffix>{{ policies.canManageCustomEmojis ? i18n.ts.yes : i18n.ts.no }}</template> <template #suffix>{{ policies.canManageCustomEmojis ? i18n.ts.yes : i18n.ts.no }}</template>
<MkSwitch v-model="policies.canManageCustomEmojis"> <MkSwitch v-model="policies.canManageCustomEmojis">
@ -55,7 +59,7 @@
</MkSwitch> </MkSwitch>
</MkFolder> </MkFolder>
<MkFolder> <MkFolder v-if="matchQuery([i18n.ts._role._options.canSearchNotes, 'canSearchNotes'])">
<template #label>{{ i18n.ts._role._options.canSearchNotes }}</template> <template #label>{{ i18n.ts._role._options.canSearchNotes }}</template>
<template #suffix>{{ policies.canSearchNotes ? i18n.ts.yes : i18n.ts.no }}</template> <template #suffix>{{ policies.canSearchNotes ? i18n.ts.yes : i18n.ts.no }}</template>
<MkSwitch v-model="policies.canSearchNotes"> <MkSwitch v-model="policies.canSearchNotes">
@ -63,7 +67,7 @@
</MkSwitch> </MkSwitch>
</MkFolder> </MkFolder>
<MkFolder> <MkFolder v-if="matchQuery([i18n.ts._role._options.driveCapacity, 'driveCapacityMb'])">
<template #label>{{ i18n.ts._role._options.driveCapacity }}</template> <template #label>{{ i18n.ts._role._options.driveCapacity }}</template>
<template #suffix>{{ policies.driveCapacityMb }}MB</template> <template #suffix>{{ policies.driveCapacityMb }}MB</template>
<MkInput v-model="policies.driveCapacityMb" type="number"> <MkInput v-model="policies.driveCapacityMb" type="number">
@ -71,21 +75,21 @@
</MkInput> </MkInput>
</MkFolder> </MkFolder>
<MkFolder> <MkFolder v-if="matchQuery([i18n.ts._role._options.pinMax, 'pinLimit'])">
<template #label>{{ i18n.ts._role._options.pinMax }}</template> <template #label>{{ i18n.ts._role._options.pinMax }}</template>
<template #suffix>{{ policies.pinLimit }}</template> <template #suffix>{{ policies.pinLimit }}</template>
<MkInput v-model="policies.pinLimit" type="number"> <MkInput v-model="policies.pinLimit" type="number">
</MkInput> </MkInput>
</MkFolder> </MkFolder>
<MkFolder> <MkFolder v-if="matchQuery([i18n.ts._role._options.antennaMax, 'antennaLimit'])">
<template #label>{{ i18n.ts._role._options.antennaMax }}</template> <template #label>{{ i18n.ts._role._options.antennaMax }}</template>
<template #suffix>{{ policies.antennaLimit }}</template> <template #suffix>{{ policies.antennaLimit }}</template>
<MkInput v-model="policies.antennaLimit" type="number"> <MkInput v-model="policies.antennaLimit" type="number">
</MkInput> </MkInput>
</MkFolder> </MkFolder>
<MkFolder> <MkFolder v-if="matchQuery([i18n.ts._role._options.wordMuteMax, 'wordMuteLimit'])">
<template #label>{{ i18n.ts._role._options.wordMuteMax }}</template> <template #label>{{ i18n.ts._role._options.wordMuteMax }}</template>
<template #suffix>{{ policies.wordMuteLimit }}</template> <template #suffix>{{ policies.wordMuteLimit }}</template>
<MkInput v-model="policies.wordMuteLimit" type="number"> <MkInput v-model="policies.wordMuteLimit" type="number">
@ -93,42 +97,42 @@
</MkInput> </MkInput>
</MkFolder> </MkFolder>
<MkFolder> <MkFolder v-if="matchQuery([i18n.ts._role._options.webhookMax, 'webhookLimit'])">
<template #label>{{ i18n.ts._role._options.webhookMax }}</template> <template #label>{{ i18n.ts._role._options.webhookMax }}</template>
<template #suffix>{{ policies.webhookLimit }}</template> <template #suffix>{{ policies.webhookLimit }}</template>
<MkInput v-model="policies.webhookLimit" type="number"> <MkInput v-model="policies.webhookLimit" type="number">
</MkInput> </MkInput>
</MkFolder> </MkFolder>
<MkFolder> <MkFolder v-if="matchQuery([i18n.ts._role._options.clipMax, 'clipLimit'])">
<template #label>{{ i18n.ts._role._options.clipMax }}</template> <template #label>{{ i18n.ts._role._options.clipMax }}</template>
<template #suffix>{{ policies.clipLimit }}</template> <template #suffix>{{ policies.clipLimit }}</template>
<MkInput v-model="policies.clipLimit" type="number"> <MkInput v-model="policies.clipLimit" type="number">
</MkInput> </MkInput>
</MkFolder> </MkFolder>
<MkFolder> <MkFolder v-if="matchQuery([i18n.ts._role._options.noteEachClipsMax, 'noteEachClipsLimit'])">
<template #label>{{ i18n.ts._role._options.noteEachClipsMax }}</template> <template #label>{{ i18n.ts._role._options.noteEachClipsMax }}</template>
<template #suffix>{{ policies.noteEachClipsLimit }}</template> <template #suffix>{{ policies.noteEachClipsLimit }}</template>
<MkInput v-model="policies.noteEachClipsLimit" type="number"> <MkInput v-model="policies.noteEachClipsLimit" type="number">
</MkInput> </MkInput>
</MkFolder> </MkFolder>
<MkFolder> <MkFolder v-if="matchQuery([i18n.ts._role._options.userListMax, 'userListLimit'])">
<template #label>{{ i18n.ts._role._options.userListMax }}</template> <template #label>{{ i18n.ts._role._options.userListMax }}</template>
<template #suffix>{{ policies.userListLimit }}</template> <template #suffix>{{ policies.userListLimit }}</template>
<MkInput v-model="policies.userListLimit" type="number"> <MkInput v-model="policies.userListLimit" type="number">
</MkInput> </MkInput>
</MkFolder> </MkFolder>
<MkFolder> <MkFolder v-if="matchQuery([i18n.ts._role._options.userEachUserListsMax, 'userEachUserListsLimit'])">
<template #label>{{ i18n.ts._role._options.userEachUserListsMax }}</template> <template #label>{{ i18n.ts._role._options.userEachUserListsMax }}</template>
<template #suffix>{{ policies.userEachUserListsLimit }}</template> <template #suffix>{{ policies.userEachUserListsLimit }}</template>
<MkInput v-model="policies.userEachUserListsLimit" type="number"> <MkInput v-model="policies.userEachUserListsLimit" type="number">
</MkInput> </MkInput>
</MkFolder> </MkFolder>
<MkFolder> <MkFolder v-if="matchQuery([i18n.ts._role._options.canHideAds, 'canHideAds'])">
<template #label>{{ i18n.ts._role._options.canHideAds }}</template> <template #label>{{ i18n.ts._role._options.canHideAds }}</template>
<template #suffix>{{ policies.canHideAds ? i18n.ts.yes : i18n.ts.no }}</template> <template #suffix>{{ policies.canHideAds ? i18n.ts.yes : i18n.ts.no }}</template>
<MkSwitch v-model="policies.canHideAds"> <MkSwitch v-model="policies.canHideAds">
@ -161,7 +165,7 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed, reactive } from 'vue'; import { computed, reactive, ref } from 'vue';
import XHeader from './_header_.vue'; import XHeader from './_header_.vue';
import MkInput from '@/components/MkInput.vue'; import MkInput from '@/components/MkInput.vue';
import MkFolder from '@/components/MkFolder.vue'; import MkFolder from '@/components/MkFolder.vue';
@ -178,6 +182,7 @@ import MkFoldableSection from '@/components/MkFoldableSection.vue';
import { ROLE_POLICIES } from '@/const'; import { ROLE_POLICIES } from '@/const';
const router = useRouter(); const router = useRouter();
const baseRoleQ = ref('');
const roles = await os.api('admin/roles/list'); const roles = await os.api('admin/roles/list');
@ -186,6 +191,11 @@ for (const ROLE_POLICY of ROLE_POLICIES) {
policies[ROLE_POLICY] = instance.policies[ROLE_POLICY]; policies[ROLE_POLICY] = instance.policies[ROLE_POLICY];
} }
function matchQuery(keywords: string[]): boolean {
if (baseRoleQ.value.trim().length === 0) return true;
return keywords.some(keyword => keyword.toLowerCase().includes(baseRoleQ.value.toLowerCase()));
}
async function updateBaseRole() { async function updateBaseRole() {
await os.apiWithDialog('admin/roles/update-default-policies', { await os.apiWithDialog('admin/roles/update-default-policies', {
policies, policies,