11import Component from " @glimmer/component" ;
2- import { tracked } from " @glimmer/tracking" ;
32import { action } from " @ember/object" ;
43import { service } from " @ember/service" ;
5- import { htmlSafe } from " @ember/template" ;
6- import { eq } from " truth-helpers" ;
74import BackButton from " discourse/components/back-button" ;
8- import Form from " discourse/components/form" ;
9- import { ajax } from " discourse/lib/ajax" ;
105import { popupAjaxError } from " discourse/lib/ajax-error" ;
116import getURL from " discourse/lib/get-url" ;
12- import discourseLater from " discourse/lib/later" ;
13- import { i18n } from " discourse-i18n" ;
147import SiteSettingComponent from " admin/components/site-setting" ;
15- import SiteSetting from " admin/models/site-setting" ;
168
179export default class AiFeatureEditor extends Component {
1810 @service toasts;
1911 @service currentUser;
2012 @service router;
2113
22- @tracked settings = null ;
23- @tracked isLoading = false ;
24- @tracked isSaving = false ;
25-
26- constructor () {
27- super (... arguments );
28- this .#loadSettings ();
29- }
30-
31- get formData () {
32- return {
33- enabled: this .args .model .enable_setting ? .value ,
34- persona_id: this .args .model .persona ? .id ,
35- additional_settings: this .args .model .additional_settings ,
36- };
37- }
38-
39- @action
40- async save (formData ) {
41- this .isSaving = true ;
42-
43- try {
44- this .args .model .save ({
45- enabled: formData .enabled ,
46- persona_id: parseInt (formData .persona_id , 10 ),
47- });
48-
49- this .toasts .success ({
50- data: {
51- message: i18n (" discourse_ai.features.editor.saved" , {
52- feature_name: this .args .model .name ,
53- }),
54- },
55- duration: 2000 ,
56- });
57-
58- discourseLater (() => {
59- this .router .transitionTo (
60- " adminPlugins.show.discourse-ai-features.index"
61- );
62- }, 500 );
63- } catch (error) {
64- popupAjaxError (error);
65- } finally {
66- this .isSaving = false ;
67- }
68- }
69-
70- get personasHint () {
71- return i18n (" discourse_ai.features.editor.persona_help" , {
72- config_url: getURL (" /admin/plugins/discourse-ai/ai-personas" ),
73- });
74- }
75-
76- async #loadSettings () {
77- this .isLoading = true ;
78-
79- try {
80- const result = await ajax (" /admin/config/site_settings.json" , {
81- data: {
82- filter_area: ` ai-features/${ this .args .model .ref } ` ,
83- plugin: " discourse-ai" ,
84- category: " discourse_ai" ,
85- },
86- });
87-
88- const settings = result .site_settings ;
89- const settingsMap = settings .map ((setting ) =>
90- SiteSetting .create (setting)
91- );
92-
93- this .settings = settingsMap;
94- } catch (error) {
95- // eslint-disable-next-line no-console
96- console .warn (` Failed to load settings with error: ${ error} ` );
97- } finally {
98- this .isLoading = false ;
99- }
100- }
101-
10214 <template >
10315 <BackButton
10416 @ route =" adminPlugins.show.discourse-ai-features"
@@ -109,62 +21,12 @@ export default class AiFeatureEditor extends Component {
10921 <p >{{@ model.description }} </p >
11022 </section >
11123
112- {{!-- <Form
113- @onSubmit={{this.save}}
114- @data={{this.formData}}
115- class="form-horizontal ai-feature-editor"
116- as |form|
117- >
118- {{#if (eq @model.enable_setting.type "bool")}}
119- <form.Field
120- @name="enabled"
121- @title={{i18n "discourse_ai.features.editor.enable_setting"}}
122- @tooltip={{i18n
123- "discourse_ai.features.editor.enable_setting_help"
124- 125- }}
126- @validation="required"
127- @type="boolean"
128- as |field|
129- >
130- <field.Toggle />
131- </form.Field>
132- {{/if}}
133-
134- <form.Field
135- @name="persona_id"
136- @title={{i18n "discourse_ai.features.editor.persona"}}
137- @format="large"
138- @helpText={{htmlSafe this.personasHint}}
139- @validation="required"
140- as |field|
141- >
142- <field.Select @includeNone={{false}} as |select|>
143- {{#each this.currentUser.ai_enabled_personas as |persona|}}
144- <select.Option @value={{persona.id}}>
145- {{persona.name}}
146- </select.Option>
147- {{/each}}
148- </field.Select>
149- </form.Field>
150-
151- <form.Actions>
152- <form.Submit
153- @label="discourse_ai.features.editor.save"
154- @disabled={{this.isSaving}}
155- />
156- </form.Actions>
157- </Form> --}}
158-
159- <section class =" ai-feature-editor__advanced-settings" >
160- <h3 >{{i18n " discourse_ai.features.editor.advanced_settings" }} </h3 >
161- {{#unless this . isLoading }}
162- {{#each this . settings as | setting | }}
163- <div >
164- <SiteSettingComponent @ setting ={{setting }} />
165- </div >
166- {{/each }}
167- {{/unless }}
24+ <section class =" ai-feature-editor" >
25+ {{#each @ model.feature_settings as | setting | }}
26+ <div >
27+ <SiteSettingComponent @ setting ={{setting }} />
28+ </div >
29+ {{/each }}
16830 </section >
16931 </template >
17032}
0 commit comments