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-04-26 18:16:21 +08:00
|
|
|
import computed 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,
|
2017-05-30 23:25:42 +08:00
|
|
|
userHistoryActions: [],
|
2013-08-08 04:04:12 +08:00
|
|
|
|
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() {
|
2019-05-27 16:15:39 +08:00
|
|
|
const filterActionId = this.filterActionId;
|
2017-05-30 23:25:42 +08:00
|
|
|
if (filterActionId) {
|
|
|
|
this._changeFilters({
|
2019-04-10 20:53:17 +08:00
|
|
|
action_name: filterActionId,
|
2019-05-27 16:15:39 +08:00
|
|
|
action_id: this.userHistoryActions.findBy("id", filterActionId)
|
2019-04-10 20:53:17 +08:00
|
|
|
.action_id
|
2017-05-30 23:25:42 +08:00
|
|
|
});
|
|
|
|
}
|
2018-06-15 23:03:24 +08:00
|
|
|
}.observes("filterActionId"),
|
2017-05-30 23:25:42 +08:00
|
|
|
|
2019-04-26 18:16:21 +08:00
|
|
|
@computed("filters.action_name")
|
|
|
|
actionFilter(name) {
|
2015-02-06 03:34:57 +08:00
|
|
|
if (name) {
|
|
|
|
return I18n.t("admin.logs.staff_actions.actions." + name);
|
2013-08-09 22:06:02 +08:00
|
|
|
} else {
|
2013-08-10 04:58:57 +08:00
|
|
|
return null;
|
2013-08-09 22:06:02 +08:00
|
|
|
}
|
2019-04-26 18:16:21 +08:00
|
|
|
},
|
2013-08-09 22:06:02 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
showInstructions: Ember.computed.gt("model.length", 0),
|
2015-02-06 03:34:57 +08:00
|
|
|
|
2017-11-10 04:34:46 +08:00
|
|
|
_refresh() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("loading", true);
|
2015-02-06 03:34:57 +08:00
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
var filters = this.filters,
|
2018-06-15 23:03:24 +08:00
|
|
|
params = {},
|
|
|
|
count = 0;
|
2015-02-06 03:34:57 +08:00
|
|
|
|
|
|
|
// 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);
|
2019-05-27 16:15:39 +08:00
|
|
|
if (this.userHistoryActions.length === 0) {
|
2019-04-10 20:53:17 +08:00
|
|
|
let actionTypes = result.user_history_actions.map(action => {
|
2018-06-15 23:03:24 +08:00
|
|
|
return {
|
2019-04-10 20:53:17 +08:00
|
|
|
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);
|
|
|
|
});
|
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
|
|
|
},
|
|
|
|
|
2015-02-06 03:34:57 +08:00
|
|
|
resetFilters: function() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("filters", Ember.Object.create());
|
2017-11-10 04:34:46 +08:00
|
|
|
this.scheduleRefresh();
|
2018-06-15 23:03:24 +08:00
|
|
|
}.on("init"),
|
2015-02-06 03:34:57 +08:00
|
|
|
|
|
|
|
_changeFilters: function(props) {
|
2019-05-27 16:15:39 +08:00
|
|
|
this.filters.setProperties(props);
|
2017-11-10 04:34:46 +08:00
|
|
|
this.scheduleRefresh();
|
2015-02-06 03:34:57 +08:00
|
|
|
},
|
2013-11-01 00:17:06 +08:00
|
|
|
|
|
|
|
actions: {
|
|
|
|
clearFilter: function(key) {
|
2015-02-06 03:34:57 +08:00
|
|
|
var changed = {};
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2015-02-06 03:34:57 +08:00
|
|
|
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")
|
2015-02-06 03:34:57 +08:00
|
|
|
});
|
2013-11-01 00:17:06 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
filterByStaffUser: function(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
|
|
|
},
|
|
|
|
|
|
|
|
filterByTargetUser: function(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
|
|
|
},
|
|
|
|
|
|
|
|
filterBySubject: function(subject) {
|
2015-02-06 03:34:57 +08:00
|
|
|
this._changeFilters({ subject: subject });
|
2014-12-07 12:15:22 +08:00
|
|
|
},
|
|
|
|
|
2015-02-06 03:34:57 +08:00
|
|
|
exportStaffActionLogs: function() {
|
2018-06-15 23:03:24 +08:00
|
|
|
exportEntity("staff_action").then(outputExportResult);
|
2013-11-01 00:17:06 +08:00
|
|
|
}
|
2013-08-08 04:04:12 +08:00
|
|
|
}
|
|
|
|
});
|