diff --git a/app/assets/javascripts/admin/addon/controllers/admin-emojis-index.js b/app/assets/javascripts/admin/addon/controllers/admin-emojis-index.js new file mode 100644 index 00000000000..37db1b2f5c4 --- /dev/null +++ b/app/assets/javascripts/admin/addon/controllers/admin-emojis-index.js @@ -0,0 +1,72 @@ +import Controller from "@ember/controller"; +import { action, computed } from "@ember/object"; +import { sort } from "@ember/object/computed"; +import { service } from "@ember/service"; +import { ajax } from "discourse/lib/ajax"; +import { popupAjaxError } from "discourse/lib/ajax-error"; +import I18n from "discourse-i18n"; + +const ALL_FILTER = "all"; + +export default class AdminEmojisIndexController extends Controller { + @service dialog; + + filter = null; + sorting = null; + + @sort("filteredEmojis.[]", "sorting") sortedEmojis; + + init() { + super.init(...arguments); + + this.setProperties({ + filter: ALL_FILTER, + sorting: ["group", "name"], + }); + } + + @computed("model.[]", "filter") + get filteredEmojis() { + if (!this.filter || this.filter === ALL_FILTER) { + return this.model; + } else { + return this.model.filterBy("group", this.filter); + } + } + + @computed("model.[]") + get emojiGroups() { + return this.model.mapBy("group").uniq(); + } + + @computed("emojiGroups.[]") + get sortingGroups() { + return [ALL_FILTER].concat(this.emojiGroups); + } + + @action + filterGroups(value) { + this.set("filter", value); + } + + @action + destroyEmoji(emoji) { + this.dialog.yesNoConfirm({ + message: I18n.t("admin.emoji.delete_confirm", { + name: emoji.get("name"), + }), + didConfirm: () => this.#destroyEmoji(emoji), + }); + } + + async #destroyEmoji(emoji) { + try { + await ajax("/admin/customize/emojis/" + emoji.get("name"), { + type: "DELETE", + }); + this.model.removeObject(emoji); + } catch (err) { + popupAjaxError(err); + } + } +} diff --git a/app/assets/javascripts/admin/addon/controllers/admin-emojis-new.js b/app/assets/javascripts/admin/addon/controllers/admin-emojis-new.js new file mode 100644 index 00000000000..9256b9a2921 --- /dev/null +++ b/app/assets/javascripts/admin/addon/controllers/admin-emojis-new.js @@ -0,0 +1,29 @@ +import Controller from "@ember/controller"; +import EmberObject, { action, computed } from "@ember/object"; +import { service } from "@ember/service"; + +const ALL_FILTER = "all"; + +export default class AdminEmojisNewController extends Controller { + @service router; + @service currentUser; + + @computed("model") + get emojiGroups() { + return this.model.mapBy("group").uniq(); + } + + @computed("emojiGroups.[]") + get sortingGroups() { + return [ALL_FILTER].concat(this.emojiGroups); + } + + @action + emojiUploaded(emoji, group) { + emoji.url += "?t=" + new Date().getTime(); + emoji.group = group; + emoji.created_by = this.currentUser.username; + this.model.pushObject(EmberObject.create(emoji)); + this.router.transitionTo("adminEmojis.index"); + } +} diff --git a/app/assets/javascripts/admin/addon/controllers/admin-emojis-settings.js b/app/assets/javascripts/admin/addon/controllers/admin-emojis-settings.js new file mode 100644 index 00000000000..dad5d1cab79 --- /dev/null +++ b/app/assets/javascripts/admin/addon/controllers/admin-emojis-settings.js @@ -0,0 +1,11 @@ +import Controller from "@ember/controller"; +import { action } from "@ember/object"; + +export default class AdminEmojisSettingsController extends Controller { + filter = ""; + + @action + filterChanged(filterData) { + this.set("filter", filterData.filter); + } +} diff --git a/app/assets/javascripts/admin/addon/controllers/admin-emojis.js b/app/assets/javascripts/admin/addon/controllers/admin-emojis.js index 0533c382754..341a141a9ab 100644 --- a/app/assets/javascripts/admin/addon/controllers/admin-emojis.js +++ b/app/assets/javascripts/admin/addon/controllers/admin-emojis.js @@ -1,86 +1,3 @@ import Controller from "@ember/controller"; -import EmberObject, { action, computed } from "@ember/object"; -import { sort } from "@ember/object/computed"; -import { service } from "@ember/service"; -import { ajax } from "discourse/lib/ajax"; -import I18n from "discourse-i18n"; -const ALL_FILTER = "all"; - -export default class AdminEmojisController extends Controller { - @service dialog; - - filter = null; - sorting = null; - - @sort("filteredEmojis.[]", "sorting") sortedEmojis; - init() { - super.init(...arguments); - - this.setProperties({ - filter: ALL_FILTER, - sorting: ["group", "name"], - }); - } - - @computed("model") - get emojiGroups() { - return this.model.mapBy("group").uniq(); - } - - @computed("emojiGroups.[]") - get sortingGroups() { - return [ALL_FILTER].concat(this.emojiGroups); - } - - @computed("model.[]", "filter") - get filteredEmojis() { - if (!this.filter || this.filter === ALL_FILTER) { - return this.model; - } else { - return this.model.filterBy("group", this.filter); - } - } - - _highlightEmojiList() { - const customEmojiListEl = document.querySelector("#custom_emoji"); - if ( - customEmojiListEl && - !customEmojiListEl.classList.contains("highlighted") - ) { - customEmojiListEl.classList.add("highlighted"); - customEmojiListEl.addEventListener("animationend", () => { - customEmojiListEl.classList.remove("highlighted"); - }); - } - } - - @action - filterGroups(value) { - this.set("filter", value); - } - - @action - emojiUploaded(emoji, group) { - emoji.url += "?t=" + new Date().getTime(); - emoji.group = group; - this.model.pushObject(EmberObject.create(emoji)); - this._highlightEmojiList(); - } - - @action - destroyEmoji(emoji) { - this.dialog.yesNoConfirm({ - message: I18n.t("admin.emoji.delete_confirm", { - name: emoji.get("name"), - }), - didConfirm: () => { - return ajax("/admin/customize/emojis/" + emoji.get("name"), { - type: "DELETE", - }).then(() => { - this.model.removeObject(emoji); - }); - }, - }); - } -} +export default class AdminEmojisController extends Controller {} diff --git a/app/assets/javascripts/admin/addon/routes/admin-emojis-settings.js b/app/assets/javascripts/admin/addon/routes/admin-emojis-settings.js new file mode 100644 index 00000000000..d618bbc46c0 --- /dev/null +++ b/app/assets/javascripts/admin/addon/routes/admin-emojis-settings.js @@ -0,0 +1,20 @@ +import DiscourseRoute from "discourse/routes/discourse"; +import I18n from "discourse-i18n"; +import SiteSetting from "admin/models/site-setting"; + +export default class AdminEmojisSettingsRoute extends DiscourseRoute { + queryParams = { + filter: { replace: true }, + }; + + titleToken() { + return I18n.t("settings"); + } + + async model() { + return { + settings: await SiteSetting.findAll(), + initialFilter: "emoji", + }; + } +} diff --git a/app/assets/javascripts/admin/addon/routes/admin-emojis.js b/app/assets/javascripts/admin/addon/routes/admin-emojis.js index 0fa0095cb4d..c5433ed3dcd 100644 --- a/app/assets/javascripts/admin/addon/routes/admin-emojis.js +++ b/app/assets/javascripts/admin/addon/routes/admin-emojis.js @@ -1,8 +1,13 @@ import EmberObject from "@ember/object"; import { ajax } from "discourse/lib/ajax"; import DiscourseRoute from "discourse/routes/discourse"; +import I18n from "discourse-i18n"; export default class AdminEmojisRoute extends DiscourseRoute { + titleToken() { + return I18n.t("admin.emoji.title"); + } + async model() { const emojis = await ajax("/admin/customize/emojis.json"); return emojis.map((emoji) => EmberObject.create(emoji)); diff --git a/app/assets/javascripts/admin/addon/routes/admin-route-map.js b/app/assets/javascripts/admin/addon/routes/admin-route-map.js index facec60a4f4..6c76f9b7098 100644 --- a/app/assets/javascripts/admin/addon/routes/admin-route-map.js +++ b/app/assets/javascripts/admin/addon/routes/admin-route-map.js @@ -72,7 +72,15 @@ export default function () { path: "/user_fields", resetNamespace: true, }); - this.route("adminEmojis", { path: "/emojis", resetNamespace: true }); + this.route( + "adminEmojis", + { path: "/emojis", resetNamespace: true }, + function () { + this.route("new"); + this.route("index", { path: "/" }); + this.route("settings"); + } + ); this.route("adminPermalinks", { path: "/permalinks", resetNamespace: true, diff --git a/app/assets/javascripts/admin/addon/templates/emojis-index.hbs b/app/assets/javascripts/admin/addon/templates/emojis-index.hbs new file mode 100644 index 00000000000..ba0718ba326 --- /dev/null +++ b/app/assets/javascripts/admin/addon/templates/emojis-index.hbs @@ -0,0 +1,63 @@ +
{{i18n "admin.emoji.image"}} | +{{i18n "admin.emoji.name"}} | +{{i18n "admin.emoji.group"}} | +{{i18n "admin.emoji.created_by"}} | +||
---|---|---|---|---|---|
+ + | +
+
+ {{i18n "admin.emoji.name"}}
+
+ :{{emoji.name}}:
+ |
+
+
+ {{i18n "admin.emoji.group"}}
+
+ {{emoji.group}}
+ |
+
+
+ {{i18n "admin.emoji.created_by"}}
+
+ {{emoji.created_by}}
+ |
+
+ |
+
{{i18n "admin.emoji.help"}}
- -{{i18n "admin.emoji.image"}} | -{{i18n "admin.emoji.name"}} | -{{i18n "admin.emoji.group"}} | -{{i18n "admin.emoji.created_by"}} | -||
---|---|---|---|---|---|
- - | -
-
- {{i18n "admin.emoji.name"}}
-
- :{{e.name}}:
- |
-
-
- {{i18n "admin.emoji.group"}}
-
- {{e.group}}
- |
-
-
- {{i18n "admin.emoji.created_by"}}
-
- {{e.created_by}}
- |
-
- |
-