discourse/app/assets/javascripts/admin/controllers/admin-logs-staff-action-logs.js.es6

133 lines
3.4 KiB
Plaintext
Raw Normal View History

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";
import computed from "ember-addons/ember-computed-decorators";
2014-12-07 12:15:22 +08:00
export default Ember.Controller.extend({
loading: false,
filters: null,
userHistoryActions: [],
2018-06-15 23:03:24 +08:00
filtersExists: Ember.computed.gt("filterCount", 0),
2013-08-10 04:58:57 +08:00
2018-06-15 23:03:24 +08:00
filterActionIdChanged: function() {
const filterActionId = this.filterActionId;
if (filterActionId) {
this._changeFilters({
action_name: filterActionId,
action_id: this.userHistoryActions.findBy("id", filterActionId)
.action_id
});
}
2018-06-15 23:03:24 +08:00
}.observes("filterActionId"),
@computed("filters.action_name")
actionFilter(name) {
if (name) {
return I18n.t("admin.logs.staff_actions.actions." + name);
} else {
2013-08-10 04:58:57 +08:00
return null;
}
},
2018-06-15 23:03:24 +08:00
showInstructions: Ember.computed.gt("model.length", 0),
_refresh() {
2018-06-15 23:03:24 +08:00
this.set("loading", true);
var filters = this.filters,
2018-06-15 23:03:24 +08:00
params = {},
count = 0;
// Don't send null values
Object.keys(filters).forEach(function(k) {
var val = filters.get(k);
if (val) {
params[k] = val;
count += 1;
}
});
2018-06-15 23:03:24 +08:00
this.set("filterCount", count);
StaffActionLog.findAll(params)
.then(result => {
this.set("model", result.staff_action_logs);
if (this.userHistoryActions.length === 0) {
let actionTypes = result.user_history_actions.map(action => {
2018-06-15 23:03:24 +08:00
return {
id: action.id,
action_id: action.action_id,
name: I18n.t("admin.logs.staff_actions.actions." + action.id),
name_raw: action.id
2018-06-15 23:03:24 +08:00
};
});
actionTypes = _.sortBy(actionTypes, row => row.name);
this.set("userHistoryActions", actionTypes);
}
})
.finally(() => {
this.set("loading", false);
});
},
scheduleRefresh() {
2018-06-15 23:03:24 +08:00
Ember.run.scheduleOnce("afterRender", this, this._refresh);
},
resetFilters: function() {
2018-06-15 23:03:24 +08:00
this.set("filters", Ember.Object.create());
this.scheduleRefresh();
2018-06-15 23:03:24 +08:00
}.on("init"),
_changeFilters: function(props) {
this.filters.setProperties(props);
this.scheduleRefresh();
},
actions: {
clearFilter: function(key) {
var changed = {};
// Special case, clear all action related stuff
2018-06-15 23:03:24 +08:00
if (key === "actionFilter") {
changed.action_name = null;
changed.action_id = null;
changed.custom_type = null;
this.set("filterActionId", null);
} else {
changed[key] = null;
}
this._changeFilters(changed);
},
clearAllFilters() {
this.set("filterActionId", null);
this.resetFilters();
},
filterByAction: function(logItem) {
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")
});
},
filterByStaffUser: function(acting_user) {
this._changeFilters({ acting_user: acting_user.username });
},
filterByTargetUser: function(target_user) {
this._changeFilters({ target_user: target_user.username });
},
filterBySubject: function(subject) {
this._changeFilters({ subject: subject });
2014-12-07 12:15:22 +08:00
},
exportStaffActionLogs: function() {
2018-06-15 23:03:24 +08:00
exportEntity("staff_action").then(outputExportResult);
}
}
});