Skip to content

A platform for community discussion. Free, open, simple.

DEV: [gjs-codemod] merge js and hbs

David Taylorb203954060a8
diff --cc app/assets/javascripts/admin/addon/components/admin-backups-logs.gjs
index 14c22af2566,ce88566cda9..bbf787f1905
--- a/app/assets/javascripts/admin/addon/components/admin-backups-logs.gjs
+++ b/app/assets/javascripts/admin/addon/components/admin-backups-logs.gjs
@@@ -1,8 -1,78 +1,87 @@@
+ import Component from "@ember/component";
+ import { scheduleOnce } from "@ember/runloop";
+ import { classNames } from "@ember-decorators/component";
+ import { observes, on } from "@ember-decorators/object";
+ import discourseDebounce from "discourse/lib/debounce";
+ import { i18n } from "discourse-i18n";
+
+ @classNames("admin-backups-logs")
+ export default class AdminBackupsLogs extends Component {
+ showLoadingSpinner = false;
+ hasFormattedLogs = false;
+ noLogsMessage = i18n("admin.backups.logs.none");
+ formattedLogs = "";
+ index = 0;
+
+ _reset() {
+ this.setProperties({ formattedLogs: "", index: 0 });
+ }
+
+ _scrollDown() {
+ const div = this.element;
+ div.scrollTop = div.scrollHeight;
+ }
+
+ @on("init")
+ @observes("logs.[]")
+ _resetFormattedLogs() {
+ if (this.logs.length === 0) {
+ this._reset(); // reset the cached logs whenever the model is reset
+ this.renderLogs();
+ }
+ }
+
+ _updateFormattedLogsFunc() {
+ const logs = this.logs;
+ if (logs.length === 0) {
+ return;
+ }
+
+ // do the log formatting only once for HELLish performance
+ let formattedLogs = this.formattedLogs;
+ for (let i = this.index, length = logs.length; i < length; i++) {
+ const date = logs[i].get("timestamp"),
+ message = logs[i].get("message");
+ formattedLogs += "[" + date + "] " + message + "\n";
+ }
+ // update the formatted logs & cache index
+ this.setProperties({
+ formattedLogs,
+ index: logs.length,
+ });
+ // force rerender
+ this.renderLogs();
+
+ scheduleOnce("afterRender", this, this._scrollDown);
+ }
+
+ @on("init")
+ @observes("logs.[]")
+ _updateFormattedLogs() {
+ discourseDebounce(this, this._updateFormattedLogsFunc, 150);
+ }
+
+ renderLogs() {
+ const formattedLogs = this.formattedLogs;
+ if (formattedLogs && formattedLogs.length > 0) {
+ this.set("hasFormattedLogs", true);
+ } else {
+ this.set("hasFormattedLogs", false);
+ }
+ // add a loading indicator
+ if (this.get("status.isOperationRunning")) {
+ this.set("showLoadingSpinner", true);
+ } else {
+ this.set("showLoadingSpinner", false);
+ }
+ }
+ }
++
+{{#if this.hasFormattedLogs}}
+ <pre>{{this.formattedLogs}}</pre>
+{{else}}
+ <p>{{this.noLogsMessage}}</p>
+{{/if}}
+{{#if this.showLoadingSpinner}}
+ <div class="spinner small"></div>
+{{/if}}
diff --cc app/assets/javascripts/admin/addon/components/admin-editable-field.gjs
index 4db9c679992,bc848ddc50d..52dda1c8bcf
--- a/app/assets/javascripts/admin/addon/components/admin-editable-field.gjs
+++ b/app/assets/javascripts/admin/addon/components/admin-editable-field.gjs
@@@ -1,26 -1,22 +1,49 @@@
+ import Component from "@ember/component";
+ import { action } from "@ember/object";
+ import { tagName } from "@ember-decorators/component";
+
+ @tagName("")
+ export default class AdminEditableField extends Component {
+ buffer = "";
+ editing = false;
+
+ @action
+ edit(event) {
+ event?.preventDefault();
+ this.set("buffer", this.value);
+ this.toggleProperty("editing");
+ }
+
+ @action
+ save() {
+ // Action has to toggle 'editing' property.
+ this.action(this.buffer);
+ }
+ }
++
+<div class="field">{{i18n this.name}}</div>
+<div class="value">
+ {{#if this.editing}}
+ <TextField
+ @value={{this.buffer}}
+ @autofocus="autofocus"
+ @autocomplete="off"
+ />
+ {{else}}
+ <a href {{on "click" this.edit}} class="inline-editable-field">
+ <span>{{this.value}}</span>
+ </a>
+ {{/if}}
+</div>
+<div class="controls">
+ {{#if this.editing}}
+ <DButton
+ class="btn-default"
+ @action={{this.save}}
+ @label="admin.user_fields.save"
+ />
+ <a href {{on "click" this.edit}}>{{i18n "cancel"}}</a>
+ {{else}}
+ <DButton class="btn-default" @action={{this.edit}} @icon="pencil" />
+ {{/if}}
+</div>
diff --cc app/assets/javascripts/admin/addon/components/admin-form-row.gjs
index bfb67fec206,dcebfe7f9f9..ac7c480b24a
--- a/app/assets/javascripts/admin/addon/components/admin-form-row.gjs
+++ b/app/assets/javascripts/admin/addon/components/admin-form-row.gjs
@@@ -1,18 -1,5 +1,24 @@@
+ import Component from "@ember/component";
+ import { classNames } from "@ember-decorators/component";
+
+ @classNames("row")
+ export default class AdminFormRow extends Component {}
++
+<div class="form-element label-area">
+ {{#if this.label}}
+ <label
+ class={{concat-class (if (eq @type "checkbox") "checkbox-label")}}
+ >{{i18n this.label}}</label>
+ {{else}}
+ &nbsp;
+ {{/if}}
+</div>
+<div class="form-element input-area">
+ {{#if this.wrapLabel}}
+ <label
+ class={{concat-class (if (eq @type "checkbox") "checkbox-label")}}
+ >{{yield}}</label>
+ {{else}}
+ {{yield}}
+ {{/if}}
+</div>
diff --cc app/assets/javascripts/admin/addon/components/admin-penalty-history.gjs
index c890f7ed80e,3aeb825842d..e8b35cee033
--- a/app/assets/javascripts/admin/addon/components/admin-penalty-history.gjs
+++ b/app/assets/javascripts/admin/addon/components/admin-penalty-history.gjs
@@@ -1,14 -1,22 +1,37 @@@
+ import Component from "@ember/component";
+ import { classNames } from "@ember-decorators/component";
+ import discourseComputed from "discourse/lib/decorators";
+
+ @classNames("penalty-history")
+ export default class AdminPenaltyHistory extends Component {
+ @discourseComputed("user.penalty_counts.suspended")
+ suspendedCountClass(count) {
+ if (count > 0) {
+ return "danger";
+ }
+ return "";
+ }
+
+ @discourseComputed("user.penalty_counts.silenced")
+ silencedCountClass(count) {
+ if (count > 0) {
+ return "danger";
+ }
+ return "";
+ }
+ }
++
+<div
+ class="suspended-count {{this.suspendedCountClass}}"
+ title={{i18n "admin.user.last_six_months"}}
+>
+ <label>{{i18n "admin.user.suspended_count"}}</label>
+ <span>{{this.user.penalty_counts.suspended}}</span>
+</div>
+<div
+ class="silenced-count {{this.silencedCountClass}}"
+ title={{i18n "admin.user.last_six_months"}}
+>
+ <label>{{i18n "admin.user.silenced_count"}}</label>
+ <span>{{this.user.penalty_counts.silenced}}</span>
+</div>
diff --cc app/assets/javascripts/admin/addon/components/admin-penalty-post-action.gjs
index 4c7832d73f0,07afb0686bc..fd78e9a7c62
--- a/app/assets/javascripts/admin/addon/components/admin-penalty-post-action.gjs
+++ b/app/assets/javascripts/admin/addon/components/admin-penalty-post-action.gjs
@@@ -1,18 -1,40 +1,59 @@@
+ import Component from "@ember/component";
+ import { action } from "@ember/object";
+ import { equal } from "@ember/object/computed";
+ import discourseComputed, { afterRender } from "discourse/lib/decorators";
+ import { i18n } from "discourse-i18n";
+
+ const ACTIONS = ["delete", "delete_replies", "edit", "none"];
+
+ export default class AdminPenaltyPostAction extends Component {
+ postId = null;
+ postAction = null;
+ postEdit = null;
+
+ @equal("postAction", "edit") editing;
+
+ @discourseComputed
+ penaltyActions() {
+ return ACTIONS.map((id) => {
+ return { id, name: i18n(`admin.user.penalty_post_${id}`) };
+ });
+ }
+
+ @action
+ penaltyChanged(postAction) {
+ this.set("postAction", postAction);
+
+ // If we switch to edit mode, jump to the edit textarea
+ if (postAction === "edit") {
+ this._focusEditTextarea();
+ }
+ }
+
+ @afterRender
+ _focusEditTextarea() {
+ const elem = this.element;
+ const body = elem.closest(".d-modal__body");
+ body.scrollTo(0, body.clientHeight);
+ elem.querySelector(".post-editor").focus();
+ }
+ }
++
+<div class="penalty-post-controls">
+ <label>
+ <div class="penalty-post-label">
+ {{html-safe (i18n "admin.user.penalty_post_actions")}}
+ </div>
+ </label>
+ <ComboBox
+ @value={{this.postAction}}
+ @content={{this.penaltyActions}}
+ @onChange={{this.penaltyChanged}}
+ />
+</div>
+
+{{#if this.editing}}
+ <div class="penalty-post-edit">
+ <Textarea @value={{this.postEdit}} class="post-editor" />
+ </div>
+{{/if}}
diff --cc app/assets/javascripts/admin/addon/components/admin-penalty-reason.gjs
index 204de3deef0,eaf589a95c6..16cadb34b9d
--- a/app/assets/javascripts/admin/addon/components/admin-penalty-reason.gjs
+++ b/app/assets/javascripts/admin/addon/components/admin-penalty-reason.gjs
@@@ -1,49 -1,55 +1,105 @@@
+ import Component from "@ember/component";
+ import { action } from "@ember/object";
+ import { equal } from "@ember/object/computed";
+ import { tagName } from "@ember-decorators/component";
+ import discourseComputed from "discourse/lib/decorators";
+ import { i18n } from "discourse-i18n";
+
+ const CUSTOM_REASON_KEY = "custom";
+
+ @tagName("")
+ export default class AdminPenaltyReason extends Component {
+ selectedReason = CUSTOM_REASON_KEY;
+ customReason = "";
+
+ reasonKeys = [
+ "not_listening_to_staff",
+ "consuming_staff_time",
+ "combative",
+ "in_wrong_place",
+ "no_constructive_purpose",
+ CUSTOM_REASON_KEY,
+ ];
+
+ @equal("selectedReason", CUSTOM_REASON_KEY) isCustomReason;
+
+ @discourseComputed("reasonKeys")
+ reasons(keys) {
+ return keys.map((key) => {
+ return { id: key, name: i18n(`admin.user.suspend_reasons.${key}`) };
+ });
+ }
+
+ @action
+ setSelectedReason(value) {
+ this.set("selectedReason", value);
+ this.setReason();
+ }
+
+ @action
+ setCustomReason(value) {
+ this.set("customReason", value);
+ this.setReason();
+ }
+
+ setReason() {
+ if (this.isCustomReason) {
+ this.set("reason", this.customReason);
+ } else {
+ this.set(
+ "reason",
+ i18n(`admin.user.suspend_reasons.${this.selectedReason}`)
+ );
+ }
+ }
+ }
++
+<div class="penalty-reason-controls">
+ {{#if (eq @penaltyType "suspend")}}
+ <label class="suspend-reason-title">{{i18n
+ "admin.user.suspend_reason_title"
+ }}</label>
+ <ComboBox
+ @content={{this.reasons}}
+ @value={{this.selectedReason}}
+ @onChange={{this.setSelectedReason}}
+ class="suspend-reason"
+ />
+
+ {{#if this.isCustomReason}}
+ <TextField
+ @value={{this.customReason}}
+ @onChange={{this.setCustomReason}}
+ class="suspend-reason"
+ />
+ {{/if}}
+ {{else if (eq @penaltyType "silence")}}
+ <label class="silence-reason-title">
+ {{html-safe (i18n "admin.user.silence_reason_label")}}</label>
+
+ <ComboBox
+ @content={{this.reasons}}
+ @value={{this.selectedReason}}
+ @onChange={{this.setSelectedReason}}
+ class="silence-reason"
+ />
+
+ {{#if this.isCustomReason}}
+ <TextField
+ @value={{this.customReason}}
+ @onChange={{this.setCustomReason}}
+ @placeholderKey="admin.user.silence_reason_placeholder"
+ class="silence-reason"
+ />
+ {{/if}}
+ {{/if}}
+</div>
+
+<div class="penalty-message-controls">
+ <label>{{i18n "admin.user.suspend_message"}}</label>
+ <Textarea
+ @value={{this.message}}
+ class="suspend-message"
+ placeholder={{i18n "admin.user.suspend_message_placeholder"}}
+ />
+</div>
diff --cc app/assets/javascripts/admin/addon/components/admin-penalty-similar-users.gjs
index 134412666a7,adaa615cf0f..184afbcebc2
--- a/app/assets/javascripts/admin/addon/components/admin-penalty-similar-users.gjs
+++ b/app/assets/javascripts/admin/addon/components/admin-penalty-similar-users.gjs
@@@ -1,46 -1,48 +1,95 @@@
+ import Component from "@glimmer/component";
+ import { tracked } from "@glimmer/tracking";
+ import { action } from "@ember/object";
+ import { ajax } from "discourse/lib/ajax";
+
+ export default class AdminPenaltySimilarUsers extends Component {
+ @tracked isLoading;
+ @tracked similarUsers = [];
+ selectedUserIds = [];
+
+ constructor() {
+ super(...arguments);
+
+ this.loadSimilarUsers();
+ }
+
+ get penaltyField() {
+ const penaltyType = this.args.penaltyType;
+ if (penaltyType === "suspend") {
+ return "can_be_suspended";
+ } else if (penaltyType === "silence") {
+ return "can_be_silenced";
+ }
+ }
+
+ async loadSimilarUsers() {
+ this.isLoading = true;
+ try {
+ const data = await ajax(
+ `/admin/users/${this.args.user.id}/similar-users.json`
+ );
+ this.similarUsers = data.users;
+ } finally {
+ this.isLoading = false;
+ }
+ }
+
+ @action
+ selectUserId(userId, event) {
+ if (event.target.checked) {
+ this.selectedUserIds.push(userId);
+ } else {
+ this.selectedUserIds = this.selectedUserIds.filter((id) => id !== userId);
+ }
+
+ this.args.onUsersChanged(this.selectedUserIds);
+ }
+ }
++
+<div class="penalty-similar-users">
+ <p class="alert alert-warning">
+ {{html-safe
+ (i18n
+ "admin.user.other_matches"
+ )
+ }}
+ </p>
+
+ <ConditionalLoadingSpinner @condition={{this.isLoading}}>
+ <table class="table">
+ <thead>
+ <tr>
+ <th></th>
+ <th>{{i18n "username"}}</th>
+ <th>{{i18n "last_seen"}}</th>
+ <th>{{i18n "admin.user.topics_entered"}}</th>
+ <th>{{i18n "admin.user.posts_read_count"}}</th>
+ <th>{{i18n "admin.user.time_read"}}</th>
+ <th>{{i18n "created"}}</th>
+ </tr>
+ </thead>
+
+ <tbody>
+ {{#each this.similarUsers as |user|}}
+ <tr>
+ <td>
+ <Input
+ @type="checkbox"
+ disabled={{not (get user this.penaltyField)}}
+ {{on "click" (fn this.selectUserId user.id)}}
+ />
+ </td>
+ <td>{{avatar user imageSize="small"}} {{user.username}}</td>
+ <td>{{format-duration user.last_seen_age}}</td>
+ <td>{{number user.topics_entered}}</td>
+ <td>{{number user.posts_read_count}}</td>
+ <td>{{format-duration user.time_read}}</td>
+ <td>{{format-duration user.created_at_age}}</td>
+ </tr>
+ {{/each}}
+ </tbody>
+ </table>
+ </ConditionalLoadingSpinner>
+</div>
diff --cc app/assets/javascripts/admin/addon/components/admin-report-counters.gjs
index 38add83626a,29d42a40204..7bab1ddf04b
--- a/app/assets/javascripts/admin/addon/components/admin-report-counters.gjs
+++ b/app/assets/javascripts/admin/addon/components/admin-report-counters.gjs
@@@ -1,35 -1,6 +1,42 @@@
+ import Component from "@ember/component";
+ import { attributeBindings, classNames } from "@ember-decorators/component";
+
+ @classNames("admin-report-counters")
+ @attributeBindings("model.description:title")
+ export default class AdminReportCounters extends Component {}
++
+<div class="cell title">
+ {{#if this.model.icon}}
+ {{d-icon this.model.icon}}
+ {{/if}}
+ <a href={{this.model.reportUrl}}>{{this.model.title}}</a>
+</div>
+
+<div class="cell value today-count">{{number this.model.todayCount}}</div>
+
+<div
+ class="cell value yesterday-count {{this.model.yesterdayTrend}}"
+ title={{this.model.yesterdayCountTitle}}
+>
+ {{number this.model.yesterdayCount}}
+ {{d-icon this.model.yesterdayTrendIcon}}
+</div>
+
+<div
+ class="cell value sevendays-count {{this.model.sevenDaysTrend}}"
+ title={{this.model.sevenDaysCountTitle}}
+>
+ {{number this.model.lastSevenDaysCount}}
+ {{d-icon this.model.sevenDaysTrendIcon}}
+</div>
+
+<div
+ class="cell value thirty-days-count {{this.model.thirtyDaysTrend}}"
+ title={{this.model.thirtyDaysCountTitle}}
+>
+ {{number this.model.lastThirtyDaysCount}}
+
+ {{#if this.model.canDisplayTrendIcon}}
+ {{d-icon this.model.thirtyDaysTrendIcon}}
+ {{/if}}
+</div>
diff --cc app/assets/javascripts/admin/addon/components/admin-report-inline-table.gjs
index 7562612b9e9,c1919679b97..8ae2b0483c9
--- a/app/assets/javascripts/admin/addon/components/admin-report-inline-table.gjs
+++ b/app/assets/javascripts/admin/addon/components/admin-report-inline-table.gjs
@@@ -1,15 -1,5 +1,21 @@@
+ import Component from "@ember/component";
+ import { classNames } from "@ember-decorators/component";
+
+ @classNames("admin-report-inline-table")
+ export default class AdminReportInlineTable extends Component {}
++
+<div class="table-container">
+ {{#each this.model.data as |data|}}
+ <a class="table-cell user-{{data.key}}" href={{data.url}}>
+ <span class="label">
+ {{#if data.icon}}
+ {{d-icon data.icon}}
+ {{/if}}
+ {{data.x}}
+ </span>
+ <span class="value">
+ {{number data.y}}
+ </span>
+ </a>
+ {{/each}}
+</div>
diff --cc app/assets/javascripts/admin/addon/components/admin-report-storage-stats.gjs
index eb885e4ff47,33301aa4b9a..b5cf42615dd
--- a/app/assets/javascripts/admin/addon/components/admin-report-storage-stats.gjs
+++ b/app/assets/javascripts/admin/addon/components/admin-report-storage-stats.gjs
@@@ -1,54 -1,45 +1,100 @@@
+ import Component from "@ember/component";
+ import { alias } from "@ember/object/computed";
+ import { classNames } from "@ember-decorators/component";
+ import { setting } from "discourse/lib/computed";
+ import discourseComputed from "discourse/lib/decorators";
+ import I18n, { i18n } from "discourse-i18n";
+
+ @classNames("admin-report-storage-stats")
+ export default class AdminReportStorageStats extends Component {
+ @setting("backup_location") backupLocation;
+
+ @alias("model.data.backups") backupStats;
+
+ @alias("model.data.uploads") uploadStats;
+
+ @discourseComputed("backupStats")
+ showBackupStats(stats) {
+ return stats && this.currentUser.admin;
+ }
+
+ @discourseComputed("backupLocation")
+ backupLocationName(backupLocation) {
+ return i18n(`admin.backups.location.${backupLocation}`);
+ }
+
+ @discourseComputed("backupStats.used_bytes")
+ usedBackupSpace(bytes) {
+ return I18n.toHumanSize(bytes);
+ }
+
+ @discourseComputed("backupStats.free_bytes")
+ freeBackupSpace(bytes) {
+ return I18n.toHumanSize(bytes);
+ }
+
+ @discourseComputed("uploadStats.used_bytes")
+ usedUploadSpace(bytes) {
+ return I18n.toHumanSize(bytes);
+ }
+
+ @discourseComputed("uploadStats.free_bytes")
+ freeUploadSpace(bytes) {
+ return I18n.toHumanSize(bytes);
+ }
+ }
++
+{{#if this.showBackupStats}}
+ <div class="backups">
+ <h3 class="storage-stats-title">
+ <a href={{get-url "/admin/backups"}}>{{d-icon "box-archive"}}
+ {{i18n "admin.dashboard.backups"}}</a>
+ </h3>
+ <p>
+ {{#if this.backupStats.free_bytes}}
+ {{i18n
+ "admin.dashboard.space_used_and_free"
+ usedSize=this.usedBackupSpace
+ freeSize=this.freeBackupSpace
+ }}
+ {{else}}
+ {{i18n "admin.dashboard.space_used" usedSize=this.usedBackupSpace}}
+ {{/if}}
+
+ <br />
+ {{i18n
+ "admin.dashboard.backup_count"
+ count=this.backupStats.count
+ location=this.backupLocationName
+ }}
+
+ {{#if this.backupStats.last_backup_taken_at}}
+ <br />
+ {{html-safe
+ (i18n
+ "admin.dashboard.lastest_backup"
+ date=(format-date
+ this.backupStats.last_backup_taken_at leaveAgo="true"
+ )
+ )
+ }}
+ {{/if}}
+ </p>
+ </div>
+{{/if}}
+
+<div class="uploads">
+ <h3 class="storage-stats-title">{{d-icon "upload"}}
+ {{i18n "admin.dashboard.uploads"}}</h3>
+ <p>
+ {{#if this.uploadStats.free_bytes}}
+ {{i18n
+ "admin.dashboard.space_used_and_free"
+ usedSize=this.usedUploadSpace
+ freeSize=this.freeUploadSpace
+ }}
+ {{else}}
+ {{i18n "admin.dashboard.space_used" usedSize=this.usedUploadSpace}}
+ {{/if}}
+ </p>
+</div>
diff --cc app/assets/javascripts/admin/addon/components/admin-report-table-cell.gjs
index e3be60948e0,6ff59249eb9..87d93aae442
--- a/app/assets/javascripts/admin/addon/components/admin-report-table-cell.gjs
+++ b/app/assets/javascripts/admin/addon/components/admin-report-table-cell.gjs
@@@ -1,1 -1,27 +1,29 @@@
+ import Component from "@ember/component";
+ import { alias } from "@ember/object/computed";
+ import {
+ attributeBindings,
+ classNameBindings,
+ classNames,
+ tagName,
+ } from "@ember-decorators/component";
+ import discourseComputed from "discourse/lib/decorators";
+
+ @tagName("td")
+ @classNames("admin-report-table-cell")
+ @classNameBindings("type", "property")
+ @attributeBindings("value:title")
+ export default class AdminReportTableCell extends Component {
+ options = null;
+
+ @alias("label.type") type;
+ @alias("label.mainProperty") property;
+ @alias("computedLabel.formattedValue") formattedValue;
+ @alias("computedLabel.value") value;
+
+ @discourseComputed("label", "data", "options")
+ computedLabel(label, data, options) {
+ return label.compute(data, options || {});
+ }
+ }
++
+{{html-safe this.formattedValue}}
diff --cc app/assets/javascripts/admin/addon/components/admin-report-table-header.gjs
index 2665d64ad23,7c8b5ce2238..606a0ffadc8
--- a/app/assets/javascripts/admin/addon/components/admin-report-table-header.gjs
+++ b/app/assets/javascripts/admin/addon/components/admin-report-table-header.gjs
@@@ -1,13 -1,24 +1,38 @@@
+ import Component from "@ember/component";
+ import {
+ attributeBindings,
+ classNameBindings,
+ classNames,
+ tagName,
+ } from "@ember-decorators/component";
+ import discourseComputed from "discourse/lib/decorators";
+
+ @tagName("th")
+ @classNames("admin-report-table-header")
+ @classNameBindings("label.mainProperty", "label.type", "isCurrentSort")
+ @attributeBindings("label.title:title")
+ export default class AdminReportTableHeader extends Component {
+ @discourseComputed("currentSortLabel.sortProperty", "label.sortProperty")
+ isCurrentSort(currentSortField, labelSortField) {
+ return currentSortField === labelSortField;
+ }
+
+ @discourseComputed("currentSortDirection")
+ sortIcon(currentSortDirection) {
+ return currentSortDirection === 1 ? "caret-up" : "caret-down";
+ }
+ }
++
+{{#if this.showSortingUI}}
+ <DButton
+ @action={{this.sortByLabel}}
+ @icon={{this.sortIcon}}
+ class="sort-btn"
+ />
+{{/if}}
+
+{{#if this.label.htmlTitle}}
+ <span class="title">{{html-safe this.label.htmlTitle}}</span>
+{{else}}
+ <span class="title">{{this.label.title}}</span>
+{{/if}}
diff --cc app/assets/javascripts/admin/addon/components/admin-report-table-row.gjs
index 6f4d792238c,53b56a1b1c6..dbd6cf4cad5
--- a/app/assets/javascripts/admin/addon/components/admin-report-table-row.gjs
+++ b/app/assets/javascripts/admin/addon/components/admin-report-table-row.gjs
@@@ -1,7 -1,8 +1,16 @@@
+ import Component from "@ember/component";
+ import { classNames, tagName } from "@ember-decorators/component";
+
+ @tagName("tr")
+ @classNames("admin-report-table-row")
+ export default class AdminReportTableRow extends Component {
+ options = null;
+ }
++
+{{#each this.labels as |label|}}
+ <AdminReportTableCell
+ @label={{label}}
+ @data={{this.data}}
+ @options={{this.options}}
+ />
+{{/each}}
diff --cc app/assets/javascripts/admin/addon/components/admin-report-table.gjs
index 5d44272690f,b0dcc672890..2d5e907a20f
--- a/app/assets/javascripts/admin/addon/components/admin-report-table.gjs
+++ b/app/assets/javascripts/admin/addon/components/admin-report-table.gjs
@@@ -1,83 -1,186 +1,270 @@@
+ import Component from "@ember/component";
+ import { action } from "@ember/object";
+ import { alias } from "@ember/object/computed";
+ import { classNameBindings, classNames } from "@ember-decorators/component";
+ import discourseComputed from "discourse/lib/decorators";
+ import { makeArray } from "discourse/lib/helpers";
+
+ const PAGES_LIMIT = 8;
+
+ @classNameBindings("sortable", "twoColumns")
+ @classNames("admin-report-table")
+ export default class AdminReportTable extends Component {
+ sortable = false;
+ sortDirection = 1;
+
+ @alias("options.perPage") perPage;
+
+ page = 0;
+
+ @discourseComputed("model.computedLabels.length")
+ twoColumns(labelsLength) {
+ return labelsLength === 2;
+ }
+
+ @discourseComputed(
+ "totalsForSample",
+ "options.total",
+ "model.dates_filtering"
+ )
+ showTotalForSample(totalsForSample, total, datesFiltering) {
+ // check if we have at least one cell which contains a value
+ const sum = totalsForSample
+ .map((t) => t.value)
+ .compact()
+ .reduce((s, v) => s + v, 0);
+
+ return sum >= 1 && total && datesFiltering;
+ }
+
+ @discourseComputed("model.total", "options.total", "twoColumns")
+ showTotal(reportTotal, total, twoColumns) {
+ return reportTotal && total && twoColumns;
+ }
+
+ @discourseComputed(
+ "model.{average,data}",
+ "totalsForSample.1.value",
+ "twoColumns"
+ )
+ showAverage(model, sampleTotalValue, hasTwoColumns) {
+ return (
+ model.average &&
+ model.data.length > 0 &&
+ sampleTotalValue &&
+ hasTwoColumns
+ );
+ }
+
+ @discourseComputed("totalsForSample.1.value", "model.data.length")
+ averageForSample(totals, count) {
+ const averageLabel = this.model.computedLabels.at(-1);
+ return averageLabel.compute({ y: (totals / count).toFixed(0) })
+ .formattedValue;
+ }
+
+ @discourseComputed("model.data.length")
+ showSortingUI(dataLength) {
+ return dataLength >= 5;
+ }
+
+ @discourseComputed("totalsForSampleRow", "model.computedLabels")
+ totalsForSample(row, labels) {
+ return labels.map((label) => {
+ const computedLabel = label.compute(row);
+ computedLabel.type = label.type;
+ computedLabel.property = label.mainProperty;
+ return computedLabel;
+ });
+ }
+
+ @discourseComputed("model.total", "model.computedLabels")
+ formattedTotal(total, labels) {
+ const totalLabel = labels.at(-1);
+ return totalLabel.compute({ y: total }).formattedValue;
+ }
+
+ @discourseComputed("model.data", "model.computedLabels")
+ totalsForSampleRow(rows, labels) {
+ if (!rows || !rows.length) {
+ return {};
+ }
+
+ let totalsRow = {};
+
+ labels.forEach((label) => {
+ const reducer = (sum, row) => {
+ const computedLabel = label.compute(row);
+ const value = computedLabel.value;
+
+ if (!["seconds", "number", "percent"].includes(label.type)) {
+ return;
+ } else {
+ return sum + Math.round(value || 0);
+ }
+ };
+
+ const total = rows.reduce(reducer, 0);
+ totalsRow[label.mainProperty] =
+ label.type === "percent" ? Math.round(total / rows.length) : total;
+ });
+
+ return totalsRow;
+ }
+
+ @discourseComputed("sortLabel", "sortDirection", "model.data.[]")
+ sortedData(sortLabel, sortDirection, data) {
+ data = makeArray(data);
+
+ if (sortLabel) {
+ const compare = (label, direction) => {
+ return (a, b) => {
+ const aValue = label.compute(a, { useSortProperty: true }).value;
+ const bValue = label.compute(b, { useSortProperty: true }).value;
+ const result = aValue < bValue ? -1 : aValue > bValue ? 1 : 0;
+ return result * direction;
+ };
+ };
+
+ return data.sort(compare(sortLabel, sortDirection));
+ }
+
+ return data;
+ }
+
+ @discourseComputed("sortedData.[]", "perPage", "page")
+ paginatedData(data, perPage, page) {
+ if (perPage < data.length) {
+ const start = perPage * page;
+ return data.slice(start, start + perPage);
+ }
+
+ return data;
+ }
+
+ @discourseComputed("model.data", "perPage", "page")
+ pages(data, perPage, page) {
+ if (!data || data.length <= perPage) {
+ return [];
+ }
+
+ const pagesIndexes = [];
+ for (let i = 0; i < Math.ceil(data.length / perPage); i++) {
+ pagesIndexes.push(i);
+ }
+
+ let pages = pagesIndexes.map((v) => {
+ return {
+ page: v + 1,
+ index: v,
+ class: v === page ? "is-current" : null,
+ };
+ });
+
+ if (pages.length > PAGES_LIMIT) {
+ const before = Math.max(0, page - PAGES_LIMIT / 2);
+ const after = Math.max(PAGES_LIMIT, page + PAGES_LIMIT / 2);
+ pages = pages.slice(before, after);
+ }
+
+ return pages;
+ }
+
+ @action
+ changePage(page) {
+ this.set("page", page);
+ }
+
+ @action
+ sortByLabel(label) {
+ if (this.sortLabel === label) {
+ this.set("sortDirection", this.sortDirection === 1 ? -1 : 1);
+ } else {
+ this.set("sortLabel", label);
+ }
+ }
+ }
++
+<table class="table">
+ <thead>
+ <tr>
+ {{#if this.model.computedLabels}}
+ {{#each this.model.computedLabels as |label|}}
+ <AdminReportTableHeader
+ @showSortingUI={{this.showSortingUI}}
+ @currentSortDirection={{this.sortDirection}}
+ @currentSortLabel={{this.sortLabel}}
+ @label={{label}}
+ @sortByLabel={{fn this.sortByLabel label}}
+ />
+ {{/each}}
+ {{else}}
+ {{#each this.model.data as |data|}}
+ <th>{{data.x}}</th>
+ {{/each}}
+ {{/if}}
+ </tr>
+ </thead>
+ <tbody>
+ {{#each this.paginatedData as |data|}}
+ <AdminReportTableRow
+ @data={{data}}
+ @labels={{this.model.computedLabels}}
+ @options={{this.options}}
+ />
+ {{/each}}
+
+ {{#if this.showTotalForSample}}
+ <tr class="total-row">
+ <td colspan={{this.totalsForSample.length}}>
+ {{i18n "admin.dashboard.reports.totals_for_sample"}}
+ </td>
+ </tr>
+ <tr class="admin-report-table-row">
+ {{#each this.totalsForSample as |total|}}
+ <td class="admin-report-table-cell {{total.type}} {{total.property}}">
+ {{total.formattedValue}}
+ </td>
+ {{/each}}
+ </tr>
+ {{/if}}
+
+ {{#if this.showTotal}}
+ <tr class="total-row">
+ <td colspan="2">
+ {{i18n "admin.dashboard.reports.total"}}
+ </td>
+ </tr>
+ <tr class="admin-report-table-row">
+ <td class="admin-report-table-cell date x">—</td>
+ <td
+ class="admin-report-table-cell number y"
+ >{{this.formattedTotal}}</td>
+ </tr>
+ {{/if}}
+
+ {{#if this.showAverage}}
+ <tr class="total-row">
+ <td colspan="2">
+ {{i18n "admin.dashboard.reports.average_for_sample"}}
+ </td>
+ </tr>
+ <tr class="admin-report-table-row">
+ <td class="admin-report-table-cell date x">—</td>
+ <td
+ class="admin-report-table-cell number y"
+ >{{this.averageForSample}}</td>
+ </tr>
+ {{/if}}
+ </tbody>
+</table>
+
+<div class="pagination">
+ {{#each this.pages as |pageState|}}
+ <DButton
+ @translatedLabel={{pageState.page}}
+ @action={{fn this.changePage pageState.index}}
+ class={{pageState.class}}
+ />
+ {{/each}}
+</div>
diff --cc app/assets/javascripts/admin/addon/components/admin-theme-editor.gjs
index 410ab1397f5,e9a3b3cd583..99ace1f24c8
--- a/app/assets/javascripts/admin/addon/components/admin-theme-editor.gjs
+++ b/app/assets/javascripts/admin/addon/components/admin-theme-editor.gjs
@@@ -1,97 -1,157 +1,255 @@@
+ import { tracked } from "@glimmer/tracking";
+ import Component from "@ember/component";
+ import { action, computed } from "@ember/object";
+ import { next } from "@ember/runloop";
+ import { service } from "@ember/service";
+ import { fmt } from "discourse/lib/computed";
+ import discourseComputed from "discourse/lib/decorators";
+ import { isDocumentRTL } from "discourse/lib/text-direction";
+ import { i18n } from "discourse-i18n";
+
+ const JS_DEFAULT_VALUE = `import { apiInitializer } from "discourse/lib/api";
+
+ export default apiInitializer((api) => {
+ // Your code here
+ });
+ `;
+
+ const ADVANCED_TARGETS = ["desktop", "mobile"];
+
+ const ADVANCED_FIELDS = [
+ "embedded_scss",
+ "embedded_header",
+ "color_definitions",
+ "body_tag",
+ ];
+
+ export default class AdminThemeEditor extends Component {
+ @service router;
+
+ @tracked showAdvanced;
+ @tracked onlyOverridden;
+ @tracked currentTargetName;
+
+ warning = null;
+
+ @fmt("fieldName", "currentTargetName", "%@|%@") editorId;
+
+ get visibleTargets() {
+ return this.theme.targets.filter((target) => {
+ if (target.edited) {
+ return true;
+ }
+ if (!this.showAdvanced && ADVANCED_TARGETS.includes(target.name)) {
+ return false;
+ }
+ if (!this.onlyOverridden) {
+ return true;
+ }
+ });
+ }
+
+ get visibleFields() {
+ let fields = this.theme.fields[this.currentTargetName];
+ if (this.onlyOverridden) {
+ fields = fields.filter((field) => field.edited);
+ }
+ if (!this.showAdvanced) {
+ fields = fields.filter(
+ (field) => field.edited || !ADVANCED_FIELDS.includes(field.name)
+ );
+ }
+ return fields;
+ }
+
+ get currentField() {
+ return this.theme.fields[this.currentTargetName].find(
+ (field) => field.name === this.fieldName
+ );
+ }
+
+ @discourseComputed("currentTargetName", "fieldName")
+ activeSectionMode(targetName, fieldName) {
+ if (fieldName === "color_definitions") {
+ return "scss";
+ }
+ if (fieldName === "js") {
+ return "javascript";
+ }
+ return fieldName && fieldName.includes("scss") ? "scss" : "html";
+ }
+
+ @discourseComputed("currentTargetName", "fieldName")
+ placeholder(targetName, fieldName) {
+ if (fieldName && fieldName === "color_definitions") {
+ const example =
+ ":root {\n" +
+ " --mytheme-tertiary-or-highlight: #{dark-light-choose($tertiary, $highlight)};\n" +
+ "}";
+
+ return i18n("admin.customize.theme.color_definitions.placeholder", {
+ example: isDocumentRTL() ? `<div dir="ltr">${example}</div>` : example,
+ });
+ }
+ return "";
+ }
+
+ @computed("fieldName", "currentTargetName", "theme")
+ get activeSection() {
+ const themeValue = this.theme.getField(
+ this.currentTargetName,
+ this.fieldName
+ );
+ if (!themeValue && this.fieldName === "js") {
+ return JS_DEFAULT_VALUE;
+ }
+ return themeValue;
+ }
+
+ set activeSection(value) {
+ if (this.fieldName === "js" && value === JS_DEFAULT_VALUE) {
+ value = "";
+ }
+ this.theme.setField(this.currentTargetName, this.fieldName, value);
+ }
+
+ @discourseComputed("maximized")
+ maximizeIcon(maximized) {
+ return maximized ? "discourse-compress" : "discourse-expand";
+ }
+
+ @discourseComputed(
+ "currentTargetName",
+ "fieldName",
+ )
+ error(target, fieldName) {
+ return this.theme.getError(target, fieldName);
+ }
+
+ @action
+ toggleMaximize(event) {
+ event?.preventDefault();
+ this.toggleProperty("maximized");
+ next(() => this.appEvents.trigger("ace:resize"));
+ }
+
+ @action
+ setWarning(message) {
+ this.set("warning", message);
+ }
+
+ @action
+ toggleShowAdvanced() {
+ this.showAdvanced = !this.showAdvanced;
+ if (
+ !this.visibleTargets.some((t) => t.name === this.currentTargetName) ||
+ !this.visibleFields.some((f) => f.name === this.fieldName)
+ ) {
+ this.router.replaceWith(
+ this.editRouteName,
+ this.theme.id,
+ this.visibleTargets[0].name,
+ this.visibleFields[0].name
+ );
+ }
+ }
+ }
++
+{{#if (gt this.visibleTargets.length 1)}}
+ <div class="edit-main-nav admin-controls">
+ <nav>
+ <ul class="nav nav-pills target">
+ {{#each this.visibleTargets as |target|}}
+ <li>
+ <LinkTo
+ @route={{this.editRouteName}}
+ @models={{array this.theme.id target.name this.fieldName}}
+ @replace={{true}}
+ title={{this.field.title}}
+ class={{if target.edited "edited" "blank"}}
+ >
+ {{#if target.error}}{{d-icon "triangle-exclamation"}}{{/if}}
+ {{#if target.icon}}{{d-icon target.icon}}{{/if}}
+ {{i18n (concat "admin.customize.theme." target.name)}}
+ </LinkTo>
+ </li>
+ {{/each}}
+ <li class="spacer"></li>
+ <li>
+ <label>
+ <Input
+ @type="checkbox"
+ @checked={{this.showAdvanced}}
+ {{on "click" this.toggleShowAdvanced}}
+ />
+ {{i18n "admin.customize.theme.show_advanced"}}
+ </label>
+ </li>
+ </ul>
+ </nav>
+ </div>
+{{/if}}
+
+<div class="admin-controls">
+ <nav>
+ <ul class="nav nav-pills fields">
+ {{#each this.visibleFields as |field|}}
+ <li>
+ <LinkTo
+ @route={{this.editRouteName}}
+ @models={{array this.theme.id this.currentTargetName field.name}}
+ @replace={{true}}
+ title={{field.title}}
+ class={{if field.edited "edited" "blank"}}
+ >
+ {{#if field.error}}{{d-icon "triangle-exclamation"}}{{/if}}
+ {{#if field.icon}}{{d-icon field.icon}}{{/if}}
+ {{field.translatedName}}
+ </LinkTo>
+ </li>
+ {{/each}}
+
+ <li class="spacer"></li>
+ <li>
+ {{#if (lte this.visibleTargets.length 1)}}
+ <label>
+ <Input
+ @type="checkbox"
+ @checked={{this.showAdvanced}}
+ {{on "click" this.toggleShowAdvanced}}
+ />
+ {{i18n "admin.customize.theme.show_advanced"}}
+ </label>
+ {{/if}}
+ <a href {{on "click" this.toggleMaximize}} class="no-text">
+ {{d-icon this.maximizeIcon}}
+ </a>
+ </li>
+ </ul>
+ </nav>
+</div>
+
+{{#if this.error}}
+ <pre class="field-error">{{this.error}}</pre>
+{{/if}}
+
+{{#if this.warning}}
+ <pre class="field-warning">{{html-safe this.warning}}</pre>
+{{/if}}
+
+<div class="field-info">
+ {{this.currentField.title}}
+</div>
+
+<AceEditor
+ @content={{this.activeSection}}
+ @onChange={{fn (mut this.activeSection)}}
+ @editorId={{this.editorId}}
+ @mode={{this.activeSectionMode}}
+ @autofocus="true"
+ @placeholder={{this.placeholder}}
+ @htmlPlaceholder={{true}}
+ @save={{this.save}}
+ @setWarning={{this.setWarning}}
+/>
diff --cc app/assets/javascripts/admin/addon/components/color-input.gjs
index dfb54a5e862,8067c6b156f..7664279d188
--- a/app/assets/javascripts/admin/addon/components/color-input.gjs
+++ b/app/assets/javascripts/admin/addon/components/color-input.gjs
@@@ -1,14 -1,74 +1,89 @@@
+ import Component from "@ember/component";
+ import { action, computed } from "@ember/object";
+ import { classNames } from "@ember-decorators/component";
+ import { observes } from "@ember-decorators/object";
+
+ /**
+ An input field for a color.
+
+ @param hexValue is a reference to the color's hex value.
+ @param brightnessValue is a number from 0 to 255 representing the brightness of the color. See ColorSchemeColor.
+ @params valid is a boolean indicating if the input field is a valid color.
+ **/
+ @classNames("color-picker")
+ export default class ColorInput extends Component {
+ onlyHex = true;
+ styleSelection = true;
+
+ @computed("onlyHex")
+ get maxlength() {
+ return this.onlyHex ? 6 : null;
+ }
+
+ @computed("hexValue")
+ get normalizedHexValue() {
+ return this.normalize(this.hexValue);
+ }
+
+ normalize(color) {
+ if (this._valid(color)) {
+ if (!color.startsWith("#")) {
+ color = "#" + color;
+ }
+ if (color.length === 4) {
+ color =
+ "#" +
+ color
+ .slice(1)
+ .split("")
+ .map((hex) => hex + hex)
+ .join("");
+ }
+ }
+ return color;
+ }
+
+ @action
+ onHexInput(event) {
+ if (this.onChangeColor) {
+ this.onChangeColor(this.normalize(event.target.value || ""));
+ }
+ }
+
+ @action
+ onPickerInput(event) {
+ this.set("hexValue", event.target.value.replace("#", ""));
+ }
+
+ @observes("hexValue", "brightnessValue", "valid")
+ hexValueChanged() {
+ const hex = this.hexValue;
+
+ if (this.onChangeColor) {
+ this.onChangeColor(this.normalize(hex));
+ }
+
+ if (this._valid()) {
+ this.element.querySelector(".picker").value = this.normalize(hex);
+ }
+ }
+
+ _valid(color = this.hexValue) {
+ return /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(color);
+ }
+ }
++
+{{#if this.onlyHex}}<span class="add-on">#</span>{{/if}}<TextField
+ @value={{this.hexValue}}
+ @maxlength={{this.maxlength}}
+ @input={{this.onHexInput}}
+ class="hex-input"
+ aria-labelledby={{this.ariaLabelledby}}
+/>
+<input
+ class="picker"
+ type="color"
+ value={{this.normalizedHexValue}}
+ {{on "input" this.onPickerInput}}
+ aria-labelledby={{this.ariaLabelledby}}
+/>
diff --cc app/assets/javascripts/admin/addon/components/email-styles-editor.gjs
index 152eca1bd2c,71ff2431f1f..4eb2789f20e
--- a/app/assets/javascripts/admin/addon/components/email-styles-editor.gjs
+++ b/app/assets/javascripts/admin/addon/components/email-styles-editor.gjs
@@@ -1,18 -1,50 +1,69 @@@
+ import Component from "@ember/component";
+ import { action, computed } from "@ember/object";
+ import { reads } from "@ember/object/computed";
+ import { service } from "@ember/service";
+ import discourseComputed from "discourse/lib/decorators";
+ import { i18n } from "discourse-i18n";
+
+ export default class EmailStylesEditor extends Component {
+ @service dialog;
+
+ @reads("fieldName") editorId;
+
+ @discourseComputed("fieldName")
+ currentEditorMode(fieldName) {
+ return fieldName === "css" ? "scss" : fieldName;
+ }
+
+ @discourseComputed("fieldName", "styles.html", "styles.css")
+ resetDisabled(fieldName) {
+ return (
+ this.get(`styles.${fieldName}`) ===
+ this.get(`styles.default_${fieldName}`)
+ );
+ }
+
+ @computed("styles", "fieldName")
+ get editorContents() {
+ return this.styles[this.fieldName];
+ }
+
+ set editorContents(value) {
+ this.styles.setField(this.fieldName, value);
+ }
+
+ @action
+ reset() {
+ this.dialog.yesNoConfirm({
+ message: i18n("admin.customize.email_style.reset_confirm", {
+ fieldName: i18n(`admin.customize.email_style.${this.fieldName}`),
+ }),
+ didConfirm: () => {
+ this.styles.setField(
+ this.fieldName,
+ this.styles.get(`default_${this.fieldName}`)
+ );
+ this.notifyPropertyChange("editorContents");
+ },
+ });
+ }
+ }
++
+<AceEditor
+ @content={{this.editorContents}}
+ @onChange={{fn (mut this.editorContents)}}
+ @mode={{this.currentEditorMode}}
+ @editorId={{this.editorId}}
+ @save={{@save}}
+/>
+
+<div class="admin-footer">
+ <div class="buttons">
+ <DButton
+ @action={{this.reset}}
+ @disabled={{this.resetDisabled}}
+ @label="admin.customize.email_style.reset"
+ class="btn-default"
+ />
+ </div>
+</div>
diff --cc app/assets/javascripts/admin/addon/components/emoji-uploader.gjs
index 65b9a0f67ef,06ae0b14189..7ffeba61c21
--- a/app/assets/javascripts/admin/addon/components/emoji-uploader.gjs
+++ b/app/assets/javascripts/admin/addon/components/emoji-uploader.gjs
@@@ -1,57 -1,92 +1,150 @@@
+ import Component from "@ember/component";
+ import { action } from "@ember/object";
+ import { notEmpty } from "@ember/object/computed";
+ import { getOwner } from "@ember/owner";
+ import { isEmpty } from "@ember/utils";
+ import discourseComputed from "discourse/lib/decorators";
+ import UppyUpload from "discourse/lib/uppy/uppy-upload";
+ import { i18n } from "discourse-i18n";
+
+ const DEFAULT_GROUP = "default";
+
+ export default class EmojiUploader extends Component {
+ uppyUpload = new UppyUpload(getOwner(this), {
+ id: "emoji-uploader",
+ type: "emoji",
+ uploadUrl: "/admin/config/emoji",
+ preventDirectS3Uploads: true,
+ validateUploadedFilesOptions: {
+ imagesOnly: true,
+ },
+
+ perFileData: () => {
+ const payload = {};
+
+ if (!isEmpty(this.name)) {
+ payload.name = this.name;
+
+ // if uploading multiple files, we can't use the name for every emoji
+ this.set("name", null);
+ }
+
+ if (!isEmpty(this.group) && this.group !== DEFAULT_GROUP) {
+ payload.group = this.group;
+ }
+
+ return payload;
+ },
+
+ uploadDone: (upload) => {
+ this.done(upload, this.group);
+ this.set("name", null);
+ },
+ });
+
+ @notEmpty("name") hasName;
+ @notEmpty("group") hasGroup;
+
+ group = "default";
+ emojiGroups = null;
+ newEmojiGroups = null;
+ tagName = null;
+
+ didReceiveAttrs() {
+ super.didReceiveAttrs(...arguments);
+ this.set("newEmojiGroups", this.emojiGroups);
+ }
+
+ @action
+ createEmojiGroup(group) {
+ let newEmojiGroups = this.newEmojiGroups;
+ if (group !== DEFAULT_GROUP) {
+ newEmojiGroups = this.emojiGroups.concat([group]).uniq();
+ }
+ this.setProperties({
+ newEmojiGroups,
+ group,
+ });
+ }
+
+ @action
+ chooseFiles() {
+ this.uppyUpload.openPicker();
+ }
+
+ @discourseComputed("uppyUpload.uploading", "uppyUpload.uploadProgress")
+ buttonLabel(uploading, uploadProgress) {
+ if (uploading) {
+ return `${i18n("admin.emoji.uploading")} ${uploadProgress}%`;
+ } else {
+ return i18n("admin.emoji.choose_files");
+ }
+ }
+
+ @discourseComputed("uppyUpload.uploading")
+ buttonIcon(uploading) {
+ if (uploading) {
+ return "spinner";
+ } else {
+ return "plus";
+ }
+ }
+ }
++
+<div class="form-kit">
+ <div class="form-kit__container form-kit__field form-kit__field-input-text">
+ <label class="form-kit__container-title">
+ {{i18n "admin.emoji.name"}}
+ </label>
+ <div class="form-kit__container-content --large">
+ <div class="form-kit__control-input-wrapper">
+ <Input
+ id="emoji-name"
+ class="form-kit__control-input"
+ name="name"
+ @value={{readonly this.name}}
+ {{on "input" (with-event-value (fn (mut this.name)))}}
+ />
+ </div>
+ </div>
+ </div>
+ <div
+ class="form-kit__container form-kit__field form-kit__field-input-combo-box"
+ >
+ <label class="form-kit__container-title">
+ {{i18n "admin.emoji.group"}}
+ </label>
+ <div class="form-kit__container-content --large">
+ <div class="form-kit__control-input-wrapper">
+ <ComboBox
+ @name="group"
+ @id="emoji-group-selector"
+ @value={{this.group}}
+ @content={{this.newEmojiGroups}}
+ @onChange={{action "createEmojiGroup"}}
+ @valueProperty={{null}}
+ @nameProperty={{null}}
+ @options={{hash allowAny=true}}
+ />
+ </div>
+ </div>
+ </div>
+ <div class="control-group">
+ <div class="input">
+ <input
+ {{did-insert this.uppyUpload.setup}}
+ class="hidden-upload-field"
+ disabled={{this.uppyUpload.uploading}}
+ type="file"
+ multiple="true"
+ accept=".png,.gif"
+ />
+ <DButton
+ @translatedLabel={{this.buttonLabel}}
+ @action={{this.chooseFiles}}
+ @disabled={{this.uppyUpload.uploading}}
+ class="btn-primary"
+ />
+ </div>
+ </div>
+</div>
diff --cc app/assets/javascripts/admin/addon/components/emoji-value-list.gjs
index 8ff5617bb87,44b08ceca57..6696a8f0c74
--- a/app/assets/javascripts/admin/addon/components/emoji-value-list.gjs
+++ b/app/assets/javascripts/admin/addon/components/emoji-value-list.gjs
@@@ -1,50 -1,163 +1,214 @@@
+ import Component from "@ember/component";
+ import { action, set, setProperties } from "@ember/object";
+ import { schedule } from "@ember/runloop";
+ import { service } from "@ember/service";
+ import { classNameBindings } from "@ember-decorators/component";
+ import EmojiPickerDetached from "discourse/components/emoji-picker/detached";
+ import discourseComputed from "discourse/lib/decorators";
+ import { emojiUrlFor } from "discourse/lib/text";
+ import { i18n } from "discourse-i18n";
+
+ @classNameBindings(":value-list", ":emoji-list")
+ export default class EmojiValueList extends Component {
+ @service menu;
+
+ values = null;
+
+ @discourseComputed("values")
+ collection(values) {
+ values = values || "";
+
+ return values
+ .split("|")
+ .filter(Boolean)
+ .map((value) => {
+ return {
+ isEditable: true,
+ isEditing: false,
+ value,
+ emojiUrl: emojiUrlFor(value),
+ };
+ });
+ }
+
+ @action
+ emojiSelected(code) {
+ if (!this._validateInput(code)) {
+ return;
+ }
+
+ const item = this.collection.findBy("isEditing");
+ if (item) {
+ setProperties(item, {
+ value: code,
+ emojiUrl: emojiUrlFor(code),
+ isEditing: false,
+ });
+
+ this._saveValues();
+ } else {
+ const newCollectionValue = {
+ value: code,
+ emojiUrl: emojiUrlFor(code),
+ isEditable: true,
+ isEditing: false,
+ };
+ this.collection.addObject(newCollectionValue);
+ this._saveValues();
+ }
+ }
+
+ @discourseComputed("collection")
+ showUpDownButtons(collection) {
+ return collection.length - 1 ? true : false;
+ }
+
+ _splitValues(values) {
+ if (values && values.length) {
+ const emojiList = [];
+ const emojis = values.split("|").filter(Boolean);
+ emojis.forEach((emojiName) => {
+ const emoji = {
+ isEditable: true,
+ isEditing: false,
+ };
+ emoji.value = emojiName;
+ emoji.emojiUrl = emojiUrlFor(emojiName);
+
+ emojiList.push(emoji);
+ });
+
+ return emojiList;
+ } else {
+ return [];
+ }
+ }
+
+ @action
+ editValue(index, event) {
+ schedule("afterRender", () => {
+ if (parseInt(index, 10) >= 0) {
+ const item = this.collection[index];
+ if (item.isEditable) {
+ set(item, "isEditing", true);
+ }
+ }
+
+ this.menu.show(event.target, {
+ identifier: "emoji-picker",
+ groupIdentifier: "emoji-picker",
+ component: EmojiPickerDetached,
+ modalForMobile: true,
+ data: {
+ context: "chat",
+ didSelectEmoji: (emoji) => {
+ this._replaceValue(index, emoji);
+ },
+ },
+ });
+ });
+ }
+
+ @action
+ removeValue(value) {
+ this._removeValue(value);
+ }
+
+ @action
+ shift(operation, index) {
+ let futureIndex = index + operation;
+
+ if (futureIndex > this.collection.length - 1) {
+ futureIndex = 0;
+ } else if (futureIndex < 0) {
+ futureIndex = this.collection.length - 1;
+ }
+
+ const shiftedEmoji = this.collection[index];
+ this.collection.removeAt(index);
+ this.collection.insertAt(futureIndex, shiftedEmoji);
+
+ this._saveValues();
+ }
+
+ _validateInput(input) {
+ if (!emojiUrlFor(input)) {
+ this.setValidationMessage(
+ i18n("admin.site_settings.emoji_list.invalid_input")
+ );
+ return false;
+ }
+
+ this.setValidationMessage(null);
+ return true;
+ }
+
+ _removeValue(value) {
+ this.collection.removeObject(value);
+ this._saveValues();
+ }
+
+ _replaceValue(index, newValue) {
+ const item = this.collection[index];
+ if (item.value === newValue) {
+ return;
+ }
+ set(item, "value", newValue);
+ this._saveValues();
+ }
+
+ _saveValues() {
+ this.set("values", this.collection.mapBy("value").join("|"));
+ }
+ }
++
+{{#if this.collection}}
+ <ul class="values emoji-value-list">
+ {{#each this.collection as |data index|}}
+ <li class="value" data-index={{index}}>
+ <DButton
+ @action={{fn this.removeValue data}}
+ @icon="xmark"
+ @disabled={{not data.isEditable}}
+ class="btn-default remove-value-btn btn-small"
+ />
+
+ <div
+ class="value-input emoji-details
+ {{if data.isEditable 'can-edit'}}
+ {{if data.isEditing 'd-editor-textarea-wrapper'}}"
+ {{on "click" (fn this.editValue index)}}
+ role="button"
+ >
+ <img
+ height="15px"
+ width="15px"
+ src={{data.emojiUrl}}
+ class="emoji-list-emoji"
+ />
+ <span class="emoji-name">{{data.value}}</span>
+ </div>
+
+ {{#if this.showUpDownButtons}}
+ <DButton
+ @action={{fn this.shift -1 index}}
+ @icon="arrow-up"
+ class="btn-default shift-up-value-btn btn-small"
+ />
+ <DButton
+ @action={{fn this.shift 1 index}}
+ @icon="arrow-down"
+ class="btn-default shift-down-value-btn btn-small"
+ />
+ {{/if}}
+ </li>
+ {{/each}}
+ </ul>
+{{/if}}
+
+<div class="value">
+ <EmojiPicker
+ @label={{i18n "admin.site_settings.emoji_list.add_emoji_button.label"}}
+ @didSelectEmoji={{this.emojiSelected}}
+ />
+</div>
diff --cc app/assets/javascripts/admin/addon/components/flag-user-lists.gjs
index 06f1101a25a,e44dc9831a0..d6c645507a3
--- a/app/assets/javascripts/admin/addon/components/flag-user-lists.gjs
+++ b/app/assets/javascripts/admin/addon/components/flag-user-lists.gjs
@@@ -1,43 -1,5 +1,49 @@@
+ import Component from "@ember/component";
+ import { classNames } from "@ember-decorators/component";
+
+ @classNames("flag-user-lists")
+ export default class FlagUserLists extends Component {}
++
+<div class="flagged-by">
+ <div class="user-list-title">
+ {{i18n "admin.flags.flagged_by"}}
+ </div>
+ <div class="flag-users">
+ {{#each this.flaggedPost.post_actions as |postAction|}}
+ <FlagUser @user={{postAction.user}} @date={{postAction.created_at}}>
+ <div class="flagger-flag-type">
+ {{post-action-title
+ postAction.post_action_type_id
+ postAction.name_key
+ }}
+ </div>
+ <UserFlagPercentage
+ @agreed={{postAction.user.flags_agreed}}
+ @disagreed={{postAction.user.flags_disagreed}}
+ @ignored={{postAction.user.flags_ignored}}
+ />
+ </FlagUser>
+ {{/each}}
+ </div>
+</div>
+
+{{#if this.showResolvedBy}}
+ <div class="flagged-post-resolved-by">
+ <div class="user-list-title">
+ {{i18n "admin.flags.resolved_by"}}
+ </div>
+ <div class="flag-users">
+ {{#each this.flaggedPost.post_actions as |postAction|}}
+ <FlagUser
+ @user={{postAction.disposed_by}}
+ @date={{postAction.disposed_at}}
+ >
+ {{disposition-icon postAction.disposition}}
+ {{#if postAction.staff_took_action}}
+ {{d-icon "gavel" title="admin.flags.took_action"}}
+ {{/if}}
+ </FlagUser>
+ {{/each}}
+ </div>
+ </div>
+{{/if}}
diff --cc app/assets/javascripts/admin/addon/components/flag-user.gjs
index ade9c36d29b,ef9b83f7803..d86e7fb9cf2
--- a/app/assets/javascripts/admin/addon/components/flag-user.gjs
+++ b/app/assets/javascripts/admin/addon/components/flag-user.gjs
@@@ -1,26 -1,3 +1,30 @@@
+ import Component from "@ember/component";
+
+ export default class FlagUser extends Component {}
++
+<div class="flag-user">
+ <LinkTo
+ @route="adminUser"
+ @models={{array this.user.id this.user.username}}
+ class="flag-user-avatar"
+ >
+ {{avatar this.user imageSize="small"}}
+ </LinkTo>
+ <div class="flag-user-details">
+ <div class="flag-user-who">
+ <LinkTo
+ @route="adminUser"
+ @models={{array this.user.id this.user.username}}
+ class="flag-user-username"
+ >
+ {{this.user.username}}
+ </LinkTo>
+ <div title={{raw-date this.date}} class="flag-user-date">
+ {{format-age this.date}}
+ </div>
+ </div>
+ <div class="flag-user-extra">
+ {{yield}}
+ </div>
+ </div>
+</div>
diff --cc app/assets/javascripts/admin/addon/components/form-template/form.gjs
index 83763e7a8aa,90e68f11288..7536f4ac7d4
--- a/app/assets/javascripts/admin/addon/components/form-template/form.gjs
+++ b/app/assets/javascripts/admin/addon/components/form-template/form.gjs
@@@ -1,81 -1,138 +1,220 @@@
+ import Component from "@glimmer/component";
+ import { tracked } from "@glimmer/tracking";
+ import { action } from "@ember/object";
+ import { service } from "@ember/service";
+ import { popupAjaxError } from "discourse/lib/ajax-error";
+ import { i18n } from "discourse-i18n";
+ import FormTemplateValidationOptionsModal from "admin/components/modal/form-template-validation-options";
+ import { templateFormFields } from "admin/lib/template-form-fields";
+ import FormTemplate from "admin/models/form-template";
+
+ export default class FormTemplateForm extends Component {
+ @service router;
+ @service dialog;
+ @service modal;
+
+ @tracked formSubmitted = false;
+ @tracked templateContent = this.args.model?.template || "";
+ @tracked templateName = this.args.model?.name || "";
+ @tracked showFormTemplateFormPreview;
+
+ isEditing = this.args.model?.id ? true : false;
+ quickInsertFields = [
+ {
+ type: "checkbox",
+ icon: "square-check",
+ },
+ {
+ type: "input",
+ icon: "grip-lines",
+ },
+ {
+ type: "textarea",
+ icon: "align-left",
+ },
+ {
+ type: "dropdown",
+ icon: "circle-chevron-down",
+ },
+ {
+ type: "upload",
+ icon: "cloud-arrow-up",
+ },
+ {
+ type: "multiselect",
+ icon: "bullseye",
+ },
+ ];
+
+ get disablePreviewButton() {
+ return Boolean(!this.templateName.length || !this.templateContent.length);
+ }
+
+ get disableSubmitButton() {
+ return (
+ Boolean(!this.templateName.length || !this.templateContent.length) ||
+ this.formSubmitted
+ );
+ }
+
+ @action
+ onSubmit() {
+ if (!this.formSubmitted) {
+ this.formSubmitted = true;
+ }
+
+ const postData = {
+ name: this.templateName,
+ template: this.templateContent,
+ };
+
+ if (this.isEditing) {
+ postData["id"] = this.args.model.id;
+ }
+
+ FormTemplate.createOrUpdateTemplate(postData)
+ .then(() => {
+ this.formSubmitted = false;
+ this.router.transitionTo("adminCustomizeFormTemplates.index");
+ })
+ .catch((e) => {
+ popupAjaxError(e);
+ this.formSubmitted = false;
+ });
+ }
+
+ @action
+ onCancel() {
+ this.router.transitionTo("adminCustomizeFormTemplates.index");
+ }
+
+ @action
+ onDelete() {
+ return this.dialog.yesNoConfirm({
+ message: i18n("admin.form_templates.delete_confirm"),
+ didConfirm: () => {
+ FormTemplate.deleteTemplate(this.args.model.id)
+ .then(() => {
+ this.router.transitionTo("adminCustomizeFormTemplates.index");
+ })
+ .catch(popupAjaxError);
+ },
+ });
+ }
+
+ @action
+ onInsertField(type) {
+ const structure = templateFormFields.findBy("type", type).structure;
+
+ if (this.templateContent.length === 0) {
+ this.templateContent += structure;
+ } else {
+ this.templateContent += `\n${structure}`;
+ }
+ }
+
+ @action
+ showValidationOptionsModal() {
+ return this.modal.show(FormTemplateValidationOptionsModal);
+ }
+
+ @action
+ showPreview() {
+ const data = {
+ name: this.templateName,
+ template: this.templateContent,
+ };
+
+ if (this.isEditing) {
+ data["id"] = this.args.model.id;
+ }
+
+ FormTemplate.validateTemplate(data)
+ .then(() => {
+ this.showFormTemplateFormPreview = true;
+ })
+ .catch(popupAjaxError);
+ }
+ }
++
+<div class="form-templates__form">
+ <div class="control-group">
+ <label for="template-name">
+ {{i18n "admin.form_templates.new_template_form.name.label"}}
+ </label>
+ <TextField
+ @value={{this.templateName}}
+ @name="template-name"
+ @placeholderKey="admin.form_templates.new_template_form.name.placeholder"
+ class="form-templates__form-name-input"
+ />
+ </div>
+ <div class="control-group form-templates__editor">
+ <div class="form-templates__quick-insert-field-buttons">
+ <span>
+ {{i18n "admin.form_templates.quick_insert_fields.add_new_field"}}
+ </span>
+ {{#each this.quickInsertFields as |field|}}
+ <DButton
+ @icon={{field.icon}}
+ @label="admin.form_templates.quick_insert_fields.{{field.type}}"
+ @action={{fn this.onInsertField field.type}}
+ class="btn-flat btn-icon-text quick-insert-{{field.type}}"
+ />
+ {{/each}}
+ <DButton
+ @label="admin.form_templates.validations_modal.button_title"
+ @icon="circle-check"
+ @action={{this.showValidationOptionsModal}}
+ class="btn-flat btn-icon-text form-templates__validations-modal-button"
+ />
+ </div>
+ <DButton
+ @icon="eye"
+ @label="admin.form_templates.new_template_form.preview"
+ @action={{this.showPreview}}
+ @disabled={{this.disablePreviewButton}}
+ class="form-templates__preview-button"
+ />
+ </div>
+
+ <div class="control-group">
+ <AceEditor
+ @content={{this.templateContent}}
+ @onChange={{fn (mut this.templateContent)}}
+ @mode="yaml"
+ />
+ </div>
+
+ <div class="footer-buttons">
+ <DButton
+ @label="admin.form_templates.new_template_form.submit"
+ @icon="check"
+ @action={{this.onSubmit}}
+ @disabled={{this.disableSubmitButton}}
+ class="btn-primary"
+ />
+
+ <DButton
+ @label="admin.form_templates.new_template_form.cancel"
+ @icon="xmark"
+ @action={{this.onCancel}}
+ />
+
+ {{#if this.isEditing}}
+ <DButton
+ @label="admin.form_templates.view_template.delete"
+ @icon="trash-can"
+ @action={{this.onDelete}}
+ class="btn-danger"
+ />
+ {{/if}}
+ </div>
+</div>
+
+{{#if this.showFormTemplateFormPreview}}
+ <Modal::FormTemplateFormPreview
+ @closeModal={{fn (mut this.showFormTemplateFormPreview) false}}
+ @content={{this.templateContent}}
+ />
+{{/if}}
diff --cc app/assets/javascripts/admin/addon/components/form-template/row-item.gjs
index a6f2e58b804,83f7adc29e8..2909a8b2f48
--- a/app/assets/javascripts/admin/addon/components/form-template/row-item.gjs
+++ b/app/assets/javascripts/admin/addon/components/form-template/row-item.gjs
@@@ -1,36 -1,44 +1,81 @@@
+ import Component from "@glimmer/component";
+ import { action } from "@ember/object";
+ import { service } from "@ember/service";
+ import { ajax } from "discourse/lib/ajax";
+ import { popupAjaxError } from "discourse/lib/ajax-error";
+ import { i18n } from "discourse-i18n";
+
+ export default class FormTemplateRowItem extends Component {
+ @service router;
+ @service dialog;
+ @service site;
+
+ get activeCategories() {
+ return this.site.categories?.filter((c) =>
+ c["form_template_ids"].includes(this.args.template.id)
+ );
+ }
+
+ @action
+ editTemplate() {
+ this.router.transitionTo(
+ "adminCustomizeFormTemplates.edit",
+ this.args.template
+ );
+ }
+
+ @action
+ deleteTemplate() {
+ return this.dialog.yesNoConfirm({
+ message: i18n("admin.form_templates.delete_confirm", {
+ template_name: this.args.template.name,
+ }),
+ didConfirm: () => {
+ ajax(`/admin/customize/form-templates/${this.args.template.id}.json`, {
+ type: "DELETE",
+ })
+ .then(() => {
+ this.args.refreshModel();
+ })
+ .catch(popupAjaxError);
+ },
+ });
+ }
+ }
++
+<tr class="admin-list-item">
+ <td class="col first">{{@template.name}}</td>
+ <td class="col categories">
+ {{#each this.activeCategories as |category|}}
+ {{category-link category}}
+ {{/each}}
+ </td>
+ <td class="col action">
+ <DButton
+ @title="admin.form_templates.list_table.actions.view"
+ @icon="far-eye"
+ @action={{fn (mut this.showViewTemplateModal) true}}
+ class="btn-view-template"
+ />
+ <DButton
+ @title="admin.form_templates.list_table.actions.edit"
+ @icon="pencil"
+ @action={{this.editTemplate}}
+ class="btn-edit-template"
+ />
+ <DButton
+ @title="admin.form_templates.list_table.actions.delete"
+ @icon="trash-can"
+ @action={{this.deleteTemplate}}
+ class="btn-danger btn-delete-template"
+ />
+ </td>
+</tr>
+
+{{#if this.showViewTemplateModal}}
+ <Modal::CustomizeFormTemplateView
+ @closeModal={{fn (mut this.showViewTemplateModal) false}}
+ @model={{@template}}
+ @refreshModel={{@refreshModel}}
+ />
+{{/if}}
diff --cc app/assets/javascripts/admin/addon/components/images-uploader.gjs
index 6c4d98cefcf,ca69f24c32b..f0e7558a8b6
--- a/app/assets/javascripts/admin/addon/components/images-uploader.gjs
+++ b/app/assets/javascripts/admin/addon/components/images-uploader.gjs
@@@ -1,19 -1,27 +1,47 @@@
+ import Component from "@ember/component";
+ import { getOwner } from "@ember/owner";
+ import { tagName } from "@ember-decorators/component";
+ import UppyUpload from "discourse/lib/uppy/uppy-upload";
+ import { i18n } from "discourse-i18n";
+
+ @tagName("span")
+ export default class ImagesUploader extends Component {
+ uppyUpload = new UppyUpload(getOwner(this), {
+ id: "images-uploader",
+ type: "avatar",
+ validateUploadedFilesOptions: {
+ imagesOnly: true,
+ },
+ uploadDone: (upload) => {
+ this.done(upload);
+ },
+ });
+
+ get uploadingOrProcessing() {
+ return this.uppyUpload.uploading || this.uppyUpload.processing;
+ }
+
+ get uploadButtonText() {
+ return this.uploadingOrProcessing ? i18n("uploading") : i18n("upload");
+ }
+ }
++
+<label
+ class="btn"
+ disabled={{this.uploadingOrProcessing}}
+ title={{i18n "admin.site_settings.uploaded_image_list.upload.title"}}
+>
+ {{d-icon "far-image"}}&nbsp;{{this.uploadButtonText}}
+ <input
+ {{did-insert this.uppyUpload.setup}}
+ class="hidden-upload-field"
+ disabled={{this.uppyUpload.uploading}}
+ type="file"
+ accept="image/*"
+ multiple
+ />
+</label>
+{{#if this.uploadingOrProcessing}}
+ <span>{{i18n "upload_selector.uploading"}}
+ {{this.uppyUpload.uploadProgress}}%</span>
+{{/if}}
diff --cc app/assets/javascripts/admin/addon/components/inline-edit-checkbox.gjs
index 4b9108c896e,4618a97abf0..a39fcc83415
--- a/app/assets/javascripts/admin/addon/components/inline-edit-checkbox.gjs
+++ b/app/assets/javascripts/admin/addon/components/inline-edit-checkbox.gjs
@@@ -1,16 -1,44 +1,61 @@@
+ import Component from "@ember/component";
+ import { action } from "@ember/object";
+ import { classNames } from "@ember-decorators/component";
+ import discourseComputed from "discourse/lib/decorators";
+
+ @classNames("inline-edit")
+ export default class InlineEditCheckbox extends Component {
+ buffer = null;
+ bufferModelId = null;
+
+ didReceiveAttrs() {
+ super.didReceiveAttrs(...arguments);
+
+ if (this.modelId !== this.bufferModelId) {
+ // HACK: The condition above ensures this method is called only when its
+ // attributes are changed (i.e. only when `checked` changes).
+ //
+ // Reproduction steps: navigate to theme #1, switch to theme #2 from the
+ // left-side panel, then switch back to theme #1 and click on the <input>
+ // element wrapped by this component. It will call `didReceiveAttrs` even
+ // though none of the attributes have changed (only `buffer` does).
+ this.setProperties({
+ buffer: this.checked,
+ bufferModelId: this.modelId,
+ });
+ }
+ }
+
+ @discourseComputed("checked", "buffer")
+ changed(checked, buffer) {
+ return !!checked !== !!buffer;
+ }
+
+ @action
+ apply() {
+ this.set("checked", this.buffer);
+ this.action();
+ }
+
+ @action
+ cancel() {
+ this.set("buffer", this.checked);
+ }
+ }
++
+<label class="checkbox-label">
+ <Input @type="checkbox" disabled={{this.disabled}} @checked={{this.buffer}} />
+ {{i18n this.labelKey}}
+</label>
+{{#if this.changed}}
+ <DButton
+ @action={{this.apply}}
+ @icon="check"
+ class="btn-primary btn-small submit-edit"
+ />
+ <DButton
+ @action={{this.cancel}}
+ @icon="xmark"
+ class="btn-small cancel-edit"
+ />
+{{/if}}
diff --cc app/assets/javascripts/admin/addon/components/modal/badge-preview.gjs
index c220b2152b4,c51d7024c6c..939d0f40608
--- a/app/assets/javascripts/admin/addon/components/modal/badge-preview.gjs
+++ b/app/assets/javascripts/admin/addon/components/modal/badge-preview.gjs
@@@ -1,55 -1,53 +1,109 @@@
+ import Component from "@glimmer/component";
+ import { escapeExpression } from "discourse/lib/utilities";
+ import { i18n } from "discourse-i18n";
+
+ export default class BadgePreview extends Component {
+ get processedSample() {
+ return this.args.model.badge.sample.map((grant) => {
+ let i18nKey = "admin.badges.preview.grant.with";
+ const i18nParams = { username: escapeExpression(grant.username) };
+
+ if (grant.post_id) {
+ i18nKey += "_post";
+ i18nParams.link = `<a href="/p/${grant.post_id}" data-auto-route="true">
+ ${escapeExpression(grant.title)}
+ </a>`;
+ }
+
+ if (grant.granted_at) {
+ i18nKey += "_time";
+ i18nParams.time = escapeExpression(
+ moment(grant.granted_at).format(i18n("dates.long_with_year"))
+ );
+ }
+
+ return i18n(i18nKey, i18nParams);
+ });
+ }
+
+ get countWarning() {
+ if (this.args.model.badge.grant_count <= 10) {
+ return (
+ this.args.model.badge.sample.length !==
+ this.args.model.badge.grant_count
+ );
+ } else {
+ return this.args.model.badge.sample?.length !== 10;
+ }
+ }
+
+ get hasQueryPlan() {
+ return !!this.args.model.badge.query_plan;
+ }
+
+ get queryPlanHtml() {
+ let output = `<pre>`;
+ this.args.model.badge.query_plan.forEach((linehash) => {
+ output += escapeExpression(linehash["QUERY PLAN"]);
+ output += "<br>";
+ });
+ output += "</pre>";
+ return output;
+ }
+ }
++
+<DModal
+ @closeModal={{@closeModal}}
+ @title={{i18n "admin.badges.preview.modal_title"}}
+ class="badge-query-preview"
+>
+ <:body>
+ {{#if @model.badge.errors}}
+ <p class="error-header">
+ {{i18n "admin.badges.preview.sql_error_header"}}
+ </p>
+ <pre class="badge-errors">{{@model.badge.errors}}</pre>
+ {{else}}
+ <p class="grant-count">
+ {{#if @model.badge.grant_count}}
+ {{html-safe
+ (i18n
+ "admin.badges.preview.grant_count" [email protected]_count
+ )
+ }}
+ {{else}}
+ {{html-safe (i18n "admin.badges.preview.no_grant_count")}}
+ {{/if}}
+ </p>
+
+ {{#if this.countWarning}}
+ <div class="count-warning">
+ <p class="heading">
+ {{d-icon "triangle-exclamation"}}
+ {{i18n "admin.badges.preview.bad_count_warning.header"}}
+ </p>
+ <p class="body">
+ {{i18n "admin.badges.preview.bad_count_warning.text"}}
+ </p>
+ </div>
+ {{/if}}
+
+ {{#if @model.badge.sample}}
+ <p class="sample">
+ {{i18n "admin.badges.preview.sample"}}
+ </p>
+ <ul>
+ {{#each this.processedSample as |html|}}
+ <li>{{html-safe html}}</li>
+ {{/each}}
+ </ul>
+ {{/if}}
+
+ {{#if this.hasQueryPlan}}
+ <div class="badge-query-plan">
+ {{html-safe this.queryPlanHtml}}
+ </div>
+ {{/if}}
+ {{/if}}
+ </:body>
+</DModal>
diff --cc app/assets/javascripts/admin/addon/components/modal/color-scheme-select-base.gjs
index 4c70a97d1f7,310bbb3a637..753ba4630c8
--- a/app/assets/javascripts/admin/addon/components/modal/color-scheme-select-base.gjs
+++ b/app/assets/javascripts/admin/addon/components/modal/color-scheme-select-base.gjs
@@@ -1,22 -1,14 +1,37 @@@
+ import Component from "@glimmer/component";
+ import { tracked } from "@glimmer/tracking";
+ import { action } from "@ember/object";
+
+ export default class ColorSchemeSelectBase extends Component {
+ @tracked
+ selectedBaseThemeId = this.args.model.baseColorSchemes?.[0]?.base_scheme_id;
+
+ @action
+ selectBase() {
+ this.args.model.newColorSchemeWithBase(this.selectedBaseThemeId);
+ this.args.closeModal();
+ }
+ }
++
+<DModal
+ @title={{i18n "admin.customize.colors.select_base.title"}}
+ @closeModal={{@closeModal}}
+>
+ <:body>
+ {{i18n "admin.customize.colors.select_base.description"}}
+ <ComboBox
+ @content={{@model.baseColorSchemes}}
+ @value={{this.selectedBaseThemeId}}
+ @onChange={{fn (mut this.selectedBaseThemeId)}}
+ @valueProperty="base_scheme_id"
+ />
+ </:body>
+ <:footer>
+ <DButton
+ class="btn-primary"
+ @action={{this.selectBase}}
+ @icon="plus"
+ @label="admin.customize.new"
+ />
+ </:footer>
+</DModal>
diff --cc app/assets/javascripts/admin/addon/components/modal/custom-date-range.gjs
index 8376d1a84b5,ba182675902..281018e97cb
--- a/app/assets/javascripts/admin/addon/components/modal/custom-date-range.gjs
+++ b/app/assets/javascripts/admin/addon/components/modal/custom-date-range.gjs
@@@ -1,22 -1,20 +1,43 @@@
+ import Component from "@glimmer/component";
+ import { tracked } from "@glimmer/tracking";
+ import { action } from "@ember/object";
+
+ export default class CustomDateRange extends Component {
+ @tracked startDate = this.args.model.startDate;
+ @tracked endDate = this.args.model.endDate;
+
+ @action
+ onChangeDateRange(range) {
+ this.startDate = range.from;
+ this.endDate = range.to;
+ }
+
+ @action
+ updateDateRange() {
+ this.args.model.setCustomDateRange(this.startDate, this.endDate);
+ this.args.closeModal();
+ }
+ }
++
+<DModal
+ class="custom-date-range-modal"
+ @title={{i18n "admin.dashboard.reports.dates"}}
+ @closeModal={{@closeModal}}
+>
+ <:body>
+ <DateTimeInputRange
+ @from={{this.startDate}}
+ @to={{this.endDate}}
+ @onChange={{this.onChangeDateRange}}
+ @showFromTime={{false}}
+ @showToTime={{false}}
+ />
+ </:body>
+ <:footer>
+ <DButton
+ @action={{this.updateDateRange}}
+ @label="admin.dashboard.reports.refresh_report"
+ @icon="arrows-rotate"
+ />
+ </:footer>
+</DModal>
diff --cc app/assets/javascripts/admin/addon/components/modal/delete-posts-confirmation.gjs
index b74516d3637,1e87b49e912..8d17d8f2e89
--- a/app/assets/javascripts/admin/addon/components/modal/delete-posts-confirmation.gjs
+++ b/app/assets/javascripts/admin/addon/components/modal/delete-posts-confirmation.gjs
@@@ -1,36 -1,18 +1,55 @@@
+ import Component from "@glimmer/component";
+ import { tracked } from "@glimmer/tracking";
+ import { i18n } from "discourse-i18n";
+
+ export default class DeletePostsConfirmation extends Component {
+ @tracked value;
+
+ get text() {
+ return i18n("admin.user.delete_posts.confirmation.text", {
+ username: this.args.model.user.username,
+ post_count: this.args.model.user.post_count,
+ });
+ }
+
+ get deleteDisabled() {
+ return !this.value || this.text !== this.value;
+ }
+ }
++
+<DModal
+ @title={{html-safe
+ (i18n
+ "admin.user.delete_posts.confirmation.title" [email protected]
+ )
+ }}
+ @closeModal={{@closeModal}}
+>
+ <:body>
+ <p>{{html-safe
+ (i18n
+ "admin.user.delete_posts.confirmation.description"
+ text=this.text
+ )
+ }}</p>
+ <Input @type="text" @value={{this.value}} />
+ </:body>
+ <:footer>
+ <DButton
+ class="btn-danger"
+ @action={{@model.deleteAllPosts}}
+ @icon="trash-can"
+ @disabled={{this.deleteDisabled}}
+ @translatedLabel={{i18n
+ "admin.user.delete_posts.confirmation.delete"
+ }}
+ />
+ <DButton
+ @action={{@closeModal}}
+ @label="admin.user.delete_posts.confirmation.cancel"
+ />
+ </:footer>
+</DModal>
diff --cc app/assets/javascripts/admin/addon/components/modal/delete-user-posts-progress.gjs
index 52e7d880f34,a726f3350ee..7ba7b64ecdc
--- a/app/assets/javascripts/admin/addon/components/modal/delete-user-posts-progress.gjs
+++ b/app/assets/javascripts/admin/addon/components/modal/delete-user-posts-progress.gjs
@@@ -1,14 -1,42 +1,57 @@@
+ import Component from "@glimmer/component";
+ import { tracked } from "@glimmer/tracking";
+ import { action } from "@ember/object";
+ import { extractError } from "discourse/lib/ajax-error";
+ import { i18n } from "discourse-i18n";
+ import AdminUser from "admin/models/admin-user";
+
+ export default class DeleteUserPostsProgress extends Component {
+ @tracked deletedPosts = 0;
+ @tracked flash;
+
+ constructor() {
+ super(...arguments);
+ this.deletePosts();
+ }
+
+ get userPostCount() {
+ return this.args.model.user.get("post_count");
+ }
+
+ get deletedPercentage() {
+ return Math.floor((this.deletedPosts * 100) / this.userPostCount);
+ }
+
+ @action
+ async deletePosts() {
+ try {
+ const progress = await this.args.model.user.deleteAllPosts();
+ this.deletedPosts = progress.posts_deleted;
+ this.args.model.updateUserPostCount(
+ this.userPostCount - this.deletedPosts
+ );
+ // continue deleting posts if more remain, otherwise exit
+ this.userPostCount > 0 ? this.deletePosts() : this.args.closeModal();
+ } catch (e) {
+ AdminUser.find(this.args.model.user.id).then((u) =>
+ this.args.model.user.setProperties(u)
+ );
+ this.flash = extractError(e, i18n("admin.user.delete_posts_failed"));
+ }
+ }
+ }
++
+<DModal
+ @title={{i18n "admin.user.delete_posts.progress.title"}}
+ @closeModal={{@closeModal}}
+ class="admin-delete-user-posts-progress-modal"
+ @flash={{this.flash}}
+ @dismissable={{false}}
+>
+ <:body>
+ <p>{{i18n "admin.user.delete_posts.progress.description"}}</p>
+ <div class="progress-bar">
+ <span style={{html-safe (concat "width: " this.deletedPercentage "%")}} />
+ </div>
+ </:body>
+</DModal>
diff --cc app/assets/javascripts/admin/addon/components/modal/edit-badge-groupings.gjs
index 74f9e9789b2,fe6eab91a8d..f10254eb5ea
--- a/app/assets/javascripts/admin/addon/components/modal/edit-badge-groupings.gjs
+++ b/app/assets/javascripts/admin/addon/components/modal/edit-badge-groupings.gjs
@@@ -1,59 -1,84 +1,144 @@@
+ import Component from "@glimmer/component";
+ import { tracked } from "@glimmer/tracking";
+ import { A } from "@ember/array";
+ import { action } from "@ember/object";
+ import { service } from "@ember/service";
+ import { TrackedArray } from "@ember-compat/tracked-built-ins";
+ import { ajax } from "discourse/lib/ajax";
+ import { i18n } from "discourse-i18n";
+
+ export default class EditBadgeGroupings extends Component {
+ @service dialog;
+ @service store;
+
+ @tracked workingCopy = new TrackedArray();
+
+ constructor() {
+ super(...arguments);
+ let copy = A();
+ if (this.args.model.badgeGroupings) {
+ this.args.model.badgeGroupings.forEach((o) =>
+ copy.pushObject(this.store.createRecord("badge-grouping", o))
+ );
+ }
+ this.workingCopy = copy;
+ }
+
+ @action
+ up(item) {
+ this.moveItem(item, -1);
+ }
+
+ @action
+ down(item) {
+ this.moveItem(item, 1);
+ }
+
+ @action
+ delete(item) {
+ this.workingCopy.removeObject(item);
+ }
+
+ @action
+ add() {
+ const obj = this.store.createRecord("badge-grouping", {
+ editing: true,
+ name: i18n("admin.badges.badge_grouping"),
+ });
+ this.workingCopy.pushObject(obj);
+ }
+
+ @action
+ async saveAll() {
+ const groupIds = this.workingCopy.map((i) => i.id || -1);
+ const names = this.workingCopy.map((i) => i.name);
+ try {
+ const data = await ajax("/admin/badges/badge_groupings", {
+ data: { ids: groupIds, names },
+ type: "POST",
+ });
+ this.workingCopy.clear();
+ data.badge_groupings.forEach((badgeGroup) => {
+ this.workingCopy.pushObject(
+ this.store.createRecord("badge-grouping", {
+ ...badgeGroup,
+ editing: false,
+ })
+ );
+ });
+ this.args.model.updateGroupings(this.workingCopy);
+ this.args.closeModal();
+ } catch {
+ this.dialog.alert(i18n("generic_error"));
+ }
+ }
+
+ moveItem(item, delta) {
+ const index = this.workingCopy.indexOf(item);
+ if (index + delta < 0 || index + delta >= this.workingCopy.length) {
+ return;
+ }
+ this.workingCopy.removeAt(index);
+ this.workingCopy.insertAt(index + delta, item);
+ }
+ }
++
+<DModal
+ @title={{i18n "admin.badges.badge_groupings.modal_title"}}
+ @bodyClass="badge-groupings-modal"
+ @closeModal={{@closeModal}}
+>
+ <:body>
+ <div class="badge-groupings">
+ <ul class="badge-groupings-list">
+ {{#each this.workingCopy as |wc|}}
+ <li class="badge-grouping-item">
+ <div class="badge-grouping">
+ {{#if wc.editing}}
+ <Input @value={{wc.name}} class="badge-grouping-name-input" />
+ {{else}}
+ <span>{{wc.displayName}}</span>
+ {{/if}}
+ </div>
+ <div class="actions">
+ {{#if wc.editing}}
+ <DButton @action={{fn (mut wc.editing) false}} @icon="check" />
+ {{else}}
+ <DButton
+ @action={{fn (mut wc.editing) true}}
+ @disabled={{wc.system}}
+ @icon="pencil"
+ />
+ {{/if}}
+ <DButton @action={{fn this.up wc}} @icon="chevron-up" />
+ <DButton @action={{fn this.down wc}} @icon="chevron-down" />
+ <DButton
+ @action={{fn this.delete wc}}
+ @disabled={{wc.system}}
+ @icon="xmark"
+ />
+ </div>
+ </li>
+ {{/each}}
+ </ul>
+ </div>
+ <DButton
+ @action={{this.add}}
+ class="badge-groupings__add-grouping"
+ @label="admin.badges.new"
+ />
+ </:body>
+ <:footer>
+ <DButton
+ @action={{this.saveAll}}
+ @label="admin.badges.save"
+ class="btn-primary badge-groupings__save"
+ @disabled={{this.submitDisabled}}
+ />
+ <DButton
+ class="btn-flat d-modal-cancel"
+ @action={{@closeModal}}
+ @label="cancel"
+ />
+ </:footer>
+</DModal>
diff --cc app/assets/javascripts/admin/addon/components/modal/form-template-validation-options.gjs
index 5bd60b89110,815cff26b78..650d11fbad7
--- a/app/assets/javascripts/admin/addon/components/modal/form-template-validation-options.gjs
+++ b/app/assets/javascripts/admin/addon/components/modal/form-template-validation-options.gjs
@@@ -1,26 -1,32 +1,59 @@@
+ import Component from "@glimmer/component";
+ import { i18n } from "discourse-i18n";
+
+ const TABLE_HEADER_KEYS = ["key", "type", "description"];
+ const VALIDATION_KEYS = ["required", "minimum", "maximum", "pattern", "type"];
+
+ export default class FormTemplateValidationOptions extends Component {
+ get tableHeaders() {
+ const translatedHeaders = [];
+ TABLE_HEADER_KEYS.forEach((header) => {
+ translatedHeaders.push(
+ i18n(`admin.form_templates.validations_modal.table_headers.${header}`)
+ );
+ });
+
+ return translatedHeaders;
+ }
+
+ get validations() {
+ const translatedValidations = [];
+ const prefix = "admin.form_templates.validations_modal.validations";
+ VALIDATION_KEYS.forEach((validation) => {
+ translatedValidations.push({
+ key: i18n(`${prefix}.${validation}.key`),
+ type: i18n(`${prefix}.${validation}.type`),
+ description: i18n(`${prefix}.${validation}.description`),
+ });
+ });
+
+ return translatedValidations;
+ }
+ }
++
+<DModal
+ class="form-templates__validation-options admin-form-template-validation-options-modal"
+ @title={{i18n "admin.form_templates.validations_modal.modal_title"}}
+ @closeModal={{@closeModal}}
+>
+ <:body>
+ <table>
+ <thead>
+ <tr>
+ {{#each this.tableHeaders as |header|}}
+ <th>{{header}}</th>
+ {{/each}}
+ </tr>
+ </thead>
+ <tbody>
+ {{#each this.validations as |item|}}
+ <tr>
+ <td><pre>{{item.key}}</pre></td>
+ <td>{{item.type}}</td>
+ <td>{{item.description}}</td>
+ </tr>
+ {{/each}}
+ </tbody>
+ </table>
+ </:body>
+</DModal>
diff --cc app/assets/javascripts/admin/addon/components/modal/merge-users-confirmation.gjs
index dd37f653309,c9a30288e23..ff8a7814843
--- a/app/assets/javascripts/admin/addon/components/modal/merge-users-confirmation.gjs
+++ b/app/assets/javascripts/admin/addon/components/modal/merge-users-confirmation.gjs
@@@ -1,36 -1,18 +1,55 @@@
+ import Component from "@glimmer/component";
+ import { tracked } from "@glimmer/tracking";
+ import { i18n } from "discourse-i18n";
+
+ export default class MergeUsersConfirmation extends Component {
+ @tracked value;
+
+ get mergeDisabled() {
+ return !this.value || this.text !== this.value;
+ }
+
+ get text() {
+ return i18n("admin.user.merge.confirmation.text", {
+ username: this.args.model.username,
+ targetUsername: this.args.model.targetUsername,
+ });
+ }
+ }
++
+<DModal
+ @title={{html-safe
+ (i18n "admin.user.merge.confirmation.title" [email protected])
+ }}
+ @closeModal={{@closeModal}}
+>
+ <:body>
+ <p>
+ {{html-safe
+ (i18n
+ "admin.user.merge.confirmation.description"
+ text=this.text
+ )
+ }}
+ </p>
+ <Input @type="text" @value={{this.value}} />
+ </:body>
+ <:footer>
+ <DButton
+ class="btn-danger"
+ @action={{fn @model.merge @model.targetUsername}}
+ @icon="trash-can"
+ @disabled={{this.mergeDisabled}}
+ @translatedLabel={{i18n
+ "admin.user.merge.confirmation.transfer_and_delete"
+ }}
+ />
+ <DButton
+ @action={{@closeModal}}
+ @label="admin.user.merge.confirmation.cancel"
+ />
+ </:footer>
+</DModal>
diff --cc app/assets/javascripts/admin/addon/components/modal/merge-users-progress.gjs
index 73393291c7d,bd88fb6b280..dc9c2244f98
--- a/app/assets/javascripts/admin/addon/components/modal/merge-users-progress.gjs
+++ b/app/assets/javascripts/admin/addon/components/modal/merge-users-progress.gjs
@@@ -1,9 -1,39 +1,49 @@@
+ import Component from "@glimmer/component";
+ import { tracked } from "@glimmer/tracking";
+ import { service } from "@ember/service";
+ import { bind } from "discourse/lib/decorators";
+ import DiscourseURL from "discourse/lib/url";
+ import { i18n } from "discourse-i18n";
+
+ export default class MergeUsersProgress extends Component {
+ @service messageBus;
+
+ @tracked message = i18n("admin.user.merging_user");
+
+ constructor() {
+ super(...arguments);
+ this.messageBus.subscribe("/merge_user", this.onMessage);
+ }
+
+ willDestroy() {
+ super.willDestroy(...arguments);
+ this.messageBus.unsubscribe("/merge_user", this.onMessage);
+ }
+
+ @bind
+ onMessage(data) {
+ if (data.merged) {
+ if (/^\/admin\/users\/list\//.test(location.href)) {
+ DiscourseURL.redirectTo(location.href);
+ } else {
+ DiscourseURL.redirectTo(
+ `/admin/users/${data.user.id}/${data.user.username}`
+ );
+ }
+ } else if (data.message) {
+ this.message = data.message;
+ } else if (data.failed) {
+ this.message = i18n("admin.user.merge_failed");
+ }
+ }
+ }
++
+<DModal
+ @title={{i18n "admin.user.merge.progress.title"}}
+ @dismissable={{false}}
+ @closeModal={{@closeModal}}
+>
+ <:body>
+ {{this.message}}
+ </:body>
+</DModal>
diff --cc app/assets/javascripts/admin/addon/components/modal/merge-users-prompt.gjs
index 3c738c58361,6af710b41f3..33bd814df35
--- a/app/assets/javascripts/admin/addon/components/modal/merge-users-prompt.gjs
+++ b/app/assets/javascripts/admin/addon/components/modal/merge-users-prompt.gjs
@@@ -1,36 -1,13 +1,50 @@@
+ import Component from "@glimmer/component";
+ import { tracked } from "@glimmer/tracking";
+
+ export default class MergeUsersPrompt extends Component {
+ @tracked targetUsername;
+
+ get mergeDisabled() {
+ return (
+ !this.targetUsername ||
+ this.args.model.user.username === this.targetUsername[0]
+ );
+ }
+ }
++
+<DModal
+ @title={{html-safe
+ (i18n "admin.user.merge.prompt.title" [email protected])
+ }}
+ @closeModal={{@closeModal}}
+>
+ <:body>
+ <p>
+ {{html-safe
+ (i18n
+ "admin.user.merge.prompt.description" [email protected]
+ )
+ }}
+ </p>
+ <EmailGroupUserChooser
+ @value={{this.targetUsername}}
+ @options={{hash
+ maximum=1
+ filterPlaceholder="admin.user.merge.prompt.target_username_placeholder"
+ }}
+ />
+ </:body>
+ <:footer>
+ <DButton
+ class="btn-primary"
+ @action={{fn @model.showMergeConfirmation (get this.targetUsername "0")}}
+ @icon="trash-can"
+ @disabled={{this.mergeDisabled}}
+ @translatedLabel={{i18n
+ "admin.user.merge.confirmation.transfer_and_delete"
+ }}
+ />
+ <DButton @action={{@closeModal}} @label="admin.user.merge.prompt.cancel" />
+ </:footer>
+</DModal>
diff --cc app/assets/javascripts/admin/addon/components/modal/penalize-user.gjs
index 8372f207098,b294d65d174..eeb7a220fc4
--- a/app/assets/javascripts/admin/addon/components/modal/penalize-user.gjs
+++ b/app/assets/javascripts/admin/addon/components/modal/penalize-user.gjs
@@@ -1,80 -1,130 +1,211 @@@
+ import Component from "@glimmer/component";
+ import { tracked } from "@glimmer/tracking";
+ import { action } from "@ember/object";
+ import { service } from "@ember/service";
+ import { isEmpty } from "@ember/utils";
+ import { extractError } from "discourse/lib/ajax-error";
+ import I18n, { i18n } from "discourse-i18n";
+
+ export default class PenalizeUser extends Component {
+ @service dialog;
+ @service siteSettings;
+
+ @tracked penalizeUntil = this.args.model.user.next_penalty;
+ @tracked confirmClose = false;
+ @tracked otherUserIds = [];
+ @tracked postAction = "delete";
+ @tracked postEdit = this.args.model.postEdit;
+ @tracked flash;
+ @tracked reason;
+ @tracked message;
+
+ constructor() {
+ super(...arguments);
+ if (this.postEdit && this.siteSettings.penalty_include_post_message) {
+ this.message = `-------------------\n${this.postEdit}\n-------------------`;
+ }
+ }
+
+ get modalTitle() {
+ if (this.args.model.penaltyType === "suspend") {
+ return "admin.user.suspend_modal_title";
+ } else if (this.args.model.penaltyType === "silence") {
+ return "admin.user.silence_modal_title";
+ }
+ }
+
+ get buttonLabel() {
+ if (this.args.model.penaltyType === "suspend") {
+ return "admin.user.suspend";
+ } else if (this.args.model.penaltyType === "silence") {
+ return "admin.user.silence";
+ }
+ }
+
+ get penaltyHistory() {
+ return I18n.messageFormat("admin.user.penalty_history_MF", {
+ SUSPENDED: this.args.model.user.penalty_counts?.suspended,
+ SILENCED: this.args.model.user.penalty_counts?.silenced,
+ });
+ }
+
+ get canPenalize() {
+ if (this.args.model.penaltyType === "suspend") {
+ return this.args.model.user.canSuspend;
+ } else if (this.args.model.penaltyType === "silence") {
+ return this.args.model.user.canSilence;
+ }
+ return false;
+ }
+
+ get submitDisabled() {
+ return (
+ this.penalizing ||
+ isEmpty(this.penalizeUntil) ||
+ !this.reason ||
+ this.reason.length < 1
+ );
+ }
+
+ @action
+ async penalizeUser() {
+ if (this.submitDisabled) {
+ return;
+ }
+ this.penalizing = true;
+ this.confirmClose = true;
+ if (this.before) {
+ this.before();
+ }
+
+ let result;
+ try {
+ const opts = {
+ reason: this.reason,
+ message: this.message,
+ post_id: this.args.model.postId,
+ post_action: this.postAction,
+ post_edit: this.postEdit,
+ other_user_ids: this.otherUserIds,
+ };
+
+ if (this.args.model.penaltyType === "suspend") {
+ opts.suspend_until = this.penalizeUntil;
+ result = await this.args.model.user.suspend(opts);
+ } else if (this.args.model.penaltyType === "silence") {
+ opts.silenced_till = this.penalizeUntil;
+ result = await this.args.model.user.silence(opts);
+ } else {
+ // eslint-disable-next-line no-console
+ console.error("Unknown penalty type:", this.args.model.penaltyType);
+ }
+ this.args.closeModal({ success: true });
+ if (this.successCallback) {
+ await this.successCallback(result);
+ }
+ } catch {
+ this.flash = extractError(result);
+ } finally {
+ this.penalizing = false;
+ }
+ }
+
+ @action
+ warnBeforeClosing() {
+ if (!this.confirmClose && (this.reason?.length || this.message?.length)) {
+ this.dialog.confirm({
+ message: i18n("admin.user.confirm_cancel_penalty"),
+ didConfirm: () => this.args.closeModal({ success: false }),
+ });
+ return false;
+ }
+
+ this.args.closeModal({ success: false });
+ }
+
+ @action
+ similarUsersChanged(userIds) {
+ this.otherUserIds = userIds;
+ }
+ }
++
+<DModal
+ class="{{@model.penaltyType}}-user-modal"
+ @title={{i18n this.modalTitle}}
+ @closeModal={{this.warnBeforeClosing}}
+ @flash={{this.flash}}
+>
+ <:body>
+ {{#if this.canPenalize}}
+ <div class="penalty-duration-controls">
+ {{#if (eq @model.penaltyType "suspend")}}
+ <FutureDateInput
+ @label="admin.user.suspend_duration"
+ @clearable={{false}}
+ @input={{this.penalizeUntil}}
+ @onChangeInput={{fn (mut this.penalizeUntil)}}
+ class="suspend-until"
+ />
+ {{else if (eq @model.penaltyType "silence")}}
+ <FutureDateInput
+ @label="admin.user.silence_duration"
+ @clearable={{false}}
+ @input={{this.penalizeUntil}}
+ @onChangeInput={{fn (mut this.penalizeUntil)}}
+ class="silence-until"
+ />
+ {{/if}}
+ </div>
+ {{#if (eq @model.penaltyType "suspend")}}
+ <div class="penalty-reason-visibility">
+ {{#if this.siteSettings.hide_suspension_reasons}}
+ {{html-safe (i18n "admin.user.suspend_reason_hidden_label")}}
+ {{else}}
+ {{html-safe (i18n "admin.user.suspend_reason_label")}}
+ {{/if}}
+ </div>
+ {{/if}}
+ <AdminPenaltyReason
+ @penaltyType={{@model.penaltyType}}
+ @reason={{this.reason}}
+ @message={{this.message}}
+ />
+ {{#if @model.postId}}
+ <AdminPenaltyPostAction
+ @postId={{@model.postId}}
+ @postAction={{this.postAction}}
+ @postEdit={{this.postEdit}}
+ />
+ {{/if}}
+ {{#if @model.user.similar_users_count}}
+ <AdminPenaltySimilarUsers
+ @penaltyType={{@model.penaltyType}}
+ @user={{@model.user}}
+ @selectedUserIds={{this.otherUserIds}}
+ @onUsersChanged={{this.similarUsersChanged}}
+ />
+ {{/if}}
+ {{else}}
+ {{#if (eq @model.penaltyType "suspend")}}
+ <div class="cant-suspend">{{i18n "admin.user.cant_suspend"}}</div>
+ {{else if (eq @model.penaltyType "silence")}}
+ <div class="cant-silence">{{i18n "admin.user.cant_silence"}}</div>
+ {{/if}}
+ {{/if}}
+ </:body>
+ <:footer>
+ <div class="penalty-history">{{html-safe this.penaltyHistory}}</div>
+ <DButton
+ class="btn-danger perform-penalize"
+ @action={{this.penalizeUser}}
+ @disabled={{this.submitDisabled}}
+ @icon="ban"
+ @label={{this.buttonLabel}}
+ />
+ <DButton
+ class="btn-flat d-modal-cancel"
+ @action={{this.warnBeforeClosing}}
+ @label="cancel"
+ />
+ </:footer>
+</DModal>
diff --cc app/assets/javascripts/admin/addon/components/modal/reseed.gjs
index 46d26972f48,6db3656768c..4f053999cd3
--- a/app/assets/javascripts/admin/addon/components/modal/reseed.gjs
+++ b/app/assets/javascripts/admin/addon/components/modal/reseed.gjs
@@@ -1,59 -1,57 +1,117 @@@
+ import Component from "@glimmer/component";
+ import { tracked } from "@glimmer/tracking";
+ import { action } from "@ember/object";
+ import { service } from "@ember/service";
+ import { ajax } from "discourse/lib/ajax";
+ import { i18n } from "discourse-i18n";
+
+ export default class Reseed extends Component {
+ @service dialog;
+
+ @tracked loading = true;
+ @tracked reseeding = false;
+ @tracked categories = null;
+ @tracked topics = null;
+ @tracked flash;
+
+ constructor() {
+ super(...arguments);
+ this.loadReseed();
+ }
+
+ @action
+ async loadReseed() {
+ try {
+ const result = await ajax("/admin/customize/reseed");
+ this.categories = result.categories;
+ this.topics = result.topics;
+ } finally {
+ this.loading = false;
+ }
+ }
+
+ _extractSelectedIds(items) {
+ return items.filter((item) => item.selected).map((item) => item.id);
+ }
+
+ @action
+ async reseed() {
+ try {
+ this.reseeding = true;
+ await ajax("/admin/customize/reseed", {
+ data: {
+ category_ids: this._extractSelectedIds(this.categories),
+ topic_ids: this._extractSelectedIds(this.topics),
+ },
+ type: "POST",
+ });
+
+ this.flash = null;
+ this.args.closeModal();
+ } catch {
+ this.flash = i18n("generic_error");
+ } finally {
+ this.reseeding = false;
+ }
+ }
+ }
++
+<DModal
+ @closeModal={{@closeModal}}
+ @title={{i18n "admin.reseed.modal.title"}}
+ @subtitle={{i18n "admin.reseed.modal.subtitle"}}
+ class="reseed-modal"
+ @flash={{this.flash}}
+>
+ <:body>
+ <ConditionalLoadingSpinner @condition={{this.loading}}>
+ {{#if this.categories}}
+ <fieldset>
+ <legend class="options-group-title">
+ {{i18n "admin.reseed.modal.categories"}}
+ </legend>
+ {{#each this.categories as |category|}}
+ <label>
+ <Input
+ class="option"
+ @type="checkbox"
+ @checked={{category.selected}}
+ />
+ <span>{{category.name}}</span>
+ </label>
+ {{/each}}
+ </fieldset>
+ {{/if}}
+ <br />
+ {{#if this.topics}}
+ <fieldset>
+ <legend class="options-group-title">
+ {{i18n "admin.reseed.modal.topics"}}
+ </legend>
+ {{#each this.topics as |topic|}}
+ <label>
+ <Input
+ class="option"
+ @type="checkbox"
+ @checked={{topic.selected}}
+ />
+ <span>{{topic.name}}</span>
+ </label>
+ {{/each}}
+ </fieldset>
+ {{/if}}
+ </ConditionalLoadingSpinner>
+ </:body>
+ <:footer>
+ <DButton
+ @action={{this.reseed}}
+ @label="admin.reseed.modal.replace"
+ @isLoading={{this.reseeding}}
+ class="btn-danger"
+ />
+
+ {{#unless this.reseeding}}
+ <DModalCancel @close={{@closeModal}} />
+ {{/unless}}
+ </:footer>
+</DModal>
diff --cc app/assets/javascripts/admin/addon/components/modal/site-setting-default-categories.gjs
index d83e9b0e449,88539f620fb..56ffe47fa19
--- a/app/assets/javascripts/admin/addon/components/modal/site-setting-default-categories.gjs
+++ b/app/assets/javascripts/admin/addon/components/modal/site-setting-default-categories.gjs
@@@ -1,23 -1,16 +1,40 @@@
+ import Component from "@glimmer/component";
+ import { action } from "@ember/object";
+
+ export default class SiteSettingDefaultCategories extends Component {
+ @action
+ updateExistingUsers() {
+ this.args.model.setUpdateExistingUsers(true);
+ this.args.closeModal();
+ }
+
+ @action
+ cancel() {
+ this.args.model.setUpdateExistingUsers(false);
+ this.args.closeModal();
+ }
+ }
++
+<DModal
+ class="incoming-emails"
+ @title={{html-safe @model.siteSetting.key}}
+ @closeModal={{this.cancel}}
+>
+ <:body>
+ {{i18n
+ "admin.site_settings.default_categories.modal_description"
+ }}
+ </:body>
+ <:footer>
+ <DButton
+ @action={{this.updateExistingUsers}}
+ class="btn-primary"
+ @label="admin.site_settings.default_categories.modal_yes"
+ />
+ <DButton
+ @action={{this.cancel}}
+ @label="admin.site_settings.default_categories.modal_no"
+ />
+ </:footer>
+</DModal>
diff --cc app/assets/javascripts/admin/addon/components/modal/staff-action-log-change.gjs
index 46039b6db6b,eddda604925..bf1cb7fcbb0
--- a/app/assets/javascripts/admin/addon/components/modal/staff-action-log-change.gjs
+++ b/app/assets/javascripts/admin/addon/components/modal/staff-action-log-change.gjs
@@@ -1,13 -1,21 +1,35 @@@
+ import Component from "@glimmer/component";
+ import { tracked } from "@glimmer/tracking";
+ import { action } from "@ember/object";
+ import { ajax } from "discourse/lib/ajax";
+
+ export default class AdminStaffActionLogComponent extends Component {
+ @tracked diff;
+
+ constructor() {
+ super(...arguments);
+ this.loadDiff();
+ }
+
+ @action
+ async loadDiff() {
+ const diff = await ajax(
+ `/admin/logs/staff_action_logs/${this.args.model.staffActionLog.id}/diff`
+ );
+ this.diff = diff.side_by_side;
+ }
+ }
++
+<DModal
+ @title={{i18n "admin.logs.staff_actions.modal_title"}}
+ @closeModal={{@closeModal}}
+ @bodyClass="theme-change-modal-body"
+ class="history-modal"
+>
+ <:body>
+ {{html-safe this.diff}}
+ </:body>
+ <:footer>
+ <DButton class="btn-primary" @action={{@closeModal}} @label="close" />
+ </:footer>
+</DModal>
diff --cc app/assets/javascripts/admin/addon/components/modal/start-backup.gjs
index 09886b7de2b,8a1f8a9a1a7..5a82b80721d
--- a/app/assets/javascripts/admin/addon/components/modal/start-backup.gjs
+++ b/app/assets/javascripts/admin/addon/components/modal/start-backup.gjs
@@@ -1,27 -1,38 +1,66 @@@
+ import Component from "@glimmer/component";
+ import { tracked } from "@glimmer/tracking";
+ import { action } from "@ember/object";
+ import { service } from "@ember/service";
+ import { i18n } from "discourse-i18n";
+
+ export default class StartBackup extends Component {
+ @service siteSettings;
+
+ @tracked includeUploads = true;
+
+ get canManageUploadsInBackup() {
+ return (
+ !this.siteSettings.enable_s3_uploads ||
+ this.siteSettings.include_s3_uploads_in_backups
+ );
+ }
+
+ get warningCssClasses() {
+ return "";
+ }
+
+ get warningMessage() {
+ if (
+ this.siteSettings.enable_s3_uploads &&
+ !this.siteSettings.include_s3_uploads_in_backups
+ ) {
+ return i18n("admin.backups.operations.backup.s3_upload_warning");
+ }
+ return "";
+ }
+
+ @action
+ startBackup() {
+ this.args.model.startBackup(this.includeUploads);
+ this.args.closeModal();
+ }
+ }
++
+<DModal
+ @title={{i18n "admin.backups.operations.backup.confirm"}}
+ @closeModal={{@closeModal}}
+ class="start-backup-modal"
+>
+ <:body>
+ {{#if this.warningMessage}}
+ <div class={{this.warningCssClasses}}>{{html-safe
+ this.warningMessage
+ }}</div>
+ {{/if}}
+ {{#if this.canManageUploadsInBackup}}
+ <label class="checkbox-label">
+ <Input @type="checkbox" @checked={{this.includeUploads}} />
+ {{i18n "admin.backups.operations.backup.include_uploads"}}
+ </label>
+ {{/if}}
+ </:body>
+ <:footer>
+ <DButton
+ class="btn-primary"
+ @action={{this.startBackup}}
+ @label="yes_value"
+ />
+ <DButton class="btn-flat" @action={{@closeModal}} @label="cancel" />
+ </:footer>
+</DModal>
diff --cc app/assets/javascripts/admin/addon/components/modal/uploaded-image-list.gjs
index 7bcd7026fe2,a872a4d3dfe..d94a77e8ffb
--- a/app/assets/javascripts/admin/addon/components/modal/uploaded-image-list.gjs
+++ b/app/assets/javascripts/admin/addon/components/modal/uploaded-image-list.gjs
@@@ -1,28 -1,27 +1,56 @@@
+ import Component from "@glimmer/component";
+ import { tracked } from "@glimmer/tracking";
+ import { action } from "@ember/object";
+
+ export default class UploadedImageList extends Component {
+ @tracked
+ images = this.args.model.value?.length
+ ? this.args.model.value.split("|")
+ : [];
+
+ @action
+ remove(url, event) {
+ event.preventDefault();
+ this.images.removeObject(url);
+ }
+
+ @action
+ uploadDone({ url }) {
+ this.images.addObject(url);
+ }
+
+ @action
+ close() {
+ this.args.model.changeValue(this.images.join("|"));
+ this.args.closeModal();
+ }
+ }
++
+<DModal
+ class="uploaded-image-list"
+ @title={{i18n @model.title}}
+ @closeModal={{@closeModal}}
+>
+ <:body>
+ <div class="selectable-avatars">
+ {{#each this.images as |image|}}
+ <a href class="selectable-avatar" {{on "click" (fn this.remove image)}}>
+ {{bound-avatar-template image "huge"}}
+ <span class="selectable-avatar__remove">{{d-icon
+ "circle-xmark"
+ }}</span>
+ </a>
+ {{else}}
+ <p>{{i18n "admin.site_settings.uploaded_image_list.empty"}}</p>
+ {{/each}}
+ </div>
+ </:body>
+ <:footer>
+ <DButton @action={{this.close}} @label="close" />
+ <ImagesUploader
+ @uploading={{this.uploading}}
+ @done={{this.uploadDone}}
+ class="pull-right"
+ />
+ </:footer>
+</DModal>
diff --cc app/assets/javascripts/admin/addon/components/permalink-form.gjs
index bc1f440a522,031c849e393..0153c4450c1
--- a/app/assets/javascripts/admin/addon/components/permalink-form.gjs
+++ b/app/assets/javascripts/admin/addon/components/permalink-form.gjs
@@@ -1,38 -1,93 +1,132 @@@
+ import Component from "@ember/component";
+ import { action } from "@ember/object";
+ import { schedule } from "@ember/runloop";
+ import { service } from "@ember/service";
+ import { tagName } from "@ember-decorators/component";
+ import { fmt } from "discourse/lib/computed";
+ import discourseComputed, { bind } from "discourse/lib/decorators";
+ import { i18n } from "discourse-i18n";
+ import Permalink from "admin/models/permalink";
+
+ @tagName("")
+ export default class PermalinkForm extends Component {
+ @service dialog;
+
+ formSubmitted = false;
+ permalinkType = "topic_id";
+
+ @fmt("permalinkType", "admin.permalink.%@") permalinkTypePlaceholder;
+
+ action = null;
+ permalinkTypeValue = null;
+
+ @discourseComputed
+ permalinkTypes() {
+ return [
+ { id: "topic_id", name: i18n("admin.permalink.topic_id") },
+ { id: "post_id", name: i18n("admin.permalink.post_id") },
+ { id: "category_id", name: i18n("admin.permalink.category_id") },
+ { id: "tag_name", name: i18n("admin.permalink.tag_name") },
+ { id: "external_url", name: i18n("admin.permalink.external_url") },
+ { id: "user_id", name: i18n("admin.permalink.user_id") },
+ ];
+ }
+
+ @bind
+ focusPermalink() {
+ schedule("afterRender", () =>
+ document.querySelector(".permalink-url")?.focus()
+ );
+ }
+
+ @action
+ submitFormOnEnter(event) {
+ if (event.key === "Enter") {
+ this.onSubmit();
+ }
+ }
+
+ @action
+ onSubmit() {
+ if (!this.formSubmitted) {
+ this.set("formSubmitted", true);
+
+ Permalink.create({
+ url: this.url,
+ permalink_type: this.permalinkType,
+ permalink_type_value: this.permalinkTypeValue,
+ })
+ .save()
+ .then(
+ (result) => {
+ this.setProperties({
+ url: "",
+ permalinkTypeValue: "",
+ formSubmitted: false,
+ });
+
+ this.action(Permalink.create(result.permalink));
+
+ this.focusPermalink();
+ },
+ (e) => {
+ this.set("formSubmitted", false);
+
+ let error;
+ if (e?.jqXHR?.responseJSON?.errors) {
+ error = i18n("generic_error_with_reason", {
+ error: e.jqXHR.responseJSON.errors.join(". "),
+ });
+ } else {
+ error = i18n("generic_error");
+ }
+
+ this.dialog.alert({
+ message: error,
+ didConfirm: () => this.focusPermalink(),
+ didCancel: () => this.focusPermalink(),
+ });
+ }
+ );
+ }
+ }
+ }
++
+<div class="permalink-form">
+ <div class="inline-form">
+ <label>{{i18n "admin.permalink.form.label"}}</label>
+
+ <TextField
+ @value={{this.url}}
+ @disabled={{this.formSubmitted}}
+ @placeholderKey="admin.permalink.url"
+ @autocorrect="off"
+ @autocapitalize="off"
+ class="permalink-url"
+ />
+
+ <ComboBox
+ @content={{this.permalinkTypes}}
+ @value={{this.permalinkType}}
+ @onChange={{fn (mut this.permalinkType)}}
+ class="permalink-type"
+ />
+
+ <TextField
+ @value={{this.permalinkTypeValue}}
+ @disabled={{this.formSubmitted}}
+ @placeholderKey={{this.permalinkTypePlaceholder}}
+ @autocorrect="off"
+ @autocapitalize="off"
+ @keyDown={{this.submitFormOnEnter}}
+ class="permalink-destination"
+ />
+
+ <DButton
+ @action={{this.onSubmit}}
+ @disabled={{this.formSubmitted}}
+ @label="admin.permalink.form.add"
+ class="permalink-add"
+ />
+ </div>
+</div>
diff --cc app/assets/javascripts/admin/addon/components/report-filters/bool.gjs
index fc23b6333ae,602ed3c0766..ec1cf37d2e8
--- a/app/assets/javascripts/admin/addon/components/report-filters/bool.gjs
+++ b/app/assets/javascripts/admin/addon/components/report-filters/bool.gjs
@@@ -1,5 -1,16 +1,22 @@@
+ import { action } from "@ember/object";
+ import FilterComponent from "admin/components/report-filters/filter";
+
+ export default class Bool extends FilterComponent {
+ checked = false;
+
+ didReceiveAttrs() {
+ super.didReceiveAttrs(...arguments);
+ this.set("checked", !!this.filter.default);
+ }
+
+ @action
+ onChange() {
+ this.applyFilter(this.filter.id, !this.checked || undefined);
+ }
+ }
++
+<Input
+ @type="checkbox"
+ @checked={{this.checked}}
+ {{on "click" this.onChange}}
+/>
diff --cc app/assets/javascripts/admin/addon/components/report-filters/category.gjs
index e241e394890,cf381edbb9b..45658cb70fb
--- a/app/assets/javascripts/admin/addon/components/report-filters/category.gjs
+++ b/app/assets/javascripts/admin/addon/components/report-filters/category.gjs
@@@ -1,5 -1,12 +1,18 @@@
+ import { action } from "@ember/object";
+ import { readOnly } from "@ember/object/computed";
+ import FilterComponent from "admin/components/report-filters/filter";
+
+ export default class Category extends FilterComponent {
+ @readOnly("filter.default") category;
+
+ @action
+ onChange(categoryId) {
+ this.applyFilter(this.filter.id, categoryId || undefined);
+ }
+ }
++
+<SearchAdvancedCategoryChooser
+ @value={{this.category}}
+ @onChange={{this.onChange}}
+ @options={{hash filterable=true disabled=this.filter.disabled}}
+/>
diff --cc app/assets/javascripts/admin/addon/components/report-filters/group.gjs
index b41478c8f53,720840e3386..eaa5eaf4b3a
--- a/app/assets/javascripts/admin/addon/components/report-filters/group.gjs
+++ b/app/assets/javascripts/admin/addon/components/report-filters/group.gjs
@@@ -1,12 -1,18 +1,31 @@@
+ import { computed } from "@ember/object";
+ import { classNames } from "@ember-decorators/component";
+ import FilterComponent from "admin/components/report-filters/filter";
+
+ @classNames("group-filter")
+ export default class Group extends FilterComponent {
+ @computed
+ get groupOptions() {
+ return (this.site.groups || []).map((group) => {
+ return { name: group["name"], value: group["id"] };
+ });
+ }
+
+ @computed("filter.default")
+ get groupId() {
+ return this.filter.default ? parseInt(this.filter.default, 10) : null;
+ }
+ }
++
+<ComboBox
+ @valueProperty="value"
+ @content={{this.groupOptions}}
+ @value={{this.groupId}}
+ @onChange={{this.onChange}}
+ @options={{hash
+ allowAny=this.filter.allow_any
+ autoInsertNoneItem=this.filter.auto_insert_none_item
+ filterable=true
+ none="admin.dashboard.reports.groups"
+ }}
+/>
diff --cc app/assets/javascripts/admin/addon/components/report-filters/list.gjs
index d1e93095eb7,7ecc076e96a..03d659a81f1
--- a/app/assets/javascripts/admin/addon/components/report-filters/list.gjs
+++ b/app/assets/javascripts/admin/addon/components/report-filters/list.gjs
@@@ -1,12 -1,3 +1,16 @@@
+ import FilterComponent from "admin/components/report-filters/filter";
+
+ export default class List extends FilterComponent {}
++
+<ComboBox
+ @content={{this.filter.choices}}
+ @value={{this.filter.default}}
+ @onChange={{this.onChange}}
+ @options={{hash
+ allowAny=this.filter.allow_any
+ autoInsertNoneItem=this.filter.auto_insert_none_item
+ filterable=true
+ none="admin.dashboard.report_filter_any"
+ disabled=this.filter.disabled
+ }}
+/>
diff --cc app/assets/javascripts/admin/addon/components/screened-ip-address-form.gjs
index 65ce8a71db6,186192d5f85..2bd371a7150
--- a/app/assets/javascripts/admin/addon/components/screened-ip-address-form.gjs
+++ b/app/assets/javascripts/admin/addon/components/screened-ip-address-form.gjs
@@@ -1,23 -1,90 +1,114 @@@
+ import Component from "@ember/component";
+ import { action } from "@ember/object";
+ import { schedule } from "@ember/runloop";
+ import { service } from "@ember/service";
+ import { classNames, tagName } from "@ember-decorators/component";
+ import discourseComputed from "discourse/lib/decorators";
+ import { i18n } from "discourse-i18n";
+ import ScreenedIpAddress from "admin/models/screened-ip-address";
+
+ /**
+ A form to create an IP address that will be blocked or allowed.
+ Example usage:
+
+ {{screened-ip-address-form action=(action "recordAdded")}}
+
+ where action is a callback on the controller or route that will get called after
+ the new record is successfully saved. It is called with the new ScreenedIpAddress record
+ as an argument.
+ **/
+
+ @tagName("form")
+ @classNames("screened-ip-address-form", "inline-form")
+ export default class ScreenedIpAddressForm extends Component {
+ @service dialog;
+
+ formSubmitted = false;
+ actionName = "block";
+
+ @discourseComputed("siteSettings.use_admin_ip_allowlist")
+ actionNames(adminAllowlistEnabled) {
+ if (adminAllowlistEnabled) {
+ return [
+ { id: "block", name: i18n("admin.logs.screened_ips.actions.block") },
+ {
+ id: "do_nothing",
+ name: i18n("admin.logs.screened_ips.actions.do_nothing"),
+ },
+ {
+ id: "allow_admin",
+ name: i18n("admin.logs.screened_ips.actions.allow_admin"),
+ },
+ ];
+ } else {
+ return [
+ { id: "block", name: i18n("admin.logs.screened_ips.actions.block") },
+ {
+ id: "do_nothing",
+ name: i18n("admin.logs.screened_ips.actions.do_nothing"),
+ },
+ ];
+ }
+ }
+
+ focusInput() {
+ schedule("afterRender", () => {
+ this.element.querySelector("input").focus();
+ });
+ }
+
+ @action
+ submitForm() {
+ if (!this.formSubmitted) {
+ this.set("formSubmitted", true);
+ const screenedIpAddress = ScreenedIpAddress.create({
+ ip_address: this.ip_address,
+ action_name: this.actionName,
+ });
+ screenedIpAddress
+ .save()
+ .then((result) => {
+ this.setProperties({ ip_address: "", formSubmitted: false });
+ this.action(ScreenedIpAddress.create(result.screened_ip_address));
+ this.focusInput();
+ })
+ .catch((e) => {
+ this.set("formSubmitted", false);
+ const message = e.jqXHR.responseJSON?.errors
+ ? i18n("generic_error_with_reason", {
+ error: e.jqXHR.responseJSON.errors.join(". "),
+ })
+ : i18n("generic_error");
+ this.dialog.alert({
+ message,
+ didConfirm: () => this.focusInput(),
+ didCancel: () => this.focusInput(),
+ });
+ });
+ }
+ }
+ }
++
+<label>{{i18n "admin.logs.screened_ips.form.label"}}</label>
+<TextField
+ @value={{this.ip_address}}
+ @disabled={{this.formSubmitted}}
+ @placeholderKey="admin.logs.screened_ips.form.ip_address"
+ @autocorrect="off"
+ @autocapitalize="off"
+ class="ip-address-input"
+/>
+
+<ComboBox
+ @content={{this.actionNames}}
+ @value={{this.actionName}}
+ @onChange={{fn (mut this.actionName)}}
+/>
+
+<DButton
+ @action={{this.submitForm}}
+ @disabled={{this.formSubmitted}}
+ @label="admin.logs.screened_ips.form.add"
+ type="submit"
+ class="btn-default"
+/>
diff --cc app/assets/javascripts/admin/addon/components/secret-value-list.gjs
index 7ffbf1bdd37,11a87ec51d8..d2720a2b8c3
--- a/app/assets/javascripts/admin/addon/components/secret-value-list.gjs
+++ b/app/assets/javascripts/admin/addon/components/secret-value-list.gjs
@@@ -1,43 -1,116 +1,160 @@@
+ import Component from "@ember/component";
+ import { action, set } from "@ember/object";
+ import { isEmpty } from "@ember/utils";
+ import { classNameBindings } from "@ember-decorators/component";
+ import { i18n } from "discourse-i18n";
+
+ @classNameBindings(":value-list", ":secret-value-list")
+ export default class SecretValueList extends Component {
+ inputDelimiter = null;
+ collection = null;
+ values = null;
+
+ didReceiveAttrs() {
+ super.didReceiveAttrs(...arguments);
+
+ this.set(
+ "collection",
+ this._splitValues(this.values, this.inputDelimiter || "\n")
+ );
+ }
+
+ @action
+ changeKey(index, event) {
+ const newValue = event.target.value;
+
+ if (this._checkInvalidInput(newValue)) {
+ return;
+ }
+
+ this._replaceValue(index, newValue, "key");
+ }
+
+ @action
+ changeSecret(index, event) {
+ const newValue = event.target.value;
+
+ if (this._checkInvalidInput(newValue)) {
+ return;
+ }
+
+ this._replaceValue(index, newValue, "secret");
+ }
+
+ @action
+ addValue() {
+ if (this._checkInvalidInput([this.newKey, this.newSecret])) {
+ return;
+ }
+ this._addValue(this.newKey, this.newSecret);
+ this.setProperties({ newKey: "", newSecret: "" });
+ }
+
+ @action
+ removeValue(value) {
+ this._removeValue(value);
+ }
+
+ _checkInvalidInput(inputs) {
+ for (let input of inputs) {
+ if (isEmpty(input) || input.includes("|")) {
+ this.setValidationMessage(
+ i18n("admin.site_settings.secret_list.invalid_input")
+ );
+ return true;
+ }
+ }
+ this.setValidationMessage(null);
+ }
+
+ _addValue(value, secret) {
+ this.collection.addObject({ key: value, secret });
+ this._saveValues();
+ }
+
+ _removeValue(value) {
+ const collection = this.collection;
+ collection.removeObject(value);
+ this._saveValues();
+ }
+
+ _replaceValue(index, newValue, keyName) {
+ let item = this.collection[index];
+ set(item, keyName, newValue);
+
+ this._saveValues();
+ }
+
+ _saveValues() {
+ this.set(
+ "values",
+ this.collection
+ .map(function (elem) {
+ return `${elem.key}|${elem.secret}`;
+ })
+ .join("\n")
+ );
+ }
+
+ _splitValues(values, delimiter) {
+ if (values && values.length) {
+ const keys = ["key", "secret"];
+ let res = [];
+ values.split(delimiter).forEach(function (str) {
+ let object = {};
+ str.split("|").forEach(function (a, i) {
+ object[keys[i]] = a;
+ });
+ res.push(object);
+ });
+
+ return res;
+ } else {
+ return [];
+ }
+ }
+ }
++
+{{#if this.collection}}
+ <div class="values">
+ {{#each this.collection as |value index|}}
+ <div class="value" data-index={{index}}>
+ <DButton
+ @action={{fn this.removeValue value}}
+ @icon="xmark"
+ class="btn-default remove-value-btn btn-small"
+ />
+ <Input
+ @value={{value.key}}
+ class="value-input"
+ {{on "focusout" (fn this.changeKey index)}}
+ />
+ <Input
+ @value={{value.secret}}
+ class="value-input"
+ @type={{if this.isSecret "password" "text"}}
+ {{on "focusout" (fn this.changeSecret index)}}
+ />
+ </div>
+ {{/each}}
+ </div>
+{{/if}}
+
+<div class="value">
+ <TextField
+ @value={{this.newKey}}
+ @placeholder={{this.setting.placeholder.key}}
+ class="new-value-input key"
+ />
+ <Input
+ @type="password"
+ @value={{this.newSecret}}
+ class="new-value-input secret"
+ placeholder={{this.setting.placeholder.value}}
+ />
+ <DButton
+ @action={{this.addValue}}
+ @icon="plus"
+ class="add-value-btn btn-small"
+ />
+</div>
diff --cc app/assets/javascripts/admin/addon/components/setting-validation-message.gjs
index eef1454b751,4e60ec9c884..c5b65e749cb
--- a/app/assets/javascripts/admin/addon/components/setting-validation-message.gjs
+++ b/app/assets/javascripts/admin/addon/components/setting-validation-message.gjs
@@@ -1,4 -1,3 +1,8 @@@
+ import Component from "@ember/component";
+
+ export default class SettingValidationMessage extends Component {}
++
+<div class="validation-error {{unless this.message 'hidden'}}">
+ {{d-icon "xmark"}}
+ {{this.message}}
+</div>
diff --cc app/assets/javascripts/admin/addon/components/silence-details.gjs
index e7ab0fd4fd7,c51e6079181..3a930eb40ba
--- a/app/assets/javascripts/admin/addon/components/silence-details.gjs
+++ b/app/assets/javascripts/admin/addon/components/silence-details.gjs
@@@ -1,23 -1,5 +1,29 @@@
+ import Component from "@ember/component";
+ import { tagName } from "@ember-decorators/component";
+
+ @tagName("")
+ export default class SilenceDetails extends Component {}
++
+<div class="penalty-reason-controls">
+ <label>
+ <div class="silence-reason-label">
+ {{html-safe (i18n "admin.user.silence_reason_label")}}
+ </div>
+ </label>
+ <TextField
+ @value={{this.reason}}
+ @placeholderKey="admin.user.silence_reason_placeholder"
+ class="silence-reason"
+ />
+</div>
+
+<label>
+ <div class="silence-message-label">
+ {{i18n "admin.user.silence_message"}}
+ </div>
+</label>
+<Textarea
+ @value={{this.message}}
+ class="silence-message"
+ placeholder={{i18n "admin.user.silence_message_placeholder"}}
+/>
diff --cc app/assets/javascripts/admin/addon/components/simple-list.gjs
index 77fd959cbd0,3733bbb53f2..7bd49be3ba2
--- a/app/assets/javascripts/admin/addon/components/simple-list.gjs
+++ b/app/assets/javascripts/admin/addon/components/simple-list.gjs
@@@ -1,65 -1,93 +1,159 @@@
+ import { arrayContentDidChange } from "@ember/-internals/metal";
+ import Component from "@ember/component";
+ import { action } from "@ember/object";
+ import { empty } from "@ember/object/computed";
+ import { isEmpty } from "@ember/utils";
+ import { classNameBindings } from "@ember-decorators/component";
+ import discourseComputed from "discourse/lib/decorators";
+
+ @classNameBindings(":simple-list", ":value-list")
+ export default class SimpleList extends Component {
+ @empty("newValue") inputEmpty;
+
+ inputDelimiter = null;
+ newValue = "";
+ collection = null;
+ values = null;
+ choices = null;
+ allowAny = false;
+
+ didReceiveAttrs() {
+ super.didReceiveAttrs(...arguments);
+ this.set("collection", this._splitValues(this.values, this.inputDelimiter));
+ this.set("isPredefinedList", !this.allowAny && !isEmpty(this.choices));
+ }
+
+ keyDown(event) {
+ if (event.which === 13) {
+ this.addValue(this.newValue);
+ return;
+ }
+ }
+
+ @action
+ changeValue(index, event) {
+ this.collection.replace(index, 1, [event.target.value]);
+ arrayContentDidChange(this.collection, index);
+ this._onChange();
+ }
+
+ @action
+ addValue(newValue) {
+ if (!newValue) {
+ return;
+ }
+
+ this.set("newValue", null);
+ this.collection.addObject(newValue);
+ this._onChange();
+ }
+
+ @action
+ removeValue(value) {
+ this.collection.removeObject(value);
+ this._onChange();
+ }
+
+ @action
+ shift(operation, index) {
+ let futureIndex = index + operation;
+
+ if (futureIndex > this.collection.length - 1) {
+ futureIndex = 0;
+ } else if (futureIndex < 0) {
+ futureIndex = this.collection.length - 1;
+ }
+
+ const shiftedValue = this.collection[index];
+ this.collection.removeAt(index);
+ this.collection.insertAt(futureIndex, shiftedValue);
+
+ this._onChange();
+ }
+
+ _onChange() {
+ this.onChange?.(this.collection);
+ }
+
+ @discourseComputed("choices", "values")
+ validValues(choices, values) {
+ return choices.filter((name) => !values.includes(name));
+ }
+
+ @discourseComputed("collection")
+ showUpDownButtons(collection) {
+ return collection.length - 1 ? true : false;
+ }
+
+ _splitValues(values, delimiter) {
+ return values && values.length
+ ? values.split(delimiter || "\n").filter(Boolean)
+ : [];
+ }
+ }
++
+{{#if this.collection}}
+ <div class="values">
+ {{#each this.collection as |value index|}}
+ <div data-index={{index}} class="value">
+ <DButton
+ @action={{fn this.removeValue value}}
+ @icon="xmark"
+ class="btn-default remove-value-btn btn-small"
+ />
+
+ <Input
+ title={{value}}
+ @value={{value}}
+ class="value-input"
+ {{on "focusout" (fn this.changeValue index)}}
+ />
+
+ {{#if this.showUpDownButtons}}
+ <DButton
+ @action={{fn this.shift -1 index}}
+ @icon="arrow-up"
+ class="btn-default shift-up-value-btn btn-small"
+ />
+ <DButton
+ @action={{fn this.shift 1 index}}
+ @icon="arrow-down"
+ class="btn-default shift-down-value-btn btn-small"
+ />
+ {{/if}}
+ </div>
+ {{/each}}
+ </div>
+{{/if}}
+
+<div class="simple-list-input">
+ {{#if this.isPredefinedList}}
+ {{#if (gt this.validValues.length 0)}}
+ <ComboBox
+ @content={{this.validValues}}
+ @value={{this.newValue}}
+ @onChange={{this.addValue}}
+ @valueProperty={{this.setting.computedValueProperty}}
+ @nameProperty={{this.setting.computedNameProperty}}
+ @options={{hash castInteger=true allowAny=false}}
+ class="add-value-input"
+ />
+ {{/if}}
+ {{else}}
+ <Input
+ @type="text"
+ @value={{this.newValue}}
+ placeholder={{i18n "admin.site_settings.simple_list.add_item"}}
+ class="add-value-input"
+ autocomplete="off"
+ autocorrect="off"
+ autocapitalize="off"
+ />
+ <DButton
+ @action={{fn this.addValue this.newValue}}
+ @disabled={{this.inputEmpty}}
+ @icon="plus"
+ class="add-value-btn btn-small"
+ />
+ {{/if}}
+</div>
diff --cc app/assets/javascripts/admin/addon/components/site-customization-change-details.gjs
index fcded776ae4,cb9487ad2b2..d9d23df9424
--- a/app/assets/javascripts/admin/addon/components/site-customization-change-details.gjs
+++ b/app/assets/javascripts/admin/addon/components/site-customization-change-details.gjs
@@@ -1,55 -1,3 +1,59 @@@
+ import Component from "@ember/component";
+
+ export default class SiteCustomizationChangeDetails extends Component {}
++
+<section class="field">
+ <b>{{i18n "admin.customize.enabled"}}</b>:
+ {{this.change.enabled}}
+</section>
+
+<SiteCustomizationChangeField
+ @field={{this.change.stylesheet}}
+ @name="admin.customize.css"
+/>
+<SiteCustomizationChangeField
+ @icon="mobile"
+ @field={{this.change.mobile_stylesheet}}
+ @name="admin.customize.css"
+/>
+
+<SiteCustomizationChangeField
+ @field={{this.change.header}}
+ @name="admin.customize.header"
+/>
+<SiteCustomizationChangeField
+ @icon="mobile"
+ @field={{this.change.mobile_header}}
+ @name="admin.customize.header"
+/>
+
+<SiteCustomizationChangeField
+ @field={{this.change.top}}
+ @name="admin.customize.top"
+/>
+<SiteCustomizationChangeField
+ @icon="mobile"
+ @field={{this.change.mobile_top}}
+ @name="admin.customize.top"
+/>
+
+<SiteCustomizationChangeField
+ @field={{this.change.footer}}
+ @name="admin.customize.footer"
+/>
+<SiteCustomizationChangeField
+ @icon="mobile"
+ @field={{this.change.mobile_footer}}
+ @name="admin.customize.footer"
+/>
+
+<SiteCustomizationChangeField
+ @icon="file-text-o"
+ @field={{this.change.head_tag}}
+ @name="admin.customize.head_tag.text"
+/>
+<SiteCustomizationChangeField
+ @icon="file-text-o"
+ @field={{this.change.body_tag}}
+ @name="admin.customize.body_tag.text"
+/>
diff --cc app/assets/javascripts/admin/addon/components/site-customization-change-field.gjs
index a64ee1c4e0a,0e361124a0f..faf2feb5867
--- a/app/assets/javascripts/admin/addon/components/site-customization-change-field.gjs
+++ b/app/assets/javascripts/admin/addon/components/site-customization-change-field.gjs
@@@ -1,10 -1,3 +1,14 @@@
+ import Component from "@ember/component";
+
+ export default class SiteCustomizationChangeField extends Component {}
++
+{{#if this.field}}
+ <section class="field">
+ <b>{{i18n this.name}}</b>: ({{i18n
+ "character_count"
+ count=this.field.length
+ }})
+ <br />
+ <Textarea @value={{this.field}} class="plain" />
+ </section>
+{{/if}}
diff --cc app/assets/javascripts/admin/addon/components/site-setting.gjs
index 57f3394ba19,8b61c431ea0..94ad47d9cbd
--- a/app/assets/javascripts/admin/addon/components/site-setting.gjs
+++ b/app/assets/javascripts/admin/addon/components/site-setting.gjs
@@@ -1,87 -1,31 +1,119 @@@
+ import { cached, tracked } from "@glimmer/tracking";
+ import Component from "@ember/component";
+ import { dependentKeyCompat } from "@ember/object/compat";
+ import { readOnly } from "@ember/object/computed";
+ import BufferedProxy from "ember-buffered-proxy/proxy";
+ import SettingComponent from "admin/mixins/setting-component";
+ import SiteSetting from "admin/models/site-setting";
+
+ export default class SiteSettingComponent extends Component.extend(
+ SettingComponent
+ ) {
+ @tracked setting = null;
+ updateExistingUsers = null;
+
+ @readOnly("setting.staffLogFilter") staffLogFilter;
+
+ @cached
+ @dependentKeyCompat
+ get buffered() {
+ return BufferedProxy.create({
+ content: this.setting,
+ });
+ }
+
+ _save() {
+ const setting = this.buffered;
+ return SiteSetting.update(setting.get("setting"), setting.get("value"), {
+ updateExistingUsers: this.updateExistingUsers,
+ });
+ }
+ }
++
+<div class="setting-label">
+ <h3>
+ {{this.settingName}}
+
+ {{#if this.staffLogFilter}}
+ <LinkTo
+ @route="adminLogs.staffActionLogs"
+ @query={{hash filters=this.staffLogFilter force_refresh=true}}
+ title={{i18n "admin.settings.history"}}
+ >
+ <span class="history-icon">
+ {{d-icon "clock-rotate-left"}}
+ </span>
+ </LinkTo>
+ {{/if}}
+ </h3>
+
+ {{#if this.defaultIsAvailable}}
+ <DButton
+ class="btn-link"
+ @action={{this.setDefaultValues}}
+ @translatedLabel={{this.setting.setDefaultValuesLabel}}
+ />
+ {{/if}}
+</div>
+
+<div class="setting-value">
+ {{#if this.settingEditButton}}
+ <DButton
+ @action={{this.settingEditButton.action}}
+ @icon={{this.settingEditButton.icon}}
+ @label={{this.settingEditButton.label}}
+ class="setting-value-edit-button"
+ />
+
+ <SiteSettings::Description @description={{this.setting.description}} />
+ {{else}}
+ {{component
+ this.componentName
+ setting=this.setting
+ value=this.buffered.value
+ preview=this.preview
+ isSecret=this.isSecret
+ allowAny=this.allowAny
+ changeValueCallback=this.changeValueCallback
+ setValidationMessage=this.setValidationMessage
+ }}
+ <SettingValidationMessage @message={{this.validationMessage}} />
+ {{#if this.displayDescription}}
+ <SiteSettings::Description @description={{this.setting.description}} />
+ {{/if}}
+ {{/if}}
+</div>
+
+{{#if this.dirty}}
+ <div class="setting-controls">
+ <DButton
+ @action={{this.update}}
+ @icon="check"
+ @disabled={{this.disableSaveButton}}
+ @ariaLabel="admin.settings.save"
+ class="ok setting-controls__ok"
+ />
+ <DButton
+ @action={{this.cancel}}
+ @icon="xmark"
+ @ariaLabel="admin.settings.cancel"
+ class="cancel setting-controls__cancel"
+ />
+ </div>
+{{else if this.overridden}}
+ {{#if this.setting.secret}}
+ <DButton
+ @action={{this.toggleSecret}}
+ @icon="far-eye-slash"
+ @ariaLabel="admin.settings.unmask"
+ class="setting-toggle-secret"
+ />
+ {{/if}}
+
+ <DButton
+ class="btn-default undo setting-controls__undo"
+ @action={{this.resetDefault}}
+ @icon="arrow-rotate-left"
+ @label="admin.settings.reset"
+ />
+{{/if}}
diff --cc app/assets/javascripts/admin/addon/components/site-settings/enum.gjs
index a9ed4c42ddb,faebe31c2d1..fcc4d74fefc
--- a/app/assets/javascripts/admin/addon/components/site-settings/enum.gjs
+++ b/app/assets/javascripts/admin/addon/components/site-settings/enum.gjs
@@@ -1,10 -1,3 +1,14 @@@
+ import Component from "@ember/component";
+
+ export default class Enum extends Component {}
++
+<ComboBox
+ @content={{this.setting.validValues}}
+ @value={{this.value}}
+ @onChange={{fn (mut this.value)}}
+ @valueProperty={{this.setting.computedValueProperty}}
+ @nameProperty={{this.setting.computedNameProperty}}
+ @options={{hash castInteger=true allowAny=this.setting.allowsNone}}
+/>
+
+{{this.preview}}
diff --cc app/assets/javascripts/admin/addon/components/site-settings/group-list.gjs
index d4b6a0592af,dafef1f6c66..28b76808bd8
--- a/app/assets/javascripts/admin/addon/components/site-settings/group-list.gjs
+++ b/app/assets/javascripts/admin/addon/components/site-settings/group-list.gjs
@@@ -1,9 -1,25 +1,35 @@@
+ import Component from "@ember/component";
+ import { action, computed } from "@ember/object";
+
+ export default class GroupList extends Component {
+ tokenSeparator = "|";
+ nameProperty = "name";
+ valueProperty = "id";
+
+ @computed("site.groups")
+ get groupChoices() {
+ return (this.site.groups || []).map((g) => {
+ return { name: g.name, id: g.id.toString() };
+ });
+ }
+
+ @computed("value")
+ get settingValue() {
+ return (this.value || "").split(this.tokenSeparator).filter(Boolean);
+ }
+
+ @action
+ onChangeGroupListSetting(value) {
+ this.set("value", value.join(this.tokenSeparator));
+ }
+ }
++
+<ListSetting
+ @value={{this.settingValue}}
+ @choices={{this.groupChoices}}
+ @settingName="name"
+ @mandatoryValues={{this.setting.mandatory_values}}
+ @nameProperty={{this.nameProperty}}
+ @valueProperty={{this.valueProperty}}
+ @onChange={{this.onChangeGroupListSetting}}
+/>
diff --cc app/assets/javascripts/admin/addon/components/site-settings/host-list.gjs
index b56d921cf05,3ce615eb4f1..5e0d57a1cf5
--- a/app/assets/javascripts/admin/addon/components/site-settings/host-list.gjs
+++ b/app/assets/javascripts/admin/addon/components/site-settings/host-list.gjs
@@@ -1,7 -1,21 +1,29 @@@
+ import Component from "@ember/component";
+ import { action, computed } from "@ember/object";
+
+ export default class HostList extends Component {
+ tokenSeparator = "|";
+ choices = null;
+
+ @computed("value")
+ get settingValue() {
+ return this.value.toString().split(this.tokenSeparator).filter(Boolean);
+ }
+
+ @action
+ onChange(value) {
+ if (value.some((v) => v.includes("?") || v.includes("*"))) {
+ return;
+ }
+
+ this.set("value", value.join(this.tokenSeparator));
+ }
+ }
++
+<ListSetting
+ @value={{this.settingValue}}
+ @settingName={{this.setting.setting}}
+ @choices={{this.settingValue}}
+ @onChange={{this.onChange}}
+ @options={{hash allowAny=this.allowAny}}
+/>
diff --cc app/assets/javascripts/admin/addon/components/site-settings/list.gjs
index e515fad9075,d23ceb2ba77..e9678a0d0dd
--- a/app/assets/javascripts/admin/addon/components/site-settings/list.gjs
+++ b/app/assets/javascripts/admin/addon/components/site-settings/list.gjs
@@@ -1,5 -1,3 +1,9 @@@
+ import Component from "@ember/component";
+
+ export default class List extends Component {}
++
+<ValueList
+ @values={{this.value}}
+ @inputDelimiter="|"
+ @choices={{this.setting.choices}}
+/>
diff --cc app/assets/javascripts/admin/addon/components/site-settings/named-list.gjs
index 7569b9a1b5d,fadfedc9f0b..f4150870e8e
--- a/app/assets/javascripts/admin/addon/components/site-settings/named-list.gjs
+++ b/app/assets/javascripts/admin/addon/components/site-settings/named-list.gjs
@@@ -1,9 -1,33 +1,43 @@@
+ import Component from "@ember/component";
+ import { action, computed } from "@ember/object";
+
+ export default class NamedList extends Component {
+ tokenSeparator = "|";
+
+ @computed("value")
+ get settingValue() {
+ return this.value.toString().split(this.tokenSeparator).filter(Boolean);
+ }
+
+ @computed("setting.choices.[]", "settingValue")
+ get settingChoices() {
+ let choices = this.setting.choices;
+
+ if (this.settingValue) {
+ const valuesSet = new Set(choices.map((choice) => choice.value));
+
+ choices = choices.concat(
+ this.settingValue
+ .filter((value) => !valuesSet.has(value))
+ .map((value) => ({ name: value, value }))
+ );
+ }
+
+ return choices;
+ }
+
+ @action
+ onChangeListSetting(value) {
+ this.set("value", value.join(this.tokenSeparator));
+ }
+ }
++
+<ListSetting
+ @value={{this.settingValue}}
+ @settingName={{this.setting.setting}}
+ @choices={{this.settingChoices}}
+ @nameProperty="name"
+ @valueProperty="value"
+ @onChange={{this.onChangeListSetting}}
+ @options={{hash allowAny=this.allowAny}}
+/>
diff --cc app/assets/javascripts/admin/addon/components/site-settings/secret-list.gjs
index a15329ee5d3,167dbdc6e55..ff2dc53f380
--- a/app/assets/javascripts/admin/addon/components/site-settings/secret-list.gjs
+++ b/app/assets/javascripts/admin/addon/components/site-settings/secret-list.gjs
@@@ -1,6 -1,3 +1,10 @@@
+ import Component from "@ember/component";
+
+ export default class SecretList extends Component {}
++
+<SecretValueList
+ @setting={{this.setting}}
+ @values={{this.value}}
+ @isSecret={{this.isSecret}}
+ @setValidationMessage={{this.setValidationMessage}}
+/>
diff --cc app/assets/javascripts/admin/addon/components/site-settings/simple-list.gjs
index e4262696eab,ccc75e2b9dd..2281448669d
--- a/app/assets/javascripts/admin/addon/components/site-settings/simple-list.gjs
+++ b/app/assets/javascripts/admin/addon/components/site-settings/simple-list.gjs
@@@ -1,7 -1,11 +1,19 @@@
+ import Component from "@ember/component";
+ import { action } from "@ember/object";
+
+ export default class SimpleList extends Component {
+ inputDelimiter = "|";
+
+ @action
+ onChange(value) {
+ this.set("value", value.join(this.inputDelimiter || "\n"));
+ }
+ }
++
+<SimpleList
+ @values={{this.value}}
+ @inputDelimiter={{this.inputDelimiter}}
+ @onChange={{this.onChange}}
+ @choices={{this.setting.choices}}
+ @allowAny={{this.setting.allow_any}}
+/>
diff --cc app/assets/javascripts/admin/addon/components/site-settings/string.gjs
index 283bd94d52e,011d71d070d..c2d25e1c1f8
--- a/app/assets/javascripts/admin/addon/components/site-settings/string.gjs
+++ b/app/assets/javascripts/admin/addon/components/site-settings/string.gjs
@@@ -1,12 -1,3 +1,16 @@@
+ import Component from "@ember/component";
+
+ export default class String extends Component {}
++
+{{#if this.setting.textarea}}
+ <Textarea @value={{this.value}} class="input-setting-textarea" />
+{{else if this.isSecret}}
+ <Input
+ @type="password"
+ @value={{this.value}}
+ class="input-setting-string"
+ autocomplete="new-password"
+ />
+{{else}}
+ <TextField @value={{this.value}} @classNames="input-setting-string" />
+{{/if}}
diff --cc app/assets/javascripts/admin/addon/components/site-settings/tag-group-list.gjs
index 7809b5a36e2,ea6382e4bcf..b83accd09ba
--- a/app/assets/javascripts/admin/addon/components/site-settings/tag-group-list.gjs
+++ b/app/assets/javascripts/admin/addon/components/site-settings/tag-group-list.gjs
@@@ -1,5 -1,15 +1,21 @@@
+ import Component from "@ember/component";
+ import { action } from "@ember/object";
+ import discourseComputed from "discourse/lib/decorators";
+
+ export default class TagGroupList extends Component {
+ @discourseComputed("value")
+ selectedTagGroups(value) {
+ return value.split("|").filter(Boolean);
+ }
+
+ @action
+ onTagGroupChange(tagGroups) {
+ this.set("value", tagGroups.join("|"));
+ }
+ }
++
+<TagGroupChooser
+ @tagGroups={{this.selectedTagGroups}}
+ @onChange={{this.onTagGroupChange}}
+ @options={{hash filterPlaceholder="category.required_tag_group.placeholder"}}
+/>
diff --cc app/assets/javascripts/admin/addon/components/site-settings/tag-list.gjs
index 13bd33a0e4e,2c2d6d2a340..813e48aff39
--- a/app/assets/javascripts/admin/addon/components/site-settings/tag-list.gjs
+++ b/app/assets/javascripts/admin/addon/components/site-settings/tag-list.gjs
@@@ -1,7 -1,15 +1,23 @@@
+ import Component from "@ember/component";
+ import { action } from "@ember/object";
+ import discourseComputed from "discourse/lib/decorators";
+
+ export default class TagList extends Component {
+ @discourseComputed("value")
+ selectedTags(value) {
+ return value.split("|").filter(Boolean);
+ }
+
+ @action
+ changeSelectedTags(tags) {
+ this.set("value", tags.join("|"));
+ }
+ }
++
+<TagChooser
+ @tags={{this.selectedTags}}
+ @onChange={{this.changeSelectedTags}}
+ @everyTag={{true}}
+ @unlimitedTagCount={{true}}
+ @options={{hash allowAny=false}}
+/>
diff --cc app/assets/javascripts/admin/addon/components/site-settings/upload.gjs
index 7dcbe21bb11,6db6b3b4aae..b30e2c6f7d3
--- a/app/assets/javascripts/admin/addon/components/site-settings/upload.gjs
+++ b/app/assets/javascripts/admin/addon/components/site-settings/upload.gjs
@@@ -1,9 -1,9 +1,19 @@@
+ import Component from "@ember/component";
+ import { action } from "@ember/object";
+
+ export default class Upload extends Component {
+ @action
+ uploadDone(upload) {
+ this.set("value", upload.url);
+ }
+ }
++
+<UppyImageUploader
+ @imageUrl={{this.value}}
+ @placeholderUrl={{this.setting.placeholder}}
+ @onUploadDone={{this.uploadDone}}
+ @onUploadDeleted={{fn (mut this.value) null}}
+ @additionalParams={{hash for_site_setting=true}}
+ @type="site_setting"
+ @id={{concat "site-setting-image-uploader-" this.setting.setting}}
+/>
diff --cc app/assets/javascripts/admin/addon/components/site-settings/uploaded-image-list.gjs
index 06bf42d1c5f,1f398874dde..f53365ab2b2
--- a/app/assets/javascripts/admin/addon/components/site-settings/uploaded-image-list.gjs
+++ b/app/assets/javascripts/admin/addon/components/site-settings/uploaded-image-list.gjs
@@@ -1,7 -1,19 +1,27 @@@
+ import Component from "@ember/component";
+ import { action } from "@ember/object";
+ import { service } from "@ember/service";
+ import UploadedImageListModal from "admin/components/modal/uploaded-image-list";
+
+ export default class UploadedImageList extends Component {
+ @service modal;
+
+ @action
+ showUploadModal({ value, setting }) {
+ this.modal.show(UploadedImageListModal, {
+ model: {
+ title: `admin.site_settings.${setting.setting}.title`,
+ changeValue: (v) => this.set("value", v),
+ value,
+ },
+ });
+ }
+ }
++
+<DButton
+ @label="admin.site_settings.uploaded_image_list.label"
+ @action={{fn
+ this.showUploadModal
+ (hash value=this.value setting=this.setting)
+ }}
+/>
diff --cc app/assets/javascripts/admin/addon/components/site-settings/url-list.gjs
index 54df5b9a43f,87e25fd4164..6890f5af173
--- a/app/assets/javascripts/admin/addon/components/site-settings/url-list.gjs
+++ b/app/assets/javascripts/admin/addon/components/site-settings/url-list.gjs
@@@ -1,1 -1,3 +1,5 @@@
+ import Component from "@ember/component";
+
+ export default class UrlList extends Component {}
++
+<ValueList @values={{this.value}} @addKey="admin.site_settings.add_url" />
diff --cc app/assets/javascripts/admin/addon/components/site-settings/value-list.gjs
index 47fd877a49a,c358c36779f..10b323b564c
--- a/app/assets/javascripts/admin/addon/components/site-settings/value-list.gjs
+++ b/app/assets/javascripts/admin/addon/components/site-settings/value-list.gjs
@@@ -1,1 -1,3 +1,5 @@@
+ import Component from "@ember/component";
+
+ export default class ValueList extends Component {}
++
+<ValueList @values={{this.value}} />
diff --cc app/assets/javascripts/admin/addon/components/staff-actions.gjs
index 8a9aabbafb6,feb9db749ec..a45ff4b6e70
--- a/app/assets/javascripts/admin/addon/components/staff-actions.gjs
+++ b/app/assets/javascripts/admin/addon/components/staff-actions.gjs
@@@ -1,4 -1,24 +1,29 @@@
+ import Component from "@ember/component";
+ import { action } from "@ember/object";
+ import { tagName } from "@ember-decorators/component";
+ import DiscourseURL from "discourse/lib/url";
+
+ @tagName("")
+ export default class StaffActions extends Component {
+ @action
+ openLinks(event) {
+ const dataset = event.target.dataset;
+
+ if (dataset.linkPostId) {
+ event.preventDefault();
+
+ this.store.find("post", dataset.linkPostId).then((post) => {
+ DiscourseURL.routeTo(post.url);
+ });
+ } else if (dataset.linkTopicId) {
+ event.preventDefault();
+
+ DiscourseURL.routeTo(`/t/${dataset.linkTopicId}`);
+ }
+ }
+ }
++
+{{! template-lint-disable no-invalid-interactive }}
+<div class="table staff-actions" {{on "click" this.openLinks}}>
+ {{yield}}
+</div>
diff --cc app/assets/javascripts/admin/addon/components/theme-settings-editor.gjs
index f35651f8b74,0473ddacf7d..cd9c24b827f
--- a/app/assets/javascripts/admin/addon/components/theme-settings-editor.gjs
+++ b/app/assets/javascripts/admin/addon/components/theme-settings-editor.gjs
@@@ -1,27 -1,207 +1,235 @@@
+ import Component from "@glimmer/component";
+ import { tracked } from "@glimmer/tracking";
+ import { action } from "@ember/object";
+ import { service } from "@ember/service";
+ import { i18n } from "discourse-i18n";
+
+ export default class ThemeSettingsEditor extends Component {
+ @service dialog;
+
+ @tracked editedContent = JSON.stringify(
+ this.condensedThemeSettings,
+ null,
+ "\t"
+ );
+ @tracked errors = [];
+ @tracked saving = false;
+
+ // we need to store the controller being passed in so that when we
+ // call `save` we have not lost context of the argument
+ customizeThemeShowController = this.args.model?.controller;
+
+ get saveButtonDisabled() {
+ return !this.documentChanged || this.saving;
+ }
+
+ get documentChanged() {
+ try {
+ if (!this.editedContent) {
+ return false;
+ }
+ const editedContentString = JSON.stringify(
+ JSON.parse(this.editedContent)
+ );
+ const themeSettingsString = JSON.stringify(this.condensedThemeSettings);
+ if (editedContentString.localeCompare(themeSettingsString) !== 0) {
+ this.errors = [];
+ return true;
+ } else {
+ return false;
+ }
+ } catch {
+ return true;
+ }
+ }
+
+ get theme() {
+ return this.args.model?.model;
+ }
+
+ get condensedThemeSettings() {
+ if (!this.theme) {
+ return null;
+ }
+
+ return this.theme.settings.map((setting) => ({
+ setting: setting.setting,
+ value: setting.value,
+ }));
+ }
+
+ // validates the following:
+ // each setting must have a 'setting' and a 'value' key and no other keys
+ validateSettingsKeys(settings) {
+ return settings.reduce((acc, setting) => {
+ if (!acc) {
+ return acc;
+ }
+ if (!("setting" in setting)) {
+ // must have a setting key
+ return false;
+ }
+ if (!("value" in setting)) {
+ // must have a value key
+ return false;
+ }
+ if (Object.keys(setting).length > 2) {
+ // at this point it's verified to have setting and value key - but must have no other keys
+ return false;
+ }
+ return true;
+ }, true);
+ }
+
+ @action
+ async save() {
+ this.saving = true;
+ this.errors = [];
+ this.success = "";
+
+ if (!this.editedContent) {
+ // no changes.
+ return;
+ }
+
+ let newSettings = "";
+
+ try {
+ newSettings = JSON.parse(this.editedContent);
+ } catch (e) {
+ this.errors = [
+ ...this.errors,
+ {
+ setting: i18n("admin.customize.syntax_error"),
+ errorMessage: e.message,
+ },
+ ];
+ this.saving = false;
+ return;
+ }
+
+ if (!this.validateSettingsKeys(newSettings)) {
+ this.errors = [
+ ...this.errors,
+ {
+ setting: i18n("admin.customize.syntax_error"),
+ errorMessage: i18n("admin.customize.validation_settings_keys"),
+ },
+ ];
+ this.saving = false;
+ return;
+ }
+
+ const originalNames = this.theme
+ ? this.theme.settings.map((setting) => setting.setting)
+ : [];
+
+ const newNames = newSettings.map((setting) => setting.setting);
+ const deletedNames = originalNames.filter(
+ (originalName) => !newNames.find((newName) => newName === originalName)
+ );
+
+ const addedNames = newNames.filter(
+ (newName) =>
+ !originalNames.find((originalName) => originalName === newName)
+ );
+
+ if (deletedNames.length) {
+ this.errors = [
+ ...this.errors,
+ {
+ setting: deletedNames.join(", "),
+ errorMessage: i18n("admin.customize.validation_settings_deleted"),
+ },
+ ];
+ }
+
+ if (addedNames.length) {
+ this.errors = [
+ ...this.errors,
+ {
+ setting: addedNames.join(","),
+ errorMessage: i18n("admin.customize.validation_settings_added"),
+ },
+ ];
+ }
+
+ if (this.errors.length) {
+ this.saving = false;
+ return;
+ }
+
+ const changedSettings = [];
+
+ newSettings.forEach((newSetting) => {
+ const originalSetting = this.theme.settings.find(
+ (_originalSetting) => _originalSetting.setting === newSetting.setting
+ );
+
+ if (originalSetting.value !== newSetting.value) {
+ changedSettings.push({
+ originalSetting,
+ value: newSetting.value,
+ });
+ }
+ });
+
+ for (let changedSetting of changedSettings) {
+ try {
+ await this.saveSetting(this.theme.id, changedSetting);
+ } catch (err) {
+ const errorObjects = JSON.parse(err.jqXHR.responseText).errors.map(
+ (error) => ({
+ setting: changedSetting.originalSetting.setting,
+ errorMessage: error,
+ })
+ );
+
+ this.errors = [...this.errors, ...errorObjects];
+ }
+ }
+
+ if (this.errors.length === 0) {
+ this.editedContent = null;
+ }
+
+ this.saving = false;
+ this.dialog.cancel();
+ this.customizeThemeShowController.send("routeRefreshModel");
+ }
+
+ async saveSetting(themeId, changedSetting) {
+ return await changedSetting.originalSetting.updateSetting(
+ themeId,
+ changedSetting.value
+ );
+ }
+ }
++
+<div class="settings-editor">
+ <div>
+ <AceEditor
+ @content={{this.editedContent}}
+ @onChange={{fn (mut this.editedContent)}}
+ @mode="html"
+ />
+
+ {{#each this.errors as |error|}}
+ <div class="validation-error">
+ {{d-icon "xmark"}}
+ <b>{{error.setting}}</b>:
+ {{error.errorMessage}}
+ </div>
+ {{/each}}
+ </div>
+
+ <div class="buttons">
+ <DButton
+ @action={{this.save}}
+ id="save"
+ class="btn-primary save"
+ @disabled={{this.saveButtonDisabled}}
+ @translatedLabel={{i18n "admin.customize.theme.save"}}
+ />
+ </div>
+</div>
diff --cc app/assets/javascripts/admin/addon/components/theme-upload-add.gjs
index e4d694eb94c,94a6dee333b..feac7228073
--- a/app/assets/javascripts/admin/addon/components/theme-upload-add.gjs
+++ b/app/assets/javascripts/admin/addon/components/theme-upload-add.gjs
@@@ -1,47 -1,115 +1,163 @@@
+ import Component from "@glimmer/component";
+ import { tracked } from "@glimmer/tracking";
+ import { action } from "@ember/object";
+ import { isEmpty } from "@ember/utils";
+ import { ajax } from "discourse/lib/ajax";
+ import { extractError } from "discourse/lib/ajax-error";
+ import { i18n } from "discourse-i18n";
+
+ const THEME_FIELD_VARIABLE_TYPE_IDS = [2, 3, 4];
+ const SCSS_VARIABLE_NAMES = [
+ // common/foundation/colors.scss
+ "primary",
+ "secondary",
+ "tertiary",
+ "quaternary",
+ "header_background",
+ "header_primary",
+ "highlight",
+ "danger",
+ "success",
+ "love",
+ // common/foundation/math.scss
+ "E",
+ "PI",
+ "LN2",
+ "SQRT2",
+ // common/foundation/variables.scss
+ "small-width",
+ "medium-width",
+ "large-width",
+ "google",
+ "instagram",
+ "facebook",
+ "cas",
+ "twitter",
+ "github",
+ "base-font-size",
+ "base-line-height",
+ "base-font-family",
+ "primary-low",
+ "primary-medium",
+ "secondary-low",
+ "secondary-medium",
+ "tertiary-low",
+ "quaternary-low",
+ "highlight-low",
+ "highlight-medium",
+ "danger-low",
+ "danger-medium",
+ "success-low",
+ "love-low",
+ ];
+
+ export default class ThemeUploadAdd extends Component {
+ @tracked name;
+ @tracked fileSelected = false;
+ @tracked flash;
+
+ uploadUrl = this.args.model.uploadUrl || "/admin/themes/upload_asset";
+
+ get disabled() {
+ return this.errorMessage && this.fileSelected;
+ }
+
+ get errorMessage() {
+ if (!this.name) {
+ return;
+ } else if (!this.name.match(/^[a-z_][a-z0-9_-]*$/i)) {
+ return i18n("admin.customize.theme.variable_name_error.invalid_syntax");
+ } else if (SCSS_VARIABLE_NAMES.includes(name.toLowerCase())) {
+ return i18n("admin.customize.theme.variable_name_error.no_overwrite");
+ } else if (
+ this.args.model.themeFields.some(
+ (tf) =>
+ THEME_FIELD_VARIABLE_TYPE_IDS.includes(tf.type_id) &&
+ this.name === tf.name
+ )
+ ) {
+ return i18n("admin.customize.theme.variable_name_error.must_be_unique");
+ }
+ }
+
+ @action
+ updateName(e) {
+ if (isEmpty(this.name)) {
+ this.name = e.target.files[0].name.split(".")[0];
+ }
+ this.fileSelected = e.target.files[0];
+ }
+
+ @action
+ async upload() {
+ const file = document.getElementById("file-input").files[0];
+ const options = {
+ type: "POST",
+ processData: false,
+ contentType: false,
+ data: new FormData(),
+ };
+ options.data.append("file", file);
+
+ try {
+ const result = await ajax(this.uploadUrl, options);
+ const upload = {
+ upload_id: result.upload_id,
+ name: this.name,
+ original_filename: file.name,
+ };
+ this.args.model.addUpload(upload);
+ this.args.closeModal();
+ } catch (e) {
+ this.flash = extractError(e);
+ }
+ }
+ }
++
+<DModal
+ class="add-upload-modal"
+ @title={{i18n "admin.customize.theme.add_upload"}}
+ @closeModal={{@closeModal}}
+ @flash={{this.flash}}
+>
+ <:body>
+ <div class="inputs">
+ <section class="field">
+ <input
+ {{on "change" this.updateName}}
+ type="file"
+ id="file-input"
+ accept="*"
+ />
+ <label for="file-input">
+ {{i18n "admin.customize.theme.upload_file_tip"}}
+ </label>
+ </section>
+ <section class="field">
+ <label for="theme-variable-name">
+ {{i18n "admin.customize.theme.variable_name"}}
+ </label>
+ <Input id="theme-variable-name" @value={{this.name}} />
+ </section>
+ {{#if this.fileSelected}}
+ {{#if this.errorMessage}}
+ <span class="alert alert-error">{{this.errorMessage}}</span>
+ {{/if}}
+ {{/if}}
+ </div>
+ </:body>
+ <:footer>
+ <DButton
+ @action={{this.upload}}
+ @disabled={{this.disabled}}
+ @icon="upload"
+ @label="admin.customize.theme.upload"
+ class="btn-primary"
+ />
+ <DButton
+ @action={{@closeModal}}
+ @label="cancel"
+ class="btn-transparent d-modal-cancel"
+ />
+ </:footer>
+</DModal>
diff --cc app/assets/javascripts/admin/addon/components/themes-list.gjs
index 20a706d651a,59e4c26c77f..33f28d0f061
--- a/app/assets/javascripts/admin/addon/components/themes-list.gjs
+++ b/app/assets/javascripts/admin/addon/components/themes-list.gjs
@@@ -1,138 -1,265 +1,404 @@@
+ import Component from "@ember/component";
+ import { action } from "@ember/object";
+ import { equal, gt, gte } from "@ember/object/computed";
+ import { service } from "@ember/service";
+ import { classNames } from "@ember-decorators/component";
+ import DeleteThemesConfirm from "discourse/components/modal/delete-themes-confirm";
+ import discourseComputed, { bind } from "discourse/lib/decorators";
+ import { i18n } from "discourse-i18n";
+ import { COMPONENTS, THEMES } from "admin/models/theme";
+
+ const ALL_FILTER = "all";
+ const ACTIVE_FILTER = "active";
+ const INACTIVE_FILTER = "inactive";
+ const ENABLED_FILTER = "enabled";
+ const DISABLED_FILTER = "disabled";
+ const UPDATES_AVAILABLE_FILTER = "updates_available";
+
+ const THEMES_FILTERS = [
+ { name: i18n("admin.customize.theme.all_filter"), id: ALL_FILTER },
+ { name: i18n("admin.customize.theme.active_filter"), id: ACTIVE_FILTER },
+ {
+ name: i18n("admin.customize.theme.inactive_filter"),
+ id: INACTIVE_FILTER,
+ },
+ {
+ name: i18n("admin.customize.theme.updates_available_filter"),
+ id: UPDATES_AVAILABLE_FILTER,
+ },
+ ];
+ const COMPONENTS_FILTERS = [
+ { name: i18n("admin.customize.component.all_filter"), id: ALL_FILTER },
+ {
+ name: i18n("admin.customize.component.used_filter"),
+ id: ACTIVE_FILTER,
+ },
+ {
+ name: i18n("admin.customize.component.unused_filter"),
+ id: INACTIVE_FILTER,
+ },
+ {
+ name: i18n("admin.customize.component.enabled_filter"),
+ id: ENABLED_FILTER,
+ },
+ {
+ name: i18n("admin.customize.component.disabled_filter"),
+ id: DISABLED_FILTER,
+ },
+ {
+ name: i18n("admin.customize.component.updates_available_filter"),
+ id: UPDATES_AVAILABLE_FILTER,
+ },
+ ];
+
+ @classNames("themes-list")
+ export default class ThemesList extends Component {
+ @service router;
+ @service modal;
+
+ THEMES = THEMES;
+ COMPONENTS = COMPONENTS;
+ searchTerm = null;
+ filter = ALL_FILTER;
+ selectInactiveMode = false;
+
+ @gt("themesList.length", 0) hasThemes;
+
+ @gt("activeThemes.length", 0) hasActiveThemes;
+
+ @gt("inactiveThemes.length", 0) hasInactiveThemes;
+
+ @gte("themesList.length", 10) showSearchAndFilter;
+
+ @equal("currentTab", THEMES) themesTabActive;
+
+ @equal("currentTab", COMPONENTS) componentsTabActive;
+
+ @equal("filter", ACTIVE_FILTER) activeFilter;
+ @equal("filter", INACTIVE_FILTER) inactiveFilter;
+
+ willRender() {
+ super.willRender(...arguments);
+ if (!this.showSearchAndFilter) {
+ this.set("searchTerm", null);
+ }
+ }
+
+ @discourseComputed("themes", "components", "currentTab")
+ themesList(themes, components) {
+ if (this.themesTabActive) {
+ return themes;
+ } else {
+ return components;
+ }
+ }
+
+ @discourseComputed("currentTab")
+ selectableFilters() {
+ if (this.themesTabActive) {
+ return THEMES_FILTERS;
+ } else {
+ return COMPONENTS_FILTERS;
+ }
+ }
+
+ @discourseComputed(
+ "themesList",
+ "currentTab",
+ "[email protected]_selectable",
+ "searchTerm",
+ "filter"
+ )
+ inactiveThemes(themes) {
+ let results;
+ if (this.componentsTabActive) {
+ results = themes.filter(
+ (theme) => theme.get("parent_themes.length") <= 0
+ );
+ } else {
+ results = themes.filter(
+ (theme) => !theme.get("user_selectable") && !theme.get("default")
+ );
+ }
+ results = this._applyFilter(results);
+ return this._searchThemes(results, this.searchTerm);
+ }
+
+ @discourseComputed("[email protected]")
+ selectedThemesOrComponents() {
+ return this.themesList.filter((theme) => theme.markedToDelete);
+ }
+
+ @discourseComputed("[email protected]")
+ selectedCount() {
+ return this.selectedThemesOrComponents.length;
+ }
+
+ @discourseComputed(
+ "themesList",
+ "currentTab",
+ "[email protected]_selectable",
+ "searchTerm",
+ "filter"
+ )
+ activeThemes(themes) {
+ let results;
+ if (this.componentsTabActive) {
+ results = themes.filter((theme) => theme.get("parent_themes.length") > 0);
+ } else {
+ results = themes
+ .filter((theme) => theme.get("user_selectable") || theme.get("default"))
+ .sort((a, b) => {
+ if (a.get("default") && !b.get("default")) {
+ return -1;
+ } else if (b.get("default")) {
+ return 1;
+ }
+ return a
+ .get("name")
+ .toLowerCase()
+ .localeCompare(b.get("name").toLowerCase());
+ });
+ }
+ results = this._applyFilter(results);
+ return this._searchThemes(results, this.searchTerm);
+ }
+
+ @discourseComputed("[email protected]")
+ someInactiveSelected() {
+ return (
+ this.selectedCount > 0 &&
+ this.selectedCount !== this.inactiveThemes.length
+ );
+ }
+
+ @discourseComputed("[email protected]")
+ allInactiveSelected() {
+ return this.selectedCount === this.inactiveThemes.length;
+ }
+
+ _searchThemes(themes, term) {
+ term = term?.trim()?.toLowerCase();
+ if (!term) {
+ return themes;
+ }
+ return themes.filter(({ name }) => name.toLowerCase().includes(term));
+ }
+
+ _applyFilter(results) {
+ switch (this.filter) {
+ case UPDATES_AVAILABLE_FILTER: {
+ return results.filterBy("isPendingUpdates");
+ }
+ case ENABLED_FILTER: {
+ return results.filterBy("enabled");
+ }
+ case DISABLED_FILTER: {
+ return results.filterBy("enabled", false);
+ }
+ default: {
+ return results;
+ }
+ }
+ }
+
+ @bind
+ toggleInactiveMode(event) {
+ event?.preventDefault();
+ this.inactiveThemes.forEach((theme) => theme.set("markedToDelete", false));
+ this.toggleProperty("selectInactiveMode");
+ }
+
+ @action
+ changeView(newTab) {
+ if (newTab !== this.currentTab) {
+ this.set("selectInactiveMode", false);
+ this.set("filter", ALL_FILTER);
+ this.router.transitionTo("adminCustomizeThemes", newTab);
+ }
+ }
+
+ @action
+ navigateToTheme(theme) {
+ this.router.transitionTo("adminCustomizeThemes.show", theme);
+ }
+
+ @action
+ toggleAllInactive() {
+ const markedToDelete = this.selectedCount === 0;
+ this.inactiveThemes.forEach((theme) =>
+ theme.set("markedToDelete", markedToDelete)
+ );
+ }
+
+ @action
+ deleteConfirmation() {
+ this.modal.show(DeleteThemesConfirm, {
+ model: {
+ selectedThemesOrComponents: this.selectedThemesOrComponents,
+ type: this.themesTabActive ? "themes" : "components",
+ refreshAfterDelete: () => {
+ this.set("selectInactiveMode", false);
+ if (this.themesTabActive) {
+ this.set(
+ "themes",
+ this.themes.filter(
+ (theme) => !this.selectedThemesOrComponents.includes(theme)
+ )
+ );
+ } else {
+ this.set(
+ "components",
+ this.components.filter(
+ (component) =>
+ !this.selectedThemesOrComponents.includes(component)
+ )
+ );
+ }
+ },
+ },
+ });
+ }
+ }
++
+<div class="themes-list-header">
+ <DButton
+ @action={{fn this.changeView this.THEMES}}
+ @label="admin.customize.theme.title"
+ class={{concat-class "themes-tab" "tab" (if this.themesTabActive "active")}}
+ />
+ <DButton
+ @action={{fn this.changeView this.COMPONENTS}}
+ @label="admin.customize.theme.components"
+ @icon="puzzle-piece"
+ class={{concat-class
+ "components-tab"
+ "tab"
+ (if this.componentsTabActive "active")
+ }}
+ />
+</div>
+
+{{#if this.showSearchAndFilter}}
+ <div class="themes-list-search">
+ <Input
+ class="themes-list-search__input"
+ placeholder={{i18n "admin.customize.theme.search_placeholder"}}
+ autocomplete="off"
+ @type="search"
+ @value={{mut this.searchTerm}}
+ />
+ {{d-icon "magnifying-glass"}}
+ </div>
+ <div class="themes-list-filter">
+ <div class="themes-list-filter__label">
+ {{i18n "admin.customize.theme.filter_by"}}
+ </div>
+ <ComboBox
+ @content={{this.selectableFilters}}
+ @value={{this.filter}}
+ class="themes-list-filter__input"
+ />
+ </div>
+{{/if}}
+<div class="themes-list-container">
+ {{#if this.hasThemes}}
+ {{#if (and this.hasActiveThemes (not this.inactiveFilter))}}
+ {{#each this.activeThemes as |theme|}}
+ <ThemesListItem
+ @theme={{theme}}
+ @navigateToTheme={{fn this.navigateToTheme theme}}
+ />
+ {{/each}}
+
+ {{#if (and this.hasInactiveThemes (not this.activeFilter))}}
+ <div class="themes-list-container__item inactive-indicator">
+ <span class="empty">
+ <div class="info">
+ {{#if this.selectInactiveMode}}
+ <Input
+ @type="checkbox"
+ @checked={{or
+ (eq this.allInactiveSelected true)
+ (eq this.someInactiveSelected true)
+ }}
+ class="toggle-all-inactive"
+ indeterminate={{this.someInactiveSelected}}
+ {{on "click" this.toggleAllInactive}}
+ />
+ {{else}}
+ <DButton
+ class="btn-transparent select-inactive-mode"
+ @action={{this.toggleInactiveMode}}
+ >
+ {{d-icon "list"}}
+ </DButton>
+ {{/if}}
+ {{#if this.selectInactiveMode}}
+ <span class="select-inactive-mode-label">
+ {{i18n
+ "admin.customize.theme.selected"
+ count=this.selectedCount
+ }}
+ </span>
+ {{else if this.themesTabActive}}
+ <span class="header">
+ {{i18n "admin.customize.theme.inactive_themes"}}
+ </span>
+ {{else}}
+ <span class="header">
+ {{i18n "admin.customize.theme.inactive_components"}}
+ </span>
+ {{/if}}
+
+ {{#if this.selectInactiveMode}}
+ <a
+ href
+ {{on "click" this.toggleInactiveMode}}
+ class="cancel-select-inactive-mode"
+ >
+ {{i18n "admin.customize.theme.cancel"}}
+ </a>
+ <DButton
+ class="btn btn-delete"
+ @action={{this.deleteConfirmation}}
+ @disabled={{eq this.selectedCount 0}}
+ >
+ {{d-icon "trash-can"}}
+ Delete
+ </DButton>
+ {{/if}}
+ </div>
+ </span>
+ </div>
+ {{/if}}
+ {{/if}}
+
+ {{#if (and this.hasInactiveThemes (not this.activeFilter))}}
+ {{#each this.inactiveThemes as |theme|}}
+ <ThemesListItem
+ class="inactive-theme"
+ @theme={{theme}}
+ @navigateToTheme={{fn this.navigateToTheme theme}}
+ @selectInactiveMode={{this.selectInactiveMode}}
+ />
+ {{/each}}
+ {{/if}}
+ {{else}}
+ <div class="themes-list-container__item">
+ <span class="empty">{{i18n "admin.customize.theme.empty"}}</span>
+ </div>
+ {{/if}}
+</div>
+
+<div class="create-actions">
+ <DButton
+ @action={{this.installModal}}
+ @icon="upload"
+ @label="admin.customize.install"
+ class="btn-primary"
+ />
+</div>
diff --cc app/assets/javascripts/admin/addon/components/value-list.gjs
index 0f026251e7b,eb8898d3897..1c345f87172
--- a/app/assets/javascripts/admin/addon/components/value-list.gjs
+++ b/app/assets/javascripts/admin/addon/components/value-list.gjs
@@@ -1,42 -1,143 +1,186 @@@
+ import Component from "@ember/component";
+ import { action } from "@ember/object";
+ import { empty, reads } from "@ember/object/computed";
+ import { classNames } from "@ember-decorators/component";
+ import discourseComputed from "discourse/lib/decorators";
+ import { makeArray } from "discourse/lib/helpers";
+
+ @classNames("value-list")
+ export default class ValueList extends Component {
+ @empty("newValue") inputInvalid;
+
+ inputDelimiter = null;
+ inputType = null;
+ newValue = "";
+ collection = null;
+ values = null;
+ onChange = null;
+
+ @reads("addKey") noneKey;
+
+ didReceiveAttrs() {
+ super.didReceiveAttrs(...arguments);
+
+ if (this.inputType === "array") {
+ this.set("collection", this.values ? [...this.values] : []);
+ return;
+ }
+
+ this.set(
+ "collection",
+ this._splitValues(this.values, this.inputDelimiter || "\n")
+ );
+ }
+
+ @discourseComputed("choices.[]", "collection.[]")
+ filteredChoices(choices, collection) {
+ return makeArray(choices).filter((i) => !collection.includes(i));
+ }
+
+ keyDown(event) {
+ if (event.key === "Enter") {
+ this.send("addValue", this.newValue);
+ }
+ }
+
+ @action
+ changeValue(index, event) {
+ this._replaceValue(index, event.target.value);
+ }
+
+ @action
+ addValue(newValue) {
+ if (this.inputInvalid) {
+ return;
+ }
+
+ this.set("newValue", null);
+ this._addValue(newValue);
+ }
+
+ @action
+ removeValue(value) {
+ this._removeValue(value);
+ }
+
+ @action
+ selectChoice(choice) {
+ this._addValue(choice);
+ }
+
+ @action
+ shift(operation, index) {
+ let futureIndex = index + operation;
+
+ if (futureIndex > this.collection.length - 1) {
+ futureIndex = 0;
+ } else if (futureIndex < 0) {
+ futureIndex = this.collection.length - 1;
+ }
+
+ const shiftedValue = this.collection[index];
+ this.collection.removeAt(index);
+ this.collection.insertAt(futureIndex, shiftedValue);
+
+ this._saveValues();
+ }
+
+ _addValue(value) {
+ this.collection.addObject(value);
+
+ if (this.choices) {
+ this.set("choices", this.choices.rejectBy("id", value));
+ } else {
+ this.set("choices", []);
+ }
+
+ this._saveValues();
+ }
+
+ _removeValue(value) {
+ this.collection.removeObject(value);
+
+ if (this.choices) {
+ this.set("choices", this.choices.concat([value]).uniq());
+ } else {
+ this.set("choices", makeArray(value));
+ }
+
+ this._saveValues();
+ }
+
+ _replaceValue(index, newValue) {
+ this.collection.replace(index, 1, [newValue]);
+ this._saveValues();
+ }
+
+ _saveValues() {
+ if (this.onChange) {
+ this.onChange([...this.collection]);
+ return;
+ }
+
+ if (this.inputType === "array") {
+ this.set("values", this.collection);
+ return;
+ }
+
+ this.set("values", this.collection.join(this.inputDelimiter || "\n"));
+ }
+
+ @discourseComputed("collection")
+ showUpDownButtons(collection) {
+ return collection.length - 1 ? true : false;
+ }
+
+ _splitValues(values, delimiter) {
+ if (values && values.length) {
+ return values.split(delimiter).filter((x) => x);
+ } else {
+ return [];
+ }
+ }
+ }
++
+{{#if this.collection}}
+ <div class="values">
+ {{#each this.collection as |value index|}}
+ <div data-index={{index}} class="value">
+ <DButton
+ @action={{fn this.removeValue value}}
+ @icon="xmark"
+ class="btn-default remove-value-btn btn-small"
+ />
+
+ <Input
+ title={{value}}
+ @value={{value}}
+ class="value-input"
+ {{on "focusout" (fn this.changeValue index)}}
+ />
+
+ {{#if this.showUpDownButtons}}
+ <DButton
+ @action={{fn this.shift -1 index}}
+ @icon="arrow-up"
+ class="btn-default shift-up-value-btn btn-small"
+ />
+ <DButton
+ @action={{fn this.shift 1 index}}
+ @icon="arrow-down"
+ class="btn-default shift-down-value-btn btn-small"
+ />
+ {{/if}}
+ </div>
+ {{/each}}
+ </div>
+{{/if}}
+
+<ComboBox
+ @valueProperty={{null}}
+ @nameProperty={{null}}
+ @value={{this.newValue}}
+ @content={{this.filteredChoices}}
+ @onChange={{this.selectChoice}}
+ @options={{hash allowAny=true none=this.noneKey}}
+/>
diff --cc app/assets/javascripts/admin/addon/components/version-checks.gjs
index 3a3ad1a73e3,b06deba9d5f..2593c7c60b9
--- a/app/assets/javascripts/admin/addon/components/version-checks.gjs
+++ b/app/assets/javascripts/admin/addon/components/version-checks.gjs
@@@ -1,145 -1,3 +1,149 @@@
+ import Component from "@ember/component";
+
+ export default class VersionChecks extends Component {}
++
+<div class="section-title">
+ <h2>
+ {{i18n "admin.dashboard.version"}}
+ </h2>
+</div>
+
+<div
+ class="dashboard-stats version-check
+ {{if this.versionCheck.critical_updates 'critical' 'normal'}}"
+>
+ <div class="version-number">
+ <h4>
+ {{i18n "admin.dashboard.installed_version"}}
+ </h4>
+ <h3>
+ {{dash-if-empty this.versionCheck.installed_version}}
+ </h3>
+ {{#if this.versionCheck.gitLink}}
+ <div class="sha-link">
+ (
+ <a
+ href={{this.versionCheck.gitLink}}
+ rel="noopener noreferrer"
+ target="_blank"
+ >
+ {{this.versionCheck.shortSha}}
+ </a>
+ )
+ </div>
+ {{/if}}
+ </div>
+ {{#if this.versionCheck.noCheckPerformed}}
+ <div class="version-number">
+ <h4>
+ {{i18n "admin.dashboard.latest_version"}}
+ </h4>
+ <h3>
+ —
+ </h3>
+ </div>
+ <div class="version-status">
+ <div class="face">
+ <span class="icon critical-updates-available">
+ {{d-icon "far-face-frown"}}
+ </span>
+ </div>
+ <div class="version-notes">
+ <span class="normal-note">
+ {{i18n "admin.dashboard.no_check_performed"}}
+ </span>
+ </div>
+ </div>
+ {{else if this.versionCheck.stale_data}}
+ <div class="version-number">
+ <h4>
+ {{i18n "admin.dashboard.latest_version"}}
+ </h4>
+ <h3>
+ {{#if this.versionCheck.version_check_pending}}
+ {{dash-if-empty this.versionCheck.installed_version}}
+ {{/if}}
+ </h3>
+ </div>
+ <div class="version-status">
+ <div class="face">
+ {{#if this.versionCheck.version_check_pending}}
+ <span class="icon up-to-date">
+ {{d-icon "far-face-smile"}}
+ </span>
+ {{else}}
+ <span class="icon critical-updates-available">
+ {{d-icon "far-face-frown"}}
+ </span>
+ {{/if}}
+ </div>
+ <div class="version-notes">
+ <span class="normal-note">
+ {{#if this.versionCheck.version_check_pending}}
+ {{i18n "admin.dashboard.version_check_pending"}}
+ {{else}}
+ {{i18n "admin.dashboard.stale_data"}}
+ {{/if}}
+ </span>
+ </div>
+ </div>
+ {{else}}
+ <div class="version-number">
+ <h4>
+ {{i18n "admin.dashboard.latest_version"}}
+ </h4>
+ <h3>
+ {{dash-if-empty this.versionCheck.latest_version}}
+ </h3>
+ </div>
+ <div class="version-status">
+ <div class="face">
+ {{#if this.versionCheck.upToDate}}
+ <span class="icon up-to-date">
+ {{d-icon "far-face-smile"}}
+ </span>
+ {{else}}
+ <span
+ class="icon
+ {{if
+ this.versionCheck.critical_updates
+ 'critical-updates-available'
+ 'updates-available'
+ }}"
+ >
+ {{#if this.versionCheck.behindByOneVersion}}
+ {{d-icon "far-face-meh"}}
+ {{else}}
+ {{d-icon "far-face-frown"}}
+ {{/if}}
+ </span>
+ {{/if}}
+ </div>
+ <div class="version-notes">
+ {{#if this.versionCheck.upToDate}}
+ {{i18n "admin.dashboard.up_to_date"}}
+ {{else}}
+ <span class="critical-note">
+ {{i18n "admin.dashboard.critical_available"}}
+ </span>
+ <span class="normal-note">
+ {{i18n "admin.dashboard.updates_available"}}
+ </span>
+ {{i18n "admin.dashboard.please_update"}}
+ {{/if}}
+ </div>
+ </div>
+ {{/if}}
+
+ <CustomHtml
+ @name="update-header"
+ @versionCheck={{this.versionCheck}}
+ @tagName="div"
+ @classNames="update-header"
+ />
+
+ <PluginOutlet
+ @name="admin-upgrade-header"
+ @outletArgs={{hash versionCheck=this.versionCheck}}
+ />
+</div>
diff --cc app/assets/javascripts/admin/addon/components/watched-word-form.gjs
index 6375e94dd42,c9b9c99e05a..b15ec3d5466
--- a/app/assets/javascripts/admin/addon/components/watched-word-form.gjs
+++ b/app/assets/javascripts/admin/addon/components/watched-word-form.gjs
@@@ -1,104 -1,130 +1,235 @@@
+ import Component from "@ember/component";
+ import { action } from "@ember/object";
+ import { empty, equal } from "@ember/object/computed";
+ import { service } from "@ember/service";
+ import { isEmpty } from "@ember/utils";
+ import { classNames, tagName } from "@ember-decorators/component";
+ import { observes } from "@ember-decorators/object";
+ import { popupAjaxError } from "discourse/lib/ajax-error";
+ import discourseComputed from "discourse/lib/decorators";
+ import { i18n } from "discourse-i18n";
+ import WatchedWord from "admin/models/watched-word";
+
+ @tagName("form")
+ @classNames("watched-word-form")
+ export default class WatchedWordForm extends Component {
+ @service dialog;
+
+ formSubmitted = false;
+ actionKey = null;
+ showMessage = false;
+ isCaseSensitive = false;
+ isHtml = false;
+ selectedTags = [];
+ words = [];
+
+ @empty("words") submitDisabled;
+ @equal("actionKey", "replace") canReplace;
+ @equal("actionKey", "tag") canTag;
+ @equal("actionKey", "link") canLink;
+
+ @discourseComputed("siteSettings.watched_words_regular_expressions")
+ placeholderKey(watchedWordsRegularExpressions) {
+ if (watchedWordsRegularExpressions) {
+ return "admin.watched_words.form.placeholder_regexp";
+ } else {
+ return "admin.watched_words.form.placeholder";
+ }
+ }
+
+ @observes("words.[]")
+ removeMessage() {
+ if (this.showMessage && !isEmpty(this.words)) {
+ this.set("showMessage", false);
+ }
+ }
+
+ @observes("actionKey")
+ actionChanged() {
+ this.setProperties({
+ showMessage: false,
+ });
+ }
+
+ @discourseComputed("words.[]")
+ isUniqueWord(words) {
+ const existingWords = this.filteredContent || [];
+ const filtered = existingWords.filter(
+ (content) => content.action === this.actionKey
+ );
+
+ const duplicate = filtered.find((content) => {
+ if (content.case_sensitive === true) {
+ return words.includes(content.word);
+ } else {
+ return words
+ .map((w) => w.toLowerCase())
+ .includes(content.word.toLowerCase());
+ }
+ });
+
+ return !duplicate;
+ }
+
+ @action
+ changeSelectedTags(tags) {
+ this.setProperties({
+ selectedTags: tags,
+ replacement: tags.join(","),
+ });
+ }
+
+ @action
+ submitForm() {
+ if (!this.isUniqueWord) {
+ this.setProperties({
+ showMessage: true,
+ message: i18n("admin.watched_words.form.exists"),
+ });
+ return;
+ }
+
+ if (!this.formSubmitted) {
+ this.set("formSubmitted", true);
+
+ const watchedWord = WatchedWord.create({
+ words: this.words,
+ replacement:
+ this.canReplace || this.canTag || this.canLink
+ ? this.replacement
+ : null,
+ action: this.actionKey,
+ isCaseSensitive: this.isCaseSensitive,
+ isHtml: this.isHtml,
+ });
+
+ watchedWord
+ .save()
+ .then((result) => {
+ this.setProperties({
+ words: [],
+ replacement: "",
+ selectedTags: [],
+ showMessage: true,
+ message: i18n("admin.watched_words.form.success"),
+ isCaseSensitive: false,
+ isHtml: false,
+ });
+ if (result.words) {
+ result.words.forEach((word) => {
+ this.action(WatchedWord.create(word));
+ });
+ } else {
+ this.action(result);
+ }
+ })
+ .catch(popupAjaxError)
+ .finally(this.set("formSubmitted", false));
+ }
+ }
+ }
++
+<div class="watched-word-input">
+ <label for="watched-word">{{i18n "admin.watched_words.form.label"}}</label>
+ <WatchedWords
+ @id="watched-words"
+ @value={{this.words}}
+ @onChange={{fn (mut this.words)}}
+ @options={{hash
+ filterPlaceholder=this.placeholderKey
+ disabled=this.formSubmitted
+ }}
+ />
+</div>
+
+{{#if this.canReplace}}
+ <div class="watched-word-input">
+ <label for="watched-replacement">{{i18n
+ "admin.watched_words.form.replace_label"
+ }}</label>
+ <TextField
+ @id="watched-replacement"
+ @value={{this.replacement}}
+ @disabled={{this.formSubmitted}}
+ @autocorrect="off"
+ @autocapitalize="off"
+ @placeholderKey="admin.watched_words.form.replace_placeholder"
+ class="watched-word-input-field"
+ />
+ </div>
+{{/if}}
+
+{{#if this.canTag}}
+ <div class="watched-word-input">
+ <label for="watched-tag">{{i18n
+ "admin.watched_words.form.tag_label"
+ }}</label>
+ <TagChooser
+ @id="watched-tag"
+ @tags={{this.selectedTags}}
+ @onChange={{this.changeSelectedTags}}
+ @everyTag={{true}}
+ @options={{hash allowAny=true disabled=this.formSubmitted}}
+ class="watched-word-input-field"
+ />
+ </div>
+{{/if}}
+
+{{#if this.canLink}}
+ <div class="watched-word-input">
+ <label for="watched-link">{{i18n
+ "admin.watched_words.form.link_label"
+ }}</label>
+ <TextField
+ @id="watched-link"
+ @value={{this.replacement}}
+ @disabled={{this.formSubmitted}}
+ @autocorrect="off"
+ @autocapitalize="off"
+ @placeholderKey="admin.watched_words.form.link_placeholder"
+ class="watched-word-input-field"
+ />
+ </div>
+{{/if}}
+
+<div class="watched-word-input">
+ <label for="watched-case-sensitivity">{{i18n
+ "admin.watched_words.form.case_sensitivity_label"
+ }}</label>
+ <label class="case-sensitivity-checkbox checkbox-label">
+ <Input
+ @type="checkbox"
+ @checked={{this.isCaseSensitive}}
+ disabled={{this.formSubmitted}}
+ />
+ {{i18n "admin.watched_words.form.case_sensitivity_description"}}
+ </label>
+</div>
+
+{{#if this.canReplace}}
+ <div class="watched-word-input">
+ <label for="watched-html">{{i18n
+ "admin.watched_words.form.html_label"
+ }}</label>
+ <label class="html-checkbox checkbox-label">
+ <Input
+ @type="checkbox"
+ @checked={{this.isHtml}}
+ disabled={{this.formSubmitted}}
+ />
+ {{i18n "admin.watched_words.form.html_description"}}
+ </label>
+ </div>
+{{/if}}
+
+<DButton
+ @action={{this.submitForm}}
+ @disabled={{this.submitDisabled}}
+ @label="admin.watched_words.form.add"
+ type="submit"
+ class="btn-primary"
+/>
+
+{{#if this.showMessage}}
+ <span class="success-message">{{this.message}}</span>
+{{/if}}
diff --cc app/assets/javascripts/admin/addon/components/watched-word-uploader.gjs
index fbb840ef237,3ff3ddf4b19..407b165beb7
--- a/app/assets/javascripts/admin/addon/components/watched-word-uploader.gjs
+++ b/app/assets/javascripts/admin/addon/components/watched-word-uploader.gjs
@@@ -1,10 -1,29 +1,40 @@@
+ import Component from "@ember/component";
+ import { alias } from "@ember/object/computed";
+ import { getOwner } from "@ember/owner";
+ import { service } from "@ember/service";
+ import { classNames } from "@ember-decorators/component";
+ import UppyUpload from "discourse/lib/uppy/uppy-upload";
+ import { i18n } from "discourse-i18n";
+
+ @classNames("watched-words-uploader")
+ export default class WatchedWordUploader extends Component {
+ @service dialog;
+
+ uppyUpload = new UppyUpload(getOwner(this), {
+ id: "watched-word-uploader",
+ type: "txt",
+ uploadUrl: "/admin/customize/watched_words/upload",
+ preventDirectS3Uploads: true,
+ validateUploadedFilesOptions: {
+ skipValidation: true,
+ },
+ perFileData: () => ({ action_key: this.actionKey }),
+ uploadDone: () => {
+ this.dialog.alert(i18n("admin.watched_words.form.upload_successful"));
+ this.done();
+ },
+ });
+
+ @alias("uppyUpload.uploading") addDisabled;
+ }
++
+<label class="btn btn-default {{if this.addDisabled 'disabled'}}">
+ {{d-icon "upload"}}
+ {{i18n "admin.watched_words.form.upload"}}
+ <input
+ {{did-insert this.uppyUpload.setup}}
+ class="hidden-upload-field"
+ disabled={{this.addDisabled}}
+ type="file"
+ />
+</label>
diff --cc app/assets/javascripts/admin/addon/components/webhook-event-chooser.gjs
index bc52bcbce17,88090f0e59e..0999d8c4dd9
--- a/app/assets/javascripts/admin/addon/components/webhook-event-chooser.gjs
+++ b/app/assets/javascripts/admin/addon/components/webhook-event-chooser.gjs
@@@ -1,4 -1,37 +1,42 @@@
+ import Component from "@glimmer/component";
+ import { i18n } from "discourse-i18n";
+
+ export default class WebhookEventChooser extends Component {
+ get details() {
+ return i18n(
+ `admin.web_hooks.${this.args.group}_event.${this.args.type.name}`
+ );
+ }
+
+ get eventTypeExists() {
+ return this.args.eventTypes.any(
+ (event) => event.name === this.args.type.name
+ );
+ }
+
+ get enabled() {
+ return this.eventTypeExists;
+ }
+
+ set enabled(value) {
+ const eventTypes = this.args.eventTypes;
+
+ // add an association when not exists
+ if (value === this.eventTypeExists) {
+ return;
+ }
+
+ if (value) {
+ eventTypes.addObject(this.args.type);
+ } else {
+ eventTypes.removeObjects(
+ eventTypes.filter((eventType) => eventType.name === this.args.type.name)
+ );
+ }
+ }
+ }
++
+<label class="hook-event">
+ <Input @type="checkbox" @checked={{this.enabled}} name="event-choice" />
+ {{this.details}}
+</label>
diff --cc app/assets/javascripts/admin/addon/components/webhook-event.gjs
index 55cb960aad5,99853810edd..25361b5c4e6
--- a/app/assets/javascripts/admin/addon/components/webhook-event.gjs
+++ b/app/assets/javascripts/admin/addon/components/webhook-event.gjs
@@@ -1,43 -1,102 +1,146 @@@
+ import Component from "@glimmer/component";
+ import { tracked } from "@glimmer/tracking";
+ import { action } from "@ember/object";
+ import { service } from "@ember/service";
+ import { ajax } from "discourse/lib/ajax";
+ import { popupAjaxError } from "discourse/lib/ajax-error";
+ import { ensureJSON, plainJSON, prettyJSON } from "discourse/lib/formatter";
+ import { i18n } from "discourse-i18n";
+
+ export default class WebhookEvent extends Component {
+ @service dialog;
+
+ @tracked body = "";
+ @tracked bodyLabel = "";
+ @tracked expandDetails = null;
+ @tracked headers = "";
+ expandDetailsRequestKey = "request";
+ expandDetailsResponseKey = "response";
+
+ get statusColorClasses() {
+ const { status } = this.args.event;
+
+ if (!status) {
+ return "";
+ }
+
+ if (status >= 200 && status <= 299) {
+ return "text-successful";
+ } else {
+ return "text-danger";
+ }
+ }
+
+ get createdAt() {
+ return moment(this.args.event.created_at).format("YYYY-MM-DD HH:mm:ss");
+ }
+
+ get completion() {
+ const seconds = Math.floor(this.args.event.duration / 10.0) / 100.0;
+ return i18n("admin.web_hooks.events.completed_in", { count: seconds });
+ }
+
+ get expandRequestIcon() {
+ return this.expandDetails === this.expandDetailsRequestKey
+ ? "ellipsis"
+ : "ellipsis-vertical";
+ }
+
+ get expandResponseIcon() {
+ return this.expandDetails === this.expandDetailsResponseKey
+ ? "ellipsis"
+ : "ellipsis-vertical";
+ }
+
+ @action
+ redeliver() {
+ return this.dialog.yesNoConfirm({
+ message: i18n("admin.web_hooks.events.redeliver_confirm"),
+ didConfirm: async () => {
+ try {
+ const json = await ajax(
+ `/admin/api/web_hooks/${this.args.event.web_hook_id}/events/${this.args.event.id}/redeliver`,
+ { type: "POST" }
+ );
+ this.args.event.setProperties(json.web_hook_event);
+ } catch (e) {
+ popupAjaxError(e);
+ }
+ },
+ });
+ }
+
+ @action
+ toggleRequest() {
+ if (this.expandDetails !== this.expandDetailsRequestKey) {
+ const headers = {
+ "Request URL": this.args.event.request_url,
+ "Request method": "POST",
+ ...ensureJSON(this.args.event.headers),
+ };
+
+ this.headers = plainJSON(headers);
+ this.body = prettyJSON(this.args.event.payload);
+ this.expandDetails = this.expandDetailsRequestKey;
+ this.bodyLabel = i18n("admin.web_hooks.events.payload");
+ } else {
+ this.expandDetails = null;
+ }
+ }
+
+ @action
+ toggleResponse() {
+ if (this.expandDetails !== this.expandDetailsResponseKey) {
+ this.headers = plainJSON(this.args.event.response_headers);
+ this.body = this.args.event.response_body;
+ this.expandDetails = this.expandDetailsResponseKey;
+ this.bodyLabel = i18n("admin.web_hooks.events.body");
+ } else {
+ this.expandDetails = null;
+ }
+ }
+ }
++
+<li>
+ <div class="col first status">
+ {{#if @event.redelivering}}
+ {{d-icon "arrows-rotate"}}
+ {{else}}
+ <span class={{this.statusColorClasses}}>{{@event.status}}</span>
+ {{/if}}
+ </div>
+
+ <div class="col event-id">{{@event.id}}</div>
+
+ <div class="col timestamp">{{this.createdAt}}</div>
+
+ <div class="col completion">{{this.completion}}</div>
+
+ <div class="col actions">
+ <DButton
+ @icon={{this.expandRequestIcon}}
+ @action={{this.toggleRequest}}
+ @label="admin.web_hooks.events.request"
+ />
+ <DButton
+ @icon={{this.expandResponseIcon}}
+ @action={{this.toggleResponse}}
+ @label="admin.web_hooks.events.response"
+ />
+ <DButton
+ @icon="arrows-rotate"
+ @action={{this.redeliver}}
+ @label="admin.web_hooks.events.redeliver"
+ />
+ </div>
+
+ {{#if this.expandDetails}}
+ <div class="details">
+ <h3>{{i18n "admin.web_hooks.events.headers"}}</h3>
+ <pre><code>{{this.headers}}</code></pre>
+
+ <h3>{{this.bodyLabel}}</h3>
+ <pre><code>{{this.body}}</code></pre>
+ </div>
+ {{/if}}
+</li>
diff --cc app/assets/javascripts/admin/addon/components/webhook-events.gjs
index 46b27bcef8e,20b4b46869c..19c8591d662
--- a/app/assets/javascripts/admin/addon/components/webhook-events.gjs
+++ b/app/assets/javascripts/admin/addon/components/webhook-events.gjs
@@@ -1,79 -1,188 +1,268 @@@
+ import Component from "@glimmer/component";
+ import { tracked } from "@glimmer/tracking";
+ import { action } from "@ember/object";
+ import { gt, readOnly } from "@ember/object/computed";
+ import { service } from "@ember/service";
+ import { ajax } from "discourse/lib/ajax";
+ import { popupAjaxError } from "discourse/lib/ajax-error";
+ import { bind } from "discourse/lib/decorators";
+ import { i18n } from "discourse-i18n";
+
+ export default class WebhookEvents extends Component {
+ @service messageBus;
+ @service store;
+ @service dialog;
+
+ @tracked pingEnabled = true;
+ @tracked events = [];
+ @tracked incomingEventIds = [];
+ @tracked redeliverEnabled = true;
+
+ @readOnly("incomingEventIds.length") incomingCount;
+ @gt("incomingCount", 0) hasIncoming;
+
+ constructor() {
+ super(...arguments);
+ this.loadEvents();
+ }
+
+ async loadEvents() {
+ this.loading = true;
+
+ try {
+ this.events = await this.store.findAll("web-hook-event", {
+ webhookId: this.args.webhookId,
+ status: this.args.status,
+ });
+ } catch (error) {
+ popupAjaxError(error);
+ } finally {
+ this.loading = false;
+ }
+
+ this.redeliverEnabled = this.failedEventIds.length;
+ }
+
+ get failedEventIds() {
+ return this.events.content
+ .filter(
+ (event) =>
+ (event.status < 200 || event.status > 299) && event.status !== 0
+ )
+ .map((event) => event.id);
+ }
+
+ get statuses() {
+ return [
+ {
+ id: "successful",
+ name: i18n("admin.web_hooks.events.filter_status.successful"),
+ },
+ {
+ id: "failed",
+ name: i18n("admin.web_hooks.events.filter_status.failed"),
+ },
+ ];
+ }
+
+ @bind
+ reloadEvents() {
+ if (this.loading) {
+ return;
+ }
+
+ this.loadEvents();
+ }
+
+ @bind
+ subscribe() {
+ const channel = `/web_hook_events/${this.args.webhookId}`;
+ this.messageBus.subscribe(channel, this._addIncoming);
+ }
+
+ @bind
+ unsubscribe() {
+ this.messageBus.unsubscribe("/web_hook_events/*", this._addIncoming);
+ }
+
+ @bind
+ _addIncoming(data) {
+ if (data.event_type === "ping") {
+ this.pingEnabled = true;
+ }
+
+ if (data.type === "redelivered") {
+ const event = this.events.find((e) => e.id === data.web_hook_event.id);
+
+ event.setProperties({
+ response_body: data.web_hook_event.response_body,
+ response_headers: data.web_hook_event.response_headers,
+ status: data.web_hook_event.status,
+ redelivering: false,
+ });
+ return;
+ }
+
+ if (data.type === "redelivery_failed") {
+ const event = this.events.find((e) => e.id === data.web_hook_event_id);
+ event.set("redelivering", false);
+ return;
+ }
+
+ if (!this.incomingEventIds.includes(data.web_hook_event_id)) {
+ this.incomingEventIds.pushObject(data.web_hook_event_id);
+ }
+ }
+
+ @action
+ async showInserted(event) {
+ event?.preventDefault();
+
+ const path = `/admin/api/web_hooks/${this.args.webhookId}/events/bulk`;
+ const data = await ajax(path, {
+ data: { ids: this.incomingEventIds },
+ });
+
+ const objects = data.map((webhookEvent) =>
+ this.store.createRecord("web-hook-event", webhookEvent)
+ );
+ this.events.unshiftObjects(objects);
+ this.incomingEventIds = [];
+ }
+
+ @action
+ loadMore() {
+ this.events.loadMore();
+ }
+
+ @action
+ async ping() {
+ this.pingEnabled = false;
+
+ try {
+ await ajax(`/admin/api/web_hooks/${this.args.webhookId}/ping`, {
+ type: "POST",
+ });
+ } catch (error) {
+ this.pingEnabled = true;
+ popupAjaxError(error);
+ }
+ }
+
+ @action
+ async redeliverFailed() {
+ if (!this.failedEventIds.length) {
+ this.dialog.alert(i18n("admin.web_hooks.events.no_events_to_redeliver"));
+ this.redeliverEnabled = false;
+ return;
+ }
+
+ return this.dialog.yesNoConfirm({
+ message: i18n("admin.web_hooks.events.redeliver_failed_confirm", {
+ count: this.failedEventIds.length,
+ }),
+ didConfirm: async () => {
+ try {
+ const response = await ajax(
+ `/admin/api/web_hooks/${this.args.webhookId}/events/failed_redeliver`,
+ { type: "POST", data: { event_ids: this.failedEventIds } }
+ );
+ if (response.event_ids?.length) {
+ response.event_ids.map((id) => {
+ const event = this.events.find((e) => e.id === id);
+ event.set("redelivering", true);
+ });
+ } else {
+ this.dialog.alert(
+ i18n("admin.web_hooks.events.no_events_to_redeliver")
+ );
+ }
+ } catch (error) {
+ popupAjaxError(error);
+ } finally {
+ this.redeliverEnabled = false;
+ }
+ },
+ });
+ }
+ }
++
+<div
+ class="web-hook-events-listing"
+ {{did-insert this.subscribe}}
+ {{did-update this.reloadEvents @status}}
+ {{will-destroy this.unsubscribe}}
+>
+ <div class="web-hook-events-actions">
+ <ComboBox
+ @value={{@status}}
+ @content={{this.statuses}}
+ @onChange={{fn (mut @status)}}
+ @options={{hash none="admin.web_hooks.events.filter_status.all"}}
+ class="delivery-status-filters"
+ />
+
+ <DButton
+ @icon="arrows-rotate"
+ @label="admin.web_hooks.events.redeliver_failed"
+ @action={{this.redeliverFailed}}
+ @disabled={{not this.redeliverEnabled}}
+ />
+
+ <DButton
+ @icon="paper-plane"
+ @label="admin.web_hooks.events.ping"
+ @action={{this.ping}}
+ @disabled={{not this.pingEnabled}}
+ class="webhook-events__ping-button"
+ />
+ </div>
+
+ {{#if this.events}}
+ <LoadMore @selector=".web-hook-events li" @action={{this.loadMore}}>
+ <div class="web-hook-events content-list">
+ <div class="heading-container">
+ <div class="col heading first status">
+ {{i18n "admin.web_hooks.events.status"}}
+ </div>
+ <div class="col heading event-id">
+ {{i18n "admin.web_hooks.events.event_id"}}
+ </div>
+ <div class="col heading timestamp">
+ {{i18n "admin.web_hooks.events.timestamp"}}
+ </div>
+ <div class="col heading completion">
+ {{i18n "admin.web_hooks.events.completion"}}
+ </div>
+ <div class="col heading actions">
+ {{i18n "admin.web_hooks.events.actions"}}
+ </div>
+ </div>
+
+ {{#if this.hasIncoming}}
+ <a
+ href
+ tabindex="0"
+ {{on "click" this.showInserted}}
+ class="alert alert-info clickable"
+ >
+ <CountI18n
+ @key="admin.web_hooks.events.incoming"
+ @count={{this.incomingCount}}
+ />
+ </a>
+ {{/if}}
+
+ <ul>
+ {{#each this.events as |event|}}
+ <WebhookEvent @event={{event}} />
+ {{/each}}
+ </ul>
+ </div>
+
+ <ConditionalLoadingSpinner @condition={{this.events.loadingMore}} />
+ </LoadMore>
+ {{else}}
+ <p>{{i18n "admin.web_hooks.events.none"}}</p>
+ {{/if}}
+</div>