1
0
mirror of https://github.com/MisskeyIO/misskey synced 2024-12-25 20:18:18 +09:00
MisskeyIO/src/client/pages/settings/registry.value.vue

150 lines
3.4 KiB
Vue
Raw Normal View History

<template>
<FormBase>
2021-04-14 01:41:49 +09:00
<FormInfo warn>{{ $ts.editTheseSettingsMayBreakAccount }}</FormInfo>
<template v-if="value">
<FormGroup>
<FormKeyValueView>
<template #key>{{ $ts._registry.domain }}</template>
<template #value>{{ $ts.system }}</template>
</FormKeyValueView>
<FormKeyValueView>
<template #key>{{ $ts._registry.scope }}</template>
<template #value>{{ scope.join('/') }}</template>
</FormKeyValueView>
<FormKeyValueView>
<template #key>{{ $ts._registry.key }}</template>
<template #value>{{ xKey }}</template>
</FormKeyValueView>
</FormGroup>
<FormGroup>
2021-09-30 00:50:45 +09:00
<FormTextarea tall v-model="valueForEditor" class="_monospace" style="tab-size: 2;">
<span>{{ $ts.value }} (JSON)</span>
</FormTextarea>
<FormButton @click="save" primary><i class="fas fa-save"></i> {{ $ts.save }}</FormButton>
</FormGroup>
<FormKeyValueView>
<template #key>{{ $ts.updatedAt }}</template>
<template #value><MkTime :time="value.updatedAt" mode="detail"/></template>
</FormKeyValueView>
<FormButton danger @click="del"><i class="fas fa-trash"></i> {{ $ts.delete }}</FormButton>
</template>
</FormBase>
</template>
<script lang="ts">
import { defineAsyncComponent, defineComponent } from 'vue';
import * as JSON5 from 'json5';
2021-09-30 00:50:45 +09:00
import FormInfo from '@client/components/debobigego/info.vue';
2021-03-23 17:30:14 +09:00
import FormSwitch from '@client/components/form/switch.vue';
import FormSelect from '@client/components/form/select.vue';
import FormTextarea from '@client/components/form/textarea.vue';
2021-09-30 00:50:45 +09:00
import FormBase from '@client/components/debobigego/base.vue';
import FormGroup from '@client/components/debobigego/group.vue';
import FormButton from '@client/components/debobigego/button.vue';
import FormKeyValueView from '@client/components/debobigego/key-value-view.vue';
2021-03-23 17:30:14 +09:00
import * as os from '@client/os';
2021-04-10 12:54:12 +09:00
import * as symbols from '@client/symbols';
export default defineComponent({
components: {
2021-04-14 01:41:49 +09:00
FormInfo,
FormBase,
FormSelect,
FormSwitch,
FormButton,
FormTextarea,
FormGroup,
FormKeyValueView,
},
props: {
scope: {
required: true
},
xKey: {
required: true
},
},
emits: ['info'],
data() {
return {
2021-04-10 12:54:12 +09:00
[symbols.PAGE_INFO]: {
title: this.$ts.registry,
2021-09-30 00:50:45 +09:00
icon: 'fas fa-cogs',
bg: 'var(--bg)',
},
value: null,
valueForEditor: null,
}
},
watch: {
key() {
this.fetch();
},
},
mounted() {
2021-04-10 12:54:12 +09:00
this.$emit('info', this[symbols.PAGE_INFO]);
this.fetch();
},
methods: {
fetch() {
os.api('i/registry/get-detail', {
scope: this.scope,
key: this.xKey
}).then(value => {
this.value = value;
this.valueForEditor = JSON5.stringify(this.value.value, null, '\t');
});
},
save() {
try {
JSON5.parse(this.valueForEditor);
} catch (e) {
os.dialog({
type: 'error',
text: this.$ts.invalidValue
});
return;
}
os.dialog({
type: 'warning',
text: this.$ts.saveConfirm,
showCancelButton: true
}).then(({ canceled }) => {
if (canceled) return;
os.apiWithDialog('i/registry/set', {
scope: this.scope,
key: this.xKey,
value: JSON5.parse(this.valueForEditor)
});
});
},
del() {
os.dialog({
type: 'warning',
text: this.$ts.deleteConfirm,
showCancelButton: true
}).then(({ canceled }) => {
if (canceled) return;
os.apiWithDialog('i/registry/remove', {
scope: this.scope,
key: this.xKey
});
});
}
}
});
</script>