2015-07-24 12:33:53 -04:00
|
|
|
import { exportEntity } from 'discourse/lib/export-csv';
|
2014-12-22 11:17:04 -05:00
|
|
|
import { outputExportResult } from 'discourse/lib/export-result';
|
2014-12-06 23:15:22 -05:00
|
|
|
|
2015-05-12 04:49:05 -04:00
|
|
|
export default Ember.ArrayController.extend({
|
2013-08-07 16:04:12 -04:00
|
|
|
loading: false,
|
2015-02-05 14:34:57 -05:00
|
|
|
filters: null,
|
2013-08-07 16:04:12 -04:00
|
|
|
|
2015-02-05 14:34:57 -05:00
|
|
|
filtersExists: Ember.computed.gt('filterCount', 0),
|
2013-08-09 16:58:57 -04:00
|
|
|
|
|
|
|
actionFilter: function() {
|
2015-02-05 14:34:57 -05:00
|
|
|
var name = this.get('filters.action_name');
|
|
|
|
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
|
|
|
}
|
2013-08-09 16:58:57 -04:00
|
|
|
}.property('filters.action_name'),
|
2013-08-09 10:06:02 -04:00
|
|
|
|
2015-02-05 14:34:57 -05:00
|
|
|
showInstructions: Ember.computed.gt('model.length', 0),
|
|
|
|
|
|
|
|
refresh: function() {
|
|
|
|
var self = this;
|
|
|
|
this.set('loading', true);
|
|
|
|
|
|
|
|
var filters = this.get('filters'),
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.set('filterCount', count);
|
|
|
|
|
2015-11-20 10:00:12 -05:00
|
|
|
Discourse.StaffActionLog.findAll(params).then(function(result) {
|
2015-02-05 14:34:57 -05:00
|
|
|
self.set('model', result);
|
|
|
|
}).finally(function() {
|
|
|
|
self.set('loading', false);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
resetFilters: function() {
|
|
|
|
this.set('filters', Ember.Object.create());
|
|
|
|
this.refresh();
|
|
|
|
}.on('init'),
|
|
|
|
|
|
|
|
_changeFilters: function(props) {
|
|
|
|
this.get('filters').setProperties(props);
|
|
|
|
this.refresh();
|
|
|
|
},
|
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
|
|
|
|
if (key === 'actionFilter') {
|
|
|
|
changed.action_name = null;
|
|
|
|
changed.action_id = null;
|
|
|
|
changed.custom_type = null;
|
|
|
|
} else {
|
|
|
|
changed[key] = null;
|
|
|
|
}
|
|
|
|
this._changeFilters(changed);
|
2013-10-31 12:17:06 -04:00
|
|
|
},
|
2013-08-09 10:06:02 -04:00
|
|
|
|
2013-10-31 12:17:06 -04:00
|
|
|
clearAllFilters: function() {
|
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({
|
|
|
|
action_name: logItem.get('action_name'),
|
|
|
|
action_id: logItem.get('action'),
|
|
|
|
custom_type: logItem.get('custom_type')
|
|
|
|
});
|
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() {
|
2015-07-24 12:33:53 -04:00
|
|
|
exportEntity('staff_action').then(outputExportResult);
|
2013-10-31 12:17:06 -04:00
|
|
|
}
|
2013-08-07 16:04:12 -04:00
|
|
|
}
|
|
|
|
});
|