allow report titles to be translatable

refs CNVS-3134

test plan
 - go to /accounts/self/settings#tab-reports
 - titles should be translatable

Change-Id: I32d47572929a729e1d5f9dc0a2f20a229005fcca
Reviewed-on: https://gerrit.instructure.com/35827
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
Product-Review: Rob Orton <rob@instructure.com>
QA-Review: Rob Orton <rob@instructure.com>
This commit is contained in:
Rob Orton 2014-05-28 22:03:28 -06:00
parent 4a62bdbca2
commit d644a287d8
10 changed files with 65 additions and 42 deletions

View File

@ -199,7 +199,7 @@ class AccountReportsController < ApplicationController
#
def available_reports
if authorized_action(@account, @current_user, :read_reports)
available_reports = AccountReport.available_reports(@account)
available_reports = AccountReport.available_reports
results = []
@ -207,7 +207,7 @@ class AccountReportsController < ApplicationController
last_run = @account.account_reports.where(:report_type => key).order('created_at DESC').first
last_run = account_report_json(last_run, @current_user, session) if last_run
report = {
:title => value[:title],
:title => value.title,
:parameters => nil,
:report => key,
:last_run => last_run
@ -238,7 +238,7 @@ class AccountReportsController < ApplicationController
#
def create
if authorized_action(@context, @current_user, :read_reports)
available_reports = AccountReport.available_reports(@account).keys
available_reports = AccountReport.available_reports.keys
raise ActiveRecord::RecordNotFound unless available_reports.include? params[:report]
report = @account.account_reports.build(:user=>@current_user, :report_type=>params[:report], :parameters=>params[:parameters])
report.workflow_state = :running

View File

@ -466,7 +466,7 @@ class AccountsController < ApplicationController
def settings
if authorized_action(@account, @current_user, :read)
@available_reports = AccountReport.available_reports(@account) if @account.grants_right?(@current_user, @session, :read_reports)
@available_reports = AccountReport.available_reports if @account.grants_right?(@current_user, @session, :read_reports)
if @available_reports
@last_complete_reports = {}
@last_reports = {}

View File

@ -1,5 +1,5 @@
#
# Copyright (C) 2011 - 2013 Instructure, Inc.
# Copyright (C) 2011 - 2014 Instructure, Inc.
#
# This file is part of Canvas.
#
@ -57,7 +57,7 @@ class AccountReport < ActiveRecord::Base
def run_report(type=nil)
self.report_type ||= type
if AccountReport.available_reports(self.account)[self.report_type]
if AccountReport.available_reports[self.report_type]
begin
Canvas::AccountReports.generate_report(self)
rescue
@ -75,9 +75,9 @@ class AccountReport < ActiveRecord::Base
self.parameters.is_a?(Hash) && self.parameters[key].presence
end
def self.available_reports(account)
def self.available_reports
# check if there is a reports plugin for this account
Canvas::AccountReports.for_account(account.root_account.id)
Canvas::AccountReports.available_reports
end
end

View File

@ -785,7 +785,7 @@ acknowledge that you have read and agreed to the
<%= r[:plural_label][] %>
</label>
</li>
<% end %>
<% end %>
<% # NilEnrollment is a special case, because it's not actually a role, just a status reflecting that the user is not part of any course %>
<li id="account_notification_role_NilEnrollment">
<label>
@ -840,9 +840,8 @@ acknowledge that you have read and agreed to the
<th class="reports"><%= t 'headers.report_last_run', 'Last Run' %></th>
<th class="reports"></th>
</tr>
<% @available_reports.sort_by {|_, details| details[:title]}.each do |report, details|
title = details[:title] || details
description = details[:description]
<% @available_reports.sort_by {|_, details| details.title}.each do |report, details|
title = details.title || details
description_partial = details[:description_partial]
description_partial = report + '_description' if description_partial == true
parameters_partial = details[:parameters_partial]
@ -856,10 +855,10 @@ acknowledge that you have read and agreed to the
<tr id="<%= report %>" class="reports">
<td class="title reports">
<span class="title"><%= title %></span>
<% if description || description_partial %>
<% if description_partial %>
<a href="#" class="open_report_description_link"><i class="icon-question standalone-icon"></i></a>
<div style="display: none" class="report_description">
<%= description_partial ? render(:partial => description_partial) : description %>
<%= render(:partial => description_partial) %>
</div>
<% end %>
</td>

View File

@ -2,7 +2,7 @@
<table style="width: 500px;" class="formtable">
<% Canvas::AccountReports::REPORTS.map.sort_by { |(report, details)| [details[:module], report] }.each do |(report, details)| %>
<tr>
<td><%= f.blabel report, "#{details[:title]} (#{details[:module]})" %></td>
<td><%= f.blabel report, "#{details.title} (#{details[:module]})" %></td>
<td><%= f.check_box report, :enabled => settings[report] %></td>
</tr>
<% end %>

View File

@ -23,18 +23,37 @@ module Canvas::AccountReports
REPORTS = {}
class Report < Struct.new(:title, :description_partial, :parameters_partial, :parameters, :module, :proc)
def title
if (title = super).is_a? String
title
else
title.call
end
end
end
def self.configure_account_report(module_name, reports)
reports.each do |report_type, details|
details[:module] ||= module_name
details[:proc] ||= "Canvas::AccountReports::#{module_name}".constantize.method(report_type)
report = Report.new(details[:title], details[:description_partial], details[:parameters_partial], details[:parameters], details[:module], details[:proc])
REPORTS[report_type] = report
end
end
# account id is ignored; use PluginSetting to enable a subset of reports
def self.add_account_reports(account_id, module_name, reports)
reports.each do |report_type, details|
details = {:title => details} if details.is_a? String
details[:module] ||= module_name
details[:proc] ||= "Canvas::AccountReports::#{module_name}".constantize.method(report_type)
REPORTS[report_type] = details
report = Report.new(details[:title], details[:description_partial], details[:parameters_partial], details[:parameters], details[:module], details[:proc])
REPORTS[report_type] = report
end
end
# again, id is ignored; use PluginSetting to enable a subset of reports
def self.for_account(id)
def self.available_reports
settings = Canvas::Plugin.find(:account_reports).settings
return REPORTS.dup unless settings
enabled_reports = settings.select { |report, enabled| enabled }.map(&:first)

View File

@ -1,5 +1,5 @@
#
# Copyright (C) 2011 Instructure, Inc.
# Copyright (C) 2011 - 2014 Instructure, Inc.
#
# This file is part of Canvas.
#
@ -479,7 +479,7 @@ describe AccountsController do
describe "#settings" do
it "should load account report details" do
account_with_admin_logged_in
report_type = AccountReport.available_reports(@account).keys.first
report_type = AccountReport.available_reports.keys.first
report = @account.account_reports.create!(report_type: report_type, user: @admin)
get 'settings', account_id: @account

View File

@ -149,7 +149,7 @@ module Canvas::AccountReports::ReportHelper
end
def check_report_key(key)
Canvas::AccountReports.for_account(account)[@account_report.report_type][:parameters].keys.include? key
Canvas::AccountReports.available_reports[@account_report.report_type][:parameters].keys.include? key
end
def report_extra_text
@ -179,8 +179,12 @@ module Canvas::AccountReports::ReportHelper
end
end
def report_title(account_report )
Canvas::AccountReports.available_reports[account_report.report_type].title
end
def send_report(file = nil, account_report = @account_report)
type = Canvas::AccountReports.for_account(account)[account_report.report_type][:title]
type = report_title(account_report)
if account_report.has_parameter? "extra_text"
options = account_report.parameters["extra_text"]
end

View File

@ -1,5 +1,5 @@
#
# Copyright (C) 2013 Instructure, Inc.
# Copyright (C) 2013 - 2014 Instructure, Inc.
#
# This file is part of Canvas.
#
@ -31,11 +31,12 @@ end
describe "report helper" do
let(:account) { Account.default }
let(:account_report) { AccountReport.new(:report_type => 'test_report', :account => account) }
let(:report){Canvas::AccountReports::TestReport.new(account_report)}
let(:report) { Canvas::AccountReports::TestReport.new(account_report) }
describe "#send_report" do
before do
Canvas::AccountReports.stubs(:for_account => {account_report.report_type => {:title => 'test_report'}})
Canvas::AccountReports.stubs(available_reports: {account_report.report_type => {title: 'test_report'}})
report.stubs(:report_title).returns('TitleReport')
end
it "Should not break for nil parameters" do
@ -45,22 +46,22 @@ describe "report helper" do
end
describe "timezone_strftime" do
it "Should format DateTime" do
date_time = DateTime.new(2003,9,13)
formatted = report.timezone_strftime(date_time, '%d-%b')
formatted.should == "13-Sep"
end
it "Should format DateTime" do
date_time = DateTime.new(2003, 9, 13)
formatted = report.timezone_strftime(date_time, '%d-%b')
formatted.should == "13-Sep"
end
it "Should format Time" do
time_zone = Time.use_zone('UTC'){Time.zone.parse('2013-09-13T00:00:00Z')}
formatted = report.timezone_strftime(time_zone, '%d-%b')
formatted.should == "13-Sep"
end
it "Should format Time" do
time_zone = Time.use_zone('UTC') { Time.zone.parse('2013-09-13T00:00:00Z') }
formatted = report.timezone_strftime(time_zone, '%d-%b')
formatted.should == "13-Sep"
end
it "Should format String" do
time_zone = Time.use_zone('UTC'){Time.zone.parse('2013-09-13T00:00:00Z')}
formatted = report.timezone_strftime(time_zone.to_s, '%d-%b')
formatted.should == "13-Sep"
end
it "Should format String" do
time_zone = Time.use_zone('UTC') { Time.zone.parse('2013-09-13T00:00:00Z') }
formatted = report.timezone_strftime(time_zone.to_s, '%d-%b')
formatted.should == "13-Sep"
end
end
end

View File

@ -1,5 +1,5 @@
#
# Copyright (C) 2012 - 2013 Instructure, Inc.
# Copyright (C) 2012 - 2014 Instructure, Inc.
#
# This file is part of Canvas.
#
@ -34,7 +34,7 @@ module ReportSpecHelper
:report_type => type)
account_report.parameters = parameters
account_report.save
Canvas::AccountReports.for_account(account)[type][:proc].call(account_report)
Canvas::AccountReports.available_reports[type].proc.call(account_report)
account_report
end