|
| 1 | +import Component from "@glimmer/component"; |
1 | 2 | import { concat } from "@ember/helper"; |
2 | 3 | import { gt } from "truth-helpers"; |
3 | 4 | import DButton from "discourse/components/d-button"; |
4 | 5 | import { i18n } from "discourse-i18n"; |
5 | 6 |
|
6 | | -const AiFeaturesList = <template> |
7 | | - <div class="ai-features-list"> |
8 | | - {{#each @modules as |module|}} |
9 | | - <div class="ai-module" data-module-name={{module.module_name}}> |
10 | | - <div class="ai-module__header"> |
11 | | - <div class="ai-module__module-title"> |
12 | | - <h3>{{i18n |
13 | | - (concat "discourse_ai.features." module.module_name ".name") |
14 | | - }}</h3> |
15 | | - <DButton |
16 | | - class="edit" |
17 | | - @label="discourse_ai.features.edit" |
18 | | - @route="adminPlugins.show.discourse-ai-features.edit" |
19 | | - @routeModels={{module.id}} |
20 | | - /> |
| 7 | +export default class AiFeaturesList extends Component { |
| 8 | + get sortedModules() { |
| 9 | + return this.args.modules.sort((a, b) => { |
| 10 | + const nameA = i18n(`discourse_ai.features.${a.module_name}.name`); |
| 11 | + const nameB = i18n(`discourse_ai.features.${b.module_name}.name`); |
| 12 | + return nameA.localeCompare(nameB); |
| 13 | + }); |
| 14 | + } |
| 15 | + |
| 16 | + <template> |
| 17 | + <div class="ai-features-list"> |
| 18 | + {{#each this.sortedModules as |module|}} |
| 19 | + <div class="ai-module" data-module-name={{module.module_name}}> |
| 20 | + <div class="ai-module__header"> |
| 21 | + <div class="ai-module__module-title"> |
| 22 | + <h3>{{i18n |
| 23 | + (concat "discourse_ai.features." module.module_name ".name") |
| 24 | + }}</h3> |
| 25 | + <DButton |
| 26 | + class="edit" |
| 27 | + @label="discourse_ai.features.edit" |
| 28 | + @route="adminPlugins.show.discourse-ai-features.edit" |
| 29 | + @routeModels={{module.id}} |
| 30 | + /> |
| 31 | + </div> |
| 32 | + <div>{{i18n |
| 33 | + (concat |
| 34 | + "discourse_ai.features." module.module_name ".description" |
| 35 | + ) |
| 36 | + }}</div> |
21 | 37 | </div> |
22 | | - <div>{{i18n |
23 | | - (concat |
24 | | - "discourse_ai.features." module.module_name ".description" |
25 | | - ) |
26 | | - }}</div> |
27 | | - </div> |
28 | 38 |
|
29 | | - <div class="admin-section-landing-wrapper ai-feature-cards"> |
30 | | - {{#each module.features as |feature|}} |
31 | | - <div |
32 | | - class="admin-section-landing-item ai-feature-card" |
33 | | - data-feature-name={{feature.name}} |
34 | | - > |
35 | | - <div class="admin-section-landing-item__content"> |
36 | | - <div class="ai-feature-card__feature-name"> |
37 | | - {{i18n |
38 | | - (concat |
39 | | - "discourse_ai.features." |
40 | | - module.module_name |
41 | | - "." |
42 | | - feature.name |
43 | | - ) |
44 | | - }} |
45 | | - {{#unless feature.enabled}} |
46 | | - <span>{{i18n "discourse_ai.features.disabled"}}</span> |
47 | | - {{/unless}} |
48 | | - </div> |
49 | | - <div class="ai-feature-card__persona"> |
50 | | - <span>{{i18n "discourse_ai.features.persona"}}</span> |
51 | | - {{#if feature.persona}} |
52 | | - <DButton |
53 | | - class="btn-flat btn-small ai-feature-card__persona-button" |
54 | | - @translatedLabel={{feature.persona.name}} |
55 | | - @route="adminPlugins.show.discourse-ai-personas.edit" |
56 | | - @routeModels={{feature.persona.id}} |
57 | | - /> |
58 | | - {{else}} |
59 | | - {{i18n "discourse_ai.features.no_persona"}} |
60 | | - {{/if}} |
61 | | - </div> |
62 | | - <div class="ai-feature-card__llm"> |
63 | | - <span>{{i18n "discourse_ai.features.llm"}}</span> |
64 | | - {{#if feature.llm_model.name}} |
65 | | - <DButton |
66 | | - class="btn-flat btn-small ai-feature-card__llm-button" |
67 | | - @translatedLabel={{feature.llm_model.name}} |
68 | | - @route="adminPlugins.show.discourse-ai-llms.edit" |
69 | | - @routeModels={{feature.llm_model.id}} |
70 | | - /> |
71 | | - {{else}} |
72 | | - {{i18n "discourse_ai.features.no_llm"}} |
73 | | - {{/if}} |
74 | | - </div> |
75 | | - {{#if feature.persona}} |
76 | | - <div class="ai-feature-card__groups"> |
77 | | - <span>{{i18n "discourse_ai.features.groups"}}</span> |
78 | | - {{#if (gt feature.persona.allowed_groups.length 0)}} |
79 | | - <ul class="ai-feature-card__item-groups"> |
80 | | - {{#each feature.persona.allowed_groups as |group|}} |
81 | | - <li>{{group.name}}</li> |
82 | | - {{/each}} |
83 | | - </ul> |
| 39 | + <div class="admin-section-landing-wrapper ai-feature-cards"> |
| 40 | + {{#each module.features as |feature|}} |
| 41 | + <div |
| 42 | + class="admin-section-landing-item ai-feature-card" |
| 43 | + data-feature-name={{feature.name}} |
| 44 | + > |
| 45 | + <div class="admin-section-landing-item__content"> |
| 46 | + <div class="ai-feature-card__feature-name"> |
| 47 | + {{i18n |
| 48 | + (concat |
| 49 | + "discourse_ai.features." |
| 50 | + module.module_name |
| 51 | + "." |
| 52 | + feature.name |
| 53 | + ) |
| 54 | + }} |
| 55 | + {{#unless feature.enabled}} |
| 56 | + <span>{{i18n "discourse_ai.features.disabled"}}</span> |
| 57 | + {{/unless}} |
| 58 | + </div> |
| 59 | + <div class="ai-feature-card__persona"> |
| 60 | + <span>{{i18n |
| 61 | + "discourse_ai.features.persona" |
| 62 | + count=feature.personas.length |
| 63 | + }}</span> |
| 64 | + {{#if feature.personas}} |
| 65 | + {{#each feature.personas as |persona|}} |
| 66 | + <DButton |
| 67 | + class="btn-flat btn-small ai-feature-card__persona-button" |
| 68 | + @translatedLabel={{persona.name}} |
| 69 | + @route="adminPlugins.show.discourse-ai-personas.edit" |
| 70 | + @routeModels={{persona.id}} |
| 71 | + /> |
| 72 | + {{/each}} |
84 | 73 | {{else}} |
85 | | - {{i18n "discourse_ai.features.no_groups"}} |
| 74 | + {{i18n "discourse_ai.features.no_persona"}} |
86 | 75 | {{/if}} |
87 | 76 | </div> |
88 | | - {{/if}} |
| 77 | + <div class="ai-feature-card__llm"> |
| 78 | + <span>{{i18n |
| 79 | + "discourse_ai.features.llm" |
| 80 | + count=feature.llm_models.length |
| 81 | + }}</span> |
| 82 | + {{#if feature.llm_models}} |
| 83 | + {{#each feature.llm_models as |llm_model|}} |
| 84 | + <DButton |
| 85 | + class="btn-flat btn-small ai-feature-card__llm-button" |
| 86 | + @translatedLabel={{llm_model.name}} |
| 87 | + @route="adminPlugins.show.discourse-ai-llms.edit" |
| 88 | + @routeModels={{llm_model.id}} |
| 89 | + /> |
| 90 | + {{/each}} |
| 91 | + {{else}} |
| 92 | + {{i18n "discourse_ai.features.no_llm"}} |
| 93 | + {{/if}} |
| 94 | + </div> |
| 95 | + {{#if feature.persona}} |
| 96 | + <div class="ai-feature-card__groups"> |
| 97 | + <span>{{i18n "discourse_ai.features.groups"}}</span> |
| 98 | + {{#if (gt feature.persona.allowed_groups.length 0)}} |
| 99 | + <ul class="ai-feature-card__item-groups"> |
| 100 | + {{#each feature.persona.allowed_groups as |group|}} |
| 101 | + <li>{{group.name}}</li> |
| 102 | + {{/each}} |
| 103 | + </ul> |
| 104 | + {{else}} |
| 105 | + {{i18n "discourse_ai.features.no_groups"}} |
| 106 | + {{/if}} |
| 107 | + </div> |
| 108 | + {{/if}} |
| 109 | + </div> |
89 | 110 | </div> |
90 | | - </div> |
91 | | - {{/each}} |
| 111 | + {{/each}} |
| 112 | + </div> |
92 | 113 | </div> |
93 | | - </div> |
94 | | - {{/each}} |
95 | | - </div> |
96 | | -</template>; |
97 | | - |
98 | | -export default AiFeaturesList; |
| 114 | + {{/each}} |
| 115 | + </div> |
| 116 | + </template> |
| 117 | +} |
0 commit comments