2018-06-15 23:03:24 +08:00
|
|
|
import { exportEntity } from "discourse/lib/export-csv";
|
|
|
|
import { outputExportResult } from "discourse/lib/export-result";
|
|
|
|
import StaffActionLog from "admin/models/staff-action-log";
|
2019-06-06 11:02:53 +08:00
|
|
|
import {
|
|
|
|
default as computed,
|
|
|
|
on
|
|
|
|
} from "ember-addons/ember-computed-decorators";
|
2014-12-07 12:15:22 +08:00
|
|
|
|
2016-10-21 01:26:41 +08:00
|
|
|
export default Ember.Controller.extend({
|
2013-08-08 04:04:12 +08:00
|
|
|
loading: false,
|
2015-02-06 03:34:57 +08:00
|
|
|
filters: null,
|
2019-06-06 11:02:53 +08:00
|
|
|
userHistoryActions: [],
|
|
|
|
model: null,
|
|
|
|
nextPage: 0,
|
|
|
|
lastPage: null,
|
2019-05-28 18:15:12 +08:00
|
|
|
|
2019-06-06 11:02:53 +08:00
|
|
|
filtersExists: Ember.computed.gt("filterCount", 0),
|
|
|
|
showTable: Ember.computed.gt("model.length", 0),
|
2017-05-30 23:25:42 +08:00
|
|
|
|
2019-04-26 18:16:21 +08:00
|
|
|
@computed("filters.action_name")
|
|
|
|
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
|
|
|
@on("init")
|
|
|
|
resetFilters() {
|
|
|
|
this.setProperties({
|
|
|
|
filters: Ember.Object.create(),
|
|
|
|
model: [],
|
|
|
|
nextPage: 0,
|
|
|
|
lastPage: null
|
|
|
|
});
|
|
|
|
this.scheduleRefresh();
|
|
|
|
},
|
|
|
|
|
|
|
|
_changeFilters(props) {
|
|
|
|
this.filters.setProperties(props);
|
|
|
|
this.setProperties({
|
|
|
|
model: [],
|
|
|
|
nextPage: 0,
|
|
|
|
lastPage: null
|
|
|
|
});
|
|
|
|
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
|
|
|
if (this.lastPage && this.nextPage >= this.lastPage) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("loading", true);
|
2015-02-06 03:34:57 +08:00
|
|
|
|
2019-06-06 11:02:53 +08:00
|
|
|
const page = this.nextPage;
|
|
|
|
let filters = this.filters;
|
|
|
|
let params = { page };
|
|
|
|
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);
|
|
|
|
|
|
|
|
StaffActionLog.findAll(params)
|
|
|
|
.then(result => {
|
2019-06-06 11:02:53 +08:00
|
|
|
this.setProperties({
|
|
|
|
model: this.model.concat(result.staff_action_logs),
|
|
|
|
nextPage: page + 1
|
|
|
|
});
|
|
|
|
|
|
|
|
if (result.staff_action_logs.length === 0) {
|
|
|
|
this.set("lastPage", page);
|
|
|
|
}
|
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
if (this.userHistoryActions.length === 0) {
|
2019-06-06 11:02:53 +08:00
|
|
|
this.set(
|
|
|
|
"userHistoryActions",
|
|
|
|
result.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 > b.name ? 1 : -1))
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
}
|
|
|
|
})
|
2019-06-06 11:02:53 +08:00
|
|
|
.finally(() => this.set("loading", false));
|
2015-02-06 03:34:57 +08:00
|
|
|
},
|
|
|
|
|
2017-11-10 04:34:46 +08:00
|
|
|
scheduleRefresh() {
|
2018-06-15 23:03:24 +08:00
|
|
|
Ember.run.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() {
|
|
|
|
this._refresh();
|
2013-11-01 00:17:06 +08:00
|
|
|
}
|
2013-08-08 04:04:12 +08:00
|
|
|
}
|
|
|
|
});
|