FIX: Don't show category options for reports that can't be scoped to a category.

This commit is contained in:
Guo Xiang Tan 2017-04-13 17:10:55 +08:00
parent bda20cc44a
commit 3d76fb9c2c
6 changed files with 58 additions and 12 deletions

View File

@ -4,7 +4,7 @@ import Report from 'admin/models/report';
import computed from 'ember-addons/ember-computed-decorators'; import computed from 'ember-addons/ember-computed-decorators';
export default Ember.Controller.extend({ export default Ember.Controller.extend({
queryParams: ["mode", "start-date", "end-date", "category-id", "group-id"], queryParams: ["mode", "start_date", "end_date", "category_id", "group_id"],
viewMode: 'graph', viewMode: 'graph',
viewingTable: Em.computed.equal('viewMode', 'table'), viewingTable: Em.computed.equal('viewMode', 'table'),
viewingGraph: Em.computed.equal('viewMode', 'graph'), viewingGraph: Em.computed.equal('viewMode', 'graph'),
@ -28,7 +28,15 @@ export default Ember.Controller.extend({
@computed('model.type') @computed('model.type')
showCategoryOptions(modelType) { showCategoryOptions(modelType) {
return !modelType.match(/_private_messages$/) && !modelType.match(/^page_view_/); return [
'topics',
'posts',
'time_to_first_response_total',
'topics_with_no_response',
'flags',
'likes',
'bookmarks'
].includes(modelType);
}, },
@computed('model.type') @computed('model.type')
@ -42,13 +50,13 @@ export default Ember.Controller.extend({
this.set("refreshing", true); this.set("refreshing", true);
this.setProperties({ this.setProperties({
'start-date': this.get('startDate'), 'start_date': this.get('startDate'),
'end-date': this.get('endDate'), 'end_date': this.get('endDate'),
'category-id': this.get('categoryId'), 'category_id': this.get('categoryId'),
}); });
if (this.get('groupId')){ if (this.get('groupId')){
this.set('group-id', this.get('groupId')); this.set('group_id', this.get('groupId'));
} }
q = Report.find(this.get("model.type"), this.get("startDate"), this.get("endDate"), this.get("categoryId"), this.get("groupId")); q = Report.find(this.get("model.type"), this.get("startDate"), this.get("endDate"), this.get("categoryId"), this.get("groupId"));

View File

@ -7,11 +7,11 @@
@module Discourse @module Discourse
**/ **/
export default Discourse.Route.extend({ export default Discourse.Route.extend({
queryParams: { mode: {}, "start-date": {}, "end-date": {}, "category-id": {}, "group-id": {}}, queryParams: { mode: {}, "start_date": {}, "end_date": {}, "category_id": {}, "group_id": {} },
model: function(params) { model: function(params) {
const Report = require('admin/models/report').default; const Report = require('admin/models/report').default;
return Report.find(params.type, params['start-date'], params['end-date'], params['category-id'], params['group-id']); return Report.find(params.type, params['start_date'], params['end_date'], params['category_id'], params['group_id']);
}, },
setupController: function(controller, model) { setupController: function(controller, model) {

View File

@ -9,7 +9,7 @@ class Admin::ReportsController < Admin::AdminController
start_date = params[:start_date].present? ? Time.parse(params[:start_date]) : 30.days.ago start_date = params[:start_date].present? ? Time.parse(params[:start_date]) : 30.days.ago
end_date = params[:end_date].present? ? Time.parse(params[:end_date]) : start_date + 30.days end_date = params[:end_date].present? ? Time.parse(params[:end_date]) : start_date + 30.days
if params.has_key?(:category_id) && params[:category_id].to_i > 0 if params.has_key?(:category_id) && params[:category_id].to_i > 0
category_id = params[:category_id].to_i category_id = params[:category_id].to_i
else else

View File

@ -82,7 +82,6 @@ class Report
.sum(:count) .sum(:count)
end end
def self.report_visits(report) def self.report_visits(report)
basic_report_about report, UserVisit, :by_day, report.start_date, report.end_date, report.group_id basic_report_about report, UserVisit, :by_day, report.start_date, report.end_date, report.group_id

View File

@ -740,7 +740,7 @@ class User < ActiveRecord::Base
(tl_badge + other_badges).take(limit) (tl_badge + other_badges).take(limit)
end end
def self.count_by_signup_date(start_date, end_date, group_id=nil) def self.count_by_signup_date(start_date, end_date, group_id = nil)
result = where('users.created_at >= ? AND users.created_at <= ?', start_date, end_date) result = where('users.created_at >= ? AND users.created_at <= ?', start_date, end_date)
if group_id if group_id

View File

@ -1,7 +1,6 @@
require 'rails_helper' require 'rails_helper'
describe Admin::ReportsController do describe Admin::ReportsController do
it "is a subclass of AdminController" do it "is a subclass of AdminController" do
expect(Admin::ReportsController < Admin::AdminController).to eq(true) expect(Admin::ReportsController < Admin::AdminController).to eq(true)
end end
@ -58,6 +57,46 @@ describe Admin::ReportsController do
end end
describe 'when report is scoped to a category' do
let(:category) { Fabricate(:category) }
let(:topic) { Fabricate(:topic, category: category) }
let(:other_topic) { Fabricate(:topic) }
it 'should render the report as JSON' do
topic
other_topic
xhr :get, :show, type: 'topics', category_id: category.id
expect(response).to be_success
report = JSON.parse(response.body)["report"]
expect(report["type"]).to eq('topics')
expect(report["data"].count).to eq(1)
end
end
describe 'when report is scoped to a group' do
let(:user) { Fabricate(:user) }
let(:other_user) { Fabricate(:user) }
let(:group) { Fabricate(:group) }
it 'should render the report as JSON' do
other_user
group.add(user)
xhr :get, :show, type: 'signups', group_id: group.id
expect(response).to be_success
report = JSON.parse(response.body)["report"]
expect(report["type"]).to eq('signups')
expect(report["data"].count).to eq(1)
end
end
end end
end end