2020-07-22 23:25:58 +08:00
|
|
|
import Controller from "@ember/controller";
|
2019-10-30 03:23:50 +08:00
|
|
|
import EmberObject from "@ember/object";
|
2019-10-30 21:48:24 +08:00
|
|
|
import I18n from "I18n";
|
2020-07-22 23:25:58 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2015-07-25 00:33:53 +08:00
|
|
|
import { exportEntity } from "discourse/lib/export-csv";
|
2014-12-23 00:17:04 +08:00
|
|
|
import { outputExportResult } from "discourse/lib/export-result";
|
2020-07-22 23:25:58 +08:00
|
|
|
import { scheduleOnce } from "@ember/runloop";
|
2014-12-07 12:15:22 +08:00
|
|
|
|
2019-10-24 01:06:54 +08:00
|
|
|
export default Controller.extend({
|
2020-07-22 23:25:58 +08:00
|
|
|
queryParams: ["filters"],
|
|
|
|
|
2019-06-06 11:02:53 +08:00
|
|
|
model: null,
|
2019-08-14 01:55:05 +08:00
|
|
|
filters: null,
|
|
|
|
userHistoryActions: null,
|
2017-05-30 23:25:42 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("filters.action_name")
|
2019-04-26 18:16:21 +08:00
|
|
|
actionFilter(name) {
|
2019-06-06 11:02:53 +08:00
|
|
|
return name ? I18n.t("admin.logs.staff_actions.actions." + name) : null;
|
2019-04-26 18:16:21 +08:00
|
|
|
},
|
2013-08-09 22:06:02 +08:00
|
|
|
|
2020-07-22 23:25:58 +08:00
|
|
|
@discourseComputed("filters")
|
|
|
|
filtersExists(filters) {
|
|
|
|
return filters && Object.keys(filters).length > 0;
|
2019-06-06 11:02:53 +08:00
|
|
|
},
|
2015-02-06 03:34:57 +08:00
|
|
|
|
2017-11-10 04:34:46 +08:00
|
|
|
_refresh() {
|
2020-07-22 23:25:58 +08:00
|
|
|
this.store.findAll("staff-action-log", this.filters).then((result) => {
|
2019-08-14 01:55:05 +08:00
|
|
|
this.set("model", result);
|
|
|
|
|
|
|
|
if (!this.userHistoryActions) {
|
|
|
|
this.set(
|
|
|
|
"userHistoryActions",
|
|
|
|
result.extras.user_history_actions
|
|
|
|
.map((action) => ({
|
|
|
|
id: action.id,
|
|
|
|
action_id: action.action_id,
|
|
|
|
name: I18n.t("admin.logs.staff_actions.actions." + action.id),
|
|
|
|
name_raw: action.id,
|
|
|
|
}))
|
|
|
|
.sort((a, b) => a.name.localeCompare(b.name))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2015-02-06 03:34:57 +08:00
|
|
|
},
|
|
|
|
|
2017-11-10 04:34:46 +08:00
|
|
|
scheduleRefresh() {
|
2019-10-30 21:48:24 +08:00
|
|
|
scheduleOnce("afterRender", this, this._refresh);
|
2017-11-10 04:34:46 +08:00
|
|
|
},
|
|
|
|
|
2020-07-22 23:25:58 +08:00
|
|
|
resetFilters() {
|
|
|
|
this.setProperties({
|
|
|
|
model: EmberObject.create({ loadingMore: true }),
|
|
|
|
filters: EmberObject.create(),
|
|
|
|
});
|
|
|
|
this.scheduleRefresh();
|
|
|
|
},
|
|
|
|
|
|
|
|
changeFilters(props) {
|
|
|
|
this.set("model", EmberObject.create({ loadingMore: true }));
|
|
|
|
|
|
|
|
if (!this.filters) {
|
|
|
|
this.set("filters", EmberObject.create());
|
|
|
|
}
|
|
|
|
|
|
|
|
Object.keys(props).forEach((key) => {
|
|
|
|
if (props[key] === undefined || props[key] === null) {
|
|
|
|
this.filters.set(key, undefined);
|
|
|
|
delete this.filters[key];
|
|
|
|
} else {
|
|
|
|
this.filters.set(key, props[key]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.send("onFiltersChange", this.filters);
|
|
|
|
this.scheduleRefresh();
|
|
|
|
},
|
|
|
|
|
2013-11-01 00:17:06 +08:00
|
|
|
actions: {
|
2019-06-06 11:02:53 +08:00
|
|
|
filterActionIdChanged(filterActionId) {
|
|
|
|
if (filterActionId) {
|
2020-07-22 23:25:58 +08:00
|
|
|
this.changeFilters({
|
2019-06-06 11:02:53 +08:00
|
|
|
action_name: filterActionId,
|
|
|
|
action_id: this.userHistoryActions.findBy("id", filterActionId)
|
|
|
|
.action_id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
clearFilter(key) {
|
2015-02-06 03:34:57 +08:00
|
|
|
if (key === "actionFilter") {
|
2017-05-30 23:25:42 +08:00
|
|
|
this.set("filterActionId", null);
|
2020-07-22 23:25:58 +08:00
|
|
|
this.changeFilters({
|
|
|
|
action_name: null,
|
|
|
|
action_id: null,
|
|
|
|
custom_type: null,
|
|
|
|
});
|
2015-02-06 03:34:57 +08:00
|
|
|
} else {
|
2020-07-22 23:25:58 +08:00
|
|
|
this.changeFilters({ [key]: null });
|
2015-02-06 03:34:57 +08:00
|
|
|
}
|
2013-11-01 00:17:06 +08:00
|
|
|
},
|
2013-08-09 22:06:02 +08:00
|
|
|
|
2017-11-10 04:34:46 +08:00
|
|
|
clearAllFilters() {
|
2017-05-30 23:25:42 +08:00
|
|
|
this.set("filterActionId", null);
|
2015-02-06 03:34:57 +08:00
|
|
|
this.resetFilters();
|
2013-11-01 00:17:06 +08:00
|
|
|
},
|
2013-08-21 01:50:51 +08:00
|
|
|
|
2019-06-06 11:02:53 +08:00
|
|
|
filterByAction(logItem) {
|
2020-07-22 23:25:58 +08:00
|
|
|
this.changeFilters({
|
2015-02-06 03:34:57 +08:00
|
|
|
action_name: logItem.get("action_name"),
|
|
|
|
action_id: logItem.get("action"),
|
|
|
|
custom_type: logItem.get("custom_type"),
|
|
|
|
});
|
2013-11-01 00:17:06 +08:00
|
|
|
},
|
|
|
|
|
2019-06-06 11:02:53 +08:00
|
|
|
filterByStaffUser(acting_user) {
|
2020-07-22 23:25:58 +08:00
|
|
|
this.changeFilters({ acting_user: acting_user.username });
|
2013-11-01 00:17:06 +08:00
|
|
|
},
|
|
|
|
|
2019-06-06 11:02:53 +08:00
|
|
|
filterByTargetUser(target_user) {
|
2020-07-22 23:25:58 +08:00
|
|
|
this.changeFilters({ target_user: target_user.username });
|
2013-11-01 00:17:06 +08:00
|
|
|
},
|
|
|
|
|
2019-06-06 11:02:53 +08:00
|
|
|
filterBySubject(subject) {
|
2021-11-10 07:31:41 +08:00
|
|
|
this.changeFilters({ subject });
|
2014-12-07 12:15:22 +08:00
|
|
|
},
|
|
|
|
|
2019-06-06 11:02:53 +08:00
|
|
|
exportStaffActionLogs() {
|
2015-07-25 00:33:53 +08:00
|
|
|
exportEntity("staff_action").then(outputExportResult);
|
2019-06-06 11:02:53 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
loadMore() {
|
2019-08-14 01:55:05 +08:00
|
|
|
this.model.loadMore();
|
2013-11-01 00:17:06 +08:00
|
|
|
},
|
2013-08-08 04:04:12 +08:00
|
|
|
},
|
|
|
|
});
|