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