@@ -7,6 +7,16 @@ import { computed } from 'vue'
77import { loadState } from '@nextcloud/initial-state'
88import { usePoliciesStore } from '../store/policies'
99
10+ // Defaults matching backend SignatureTextPolicyValue::DEFAULTS
11+ const SIGNATURE_TEXT_DEFAULTS = {
12+ template : '' ,
13+ templateFontSize : 9.0 ,
14+ signatureFontSize : 9.0 ,
15+ signatureWidth : 90.0 ,
16+ signatureHeight : 60.0 ,
17+ renderMode : 'default' ,
18+ }
19+
1020interface SignatureTextValues {
1121 template : string
1222 templateFontSize : number
@@ -16,11 +26,6 @@ interface SignatureTextValues {
1626 renderMode : string
1727 templateError : string
1828 parsed : string
19- defaultTemplate : string
20- defaultTemplateFontSize : number
21- defaultSignatureFontSize : number
22- defaultSignatureWidth : number
23- defaultSignatureHeight : number
2429}
2530
2631export function useSignatureTextPolicy ( ) : { values : ReturnType < typeof computed < SignatureTextValues > > } {
@@ -29,44 +34,29 @@ export function useSignatureTextPolicy(): { values: ReturnType<typeof computed<S
2934 const values = computed < SignatureTextValues > ( ( ) => {
3035 const signatureTextPolicy = policiesStore . policies . signature_text
3136
32- // If policy exists, use its effective value
37+ // Always use policy value; fallback to defaults if not defined
38+ let policyValue = SIGNATURE_TEXT_DEFAULTS
39+
3340 if ( signatureTextPolicy ?. value ) {
34- const value = typeof signatureTextPolicy . value === 'string'
41+ const decoded = typeof signatureTextPolicy . value === 'string'
3542 ? JSON . parse ( signatureTextPolicy . value )
3643 : signatureTextPolicy . value
3744
38- return {
39- template : String ( value . template ?? '' ) ,
40- templateFontSize : Number ( value . template_font_size ?? 9.0 ) ,
41- signatureFontSize : Number ( value . signature_font_size ?? 9.0 ) ,
42- signatureWidth : Number ( value . signature_width ?? 90.0 ) ,
43- signatureHeight : Number ( value . signature_height ?? 60.0 ) ,
44- renderMode : String ( value . render_mode ?? 'default' ) ,
45- templateError : loadState < string > ( 'libresign' , 'signature_text_template_error' , '' ) ,
46- parsed : loadState < string > ( 'libresign' , 'signature_text_parsed' , '' ) ,
47- defaultTemplate : loadState < string > ( 'libresign' , 'default_signature_text_template' , '' ) ,
48- defaultTemplateFontSize : loadState < number > ( 'libresign' , 'default_template_font_size' , 9.0 ) ,
49- defaultSignatureFontSize : loadState < number > ( 'libresign' , 'default_signature_font_size' , 9.0 ) ,
50- defaultSignatureWidth : loadState < number > ( 'libresign' , 'default_signature_width' , 90.0 ) ,
51- defaultSignatureHeight : loadState < number > ( 'libresign' , 'default_signature_height' , 60.0 ) ,
45+ policyValue = {
46+ template : String ( decoded . template ?? SIGNATURE_TEXT_DEFAULTS . template ) ,
47+ templateFontSize : Number ( decoded . template_font_size ?? SIGNATURE_TEXT_DEFAULTS . templateFontSize ) ,
48+ signatureFontSize : Number ( decoded . signature_font_size ?? SIGNATURE_TEXT_DEFAULTS . signatureFontSize ) ,
49+ signatureWidth : Number ( decoded . signature_width ?? SIGNATURE_TEXT_DEFAULTS . signatureWidth ) ,
50+ signatureHeight : Number ( decoded . signature_height ?? SIGNATURE_TEXT_DEFAULTS . signatureHeight ) ,
51+ renderMode : String ( decoded . render_mode ?? SIGNATURE_TEXT_DEFAULTS . renderMode ) ,
5252 }
5353 }
5454
55- // Fallback to legacy loadState keys (for backward compatibility during transition )
55+ // Only non-policy values come from loadState (error/parsing results )
5656 return {
57- template : loadState < string > ( 'libresign' , 'signature_text_template' , '' ) ,
58- templateFontSize : loadState < number > ( 'libresign' , 'template_font_size' , 9.0 ) ,
59- signatureFontSize : loadState < number > ( 'libresign' , 'signature_font_size' , 9.0 ) ,
60- signatureWidth : loadState < number > ( 'libresign' , 'signature_width' , 90.0 ) ,
61- signatureHeight : loadState < number > ( 'libresign' , 'signature_height' , 60.0 ) ,
62- renderMode : loadState < string > ( 'libresign' , 'signature_render_mode' , 'default' ) ,
57+ ...policyValue ,
6358 templateError : loadState < string > ( 'libresign' , 'signature_text_template_error' , '' ) ,
6459 parsed : loadState < string > ( 'libresign' , 'signature_text_parsed' , '' ) ,
65- defaultTemplate : loadState < string > ( 'libresign' , 'default_signature_text_template' , '' ) ,
66- defaultTemplateFontSize : loadState < number > ( 'libresign' , 'default_template_font_size' , 9.0 ) ,
67- defaultSignatureFontSize : loadState < number > ( 'libresign' , 'default_signature_font_size' , 9.0 ) ,
68- defaultSignatureWidth : loadState < number > ( 'libresign' , 'default_signature_width' , 90.0 ) ,
69- defaultSignatureHeight : loadState < number > ( 'libresign' , 'default_signature_height' , 60.0 ) ,
7060 }
7161 } )
7262
0 commit comments