2020-05-14 04:23:41 +08:00
|
|
|
import I18n from "I18n";
|
2019-10-31 04:28:29 +08:00
|
|
|
import { gt } from "@ember/object/computed";
|
2019-10-30 03:23:50 +08:00
|
|
|
import EmberObject from "@ember/object";
|
2019-10-30 21:48:24 +08:00
|
|
|
import { scheduleOnce } from "@ember/runloop";
|
2019-10-24 01:06:54 +08:00
|
|
|
import Controller from "@ember/controller";
|
2018-06-15 23:03:24 +08:00
|
|
|
import { exportEntity } from "discourse/lib/export-csv";
|
|
|
|
import { outputExportResult } from "discourse/lib/export-result";
|
2020-04-03 11:13:01 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2014-12-07 12:15:22 +08:00
|
|
|
|
2019-10-24 01:06:54 +08:00
|
|
|
export default Controller.extend({
|
2019-06-06 11:02:53 +08:00
|
|
|
model: null,
|
2019-08-14 01:55:05 +08:00
|
|
|
filters: null,
|
2019-10-31 04:28:29 +08:00
|
|
|
filtersExists: gt("filterCount", 0),
|
2019-08-14 01:55:05 +08:00
|
|
|
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
|
|
|
|
2019-06-06 11:02:53 +08:00
|
|
|
resetFilters() {
|
|
|
|
this.setProperties({
|
2019-10-30 03:23:50 +08:00
|
|
|
model: EmberObject.create({ loadingMore: true }),
|
|
|
|
filters: EmberObject.create()
|
2019-06-06 11:02:53 +08:00
|
|
|
});
|
|
|
|
this.scheduleRefresh();
|
|
|
|
},
|
|
|
|
|
|
|
|
_changeFilters(props) {
|
2019-10-30 03:23:50 +08:00
|
|
|
this.set("model", EmberObject.create({ loadingMore: true }));
|
2019-06-06 11:02:53 +08:00
|
|
|
this.filters.setProperties(props);
|
|
|
|
this.scheduleRefresh();
|
|
|
|
},
|
2015-02-06 03:34:57 +08:00
|
|
|
|
2017-11-10 04:34:46 +08:00
|
|
|
_refresh() {
|
2019-06-06 11:02:53 +08:00
|
|
|
let filters = this.filters;
|
2019-08-14 01:55:05 +08:00
|
|
|
let params = {};
|
2019-06-06 11:02:53 +08:00
|
|
|
let count = 0;
|
2015-02-06 03:34:57 +08:00
|
|
|
|
|
|
|
// Don't send null values
|
2019-06-06 11:02:53 +08:00
|
|
|
Object.keys(filters).forEach(k => {
|
|
|
|
let val = filters.get(k);
|
2015-02-06 03:34:57 +08:00
|
|
|
if (val) {
|
|
|
|
params[k] = val;
|
|
|
|
count += 1;
|
|
|
|
}
|
|
|
|
});
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("filterCount", count);
|
|
|
|
|
2019-08-14 01:55:05 +08:00
|
|
|
this.store.findAll("staff-action-log", params).then(result => {
|
|
|
|
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
|
|
|
},
|
|
|
|
|
2013-11-01 00:17:06 +08:00
|
|
|
actions: {
|
2019-06-06 11:02:53 +08:00
|
|
|
filterActionIdChanged(filterActionId) {
|
|
|
|
if (filterActionId) {
|
|
|
|
this._changeFilters({
|
|
|
|
action_name: filterActionId,
|
|
|
|
action_id: this.userHistoryActions.findBy("id", filterActionId)
|
|
|
|
.action_id
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
clearFilter(key) {
|
|
|
|
let changed = {};
|
2015-02-06 03:34:57 +08:00
|
|
|
|
|
|
|
// Special case, clear all action related stuff
|
2018-06-15 23:03:24 +08:00
|
|
|
if (key === "actionFilter") {
|
2015-02-06 03:34:57 +08:00
|
|
|
changed.action_name = null;
|
|
|
|
changed.action_id = null;
|
|
|
|
changed.custom_type = null;
|
2017-05-30 23:25:42 +08:00
|
|
|
this.set("filterActionId", null);
|
2015-02-06 03:34:57 +08:00
|
|
|
} else {
|
|
|
|
changed[key] = null;
|
|
|
|
}
|
|
|
|
this._changeFilters(changed);
|
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) {
|
2015-02-06 03:34:57 +08:00
|
|
|
this._changeFilters({
|
2018-06-15 23:03:24 +08:00
|
|
|
action_name: logItem.get("action_name"),
|
|
|
|
action_id: logItem.get("action"),
|
|
|
|
custom_type: logItem.get("custom_type")
|
2015-02-06 03:34:57 +08:00
|
|
|
});
|
2013-11-01 00:17:06 +08:00
|
|
|
},
|
|
|
|
|
2019-06-06 11:02:53 +08:00
|
|
|
filterByStaffUser(acting_user) {
|
2015-02-06 03:34:57 +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) {
|
2015-02-06 03:34:57 +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) {
|
2015-02-06 03:34:57 +08:00
|
|
|
this._changeFilters({ subject: subject });
|
2014-12-07 12:15:22 +08:00
|
|
|
},
|
|
|
|
|
2019-06-06 11:02:53 +08:00
|
|
|
exportStaffActionLogs() {
|
2018-06-15 23:03:24 +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
|
|
|
}
|
|
|
|
});
|