2018-06-15 11:03:24 -04: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 06:16:21 -04:00
|
|
|
import computed from "ember-addons/ember-computed-decorators";
|
2014-12-06 23:15:22 -05:00
|
|
|
|
2016-10-20 13:26:41 -04:00
|
|
|
export default Ember.Controller.extend({
|
2013-08-07 16:04:12 -04:00
|
|
|
loading: false,
|
2015-02-05 14:34:57 -05:00
|
|
|
filters: null,
|
2017-05-30 11:25:42 -04:00
|
|
|
userHistoryActions: [],
|
2013-08-07 16:04:12 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
filtersExists: Ember.computed.gt("filterCount", 0),
|
2013-08-09 16:58:57 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
filterActionIdChanged: function() {
|
2019-05-27 04:15:39 -04:00
|
|
|
const filterActionId = this.filterActionId;
|
2017-05-30 11:25:42 -04:00
|
|
|
if (filterActionId) {
|
|
|
|
this._changeFilters({
|
2019-04-10 08:53:17 -04:00
|
|
|
action_name: filterActionId,
|
2019-05-27 04:15:39 -04:00
|
|
|
action_id: this.userHistoryActions.findBy("id", filterActionId)
|
2019-04-10 08:53:17 -04:00
|
|
|
.action_id
|
2017-05-30 11:25:42 -04:00
|
|
|
});
|
|
|
|
}
|
2018-06-15 11:03:24 -04:00
|
|
|
}.observes("filterActionId"),
|
2017-05-30 11:25:42 -04:00
|
|
|
|
2019-04-26 06:16:21 -04:00
|
|
|
@computed("filters.action_name")
|
|
|
|
actionFilter(name) {
|
2015-02-05 14:34:57 -05:00
|
|
|
if (name) {
|
|
|
|
return I18n.t("admin.logs.staff_actions.actions." + name);
|
2013-08-09 10:06:02 -04:00
|
|
|
} else {
|
2013-08-09 16:58:57 -04:00
|
|
|
return null;
|
2013-08-09 10:06:02 -04:00
|
|
|
}
|
2019-04-26 06:16:21 -04:00
|
|
|
},
|
2013-08-09 10:06:02 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
showInstructions: Ember.computed.gt("model.length", 0),
|
2015-02-05 14:34:57 -05:00
|
|
|
|
2017-11-09 15:34:46 -05:00
|
|
|
_refresh() {
|
2018-06-15 11:03:24 -04:00
|
|
|
this.set("loading", true);
|
2015-02-05 14:34:57 -05:00
|
|
|
|
2019-05-27 04:15:39 -04:00
|
|
|
var filters = this.filters,
|
2018-06-15 11:03:24 -04:00
|
|
|
params = {},
|
|
|
|
count = 0;
|
2015-02-05 14:34:57 -05: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 11:03:24 -04:00
|
|
|
this.set("filterCount", count);
|
|
|
|
|
|
|
|
StaffActionLog.findAll(params)
|
|
|
|
.then(result => {
|
|
|
|
this.set("model", result.staff_action_logs);
|
2019-05-27 04:15:39 -04:00
|
|
|
if (this.userHistoryActions.length === 0) {
|
2019-04-10 08:53:17 -04:00
|
|
|
let actionTypes = result.user_history_actions.map(action => {
|
2018-06-15 11:03:24 -04:00
|
|
|
return {
|
2019-04-10 08:53:17 -04: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 11:03:24 -04:00
|
|
|
};
|
|
|
|
});
|
|
|
|
actionTypes = _.sortBy(actionTypes, row => row.name);
|
|
|
|
this.set("userHistoryActions", actionTypes);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.set("loading", false);
|
|
|
|
});
|
2015-02-05 14:34:57 -05:00
|
|
|
},
|
|
|
|
|
2017-11-09 15:34:46 -05:00
|
|
|
scheduleRefresh() {
|
2018-06-15 11:03:24 -04:00
|
|
|
Ember.run.scheduleOnce("afterRender", this, this._refresh);
|
2017-11-09 15:34:46 -05:00
|
|
|
},
|
|
|
|
|
2015-02-05 14:34:57 -05:00
|
|
|
resetFilters: function() {
|
2018-06-15 11:03:24 -04:00
|
|
|
this.set("filters", Ember.Object.create());
|
2017-11-09 15:34:46 -05:00
|
|
|
this.scheduleRefresh();
|
2018-06-15 11:03:24 -04:00
|
|
|
}.on("init"),
|
2015-02-05 14:34:57 -05:00
|
|
|
|
|
|
|
_changeFilters: function(props) {
|
2019-05-27 04:15:39 -04:00
|
|
|
this.filters.setProperties(props);
|
2017-11-09 15:34:46 -05:00
|
|
|
this.scheduleRefresh();
|
2015-02-05 14:34:57 -05:00
|
|
|
},
|
2013-10-31 12:17:06 -04:00
|
|
|
|
|
|
|
actions: {
|
|
|
|
clearFilter: function(key) {
|
2015-02-05 14:34:57 -05:00
|
|
|
var changed = {};
|
|
|
|
|
|
|
|
// Special case, clear all action related stuff
|
2018-06-15 11:03:24 -04:00
|
|
|
if (key === "actionFilter") {
|
2015-02-05 14:34:57 -05:00
|
|
|
changed.action_name = null;
|
|
|
|
changed.action_id = null;
|
|
|
|
changed.custom_type = null;
|
2017-05-30 11:25:42 -04:00
|
|
|
this.set("filterActionId", null);
|
2015-02-05 14:34:57 -05:00
|
|
|
} else {
|
|
|
|
changed[key] = null;
|
|
|
|
}
|
|
|
|
this._changeFilters(changed);
|
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
|
|
|
|
2015-02-05 14:34:57 -05:00
|
|
|
filterByAction: function(logItem) {
|
|
|
|
this._changeFilters({
|
2018-06-15 11:03:24 -04:00
|
|
|
action_name: logItem.get("action_name"),
|
|
|
|
action_id: logItem.get("action"),
|
|
|
|
custom_type: logItem.get("custom_type")
|
2015-02-05 14:34:57 -05:00
|
|
|
});
|
2013-10-31 12:17:06 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
filterByStaffUser: function(acting_user) {
|
2015-02-05 14:34:57 -05:00
|
|
|
this._changeFilters({ acting_user: acting_user.username });
|
2013-10-31 12:17:06 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
filterByTargetUser: function(target_user) {
|
2015-02-05 14:34:57 -05:00
|
|
|
this._changeFilters({ target_user: target_user.username });
|
2013-10-31 12:17:06 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
filterBySubject: function(subject) {
|
2015-02-05 14:34:57 -05:00
|
|
|
this._changeFilters({ subject: subject });
|
2014-12-06 23:15:22 -05:00
|
|
|
},
|
|
|
|
|
2015-02-05 14:34:57 -05:00
|
|
|
exportStaffActionLogs: function() {
|
2018-06-15 11:03:24 -04:00
|
|
|
exportEntity("staff_action").then(outputExportResult);
|
2013-10-31 12:17:06 -04:00
|
|
|
}
|
2013-08-07 16:04:12 -04:00
|
|
|
}
|
|
|
|
});
|