2023-07-27 07:31:52 +02:00
<!--
SPDX - FileCopyrightText : syuilo and other misskey contributors
SPDX - License - Identifier : AGPL - 3.0 - only
-- >
2020-07-18 05:12:10 +02:00
< template >
2023-01-06 01:41:14 +01:00
< MkModalWindow
2022-09-05 11:34:59 +02:00
ref = "dialog"
2020-10-17 13:12:00 +02:00
: width = "400"
: height = "450"
2023-05-19 06:58:09 +02:00
: withOkButton = "true"
: okButtonDisabled = "false"
: canClose = "false"
2024-01-05 04:52:24 +01:00
@ close = "dialog?.close()"
2020-10-17 13:12:00 +02:00
@ closed = "$emit('closed')"
@ ok = "ok()"
>
2023-04-01 07:01:57 +02:00
< template # header > { { title || i18n . ts . generateAccessToken } } < / template >
2023-01-05 11:50:52 +01:00
2023-05-19 06:58:09 +02:00
< MkSpacer :marginMin = "20" :marginMax = "28" >
2023-01-06 05:40:17 +01:00
< div class = "_gaps_m" >
2023-01-05 13:04:56 +01:00
< div v-if = "information" >
2023-01-05 11:50:52 +01:00
< MkInfo warn > { { information } } < / MkInfo >
< / div >
2023-01-05 13:04:56 +01:00
< div >
2023-01-05 11:50:52 +01:00
< MkInput v-model = "name" >
2023-04-01 07:01:57 +02:00
< template # label > { { i18n . ts . name } } < / template >
2023-01-05 11:50:52 +01:00
< / MkInput >
< / div >
2023-04-01 07:01:57 +02:00
< div > < b > { { i18n . ts . permission } } < / b > < / div >
2023-01-06 01:41:14 +01:00
< div class = "_buttons" >
2023-01-05 11:50:52 +01:00
< MkButton inline @click ="disableAll" > {{ i18n.ts.disableAll }} < / MkButton >
< MkButton inline @click ="enableAll" > {{ i18n.ts.enableAll }} < / MkButton >
< / div >
2023-09-24 04:04:08 +02:00
< div class = "_gaps_s" >
2024-01-09 13:18:09 +01:00
< MkSwitch v-for = "kind in Object.keys(permissionSwitches)" :key="kind" v-model="permissionSwitches[kind]" > {{ i18n.t ( ` _permissions. $ { kind } ` ) }} < / MkSwitch >
< / div >
< div v-if = "iAmAdmin" :class="$style.adminPermissions" >
< div :class = "$style.adminPermissionsHeader" > < b > { { i18n . ts . adminPermission } } < / b > < / div >
< div class = "_gaps_s" >
< MkSwitch v-for = "kind in Object.keys(permissionSwitchesForAdmin)" :key="kind" v-model="permissionSwitchesForAdmin[kind]" > {{ i18n.t ( ` _permissions. $ { kind } ` ) }} < / MkSwitch >
< / div >
2023-09-24 04:04:08 +02:00
< / div >
2023-01-05 11:50:52 +01:00
< / div >
< / MkSpacer >
2023-01-06 01:41:14 +01:00
< / MkModalWindow >
2020-07-18 05:12:10 +02:00
< / template >
2022-09-05 11:34:59 +02:00
< script lang = "ts" setup >
2023-12-07 06:42:09 +01:00
import { shallowRef , ref } from 'vue' ;
2023-09-04 06:33:38 +02:00
import * as Misskey from 'misskey-js' ;
2023-01-07 07:09:46 +01:00
import MkInput from './MkInput.vue' ;
2023-01-07 06:59:54 +01:00
import MkSwitch from './MkSwitch.vue' ;
2022-09-06 11:21:49 +02:00
import MkButton from './MkButton.vue' ;
import MkInfo from './MkInfo.vue' ;
2023-01-06 01:41:14 +01:00
import MkModalWindow from '@/components/MkModalWindow.vue' ;
2023-09-19 09:37:43 +02:00
import { i18n } from '@/i18n.js' ;
2024-01-09 13:18:09 +01:00
import { iAmAdmin } from '@/account.js' ;
2020-07-18 05:12:10 +02:00
2022-09-05 11:34:59 +02:00
const props = withDefaults ( defineProps < {
title ? : string | null ;
information ? : string | null ;
initialName ? : string | null ;
2023-12-27 07:08:59 +01:00
initialPermissions ? : ( typeof Misskey . permissions ) [ number ] [ ] | null ;
2022-09-05 11:34:59 +02:00
} > ( ) , {
title : null ,
information : null ,
initialName : null ,
initialPermissions : null ,
} ) ;
2020-07-18 05:12:10 +02:00
2022-09-05 11:34:59 +02:00
const emit = defineEmits < {
( ev : 'closed' ) : void ;
( ev : 'done' , result : { name : string | null , permissions : string [ ] } ) : void ;
} > ( ) ;
2020-10-17 13:12:00 +02:00
2023-12-27 07:08:59 +01:00
const defaultPermissions = Misskey . permissions . filter ( p => ! p . startsWith ( 'read:admin' ) && ! p . startsWith ( 'write:admin' ) ) ;
2024-01-09 13:18:09 +01:00
const adminPermissions = Misskey . permissions . filter ( p => p . startsWith ( 'read:admin' ) || p . startsWith ( 'write:admin' ) ) ;
2023-12-07 06:42:09 +01:00
const dialog = shallowRef < InstanceType < typeof MkModalWindow > > ( ) ;
const name = ref ( props . initialName ) ;
2024-01-09 13:18:09 +01:00
const permissionSwitches = ref ( < Record < ( typeof Misskey.permissions ) [ number ] , boolean > > { } ) ;
const permissionSwitchesForAdmin = ref ( < Record < ( typeof Misskey.permissions ) [ number ] , boolean > > { } ) ;
2020-07-18 05:12:10 +02:00
2022-09-05 11:34:59 +02:00
if ( props . initialPermissions ) {
for ( const kind of props . initialPermissions ) {
2024-01-09 13:18:09 +01:00
permissionSwitches . value [ kind ] = true ;
2022-09-05 11:34:59 +02:00
}
} else {
2023-12-27 07:08:59 +01:00
for ( const kind of defaultPermissions ) {
2024-01-09 13:18:09 +01:00
permissionSwitches . value [ kind ] = false ;
}
if ( iAmAdmin ) {
for ( const kind of adminPermissions ) {
permissionSwitchesForAdmin . value [ kind ] = false ;
}
2022-09-05 11:34:59 +02:00
}
}
2020-07-18 05:12:10 +02:00
2022-09-05 11:34:59 +02:00
function ok ( ) : void {
emit ( 'done' , {
2023-12-07 06:42:09 +01:00
name : name . value ,
2024-01-09 13:18:09 +01:00
permissions : [
... Object . keys ( permissionSwitches . value ) . filter ( p => permissionSwitches . value [ p ] ) ,
... ( iAmAdmin ? Object . keys ( permissionSwitchesForAdmin . value ) . filter ( p => permissionSwitchesForAdmin . value [ p ] ) : [ ] ) ,
] ,
2022-09-05 11:34:59 +02:00
} ) ;
2024-01-05 04:52:24 +01:00
dialog . value ? . close ( ) ;
2022-09-05 11:34:59 +02:00
}
2020-07-18 05:12:10 +02:00
2022-09-05 11:34:59 +02:00
function disableAll ( ) : void {
2024-01-09 13:18:09 +01:00
for ( const p in permissionSwitches . value ) {
permissionSwitches . value [ p ] = false ;
}
if ( iAmAdmin ) {
for ( const p in permissionSwitchesForAdmin . value ) {
permissionSwitchesForAdmin . value [ p ] = false ;
}
2022-09-05 11:34:59 +02:00
}
}
2020-07-18 05:12:10 +02:00
2022-09-05 11:34:59 +02:00
function enableAll ( ) : void {
2024-01-09 13:18:09 +01:00
for ( const p in permissionSwitches . value ) {
permissionSwitches . value [ p ] = true ;
}
if ( iAmAdmin ) {
for ( const p in permissionSwitchesForAdmin . value ) {
permissionSwitchesForAdmin . value [ p ] = true ;
}
2020-07-18 05:12:10 +02:00
}
2022-09-05 11:34:59 +02:00
}
2020-07-18 05:12:10 +02:00
< / script >
2024-01-09 13:18:09 +01:00
< style module lang = "scss" >
. adminPermissions {
margin : 8 px - 6 px 0 ;
padding : 24 px 6 px 6 px ;
border : 2 px solid var ( -- error ) ;
border - radius : calc ( var ( -- radius ) / 2 ) ;
}
. adminPermissionsHeader {
margin : - 34 px 0 6 px 12 px ;
padding : 0 4 px ;
width : fit - content ;
color : var ( -- error ) ;
background : var ( -- panel ) ;
}
< / style >