enhance(frontend): improve forms usability

This commit is contained in:
syuilo 2024-09-23 14:42:38 +09:00
parent 2c615357f2
commit 1ba09e1eee
8 changed files with 530 additions and 464 deletions

12
locales/index.d.ts vendored
View File

@ -5096,6 +5096,18 @@ export interface Locale extends ILocale {
* *
*/ */
"performance": string; "performance": string;
/**
*
*/
"modified": string;
/**
*
*/
"discard": string;
/**
* {n}
*/
"thereAreNChanges": ParameterizedString<"n">;
"_delivery": { "_delivery": {
/** /**
* *

View File

@ -1270,6 +1270,9 @@ genEmbedCode: "埋め込みコードを生成"
noteOfThisUser: "このユーザーのノート一覧" noteOfThisUser: "このユーザーのノート一覧"
clipNoteLimitExceeded: "これ以上このクリップにノートを追加できません。" clipNoteLimitExceeded: "これ以上このクリップにノートを追加できません。"
performance: "パフォーマンス" performance: "パフォーマンス"
modified: "変更あり"
discard: "破棄"
thereAreNChanges: "{n}件の変更があります"
_delivery: _delivery:
status: "配信状態" status: "配信状態"

View File

@ -237,6 +237,8 @@ onMounted(() => {
background: var(--acrylicBg); background: var(--acrylicBg);
-webkit-backdrop-filter: var(--blur, blur(15px)); -webkit-backdrop-filter: var(--blur, blur(15px));
backdrop-filter: var(--blur, blur(15px)); backdrop-filter: var(--blur, blur(15px));
background-size: auto auto;
background-image: repeating-linear-gradient(135deg, transparent, transparent 5px, var(--panel) 5px, var(--panel) 10px);
border-radius: 0 0 6px 6px; border-radius: 0 0 6px 6px;
} }
</style> </style>

View File

@ -0,0 +1,49 @@
<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
<div :class="$style.root">
<div :class="$style.text">{{ i18n.tsx.thereAreNChanges({ n: form.modifiedCount.value }) }}</div>
<div style="margin-left: auto;" class="_buttons">
<MkButton danger rounded @click="form.discard"><i class="ti ti-x"></i> {{ i18n.ts.discard }}</MkButton>
<MkButton primary rounded @click="form.save"><i class="ti ti-check"></i> {{ i18n.ts.save }}</MkButton>
</div>
</div>
</template>
<script lang="ts" setup>
import { } from 'vue';
import MkButton from './MkButton.vue';
import { i18n } from '@/i18n.js';
const props = defineProps<{
form: {
modifiedCount: {
value: number;
};
discard: () => void;
save: () => void;
};
}>();
</script>
<style lang="scss" module>
.root {
display: flex;
align-items: center;
}
.text {
color: var(--warn);
font-size: 90%;
animation: modified-blink 2s infinite;
}
@keyframes modified-blink {
0% { opacity: 1; }
50% { opacity: 0.5; }
100% { opacity: 1; }
}
</style>

View File

@ -7,7 +7,6 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkStickyContainer> <MkStickyContainer>
<template #header><XHeader :actions="headerActions" :tabs="headerTabs"/></template> <template #header><XHeader :actions="headerActions" :tabs="headerTabs"/></template>
<MkSpacer :contentMax="700" :marginMin="16" :marginMax="32"> <MkSpacer :contentMax="700" :marginMin="16" :marginMax="32">
<FormSuspense :p="init">
<div class="_gaps"> <div class="_gaps">
<div class="_panel" style="padding: 16px;"> <div class="_panel" style="padding: 16px;">
<MkSwitch v-model="enableServerMachineStats" @change="onChange_enableServerMachineStats"> <MkSwitch v-model="enableServerMachineStats" @change="onChange_enableServerMachineStats">
@ -40,40 +39,40 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkFolder :defaultOpen="true"> <MkFolder :defaultOpen="true">
<template #icon><i class="ti ti-bolt"></i></template> <template #icon><i class="ti ti-bolt"></i></template>
<template #label>Misskey® Fan-out Timeline Technology (FTT)</template> <template #label>Misskey® Fan-out Timeline Technology (FTT)</template>
<template v-if="enableFanoutTimeline" #suffix>Enabled</template> <template v-if="fttForm.savedState.enableFanoutTimeline" #suffix>Enabled</template>
<template v-else #suffix>Disabled</template> <template v-else #suffix>Disabled</template>
<template v-if="isFttModified" #footer> <template v-if="fttForm.modified.value" #footer>
<MkButton primary rounded @click="saveFtt">{{ i18n.ts.save }}</MkButton> <MkFormFooter :form="fttForm"/>
</template> </template>
<div class="_gaps_m"> <div class="_gaps_m">
<MkSwitch v-model="enableFanoutTimeline"> <MkSwitch v-model="fttForm.state.enableFanoutTimeline">
<template #label>{{ i18n.ts.enable }}</template> <template #label>{{ i18n.ts.enable }}<span v-if="fttForm.modifiedStates.enableFanoutTimeline" class="_modified">{{ i18n.ts.modified }}</span></template>
<template #caption> <template #caption>
<div>{{ i18n.ts._serverSettings.fanoutTimelineDescription }}</div> <div>{{ i18n.ts._serverSettings.fanoutTimelineDescription }}</div>
<div><MkLink target="_blank" url="https://misskey-hub.net/docs/for-admin/features/ftt/">{{ i18n.ts.details }}</MkLink></div> <div><MkLink target="_blank" url="https://misskey-hub.net/docs/for-admin/features/ftt/">{{ i18n.ts.details }}</MkLink></div>
</template> </template>
</MkSwitch> </MkSwitch>
<MkSwitch v-model="enableFanoutTimelineDbFallback"> <MkSwitch v-model="fttForm.state.enableFanoutTimelineDbFallback">
<template #label>{{ i18n.ts._serverSettings.fanoutTimelineDbFallback }}</template> <template #label>{{ i18n.ts._serverSettings.fanoutTimelineDbFallback }}<span v-if="fttForm.modifiedStates.enableFanoutTimelineDbFallback" class="_modified">{{ i18n.ts.modified }}</span></template>
<template #caption>{{ i18n.ts._serverSettings.fanoutTimelineDbFallbackDescription }}</template> <template #caption>{{ i18n.ts._serverSettings.fanoutTimelineDbFallbackDescription }}</template>
</MkSwitch> </MkSwitch>
<MkInput v-model="perLocalUserUserTimelineCacheMax" type="number"> <MkInput v-model="fttForm.state.perLocalUserUserTimelineCacheMax" type="number">
<template #label>perLocalUserUserTimelineCacheMax</template> <template #label>perLocalUserUserTimelineCacheMax<span v-if="fttForm.modifiedStates.perLocalUserUserTimelineCacheMax" class="_modified">{{ i18n.ts.modified }}</span></template>
</MkInput> </MkInput>
<MkInput v-model="perRemoteUserUserTimelineCacheMax" type="number"> <MkInput v-model="fttForm.state.perRemoteUserUserTimelineCacheMax" type="number">
<template #label>perRemoteUserUserTimelineCacheMax</template> <template #label>perRemoteUserUserTimelineCacheMax<span v-if="fttForm.modifiedStates.perRemoteUserUserTimelineCacheMax" class="_modified">{{ i18n.ts.modified }}</span></template>
</MkInput> </MkInput>
<MkInput v-model="perUserHomeTimelineCacheMax" type="number"> <MkInput v-model="fttForm.state.perUserHomeTimelineCacheMax" type="number">
<template #label>perUserHomeTimelineCacheMax</template> <template #label>perUserHomeTimelineCacheMax<span v-if="fttForm.modifiedStates.perUserHomeTimelineCacheMax" class="_modified">{{ i18n.ts.modified }}</span></template>
</MkInput> </MkInput>
<MkInput v-model="perUserListTimelineCacheMax" type="number"> <MkInput v-model="fttForm.state.perUserListTimelineCacheMax" type="number">
<template #label>perUserListTimelineCacheMax</template> <template #label>perUserListTimelineCacheMax<span v-if="fttForm.modifiedStates.perUserListTimelineCacheMax" class="_modified">{{ i18n.ts.modified }}</span></template>
</MkInput> </MkInput>
</div> </div>
</MkFolder> </MkFolder>
@ -81,29 +80,27 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkFolder :defaultOpen="true"> <MkFolder :defaultOpen="true">
<template #icon><i class="ti ti-bolt"></i></template> <template #icon><i class="ti ti-bolt"></i></template>
<template #label>Misskey® Reactions Boost Technology (RBT)<span class="_beta">{{ i18n.ts.beta }}</span></template> <template #label>Misskey® Reactions Boost Technology (RBT)<span class="_beta">{{ i18n.ts.beta }}</span></template>
<template v-if="enableReactionsBuffering" #suffix>Enabled</template> <template v-if="rbtForm.savedState.enableReactionsBuffering" #suffix>Enabled</template>
<template v-else #suffix>Disabled</template> <template v-else #suffix>Disabled</template>
<template v-if="isRbtModified" #footer> <template v-if="rbtForm.modified.value" #footer>
<MkButton primary rounded @click="saveRbt">{{ i18n.ts.save }}</MkButton> <MkFormFooter :form="rbtForm"/>
</template> </template>
<div class="_gaps_m"> <div class="_gaps_m">
<MkSwitch v-model="enableReactionsBuffering"> <MkSwitch v-model="rbtForm.state.enableReactionsBuffering">
<template #label>{{ i18n.ts.enable }}</template> <template #label>{{ i18n.ts.enable }}<span v-if="rbtForm.modifiedStates.enableReactionsBuffering" class="_modified">{{ i18n.ts.modified }}</span></template>
<template #caption>{{ i18n.ts._serverSettings.reactionsBufferingDescription }}</template> <template #caption>{{ i18n.ts._serverSettings.reactionsBufferingDescription }}</template>
</MkSwitch> </MkSwitch>
</div> </div>
</MkFolder> </MkFolder>
</div> </div>
</FormSuspense>
</MkSpacer> </MkSpacer>
</MkStickyContainer> </MkStickyContainer>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, computed, watch } from 'vue'; import { ref, computed } from 'vue';
import XHeader from './_header_.vue'; import XHeader from './_header_.vue';
import FormSuspense from '@/components/form/suspense.vue';
import * as os from '@/os.js'; import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js'; import { misskeyApi } from '@/scripts/misskey-api.js';
import { fetchInstance } from '@/instance.js'; import { fetchInstance } from '@/instance.js';
@ -114,45 +111,15 @@ import MkFolder from '@/components/MkFolder.vue';
import MkInput from '@/components/MkInput.vue'; import MkInput from '@/components/MkInput.vue';
import MkLink from '@/components/MkLink.vue'; import MkLink from '@/components/MkLink.vue';
import MkButton from '@/components/MkButton.vue'; import MkButton from '@/components/MkButton.vue';
import { useForm } from '@/scripts/use-form.js';
import MkFormFooter from '@/components/MkFormFooter.vue';
const enableServerMachineStats = ref<boolean>(false);
const enableIdenticonGeneration = ref<boolean>(false);
const enableChartsForRemoteUser = ref<boolean>(false);
const enableChartsForFederatedInstances = ref<boolean>(false);
const enableFanoutTimeline = ref<boolean>(false);
const enableFanoutTimelineDbFallback = ref<boolean>(false);
const perLocalUserUserTimelineCacheMax = ref<number>(0);
const perRemoteUserUserTimelineCacheMax = ref<number>(0);
const perUserHomeTimelineCacheMax = ref<number>(0);
const perUserListTimelineCacheMax = ref<number>(0);
const enableReactionsBuffering = ref<boolean>(false);
const isFttModified = ref<boolean>(false);
const isRbtModified = ref<boolean>(false);
async function init() {
const meta = await misskeyApi('admin/meta'); const meta = await misskeyApi('admin/meta');
enableServerMachineStats.value = meta.enableServerMachineStats;
enableIdenticonGeneration.value = meta.enableIdenticonGeneration;
enableChartsForRemoteUser.value = meta.enableChartsForRemoteUser;
enableChartsForFederatedInstances.value = meta.enableChartsForFederatedInstances;
enableFanoutTimeline.value = meta.enableFanoutTimeline;
enableFanoutTimelineDbFallback.value = meta.enableFanoutTimelineDbFallback;
perLocalUserUserTimelineCacheMax.value = meta.perLocalUserUserTimelineCacheMax;
perRemoteUserUserTimelineCacheMax.value = meta.perRemoteUserUserTimelineCacheMax;
perUserHomeTimelineCacheMax.value = meta.perUserHomeTimelineCacheMax;
perUserListTimelineCacheMax.value = meta.perUserListTimelineCacheMax;
enableReactionsBuffering.value = meta.enableReactionsBuffering;
watch([enableFanoutTimeline, enableFanoutTimelineDbFallback, perLocalUserUserTimelineCacheMax, perRemoteUserUserTimelineCacheMax, perUserHomeTimelineCacheMax, perUserListTimelineCacheMax], () => { const enableServerMachineStats = ref(meta.enableServerMachineStats);
isFttModified.value = true; const enableIdenticonGeneration = ref(meta.enableIdenticonGeneration);
}); const enableChartsForRemoteUser = ref(meta.enableChartsForRemoteUser);
const enableChartsForFederatedInstances = ref(meta.enableChartsForFederatedInstances);
watch(enableReactionsBuffering, () => {
isRbtModified.value = true;
});
}
function onChange_enableServerMachineStats(value: boolean) { function onChange_enableServerMachineStats(value: boolean) {
os.apiWithDialog('admin/update-meta', { os.apiWithDialog('admin/update-meta', {
@ -186,28 +153,33 @@ function onChange_enableChartsForFederatedInstances(value: boolean) {
}); });
} }
function saveFtt() { const fttForm = useForm({
os.apiWithDialog('admin/update-meta', { enableFanoutTimeline: meta.enableFanoutTimeline,
enableFanoutTimeline: enableFanoutTimeline.value, enableFanoutTimelineDbFallback: meta.enableFanoutTimelineDbFallback,
enableFanoutTimelineDbFallback: enableFanoutTimelineDbFallback.value, perLocalUserUserTimelineCacheMax: meta.perLocalUserUserTimelineCacheMax,
perLocalUserUserTimelineCacheMax: perLocalUserUserTimelineCacheMax.value, perRemoteUserUserTimelineCacheMax: meta.perRemoteUserUserTimelineCacheMax,
perRemoteUserUserTimelineCacheMax: perRemoteUserUserTimelineCacheMax.value, perUserHomeTimelineCacheMax: meta.perUserHomeTimelineCacheMax,
perUserHomeTimelineCacheMax: perUserHomeTimelineCacheMax.value, perUserListTimelineCacheMax: meta.perUserListTimelineCacheMax,
perUserListTimelineCacheMax: perUserListTimelineCacheMax.value, }, async (state) => {
}).then(() => { await os.apiWithDialog('admin/update-meta', {
isFttModified.value = false; enableFanoutTimeline: state.enableFanoutTimeline,
enableFanoutTimelineDbFallback: state.enableFanoutTimelineDbFallback,
perLocalUserUserTimelineCacheMax: state.perLocalUserUserTimelineCacheMax,
perRemoteUserUserTimelineCacheMax: state.perRemoteUserUserTimelineCacheMax,
perUserHomeTimelineCacheMax: state.perUserHomeTimelineCacheMax,
perUserListTimelineCacheMax: state.perUserListTimelineCacheMax,
});
fetchInstance(true); fetchInstance(true);
}); });
}
function saveRbt() { const rbtForm = useForm({
os.apiWithDialog('admin/update-meta', { enableReactionsBuffering: meta.enableReactionsBuffering,
enableReactionsBuffering: enableReactionsBuffering.value, }, async (state) => {
}).then(() => { await os.apiWithDialog('admin/update-meta', {
isRbtModified.value = false; enableReactionsBuffering: state.enableReactionsBuffering,
});
fetchInstance(true); fetchInstance(true);
}); });
}
const headerActions = computed(() => []); const headerActions = computed(() => []);

View File

@ -8,70 +8,69 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkStickyContainer> <MkStickyContainer>
<template #header><XHeader :tabs="headerTabs"/></template> <template #header><XHeader :tabs="headerTabs"/></template>
<MkSpacer :contentMax="700" :marginMin="16" :marginMax="32"> <MkSpacer :contentMax="700" :marginMin="16" :marginMax="32">
<FormSuspense :p="init">
<div class="_gaps_m"> <div class="_gaps_m">
<MkFolder :defaultOpen="true"> <MkFolder :defaultOpen="true">
<template #icon><i class="ti ti-info-circle"></i></template> <template #icon><i class="ti ti-info-circle"></i></template>
<template #label>{{ i18n.ts.info }}</template> <template #label>{{ i18n.ts.info }}</template>
<template #footer> <template v-if="infoForm.modified.value" #footer>
<MkButton primary rounded @click="saveInfo">{{ i18n.ts.save }}</MkButton> <MkFormFooter :form="infoForm"/>
</template> </template>
<div class="_gaps"> <div class="_gaps">
<MkInput v-model="name"> <MkInput v-model="infoForm.state.name">
<template #label>{{ i18n.ts.instanceName }}</template> <template #label>{{ i18n.ts.instanceName }}<span v-if="infoForm.modifiedStates.name" class="_modified">{{ i18n.ts.modified }}</span></template>
</MkInput> </MkInput>
<MkInput v-model="shortName"> <MkInput v-model="infoForm.state.shortName">
<template #label>{{ i18n.ts._serverSettings.shortName }} ({{ i18n.ts.optional }})</template> <template #label>{{ i18n.ts._serverSettings.shortName }} ({{ i18n.ts.optional }})<span v-if="infoForm.modifiedStates.shortName" class="_modified">{{ i18n.ts.modified }}</span></template>
<template #caption>{{ i18n.ts._serverSettings.shortNameDescription }}</template> <template #caption>{{ i18n.ts._serverSettings.shortNameDescription }}</template>
</MkInput> </MkInput>
<MkTextarea v-model="description"> <MkTextarea v-model="infoForm.state.description">
<template #label>{{ i18n.ts.instanceDescription }}</template> <template #label>{{ i18n.ts.instanceDescription }}<span v-if="infoForm.modifiedStates.description" class="_modified">{{ i18n.ts.modified }}</span></template>
</MkTextarea> </MkTextarea>
<FormSplit :minWidth="300"> <FormSplit :minWidth="300">
<MkInput v-model="maintainerName"> <MkInput v-model="infoForm.state.maintainerName">
<template #label>{{ i18n.ts.maintainerName }}</template> <template #label>{{ i18n.ts.maintainerName }}<span v-if="infoForm.modifiedStates.maintainerName" class="_modified">{{ i18n.ts.modified }}</span></template>
</MkInput> </MkInput>
<MkInput v-model="maintainerEmail" type="email"> <MkInput v-model="infoForm.state.maintainerEmail" type="email">
<template #label>{{ i18n.ts.maintainerEmail }}<span v-if="infoForm.modifiedStates.maintainerEmail" class="_modified">{{ i18n.ts.modified }}</span></template>
<template #prefix><i class="ti ti-mail"></i></template> <template #prefix><i class="ti ti-mail"></i></template>
<template #label>{{ i18n.ts.maintainerEmail }}</template>
</MkInput> </MkInput>
</FormSplit> </FormSplit>
<MkInput v-model="tosUrl" type="url"> <MkInput v-model="infoForm.state.tosUrl" type="url">
<template #label>{{ i18n.ts.tosUrl }}<span v-if="infoForm.modifiedStates.tosUrl" class="_modified">{{ i18n.ts.modified }}</span></template>
<template #prefix><i class="ti ti-link"></i></template> <template #prefix><i class="ti ti-link"></i></template>
<template #label>{{ i18n.ts.tosUrl }}</template>
</MkInput> </MkInput>
<MkInput v-model="privacyPolicyUrl" type="url"> <MkInput v-model="infoForm.state.privacyPolicyUrl" type="url">
<template #label>{{ i18n.ts.privacyPolicyUrl }}<span v-if="infoForm.modifiedStates.privacyPolicyUrl" class="_modified">{{ i18n.ts.modified }}</span></template>
<template #prefix><i class="ti ti-link"></i></template> <template #prefix><i class="ti ti-link"></i></template>
<template #label>{{ i18n.ts.privacyPolicyUrl }}</template>
</MkInput> </MkInput>
<MkInput v-model="inquiryUrl" type="url"> <MkInput v-model="infoForm.state.inquiryUrl" type="url">
<template #prefix><i class="ti ti-link"></i></template> <template #label>{{ i18n.ts._serverSettings.inquiryUrl }}<span v-if="infoForm.modifiedStates.inquiryUrl" class="_modified">{{ i18n.ts.modified }}</span></template>
<template #label>{{ i18n.ts._serverSettings.inquiryUrl }}</template>
<template #caption>{{ i18n.ts._serverSettings.inquiryUrlDescription }}</template> <template #caption>{{ i18n.ts._serverSettings.inquiryUrlDescription }}</template>
</MkInput>
<MkInput v-model="repositoryUrl" type="url">
<template #label>{{ i18n.ts.repositoryUrl }}</template>
<template #prefix><i class="ti ti-link"></i></template> <template #prefix><i class="ti ti-link"></i></template>
<template #caption>{{ i18n.ts.repositoryUrlDescription }}</template>
</MkInput> </MkInput>
<MkInfo v-if="!instance.providesTarball && !repositoryUrl" warn> <MkInput v-model="infoForm.state.repositoryUrl" type="url">
<template #label>{{ i18n.ts.repositoryUrl }}<span v-if="infoForm.modifiedStates.repositoryUrl" class="_modified">{{ i18n.ts.modified }}</span></template>
<template #caption>{{ i18n.ts.repositoryUrlDescription }}</template>
<template #prefix><i class="ti ti-link"></i></template>
</MkInput>
<MkInfo v-if="!instance.providesTarball && !infoForm.state.repositoryUrl" warn>
{{ i18n.ts.repositoryUrlOrTarballRequired }} {{ i18n.ts.repositoryUrlOrTarballRequired }}
</MkInfo> </MkInfo>
<MkInput v-model="impressumUrl" type="url"> <MkInput v-model="infoForm.state.impressumUrl" type="url">
<template #label>{{ i18n.ts.impressumUrl }}</template> <template #label>{{ i18n.ts.impressumUrl }}<span v-if="infoForm.modifiedStates.impressumUrl" class="_modified">{{ i18n.ts.modified }}</span></template>
<template #prefix><i class="ti ti-link"></i></template>
<template #caption>{{ i18n.ts.impressumDescription }}</template> <template #caption>{{ i18n.ts.impressumDescription }}</template>
<template #prefix><i class="ti ti-link"></i></template>
</MkInput> </MkInput>
</div> </div>
</MkFolder> </MkFolder>
@ -79,12 +78,12 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkFolder> <MkFolder>
<template #icon><i class="ti ti-user-star"></i></template> <template #icon><i class="ti ti-user-star"></i></template>
<template #label>{{ i18n.ts.pinnedUsers }}</template> <template #label>{{ i18n.ts.pinnedUsers }}</template>
<template #footer> <template v-if="pinnedUsersForm.modified.value" #footer>
<MkButton primary rounded @click="save_pinnedUsers">{{ i18n.ts.save }}</MkButton> <MkFormFooter :form="pinnedUsersForm"/>
</template> </template>
<MkTextarea v-model="pinnedUsers"> <MkTextarea v-model="pinnedUsersForm.state.pinnedUsers">
<template #label>{{ i18n.ts.pinnedUsers }}</template> <template #label>{{ i18n.ts.pinnedUsers }}<span v-if="pinnedUsersForm.modifiedStates.pinnedUsers" class="_modified">{{ i18n.ts.modified }}</span></template>
<template #caption>{{ i18n.ts.pinnedUsersDescription }}</template> <template #caption>{{ i18n.ts.pinnedUsersDescription }}</template>
</MkTextarea> </MkTextarea>
</MkFolder> </MkFolder>
@ -92,19 +91,19 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkFolder> <MkFolder>
<template #icon><i class="ti ti-cloud"></i></template> <template #icon><i class="ti ti-cloud"></i></template>
<template #label>{{ i18n.ts.files }}</template> <template #label>{{ i18n.ts.files }}</template>
<template #footer> <template v-if="filesForm.modified.value" #footer>
<MkButton primary rounded @click="saveFiles">{{ i18n.ts.save }}</MkButton> <MkFormFooter :form="filesForm"/>
</template> </template>
<div class="_gaps"> <div class="_gaps">
<MkSwitch v-model="cacheRemoteFiles"> <MkSwitch v-model="filesForm.state.cacheRemoteFiles">
<template #label>{{ i18n.ts.cacheRemoteFiles }}</template> <template #label>{{ i18n.ts.cacheRemoteFiles }}<span v-if="filesForm.modifiedStates.cacheRemoteFiles" class="_modified">{{ i18n.ts.modified }}</span></template>
<template #caption>{{ i18n.ts.cacheRemoteFilesDescription }}{{ i18n.ts.youCanCleanRemoteFilesCache }}</template> <template #caption>{{ i18n.ts.cacheRemoteFilesDescription }}{{ i18n.ts.youCanCleanRemoteFilesCache }}</template>
</MkSwitch> </MkSwitch>
<template v-if="cacheRemoteFiles"> <template v-if="filesForm.state.cacheRemoteFiles">
<MkSwitch v-model="cacheRemoteSensitiveFiles"> <MkSwitch v-model="filesForm.state.cacheRemoteSensitiveFiles">
<template #label>{{ i18n.ts.cacheRemoteSensitiveFiles }}</template> <template #label>{{ i18n.ts.cacheRemoteSensitiveFiles }}<span v-if="filesForm.modifiedStates.cacheRemoteSensitiveFiles" class="_modified">{{ i18n.ts.modified }}</span></template>
<template #caption>{{ i18n.ts.cacheRemoteSensitiveFilesDescription }}</template> <template #caption>{{ i18n.ts.cacheRemoteSensitiveFilesDescription }}</template>
</MkSwitch> </MkSwitch>
</template> </template>
@ -114,25 +113,25 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkFolder> <MkFolder>
<template #icon><i class="ti ti-world-cog"></i></template> <template #icon><i class="ti ti-world-cog"></i></template>
<template #label>ServiceWorker</template> <template #label>ServiceWorker</template>
<template #footer> <template v-if="serviceWorkerForm.modified.value" #footer>
<MkButton primary rounded @click="saveServiceWorker">{{ i18n.ts.save }}</MkButton> <MkFormFooter :form="serviceWorkerForm"/>
</template> </template>
<div class="_gaps"> <div class="_gaps">
<MkSwitch v-model="enableServiceWorker"> <MkSwitch v-model="serviceWorkerForm.state.enableServiceWorker">
<template #label>{{ i18n.ts.enableServiceworker }}</template> <template #label>{{ i18n.ts.enableServiceworker }}<span v-if="serviceWorkerForm.modifiedStates.enableServiceWorker" class="_modified">{{ i18n.ts.modified }}</span></template>
<template #caption>{{ i18n.ts.serviceworkerInfo }}</template> <template #caption>{{ i18n.ts.serviceworkerInfo }}</template>
</MkSwitch> </MkSwitch>
<template v-if="enableServiceWorker"> <template v-if="serviceWorkerForm.state.enableServiceWorker">
<MkInput v-model="swPublicKey"> <MkInput v-model="serviceWorkerForm.state.swPublicKey">
<template #label>Public key<span v-if="serviceWorkerForm.modifiedStates.swPublicKey" class="_modified">{{ i18n.ts.modified }}</span></template>
<template #prefix><i class="ti ti-key"></i></template> <template #prefix><i class="ti ti-key"></i></template>
<template #label>Public key</template>
</MkInput> </MkInput>
<MkInput v-model="swPrivateKey"> <MkInput v-model="serviceWorkerForm.state.swPrivateKey">
<template #label>Private key<span v-if="serviceWorkerForm.modifiedStates.swPrivateKey" class="_modified">{{ i18n.ts.modified }}</span></template>
<template #prefix><i class="ti ti-key"></i></template> <template #prefix><i class="ti ti-key"></i></template>
<template #label>Private key</template>
</MkInput> </MkInput>
</template> </template>
</div> </div>
@ -141,17 +140,17 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkFolder> <MkFolder>
<template #icon><i class="ti ti-ad"></i></template> <template #icon><i class="ti ti-ad"></i></template>
<template #label>{{ i18n.ts._ad.adsSettings }}</template> <template #label>{{ i18n.ts._ad.adsSettings }}</template>
<template #footer> <template v-if="adForm.modified.value" #footer>
<MkButton primary rounded @click="saveAd">{{ i18n.ts.save }}</MkButton> <MkFormFooter :form="adForm"/>
</template> </template>
<div class="_gaps"> <div class="_gaps">
<div class="_gaps_s"> <div class="_gaps_s">
<MkInput v-model="notesPerOneAd" :min="0" type="number"> <MkInput v-model="adForm.state.notesPerOneAd" :min="0" type="number">
<template #label>{{ i18n.ts._ad.notesPerOneAd }}</template> <template #label>{{ i18n.ts._ad.notesPerOneAd }}<span v-if="adForm.modifiedStates.notesPerOneAd" class="_modified">{{ i18n.ts.modified }}</span></template>
<template #caption>{{ i18n.ts._ad.setZeroToDisable }}</template> <template #caption>{{ i18n.ts._ad.setZeroToDisable }}</template>
</MkInput> </MkInput>
<MkInfo v-if="notesPerOneAd > 0 && notesPerOneAd < 20" :warn="true"> <MkInfo v-if="adForm.state.notesPerOneAd > 0 && adForm.state.notesPerOneAd < 20" :warn="true">
{{ i18n.ts._ad.adsTooClose }} {{ i18n.ts._ad.adsTooClose }}
</MkInfo> </MkInfo>
</div> </div>
@ -161,38 +160,38 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkFolder> <MkFolder>
<template #icon><i class="ti ti-world-search"></i></template> <template #icon><i class="ti ti-world-search"></i></template>
<template #label>{{ i18n.ts._urlPreviewSetting.title }}</template> <template #label>{{ i18n.ts._urlPreviewSetting.title }}</template>
<template #footer> <template v-if="urlPreviewForm.modified.value" #footer>
<MkButton primary rounded @click="saveUrlPreview">{{ i18n.ts.save }}</MkButton> <MkFormFooter :form="urlPreviewForm"/>
</template> </template>
<div class="_gaps"> <div class="_gaps">
<MkSwitch v-model="urlPreviewEnabled"> <MkSwitch v-model="urlPreviewForm.state.urlPreviewEnabled">
<template #label>{{ i18n.ts._urlPreviewSetting.enable }}</template> <template #label>{{ i18n.ts._urlPreviewSetting.enable }}<span v-if="urlPreviewForm.modifiedStates.urlPreviewEnabled" class="_modified">{{ i18n.ts.modified }}</span></template>
</MkSwitch> </MkSwitch>
<MkSwitch v-model="urlPreviewRequireContentLength"> <MkSwitch v-model="urlPreviewForm.state.urlPreviewRequireContentLength">
<template #label>{{ i18n.ts._urlPreviewSetting.requireContentLength }}</template> <template #label>{{ i18n.ts._urlPreviewSetting.requireContentLength }}<span v-if="urlPreviewForm.modifiedStates.urlPreviewRequireContentLength" class="_modified">{{ i18n.ts.modified }}</span></template>
<template #caption>{{ i18n.ts._urlPreviewSetting.requireContentLengthDescription }}</template> <template #caption>{{ i18n.ts._urlPreviewSetting.requireContentLengthDescription }}</template>
</MkSwitch> </MkSwitch>
<MkInput v-model="urlPreviewMaximumContentLength" type="number"> <MkInput v-model="urlPreviewForm.state.urlPreviewMaximumContentLength" type="number">
<template #label>{{ i18n.ts._urlPreviewSetting.maximumContentLength }}</template> <template #label>{{ i18n.ts._urlPreviewSetting.maximumContentLength }}<span v-if="urlPreviewForm.modifiedStates.urlPreviewMaximumContentLength" class="_modified">{{ i18n.ts.modified }}</span></template>
<template #caption>{{ i18n.ts._urlPreviewSetting.maximumContentLengthDescription }}</template> <template #caption>{{ i18n.ts._urlPreviewSetting.maximumContentLengthDescription }}</template>
</MkInput> </MkInput>
<MkInput v-model="urlPreviewTimeout" type="number"> <MkInput v-model="urlPreviewForm.state.urlPreviewTimeout" type="number">
<template #label>{{ i18n.ts._urlPreviewSetting.timeout }}</template> <template #label>{{ i18n.ts._urlPreviewSetting.timeout }}<span v-if="urlPreviewForm.modifiedStates.urlPreviewTimeout" class="_modified">{{ i18n.ts.modified }}</span></template>
<template #caption>{{ i18n.ts._urlPreviewSetting.timeoutDescription }}</template> <template #caption>{{ i18n.ts._urlPreviewSetting.timeoutDescription }}</template>
</MkInput> </MkInput>
<MkInput v-model="urlPreviewUserAgent" type="text"> <MkInput v-model="urlPreviewForm.state.urlPreviewUserAgent" type="text">
<template #label>{{ i18n.ts._urlPreviewSetting.userAgent }}</template> <template #label>{{ i18n.ts._urlPreviewSetting.userAgent }}<span v-if="urlPreviewForm.modifiedStates.urlPreviewUserAgent" class="_modified">{{ i18n.ts.modified }}</span></template>
<template #caption>{{ i18n.ts._urlPreviewSetting.userAgentDescription }}</template> <template #caption>{{ i18n.ts._urlPreviewSetting.userAgentDescription }}</template>
</MkInput> </MkInput>
<div> <div>
<MkInput v-model="urlPreviewSummaryProxyUrl" type="text"> <MkInput v-model="urlPreviewForm.state.urlPreviewSummaryProxyUrl" type="text">
<template #label>{{ i18n.ts._urlPreviewSetting.summaryProxy }}</template> <template #label>{{ i18n.ts._urlPreviewSetting.summaryProxy }}<span v-if="urlPreviewForm.modifiedStates.urlPreviewSummaryProxyUrl" class="_modified">{{ i18n.ts.modified }}</span></template>
<template #caption>[{{ i18n.ts.notUsePleaseLeaveBlank }}] {{ i18n.ts._urlPreviewSetting.summaryProxyDescription }}</template> <template #caption>[{{ i18n.ts.notUsePleaseLeaveBlank }}] {{ i18n.ts._urlPreviewSetting.summaryProxyDescription }}</template>
</MkInput> </MkInput>
@ -224,7 +223,6 @@ SPDX-License-Identifier: AGPL-3.0-only
</div> </div>
</MkFolder> </MkFolder>
</div> </div>
</FormSuspense>
</MkSpacer> </MkSpacer>
</MkStickyContainer> </MkStickyContainer>
</div> </div>
@ -239,7 +237,6 @@ import MkInput from '@/components/MkInput.vue';
import MkTextarea from '@/components/MkTextarea.vue'; import MkTextarea from '@/components/MkTextarea.vue';
import MkInfo from '@/components/MkInfo.vue'; import MkInfo from '@/components/MkInfo.vue';
import FormSplit from '@/components/form/split.vue'; import FormSplit from '@/components/form/split.vue';
import FormSuspense from '@/components/form/suspense.vue';
import * as os from '@/os.js'; import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js'; import { misskeyApi } from '@/scripts/misskey-api.js';
import { fetchInstance, instance } from '@/instance.js'; import { fetchInstance, instance } from '@/instance.js';
@ -249,144 +246,110 @@ import MkButton from '@/components/MkButton.vue';
import MkFolder from '@/components/MkFolder.vue'; import MkFolder from '@/components/MkFolder.vue';
import MkSelect from '@/components/MkSelect.vue'; import MkSelect from '@/components/MkSelect.vue';
import MkKeyValue from '@/components/MkKeyValue.vue'; import MkKeyValue from '@/components/MkKeyValue.vue';
import { useForm } from '@/scripts/use-form.js';
import MkFormFooter from '@/components/MkFormFooter.vue';
const proxyAccount = ref<Misskey.entities.UserDetailed | null>(null);
const name = ref<string | null>(null);
const shortName = ref<string | null>(null);
const description = ref<string | null>(null);
const maintainerName = ref<string | null>(null);
const maintainerEmail = ref<string | null>(null);
const tosUrl = ref<string | null>(null);
const privacyPolicyUrl = ref<string | null>(null);
const inquiryUrl = ref<string | null>(null);
const repositoryUrl = ref<string | null>(null);
const impressumUrl = ref<string | null>(null);
const pinnedUsers = ref<string>('');
const cacheRemoteFiles = ref<boolean>(false);
const cacheRemoteSensitiveFiles = ref<boolean>(false);
const enableServiceWorker = ref<boolean>(false);
const swPublicKey = ref<string | null>(null);
const swPrivateKey = ref<string | null>(null);
const notesPerOneAd = ref<number>(0);
const urlPreviewEnabled = ref<boolean>(true);
const urlPreviewTimeout = ref<number>(10000);
const urlPreviewMaximumContentLength = ref<number>(1024 * 1024 * 10);
const urlPreviewRequireContentLength = ref<boolean>(true);
const urlPreviewUserAgent = ref<string | null>(null);
const urlPreviewSummaryProxyUrl = ref<string | null>(null);
const proxyAccountId = ref<string | null>(null);
async function init(): Promise<void> {
const meta = await misskeyApi('admin/meta'); const meta = await misskeyApi('admin/meta');
name.value = meta.name;
shortName.value = meta.shortName;
description.value = meta.description;
maintainerName.value = meta.maintainerName;
maintainerEmail.value = meta.maintainerEmail;
tosUrl.value = meta.tosUrl;
privacyPolicyUrl.value = meta.privacyPolicyUrl;
inquiryUrl.value = meta.inquiryUrl;
repositoryUrl.value = meta.repositoryUrl;
impressumUrl.value = meta.impressumUrl;
pinnedUsers.value = meta.pinnedUsers.join('\n');
cacheRemoteFiles.value = meta.cacheRemoteFiles;
cacheRemoteSensitiveFiles.value = meta.cacheRemoteSensitiveFiles;
enableServiceWorker.value = meta.enableServiceWorker;
swPublicKey.value = meta.swPublickey;
swPrivateKey.value = meta.swPrivateKey;
notesPerOneAd.value = meta.notesPerOneAd;
urlPreviewEnabled.value = meta.urlPreviewEnabled;
urlPreviewTimeout.value = meta.urlPreviewTimeout;
urlPreviewMaximumContentLength.value = meta.urlPreviewMaximumContentLength;
urlPreviewRequireContentLength.value = meta.urlPreviewRequireContentLength;
urlPreviewUserAgent.value = meta.urlPreviewUserAgent;
urlPreviewSummaryProxyUrl.value = meta.urlPreviewSummaryProxyUrl;
proxyAccountId.value = meta.proxyAccountId;
if (proxyAccountId.value) {
proxyAccount.value = await misskeyApi('users/show', { userId: proxyAccountId.value });
}
}
function saveInfo() { const proxyAccount = ref(meta.proxyAccountId ? await misskeyApi('users/show', { userId: meta.proxyAccountId }) : null);
os.apiWithDialog('admin/update-meta', {
name: name.value, const infoForm = useForm({
shortName: shortName.value === '' ? null : shortName.value, name: meta.name ?? '',
description: description.value, shortName: meta.shortName ?? '',
maintainerName: maintainerName.value, description: meta.description ?? '',
maintainerEmail: maintainerEmail.value, maintainerName: meta.maintainerName ?? '',
tosUrl: tosUrl.value, maintainerEmail: meta.maintainerEmail ?? '',
privacyPolicyUrl: privacyPolicyUrl.value, tosUrl: meta.tosUrl ?? '',
inquiryUrl: inquiryUrl.value, privacyPolicyUrl: meta.privacyPolicyUrl ?? '',
repositoryUrl: repositoryUrl.value, inquiryUrl: meta.inquiryUrl ?? '',
impressumUrl: impressumUrl.value, repositoryUrl: meta.repositoryUrl ?? '',
}).then(() => { impressumUrl: meta.impressumUrl ?? '',
}, async (state) => {
await os.apiWithDialog('admin/update-meta', {
name: state.name,
shortName: state.shortName === '' ? null : state.shortName,
description: state.description,
maintainerName: state.maintainerName,
maintainerEmail: state.maintainerEmail,
tosUrl: state.tosUrl,
privacyPolicyUrl: state.privacyPolicyUrl,
inquiryUrl: state.inquiryUrl,
repositoryUrl: state.repositoryUrl,
impressumUrl: state.impressumUrl,
});
fetchInstance(true); fetchInstance(true);
}); });
}
function save_pinnedUsers() { const pinnedUsersForm = useForm({
os.apiWithDialog('admin/update-meta', { pinnedUsers: meta.pinnedUsers.join('\n'),
pinnedUsers: pinnedUsers.value.split('\n'), }, async (state) => {
}).then(() => { await os.apiWithDialog('admin/update-meta', {
pinnedUsers: state.pinnedUsers.split('\n'),
});
fetchInstance(true); fetchInstance(true);
}); });
}
function saveFiles() { const filesForm = useForm({
os.apiWithDialog('admin/update-meta', { cacheRemoteFiles: meta.cacheRemoteFiles,
cacheRemoteFiles: cacheRemoteFiles.value, cacheRemoteSensitiveFiles: meta.cacheRemoteSensitiveFiles,
cacheRemoteSensitiveFiles: cacheRemoteSensitiveFiles.value, }, async (state) => {
}).then(() => { await os.apiWithDialog('admin/update-meta', {
cacheRemoteFiles: state.cacheRemoteFiles,
cacheRemoteSensitiveFiles: state.cacheRemoteSensitiveFiles,
});
fetchInstance(true); fetchInstance(true);
}); });
}
function saveServiceWorker() { const serviceWorkerForm = useForm({
os.apiWithDialog('admin/update-meta', { enableServiceWorker: meta.enableServiceWorker,
enableServiceWorker: enableServiceWorker.value, swPublicKey: meta.swPublickey ?? '',
swPublicKey: swPublicKey.value, swPrivateKey: meta.swPrivateKey ?? '',
swPrivateKey: swPrivateKey.value, }, async (state) => {
}).then(() => { await os.apiWithDialog('admin/update-meta', {
enableServiceWorker: state.enableServiceWorker,
swPublicKey: state.swPublicKey,
swPrivateKey: state.swPrivateKey,
});
fetchInstance(true); fetchInstance(true);
}); });
}
function saveAd() { const adForm = useForm({
os.apiWithDialog('admin/update-meta', { notesPerOneAd: meta.notesPerOneAd,
notesPerOneAd: notesPerOneAd.value, }, async (state) => {
}).then(() => { await os.apiWithDialog('admin/update-meta', {
notesPerOneAd: state.notesPerOneAd,
});
fetchInstance(true); fetchInstance(true);
}); });
}
function saveUrlPreview() { const urlPreviewForm = useForm({
os.apiWithDialog('admin/update-meta', { urlPreviewEnabled: meta.urlPreviewEnabled,
urlPreviewEnabled: urlPreviewEnabled.value, urlPreviewTimeout: meta.urlPreviewTimeout,
urlPreviewTimeout: urlPreviewTimeout.value, urlPreviewMaximumContentLength: meta.urlPreviewMaximumContentLength,
urlPreviewMaximumContentLength: urlPreviewMaximumContentLength.value, urlPreviewRequireContentLength: meta.urlPreviewRequireContentLength,
urlPreviewRequireContentLength: urlPreviewRequireContentLength.value, urlPreviewUserAgent: meta.urlPreviewUserAgent ?? '',
urlPreviewUserAgent: urlPreviewUserAgent.value, urlPreviewSummaryProxyUrl: meta.urlPreviewSummaryProxyUrl ?? '',
urlPreviewSummaryProxyUrl: urlPreviewSummaryProxyUrl.value, }, async (state) => {
}).then(() => { await os.apiWithDialog('admin/update-meta', {
urlPreviewEnabled: state.urlPreviewEnabled,
urlPreviewTimeout: state.urlPreviewTimeout,
urlPreviewMaximumContentLength: state.urlPreviewMaximumContentLength,
urlPreviewRequireContentLength: state.urlPreviewRequireContentLength,
urlPreviewUserAgent: state.urlPreviewUserAgent,
urlPreviewSummaryProxyUrl: state.urlPreviewSummaryProxyUrl,
});
fetchInstance(true); fetchInstance(true);
}); });
}
function chooseProxyAccount() { function chooseProxyAccount() {
os.selectUser({ localOnly: true }).then(user => { os.selectUser({ localOnly: true }).then(user => {
proxyAccount.value = user; proxyAccount.value = user;
proxyAccountId.value = user.id;
saveProxyAccount();
});
}
function saveProxyAccount() {
os.apiWithDialog('admin/update-meta', { os.apiWithDialog('admin/update-meta', {
proxyAccountId: proxyAccountId.value, proxyAccountId: user.id,
}).then(() => { }).then(() => {
fetchInstance(true); fetchInstance(true);
}); });
});
} }
const headerTabs = computed(() => []); const headerTabs = computed(() => []);

View File

@ -0,0 +1,55 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { computed, Reactive, reactive, watch } from 'vue';
function copy<T>(v: T): T {
return JSON.parse(JSON.stringify(v));
}
function unwrapReactive<T>(v: Reactive<T>): T {
return JSON.parse(JSON.stringify(v));
}
export function useForm<T extends Record<string, any>>(initialState: T, save: (newState: T) => Promise<void>) {
const currentState = reactive<T>(copy(initialState));
const previousState = reactive<T>(copy(initialState));
const modifiedStates = reactive<Record<keyof T, boolean>>({} as any);
for (const key in currentState) {
modifiedStates[key] = false;
}
const modified = computed(() => Object.values(modifiedStates).some(v => v));
const modifiedCount = computed(() => Object.values(modifiedStates).filter(v => v).length);
watch([currentState, previousState], () => {
for (const key in modifiedStates) {
modifiedStates[key] = currentState[key] !== previousState[key];
}
}, { deep: true });
async function _save() {
await save(unwrapReactive(currentState));
for (const key in currentState) {
previousState[key] = copy(currentState[key]);
}
}
function discard() {
for (const key in currentState) {
currentState[key] = copy(previousState[key]);
}
}
return {
state: currentState,
savedState: previousState,
modifiedStates,
modified,
modifiedCount,
save: _save,
discard,
};
}

View File

@ -378,6 +378,16 @@ rt {
vertical-align: top; vertical-align: top;
} }
._modified {
margin-left: 0.7em;
font-size: 65%;
padding: 2px 3px;
color: var(--warn);
border: solid 1px var(--warn);
border-radius: 4px;
vertical-align: top;
}
._table { ._table {
> ._row { > ._row {
display: flex; display: flex;