0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-30 12:31:10 +01:00
discourse-custom-wizard/assets/javascripts/discourse/models/custom-wizard-logs.js.es6

58 Zeilen
1,3 KiB
Text

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();
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({
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");
}
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");
}
return map;
});
}
return result;
});
},
2020-04-15 04:10:39 +02:00
});
export default CustomWizardLogs;