@@ -29,23 +29,7 @@ const DEFAULT_REPUTATION_UPPER_LIMIT = 5;
2929
3030@customElement ( "ak-admin-settings-form" )
3131export class AdminSettingsForm extends Form < SettingsRequest > {
32- //
33- // Custom property accessors in Lit 2 require a manual call to requestUpdate(). See:
34- // https://lit.dev/docs/v2/components/properties/#accessors-custom
35- //
36- set settings ( value : Settings | undefined ) {
37- this . _settings = value ;
38- this . requestUpdate ( ) ;
39- }
40-
41- @property ( { type : Object } )
42- get settings ( ) {
43- return this . _settings ;
44- }
45-
46- private _settings ?: Settings ;
47-
48- static styles : CSSResult [ ] = [
32+ public static styles : CSSResult [ ] = [
4933 ...super . styles ,
5034 PFList ,
5135 css `
@@ -55,25 +39,35 @@ export class AdminSettingsForm extends Form<SettingsRequest> {
5539 ` ,
5640 ] ;
5741
42+ @property ( { attribute : false } )
43+ public settings ! : Settings ;
44+
5845 getSuccessMessage ( ) : string {
5946 return msg ( "Successfully updated settings." ) ;
6047 }
6148
62- async send ( data : SettingsRequest ) : Promise < Settings > {
49+ async send ( settingsRequest : SettingsRequest ) : Promise < Settings > {
50+ settingsRequest . flags ??= this . settings . flags ;
51+
6352 const result = await new AdminApi ( DEFAULT_CONFIG ) . adminSettingsUpdate ( {
64- settingsRequest : data ,
53+ settingsRequest,
6554 } ) ;
55+
6656 this . dispatchEvent ( new CustomEvent ( "ak-admin-setting-changed" ) ) ;
57+
6758 return result ;
6859 }
6960
7061 renderForm ( ) : TemplateResult {
62+ const { settings } = this ;
63+
7164 return html `
7265 < ak-text-input
7366 name ="avatars "
7467 label =${ msg ( "Avatars" ) }
75- value ="${ ifDefined ( this . _settings ? .avatars ) } "
68+ value ="${ ifDefined ( settings . avatars ) } "
7669 input-hint="code"
70+ required
7771 .bighelp=${ html `
7872 < p class ="pf-c-form__helper-text ">
7973 ${ msg (
@@ -133,27 +127,26 @@ export class AdminSettingsForm extends Form<SettingsRequest> {
133127 ) }
134128 </ p >
135129 ` }
136- required
137130 >
138131 </ ak-text-input>
139132 < ak-switch-input
140133 name ="defaultUserChangeName "
141134 label =${ msg ( "Allow users to change name" ) }
142- ?checked =" ${ this . _settings ?. defaultUserChangeName } "
135+ ?checked =${ settings . defaultUserChangeName }
143136 help=${ msg ( "Enable the ability for users to change their name." ) }
144137 >
145138 </ ak-switch-input >
146139 < ak-switch-input
147140 name ="defaultUserChangeEmail "
148141 label =${ msg ( "Allow users to change email" ) }
149- ?checked =" ${ this . _settings ?. defaultUserChangeEmail } "
142+ ?checked =${ settings . defaultUserChangeEmail }
150143 help=${ msg ( "Enable the ability for users to change their email." ) }
151144 >
152145 </ ak-switch-input >
153146 < ak-switch-input
154147 name ="defaultUserChangeUsername "
155148 label =${ msg ( "Allow users to change username" ) }
156- ?checked =" ${ this . _settings ?. defaultUserChangeUsername } "
149+ ?checked =${ settings . defaultUserChangeUsername }
157150 help=${ msg ( "Enable the ability for users to change their username." ) }
158151 >
159152 </ ak-switch-input >
@@ -162,7 +155,7 @@ export class AdminSettingsForm extends Form<SettingsRequest> {
162155 label =${ msg ( "Event retention" ) }
163156 input-hint ="code"
164157 required
165- value="${ ifDefined ( this . _settings ? .eventRetention ) } "
158+ value="${ ifDefined ( settings . eventRetention ) } "
166159 .bighelp=${ html `< p class ="pf-c-form__helper-text ">
167160 ${ msg ( "Duration after which events will be deleted from the database." ) }
168161 </ p >
@@ -184,19 +177,19 @@ export class AdminSettingsForm extends Form<SettingsRequest> {
184177 label =${ msg ( "Reputation: lower limit" ) }
185178 required
186179 name ="reputationLowerLimit "
187- value ="${ this . _settings ? .reputationLowerLimit ?? DEFAULT_REPUTATION_LOWER_LIMIT } "
180+ value ="${ settings . reputationLowerLimit ?? DEFAULT_REPUTATION_LOWER_LIMIT } "
188181 help =${ msg ( "Reputation cannot decrease lower than this value. Zero or negative." ) }
189182 > </ ak-number-input >
190183 < ak-number-input
191184 label =${ msg ( "Reputation: upper limit" ) }
192185 required
193186 name ="reputationUpperLimit "
194- value ="${ this . _settings ? .reputationUpperLimit ?? DEFAULT_REPUTATION_UPPER_LIMIT } "
187+ value ="${ settings . reputationUpperLimit ?? DEFAULT_REPUTATION_UPPER_LIMIT } "
195188 help =${ msg ( "Reputation cannot increase higher than this value. Zero or positive." ) }
196189 > </ ak-number-input >
197190 < ak-form-element-horizontal label =${ msg ( "Footer links" ) } name ="footerLinks">
198191 < ak-array-input
199- .items =${ this . _settings ? .footerLinks ?? [ ] }
192+ .items =${ settings . footerLinks ?? [ ] }
200193 .newItem =${ ( ) => ( { name : "" , href : "" } ) }
201194 .row=${ ( f ?: FooterLink ) =>
202195 akFooterLinkInput ( {
@@ -215,7 +208,7 @@ export class AdminSettingsForm extends Form<SettingsRequest> {
215208 < ak-switch-input
216209 name ="gdprCompliance "
217210 label =${ msg ( "GDPR compliance" ) }
218- ?checked =" ${ this . _settings ?. gdprCompliance } "
211+ ?checked =${ settings . gdprCompliance }
219212 help=${ msg (
220213 "When enabled, all the events caused by a user will be deleted upon the user's deletion." ,
221214 ) }
@@ -224,14 +217,14 @@ export class AdminSettingsForm extends Form<SettingsRequest> {
224217 < ak-switch-input
225218 name ="impersonation "
226219 label =${ msg ( "Impersonation" ) }
227- ?checked =" ${ this . _settings ?. impersonation } "
220+ ?checked =${ settings . impersonation }
228221 help=${ msg ( "Globally enable/disable impersonation." ) }
229222 >
230223 </ ak-switch-input >
231224 < ak-switch-input
232225 name ="impersonationRequireReason "
233226 label =${ msg ( "Require reason for impersonation" ) }
234- ?checked =" ${ this . _settings ?. impersonationRequireReason } "
227+ ?checked =${ settings . impersonationRequireReason }
235228 help=${ msg ( "Require administrators to provide a reason for impersonating a user." ) }
236229 >
237230 </ ak-switch-input >
@@ -240,7 +233,7 @@ export class AdminSettingsForm extends Form<SettingsRequest> {
240233 label =${ msg ( "Default token duration" ) }
241234 input-hint ="code"
242235 required
243- value="${ ifDefined ( this . _settings ? .defaultTokenDuration ) } "
236+ value="${ ifDefined ( settings . defaultTokenDuration ) } "
244237 .bighelp=${ html `< p class ="pf-c-form__helper-text ">
245238 ${ msg ( "Default duration for generated tokens" ) }
246239 </ p >
@@ -251,7 +244,7 @@ export class AdminSettingsForm extends Form<SettingsRequest> {
251244 label =${ msg ( "Default token length" ) }
252245 required
253246 name ="defaultTokenLength "
254- value ="${ this . _settings ? .defaultTokenLength ?? 60 } "
247+ value ="${ settings . defaultTokenLength ?? 60 } "
255248 help =${ msg ( "Default length of generated tokens" ) }
256249 > </ ak-number-input >
257250 ` ;
0 commit comments