Skip to content

Commit 70bd7de

Browse files
committed
feat(ui): add docmdp scalar rule editor
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 0de711e commit 70bd7de

1 file changed

Lines changed: 124 additions & 0 deletions

File tree

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<!--
2+
- SPDX-FileCopyrightText: 2026 LibreCode coop and LibreCode contributors
3+
- SPDX-License-Identifier: AGPL-3.0-or-later
4+
-->
5+
6+
<template>
7+
<div class="docmdp-scalar-editor">
8+
<div class="docmdp-scalar-editor__options">
9+
<NcCheckboxRadioSwitch
10+
v-for="level in levels"
11+
:key="level.value"
12+
class="docmdp-scalar-editor__option"
13+
type="radio"
14+
:model-value="normalizedValue === level.value"
15+
name="docmdp-scalar-editor"
16+
@update:modelValue="onLevelChange(level.value, $event)">
17+
<div class="docmdp-scalar-editor__copy">
18+
<strong>{{ level.label }}</strong>
19+
<p>{{ level.description }}</p>
20+
</div>
21+
</NcCheckboxRadioSwitch>
22+
</div>
23+
</div>
24+
</template>
25+
26+
<script setup lang="ts">
27+
import { computed } from 'vue'
28+
import { t } from '@nextcloud/l10n'
29+
30+
import NcCheckboxRadioSwitch from '@nextcloud/vue/components/NcCheckboxRadioSwitch'
31+
import type { EffectivePolicyValue } from '../../../../../types/index'
32+
33+
defineOptions({
34+
name: 'DocMdpScalarRuleEditor',
35+
})
36+
37+
const props = defineProps<{
38+
modelValue: EffectivePolicyValue
39+
}>()
40+
41+
const emit = defineEmits<{
42+
'update:modelValue': [value: EffectivePolicyValue]
43+
}>()
44+
45+
const levels: Array<{ value: number, label: string, description: string }> = [
46+
{
47+
value: 0,
48+
label: t('libresign', 'Disabled'),
49+
description: t('libresign', 'Do not apply DocMDP certification by default.'),
50+
},
51+
{
52+
value: 1,
53+
label: t('libresign', 'No changes allowed'),
54+
description: t('libresign', 'After signing, no changes are allowed in the document.'),
55+
},
56+
{
57+
value: 2,
58+
label: t('libresign', 'Form filling'),
59+
description: t('libresign', 'After signing, only form filling is allowed.'),
60+
},
61+
{
62+
value: 3,
63+
label: t('libresign', 'Form filling and annotations'),
64+
description: t('libresign', 'After signing, form filling and annotations are allowed.'),
65+
},
66+
]
67+
68+
const normalizedValue = computed<number | null>(() => {
69+
const value = props.modelValue
70+
if (typeof value === 'number' && value >= 0 && value <= 3) {
71+
return value
72+
}
73+
74+
if (typeof value === 'string' && /^[0-3]$/.test(value)) {
75+
return Number(value)
76+
}
77+
78+
return null
79+
})
80+
81+
function onLevelChange(level: number, selected?: unknown) {
82+
if (selected === false) {
83+
return
84+
}
85+
86+
emit('update:modelValue', level)
87+
}
88+
</script>
89+
90+
<style scoped lang="scss">
91+
.docmdp-scalar-editor {
92+
display: flex;
93+
flex-direction: column;
94+
gap: 1rem;
95+
96+
&__options {
97+
display: flex;
98+
flex-direction: column;
99+
gap: 0.75rem;
100+
}
101+
102+
&__option {
103+
width: 100%;
104+
}
105+
106+
&__copy p {
107+
margin: 0.35rem 0 0;
108+
color: var(--color-text-maxcontrast);
109+
}
110+
111+
:deep(.docmdp-scalar-editor__option.checkbox-radio-switch) {
112+
width: 100%;
113+
}
114+
115+
:deep(.docmdp-scalar-editor__option .checkbox-radio-switch__content) {
116+
width: 100%;
117+
max-width: none;
118+
}
119+
120+
:deep(.docmdp-scalar-editor__option.checkbox-radio-switch--checked:focus-within .checkbox-radio-switch__content) {
121+
background-color: transparent;
122+
}
123+
}
124+
</style>

0 commit comments

Comments
 (0)