misskey/packages/frontend/src/pages/admin/roles.edit.vue

105 lines
2.5 KiB
Vue
Raw Normal View History

<!--
SPDX-FileCopyrightText: syuilo and other misskey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
<div>
<MkStickyContainer>
2023-03-02 11:47:24 +00:00
<template #header><XHeader :tabs="headerTabs"/></template>
2023-05-19 11:52:15 +00:00
<MkSpacer :contentMax="600" :marginMin="16" :marginMax="32">
2023-03-02 11:47:24 +00:00
<XEditor v-if="data" v-model="data"/>
</MkSpacer>
2023-03-02 11:47:24 +00:00
<template #footer>
<div :class="$style.footer">
2023-05-19 11:52:15 +00:00
<MkSpacer :contentMax="600" :marginMin="16" :marginMax="16">
2023-03-02 11:47:24 +00:00
<MkButton primary rounded @click="save"><i class="ti ti-check"></i> {{ i18n.ts.save }}</MkButton>
</MkSpacer>
</div>
</template>
</MkStickyContainer>
</div>
</template>
<script lang="ts" setup>
import { computed, ref } from 'vue';
import * as Misskey from 'misskey-js';
2023-03-02 11:47:24 +00:00
import { v4 as uuid } from 'uuid';
import XHeader from './_header_.vue';
import XEditor from './roles.editor.vue';
2023-09-19 07:37:43 +00:00
import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
2023-09-19 07:37:43 +00:00
import { i18n } from '@/i18n.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
2023-03-02 11:47:24 +00:00
import MkButton from '@/components/MkButton.vue';
import { rolesCache } from '@/cache.js';
import { useRouter } from '@/router/supplier.js';
const router = useRouter();
const props = defineProps<{
id?: string;
}>();
const role = ref<Misskey.entities.Role | null>(null);
const data = ref<any>(null);
if (props.id) {
role.value = await misskeyApi('admin/roles/show', {
roleId: props.id,
});
data.value = role.value;
2023-03-02 11:47:24 +00:00
} else {
data.value = {
2023-03-02 11:47:24 +00:00
name: 'New Role',
description: '',
isAdministrator: false,
isModerator: false,
2023-03-02 11:47:24 +00:00
color: null,
iconUrl: null,
target: 'manual',
condFormula: { id: uuid(), type: 'isRemote' },
isPublic: false,
isExplorable: false,
2023-03-02 11:47:24 +00:00
asBadge: false,
canEditMembersByModerator: false,
displayOrder: 0,
2023-03-02 11:47:24 +00:00
policies: {},
};
}
2023-03-02 11:47:24 +00:00
async function save() {
rolesCache.delete();
if (role.value) {
2023-03-02 11:47:24 +00:00
os.apiWithDialog('admin/roles/update', {
roleId: role.value.id,
...data.value,
2023-03-02 11:47:24 +00:00
});
router.push('/admin/roles/' + role.value.id);
2023-03-02 11:47:24 +00:00
} else {
const created = await os.apiWithDialog('admin/roles/create', {
...data.value,
2023-03-02 11:47:24 +00:00
});
router.push('/admin/roles/' + created.id);
}
}
const headerTabs = computed(() => []);
definePageMetadata(computed(() => role.value ? {
title: i18n.ts._role.edit + ': ' + role.value.name,
icon: 'ti ti-badge',
} : {
title: i18n.ts._role.new,
icon: 'ti ti-badge',
}));
</script>
<style lang="scss" module>
2023-03-02 11:47:24 +00:00
.footer {
-webkit-backdrop-filter: var(--blur, blur(15px));
backdrop-filter: var(--blur, blur(15px));
}
</style>