|
| 1 | +import Component from "@glimmer/component"; |
| 2 | +import { service } from "@ember/service"; |
| 3 | +import RouteTemplate from "ember-route-template"; |
| 4 | +import { gt } from "truth-helpers"; |
| 5 | +import DBreadcrumbsItem from "discourse/components/d-breadcrumbs-item"; |
| 6 | +import DButton from "discourse/components/d-button"; |
| 7 | +import DPageSubheader from "discourse/components/d-page-subheader"; |
| 8 | +import { i18n } from "discourse-i18n"; |
| 9 | + |
| 10 | +export default RouteTemplate( |
| 11 | + class extends Component { |
| 12 | + @service adminPluginNavManager; |
| 13 | + |
| 14 | + get tableHeaders() { |
| 15 | + const prefix = "discourse_ai.features.list.header"; |
| 16 | + return [ |
| 17 | + i18n(`${prefix}.name`), |
| 18 | + i18n(`${prefix}.persona`), |
| 19 | + i18n(`${prefix}.groups`), |
| 20 | + "", |
| 21 | + ]; |
| 22 | + } |
| 23 | + |
| 24 | + get configuredFeatures() { |
| 25 | + return this.args.model.filter( |
| 26 | + (feature) => feature.enable_setting.value === true |
| 27 | + ); |
| 28 | + } |
| 29 | + |
| 30 | + get unconfiguredFeatures() { |
| 31 | + return this.args.model.filter( |
| 32 | + (feature) => feature.enable_setting.value === false |
| 33 | + ); |
| 34 | + } |
| 35 | + |
| 36 | + <template> |
| 37 | + <DBreadcrumbsItem |
| 38 | + @path="/admin/plugins/{{this.adminPluginNavManager.currentPlugin.name}}/ai-features" |
| 39 | + @label={{i18n "discourse_ai.features.short_title"}} |
| 40 | + /> |
| 41 | + <section class="ai-feature-list admin-detail"> |
| 42 | + <DPageSubheader |
| 43 | + @titleLabel={{i18n "discourse_ai.features.short_title"}} |
| 44 | + @descriptionLabel={{i18n "discourse_ai.features.description"}} |
| 45 | + @learnMoreUrl="todo" |
| 46 | + /> |
| 47 | + |
| 48 | + {{#if (gt this.configuredFeatures.length 0)}} |
| 49 | + <div class="ai-feature-list__configured-features"> |
| 50 | + <h3>{{i18n "discourse_ai.features.list.configured_features"}}</h3> |
| 51 | + |
| 52 | + <table class="d-admin-table"> |
| 53 | + <thead> |
| 54 | + <tr> |
| 55 | + {{#each this.tableHeaders as |header|}} |
| 56 | + <th>{{header}}</th> |
| 57 | + {{/each}} |
| 58 | + </tr> |
| 59 | + </thead> |
| 60 | + |
| 61 | + <tbody> |
| 62 | + {{#each this.configuredFeatures as |feature|}} |
| 63 | + <tr |
| 64 | + class="ai-feature-list__row d-admin-row__content" |
| 65 | + data-feature-name={{feature.name}} |
| 66 | + > |
| 67 | + <td class="d-admin-row__overview ai-feature-list__row-item"> |
| 68 | + <span class="ai-feature-list__row-item-name"> |
| 69 | + <strong> |
| 70 | + {{feature.name}} |
| 71 | + </strong> |
| 72 | + </span> |
| 73 | + <span class="ai-feature-list__row-item-description"> |
| 74 | + {{feature.description}} |
| 75 | + </span> |
| 76 | + </td> |
| 77 | + <td |
| 78 | + class="d-admin-row__detail ai-feature-list__row-item ai-feature-list__persona" |
| 79 | + > |
| 80 | + <DButton |
| 81 | + class="btn-flat btn-small ai-feature-list__row-item-persona" |
| 82 | + @translatedLabel={{feature.persona.name}} |
| 83 | + @route="adminPlugins.show.discourse-ai-personas.edit" |
| 84 | + @routeModels={{feature.persona.id}} |
| 85 | + /> |
| 86 | + </td> |
| 87 | + <td |
| 88 | + class="d-admin-row__detail ai-feature-list__row-item ai-feature-list__groups" |
| 89 | + > |
| 90 | + {{#if (gt feature.persona.allowed_groups.length 0)}} |
| 91 | + <ul class="ai-feature-list__row-item-groups"> |
| 92 | + {{#each feature.persona.allowed_groups as |group|}} |
| 93 | + <li>{{group.name}}</li> |
| 94 | + {{/each}} |
| 95 | + </ul> |
| 96 | + {{/if}} |
| 97 | + </td> |
| 98 | + <td class="d-admin-row_controls"> |
| 99 | + <DButton |
| 100 | + class="btn-small edit" |
| 101 | + @label="discourse_ai.features.list.edit" |
| 102 | + @route="adminPlugins.show.discourse-ai-features.edit" |
| 103 | + @routeModels={{feature.id}} |
| 104 | + /> |
| 105 | + </td> |
| 106 | + </tr> |
| 107 | + {{/each}} |
| 108 | + </tbody> |
| 109 | + </table> |
| 110 | + </div> |
| 111 | + {{/if}} |
| 112 | + |
| 113 | + {{#if (gt this.unconfiguredFeatures.length 0)}} |
| 114 | + <div class="ai-feature-list__unconfigured-features"> |
| 115 | + <h3>{{i18n "discourse_ai.features.list.unconfigured_features"}}</h3> |
| 116 | + |
| 117 | + <table class="d-admin-table"> |
| 118 | + <thead> |
| 119 | + <tr> |
| 120 | + <th>{{i18n "discourse_ai.features.list.header.name"}}</th> |
| 121 | + <th></th> |
| 122 | + </tr> |
| 123 | + </thead> |
| 124 | + |
| 125 | + <tbody> |
| 126 | + {{#each this.unconfiguredFeatures as |feature|}} |
| 127 | + <tr class="ai-feature-list__row d-admin-row__content"> |
| 128 | + <td class="d-admin-row__overview ai-feature-list__row-item"> |
| 129 | + <span class="ai-feature-list__row-item-name"> |
| 130 | + <strong> |
| 131 | + {{feature.name}} |
| 132 | + </strong> |
| 133 | + </span> |
| 134 | + <span class="ai-feature-list__row-item-description"> |
| 135 | + {{feature.description}} |
| 136 | + </span> |
| 137 | + </td> |
| 138 | + |
| 139 | + <td class="d-admin-row_controls"> |
| 140 | + <DButton |
| 141 | + class="btn-small" |
| 142 | + @label="discourse_ai.features.list.set_up" |
| 143 | + @route="adminPlugins.show.discourse-ai-features.edit" |
| 144 | + @routeModels={{feature.id}} |
| 145 | + /> |
| 146 | + </td> |
| 147 | + </tr> |
| 148 | + {{/each}} |
| 149 | + </tbody> |
| 150 | + </table> |
| 151 | + </div> |
| 152 | + {{/if}} |
| 153 | + </section> |
| 154 | + </template> |
| 155 | + } |
| 156 | +); |
0 commit comments