diff --git a/app/assets/javascripts/admin/addon/components/admin-web-hook-event-chooser.js b/app/assets/javascripts/admin/addon/components/admin-web-hook-event-chooser.js deleted file mode 100644 index 1c8e59fd275..00000000000 --- a/app/assets/javascripts/admin/addon/components/admin-web-hook-event-chooser.js +++ /dev/null @@ -1,47 +0,0 @@ -import Component from "@ember/component"; -import I18n from "I18n"; -import { alias } from "@ember/object/computed"; -import discourseComputed from "discourse-common/utils/decorators"; - -export default Component.extend({ - classNames: ["hook-event"], - typeName: alias("type.name"), - - @discourseComputed("typeName") - name(typeName) { - return I18n.t(`admin.web_hooks.${typeName}_event.name`); - }, - - @discourseComputed("typeName") - details(typeName) { - return I18n.t(`admin.web_hooks.${typeName}_event.details`); - }, - - @discourseComputed("model.[]", "typeName") - eventTypeExists(eventTypes, typeName) { - return eventTypes.any((event) => event.name === typeName); - }, - - @discourseComputed("eventTypeExists") - enabled: { - get(eventTypeExists) { - return eventTypeExists; - }, - set(value, eventTypeExists) { - const type = this.type; - const model = this.model; - // add an association when not exists - if (value !== eventTypeExists) { - if (value) { - model.addObject(type); - } else { - model.removeObjects( - model.filter((eventType) => eventType.name === type.name) - ); - } - } - - return value; - }, - }, -}); diff --git a/app/assets/javascripts/admin/addon/components/admin-web-hook-event.js b/app/assets/javascripts/admin/addon/components/admin-web-hook-event.js deleted file mode 100644 index dd13384a2d1..00000000000 --- a/app/assets/javascripts/admin/addon/components/admin-web-hook-event.js +++ /dev/null @@ -1,110 +0,0 @@ -import { ensureJSON, plainJSON, prettyJSON } from "discourse/lib/formatter"; -import Component from "@ember/component"; -import I18n from "I18n"; -import { ajax } from "discourse/lib/ajax"; -import discourseComputed from "discourse-common/utils/decorators"; -import { popupAjaxError } from "discourse/lib/ajax-error"; -import { inject as service } from "@ember/service"; - -export default Component.extend({ - tagName: "li", - expandDetails: null, - expandDetailsRequestKey: "request", - expandDetailsResponseKey: "response", - dialog: service(), - - @discourseComputed("model.status") - statusColorClasses(status) { - if (!status) { - return ""; - } - - if (status >= 200 && status <= 299) { - return "text-successful"; - } else { - return "text-danger"; - } - }, - - @discourseComputed("model.created_at") - createdAt(createdAt) { - return moment(createdAt).format("YYYY-MM-DD HH:mm:ss"); - }, - - @discourseComputed("model.duration") - completion(duration) { - const seconds = Math.floor(duration / 10.0) / 100.0; - return I18n.t("admin.web_hooks.events.completed_in", { count: seconds }); - }, - - @discourseComputed("expandDetails") - expandRequestIcon(expandDetails) { - return expandDetails === this.expandDetailsRequestKey - ? "ellipsis-h" - : "ellipsis-v"; - }, - - @discourseComputed("expandDetails") - expandResponseIcon(expandDetails) { - return expandDetails === this.expandDetailsResponseKey - ? "ellipsis-h" - : "ellipsis-v"; - }, - - actions: { - redeliver() { - return this.dialog.yesNoConfirm({ - message: I18n.t("admin.web_hooks.events.redeliver_confirm"), - didConfirm: () => { - return ajax( - `/admin/api/web_hooks/${this.get( - "model.web_hook_id" - )}/events/${this.get("model.id")}/redeliver`, - { type: "POST" } - ) - .then((json) => { - this.set("model", json.web_hook_event); - }) - .catch(popupAjaxError); - }, - }); - }, - - toggleRequest() { - const expandDetailsKey = this.expandDetailsRequestKey; - - if (this.expandDetails !== expandDetailsKey) { - let headers = Object.assign( - { - "Request URL": this.get("model.request_url"), - "Request method": "POST", - }, - ensureJSON(this.get("model.headers")) - ); - this.setProperties({ - headers: plainJSON(headers), - body: prettyJSON(this.get("model.payload")), - expandDetails: expandDetailsKey, - bodyLabel: I18n.t("admin.web_hooks.events.payload"), - }); - } else { - this.set("expandDetails", null); - } - }, - - toggleResponse() { - const expandDetailsKey = this.expandDetailsResponseKey; - - if (this.expandDetails !== expandDetailsKey) { - this.setProperties({ - headers: plainJSON(this.get("model.response_headers")), - body: this.get("model.response_body"), - expandDetails: expandDetailsKey, - bodyLabel: I18n.t("admin.web_hooks.events.body"), - }); - } else { - this.set("expandDetails", null); - } - }, - }, -}); diff --git a/app/assets/javascripts/admin/addon/components/admin-web-hook-status.js b/app/assets/javascripts/admin/addon/components/admin-web-hook-status.js deleted file mode 100644 index 880e91621c1..00000000000 --- a/app/assets/javascripts/admin/addon/components/admin-web-hook-status.js +++ /dev/null @@ -1,39 +0,0 @@ -import Component from "@ember/component"; -import I18n from "I18n"; -import discourseComputed from "discourse-common/utils/decorators"; -import { iconHTML } from "discourse-common/lib/icon-library"; -import { htmlSafe } from "@ember/template"; - -export default Component.extend({ - classes: ["text-muted", "text-danger", "text-successful", "text-muted"], - icons: ["far-circle", "times-circle", "circle", "circle"], - circleIcon: null, - deliveryStatus: null, - - @discourseComputed("deliveryStatuses", "model.last_delivery_status") - status(deliveryStatuses, lastDeliveryStatus) { - return deliveryStatuses.find((s) => s.id === lastDeliveryStatus); - }, - - @discourseComputed("status.id", "icons") - icon(statusId, icons) { - return icons[statusId - 1]; - }, - - @discourseComputed("status.id", "classes") - class(statusId, classes) { - return classes[statusId - 1]; - }, - - didReceiveAttrs() { - this._super(...arguments); - this.set( - "circleIcon", - htmlSafe(iconHTML(this.icon, { class: this.class })) - ); - this.set( - "deliveryStatus", - I18n.t(`admin.web_hooks.delivery_status.${this.get("status.name")}`) - ); - }, -}); diff --git a/app/assets/javascripts/admin/addon/templates/components/admin-web-hook-event-chooser.hbs b/app/assets/javascripts/admin/addon/components/webhook-event-chooser.hbs similarity index 84% rename from app/assets/javascripts/admin/addon/templates/components/admin-web-hook-event-chooser.hbs rename to app/assets/javascripts/admin/addon/components/webhook-event-chooser.hbs index b2420e4ebb9..df4b1b6f11c 100644 --- a/app/assets/javascripts/admin/addon/templates/components/admin-web-hook-event-chooser.hbs +++ b/app/assets/javascripts/admin/addon/components/webhook-event-chooser.hbs @@ -1,4 +1,4 @@ -