2021-03-28 11:06:49 +02:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2020-04-15 04:10:39 +02:00
|
|
|
import EmberObject from "@ember/object";
|
|
|
|
|
|
|
|
const CustomWizardLogs = EmberObject.extend();
|
2021-09-09 08:07:12 +02:00
|
|
|
const logItemTypes = {
|
|
|
|
date: "date_time",
|
|
|
|
action: "text",
|
|
|
|
message: "long_text",
|
|
|
|
user: "user",
|
|
|
|
username: "text",
|
|
|
|
};
|
|
|
|
|
|
|
|
function logItem(item, attr) {
|
|
|
|
return {
|
|
|
|
value: item[attr],
|
|
|
|
type: logItemTypes[attr],
|
|
|
|
};
|
|
|
|
}
|
2020-04-15 04:10:39 +02:00
|
|
|
|
|
|
|
CustomWizardLogs.reopenClass({
|
2021-09-09 08:07:12 +02:00
|
|
|
list(wizardId, page = 0) {
|
|
|
|
let data = {
|
|
|
|
page,
|
|
|
|
};
|
|
|
|
|
|
|
|
return ajax(`/admin/wizards/logs/${wizardId}`, { data })
|
|
|
|
.catch(popupAjaxError)
|
|
|
|
.then((result) => {
|
|
|
|
if (result.logs) {
|
|
|
|
result.logs = result.logs.map((item) => {
|
|
|
|
let map = {};
|
|
|
|
|
2021-09-14 05:33:16 +02:00
|
|
|
if (item.date) {
|
|
|
|
map.date = logItem(item, "date");
|
|
|
|
}
|
|
|
|
if (item.action) {
|
|
|
|
map.action = logItem(item, "action");
|
|
|
|
}
|
2021-09-09 08:07:12 +02:00
|
|
|
if (item.user) {
|
|
|
|
map.user = item.user;
|
|
|
|
} else {
|
|
|
|
map.user = logItem(item, "username");
|
|
|
|
}
|
2021-09-14 05:33:16 +02:00
|
|
|
if (item.message) {
|
|
|
|
map.message = logItem(item, "message");
|
|
|
|
}
|
2021-09-09 08:07:12 +02:00
|
|
|
|
|
|
|
return map;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
});
|
2021-03-28 11:06:49 +02:00
|
|
|
},
|
2020-04-15 04:10:39 +02:00
|
|
|
});
|
|
|
|
|
2021-03-28 11:06:49 +02:00
|
|
|
export default CustomWizardLogs;
|