fix
This commit is contained in:
parent
6ca83c541d
commit
a18f4cda84
|
|
@ -17,13 +17,13 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
<div class="_gaps">
|
<div class="_gaps">
|
||||||
<MkSwitch v-if="!isBaseRole && rolePolicyMetaModel != null" v-model="rolePolicyMetaModel.useDefault" :disabled="readonly">
|
<MkSwitch v-if="!isBaseRole && rolePolicyMetaModel != null" v-model="useDefaultModel" :disabled="readonly">
|
||||||
<template #label>{{ i18n.ts._role.useBaseValue }}</template>
|
<template #label>{{ i18n.ts._role.useBaseValue }}</template>
|
||||||
</MkSwitch>
|
</MkSwitch>
|
||||||
<div>
|
<div>
|
||||||
<slot :disabled="readonly || (!isBaseRole && rolePolicyMetaModel?.useDefault)"></slot>
|
<slot :disabled="readonly || (!isBaseRole && rolePolicyMetaModel?.useDefault)"></slot>
|
||||||
</div>
|
</div>
|
||||||
<MkRange v-if="!isBaseRole && rolePolicyMetaModel != null" v-model="rolePolicyMetaModel.priority" :min="0" :max="2" :step="1" easing :textConverter="priroityRangeTextConverter" :disabled="readonly">
|
<MkRange v-if="!isBaseRole && rolePolicyMetaModel != null" v-model="priorityModel" :min="0" :max="2" :step="1" easing :textConverter="priroityRangeTextConverter" :disabled="readonly">
|
||||||
<template #label>{{ i18n.ts._role.priority }}</template>
|
<template #label>{{ i18n.ts._role.priority }}</template>
|
||||||
</MkRange>
|
</MkRange>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -31,7 +31,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, watch } from 'vue';
|
import { computed } from 'vue';
|
||||||
import MkFolder from '@/components/MkFolder.vue';
|
import MkFolder from '@/components/MkFolder.vue';
|
||||||
import MkSwitch from '@/components/MkSwitch.vue';
|
import MkSwitch from '@/components/MkSwitch.vue';
|
||||||
import MkRange from '@/components/MkRange.vue';
|
import MkRange from '@/components/MkRange.vue';
|
||||||
|
|
@ -48,19 +48,27 @@ const emit = defineEmits<{
|
||||||
(ev: 'update:policyMeta', v: PolicyMeta): void;
|
(ev: 'update:policyMeta', v: PolicyMeta): void;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const rolePolicyMetaModel = ref<PolicyMeta | null>(null);
|
const rolePolicyMetaModel = computed<PolicyMeta | null>(() => props.policyMeta ?? null);
|
||||||
watch(() => props.policyMeta, (v) => {
|
|
||||||
if (v != null) {
|
const useDefaultModel = computed<boolean>({
|
||||||
rolePolicyMetaModel.value = v;
|
get: () => props.policyMeta?.useDefault ?? false,
|
||||||
} else {
|
set: (value) => {
|
||||||
rolePolicyMetaModel.value = null;
|
const current = props.policyMeta;
|
||||||
}
|
if (current == null) return;
|
||||||
}, { immediate: true, deep: true });
|
if (current.useDefault === value) return;
|
||||||
watch(rolePolicyMetaModel, (v) => {
|
emit('update:policyMeta', { ...current, useDefault: value });
|
||||||
if (v != null) {
|
},
|
||||||
emit('update:policyMeta', v);
|
});
|
||||||
}
|
|
||||||
}, { deep: true });
|
const priorityModel = computed<number>({
|
||||||
|
get: () => props.policyMeta?.priority ?? 0,
|
||||||
|
set: (value) => {
|
||||||
|
const current = props.policyMeta;
|
||||||
|
if (current == null) return;
|
||||||
|
if (current.priority === value) return;
|
||||||
|
emit('update:policyMeta', { ...current, priority: value });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
function getPriorityIcon(priority: number): string {
|
function getPriorityIcon(priority: number): string {
|
||||||
if (priority === 2) return 'ti ti-arrows-up';
|
if (priority === 2) return 'ti ti-arrows-up';
|
||||||
|
|
|
||||||
|
|
@ -403,7 +403,7 @@ type PolicyMetaRecord = {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, ref, watch } from 'vue';
|
import { computed } from 'vue';
|
||||||
import { i18n } from '@/i18n.js';
|
import { i18n } from '@/i18n.js';
|
||||||
import XFolder from './roles.policy-editor.folder.vue';
|
import XFolder from './roles.policy-editor.folder.vue';
|
||||||
|
|
||||||
|
|
@ -426,25 +426,36 @@ const emit = defineEmits<{
|
||||||
(event: 'update:policiesMeta', value: PolicyMetaRecord): void;
|
(event: 'update:policiesMeta', value: PolicyMetaRecord): void;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const valuesModel = ref<Misskey.entities.RolePolicies>(props.rolePolicies);
|
const valuesModel = new Proxy({} as Misskey.entities.RolePolicies, {
|
||||||
watch(() => props.rolePolicies, (newVal) => {
|
get(_target, prop) {
|
||||||
valuesModel.value = newVal;
|
if (typeof prop !== 'string') return undefined;
|
||||||
}, { deep: true });
|
return props.rolePolicies[prop as keyof Misskey.entities.RolePolicies];
|
||||||
watch(valuesModel, (newVal) => {
|
},
|
||||||
emit('update:rolePolicies', newVal);
|
set(_target, prop, value) {
|
||||||
}, { deep: true });
|
if (typeof prop !== 'string') return false;
|
||||||
|
emit('update:rolePolicies', { ...props.rolePolicies, [prop]: value });
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
function createDefaultPolicyMeta() {
|
function createDefaultPolicyMeta() {
|
||||||
return Object.fromEntries(Object.keys(Misskey.rolePolicies).map(key => [key, { useDefault: true, priority: 0 }])) as PolicyMetaRecord;
|
return Object.fromEntries(Object.keys(Misskey.rolePolicies).map(key => [key, { useDefault: true, priority: 0 }])) as PolicyMetaRecord;
|
||||||
}
|
}
|
||||||
const policyMetaModel = ref<PolicyMetaRecord>(props.policiesMeta ?? createDefaultPolicyMeta());
|
|
||||||
watch(() => props.policiesMeta, (newVal) => {
|
const policiesMetaFallback = createDefaultPolicyMeta();
|
||||||
policyMetaModel.value = newVal ?? createDefaultPolicyMeta();
|
const policyMetaModel = new Proxy({} as PolicyMetaRecord, {
|
||||||
}, { deep: true });
|
get(_target, prop) {
|
||||||
watch(policyMetaModel, (newVal) => {
|
if (typeof prop !== 'string') return undefined;
|
||||||
if (newVal == null) return;
|
const base = props.policiesMeta ?? policiesMetaFallback;
|
||||||
emit('update:policiesMeta', newVal);
|
return base[prop as keyof PolicyMetaRecord];
|
||||||
}, { deep: true });
|
},
|
||||||
|
set(_target, prop, value) {
|
||||||
|
if (typeof prop !== 'string') return false;
|
||||||
|
const base = props.policiesMeta ?? policiesMetaFallback;
|
||||||
|
emit('update:policiesMeta', { ...base, [prop]: value });
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
function matchQuery(keywords: string[]): boolean {
|
function matchQuery(keywords: string[]): boolean {
|
||||||
if (props.roleQuery == null || props.roleQuery.trim().length === 0) return true;
|
if (props.roleQuery == null || props.roleQuery.trim().length === 0) return true;
|
||||||
|
|
@ -452,9 +463,9 @@ function matchQuery(keywords: string[]): boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
const avatarDecorationLimit = computed({
|
const avatarDecorationLimit = computed({
|
||||||
get: () => Math.min(16, Math.max(0, valuesModel.value.avatarDecorationLimit)),
|
get: () => Math.min(16, Math.max(0, Number(valuesModel.avatarDecorationLimit ?? 0))),
|
||||||
set: (value) => {
|
set: (value) => {
|
||||||
valuesModel.value.avatarDecorationLimit = Math.min(Number(value), 16);
|
valuesModel.avatarDecorationLimit = Math.min(Number(value), 16);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue