2019-11-07 16:38:28 -05:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2019-10-23 12:30:52 -04:00
|
|
|
import Component from "@ember/component";
|
2018-06-15 11:03:24 -04:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
|
|
|
import { ensureJSON, plainJSON, prettyJSON } from "discourse/lib/formatter";
|
2016-06-15 13:49:57 -04:00
|
|
|
|
2019-10-23 12:30:52 -04:00
|
|
|
export default Component.extend({
|
2018-06-15 11:03:24 -04:00
|
|
|
tagName: "li",
|
2016-06-15 13:49:57 -04:00
|
|
|
expandDetails: null,
|
2019-04-16 02:24:30 -04:00
|
|
|
expandDetailsRequestKey: "request",
|
|
|
|
expandDetailsResponseKey: "response",
|
2016-06-15 13:49:57 -04:00
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("model.status")
|
2016-06-15 13:49:57 -04:00
|
|
|
statusColorClasses(status) {
|
2018-06-15 11:03:24 -04:00
|
|
|
if (!status) return "";
|
2016-06-15 13:49:57 -04:00
|
|
|
|
|
|
|
if (status >= 200 && status <= 299) {
|
2018-06-15 11:03:24 -04:00
|
|
|
return "text-successful";
|
2016-06-15 13:49:57 -04:00
|
|
|
} else {
|
2018-06-15 11:03:24 -04:00
|
|
|
return "text-danger";
|
2016-06-15 13:49:57 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("model.created_at")
|
2016-06-15 13:49:57 -04:00
|
|
|
createdAt(createdAt) {
|
2018-06-15 11:03:24 -04:00
|
|
|
return moment(createdAt).format("YYYY-MM-DD HH:mm:ss");
|
2016-06-15 13:49:57 -04:00
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("model.duration")
|
2016-06-15 13:49:57 -04:00
|
|
|
completion(duration) {
|
|
|
|
const seconds = Math.floor(duration / 10.0) / 100.0;
|
2018-06-15 11:03:24 -04:00
|
|
|
return I18n.t("admin.web_hooks.events.completed_in", { count: seconds });
|
2016-06-15 13:49:57 -04:00
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("expandDetails")
|
2019-04-16 02:24:30 -04:00
|
|
|
expandRequestIcon(expandDetails) {
|
2019-05-27 04:15:39 -04:00
|
|
|
return expandDetails === this.expandDetailsRequestKey
|
2019-04-16 02:24:30 -04:00
|
|
|
? "ellipsis-h"
|
|
|
|
: "ellipsis-v";
|
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("expandDetails")
|
2019-04-16 02:24:30 -04:00
|
|
|
expandResponseIcon(expandDetails) {
|
2019-05-27 04:15:39 -04:00
|
|
|
return expandDetails === this.expandDetailsResponseKey
|
2019-04-16 02:24:30 -04:00
|
|
|
? "ellipsis-h"
|
|
|
|
: "ellipsis-v";
|
|
|
|
},
|
|
|
|
|
2016-06-15 13:49:57 -04:00
|
|
|
actions: {
|
|
|
|
redeliver() {
|
2018-06-15 11:03:24 -04:00
|
|
|
return bootbox.confirm(
|
|
|
|
I18n.t("admin.web_hooks.events.redeliver_confirm"),
|
|
|
|
I18n.t("no_value"),
|
|
|
|
I18n.t("yes_value"),
|
|
|
|
result => {
|
|
|
|
if (result) {
|
|
|
|
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);
|
|
|
|
}
|
2016-06-15 13:49:57 -04:00
|
|
|
}
|
2018-06-15 11:03:24 -04:00
|
|
|
);
|
2016-06-15 13:49:57 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
toggleRequest() {
|
2019-05-27 04:15:39 -04:00
|
|
|
const expandDetailsKey = this.expandDetailsRequestKey;
|
2016-06-15 13:49:57 -04:00
|
|
|
|
2019-05-27 04:15:39 -04:00
|
|
|
if (this.expandDetails !== expandDetailsKey) {
|
2018-06-15 11:03:24 -04:00
|
|
|
let headers = _.extend(
|
|
|
|
{
|
|
|
|
"Request URL": this.get("model.request_url"),
|
|
|
|
"Request method": "POST"
|
|
|
|
},
|
|
|
|
ensureJSON(this.get("model.headers"))
|
|
|
|
);
|
2016-06-15 13:49:57 -04:00
|
|
|
this.setProperties({
|
|
|
|
headers: plainJSON(headers),
|
2018-06-15 11:03:24 -04:00
|
|
|
body: prettyJSON(this.get("model.payload")),
|
2016-06-15 13:49:57 -04:00
|
|
|
expandDetails: expandDetailsKey,
|
2018-06-15 11:03:24 -04:00
|
|
|
bodyLabel: I18n.t("admin.web_hooks.events.payload")
|
2016-06-15 13:49:57 -04:00
|
|
|
});
|
|
|
|
} else {
|
2018-06-15 11:03:24 -04:00
|
|
|
this.set("expandDetails", null);
|
2016-06-15 13:49:57 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleResponse() {
|
2019-05-27 04:15:39 -04:00
|
|
|
const expandDetailsKey = this.expandDetailsResponseKey;
|
2016-06-15 13:49:57 -04:00
|
|
|
|
2019-05-27 04:15:39 -04:00
|
|
|
if (this.expandDetails !== expandDetailsKey) {
|
2016-06-15 13:49:57 -04:00
|
|
|
this.setProperties({
|
2018-06-15 11:03:24 -04:00
|
|
|
headers: plainJSON(this.get("model.response_headers")),
|
|
|
|
body: this.get("model.response_body"),
|
2016-06-15 13:49:57 -04:00
|
|
|
expandDetails: expandDetailsKey,
|
2018-06-15 11:03:24 -04:00
|
|
|
bodyLabel: I18n.t("admin.web_hooks.events.body")
|
2016-06-15 13:49:57 -04:00
|
|
|
});
|
|
|
|
} else {
|
2018-06-15 11:03:24 -04:00
|
|
|
this.set("expandDetails", null);
|
2016-06-15 13:49:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|