Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizable chart top values (dropdown choices) #8826

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions app/controllers/report_controller/reports/editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ module ReportController::Reports::Editor
DEFAULT_PDF_PAGE_SIZE = "US-Letter".freeze

MAX_REPORT_COLUMNS = 100 # Default maximum number of columns in a report
GRAPH_MAX_COUNT = 10

CHAREGEBACK_ALLOCATED_METHODS = {
:max => N_('Maximum'),
:avg => N_('Average')
}.freeze

def self.chart_top_values
::Settings.reporting.chart_top_values
end

def chargeback_allocated_methods
CHAREGEBACK_ALLOCATED_METHODS.map { |k, v| [k, _(v)] }.to_h
end
Expand Down Expand Up @@ -632,7 +635,7 @@ def gfv_charts
else
@edit[:new][:graph_other] = true if @edit[:new][:graph_type].nil? # Reset other setting if choosing first chart
@edit[:new][:graph_type] = params[:chosen_graph] # Save graph type
@edit[:new][:graph_count] ||= GRAPH_MAX_COUNT # Reset graph count, if not set
@edit[:new][:graph_count] ||= ReportController::Reports::Editor.chart_top_values # Reset graph count, if not set
@edit[:new][:chart_mode] ||= 'counts'
@edit[:new][:chart_column] ||= ''
end
Expand All @@ -653,7 +656,7 @@ def gfv_charts
end

if params[:chosen_count] && params[:chosen_count] != @edit[:new][:graph_count]
@edit[:new][:graph_count] = params[:chosen_count]
@edit[:new][:graph_count] = params[:chosen_count].to_i
@refresh_div = "chart_sample_div"
@refresh_partial = "form_chart_sample"
end
Expand Down Expand Up @@ -1202,7 +1205,7 @@ def set_form_vars
@edit[:new][:graph_other] = @rpt.graph[:other] ? @rpt.graph[:other] : false
else
@edit[:new][:graph_type] = @rpt.graph
@edit[:new][:graph_count] = GRAPH_MAX_COUNT
@edit[:new][:graph_count] = ReportController::Reports::Editor.chart_top_values
@edit[:new][:chart_mode] = 'counts'
@edit[:new][:chart_column] = ''
@edit[:new][:graph_other] = true
Expand Down
2 changes: 1 addition & 1 deletion app/views/report/_form_chart.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
= _('Top values to show')
.col-md-8
= select_tag('chosen_count',
options_for_select(3..ReportController::Reports::Editor::GRAPH_MAX_COUNT, @edit[:new][:graph_count].to_i),
options_for_select(3..ReportController::Reports::Editor.chart_top_values, @edit[:new][:graph_count].to_i),
:multiple => false,
:class => "selectpicker")
:javascript
Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/report_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@
edit_new = assigns(:edit)[:new]
expect(edit_new[:graph_type]).to eq(chosen_graph)
expect(edit_new[:graph_other]).to be_truthy
expect(edit_new[:graph_count]).to eq(ReportController::Reports::Editor::GRAPH_MAX_COUNT)
expect(edit_new[:graph_count]).to eq(ReportController::Reports::Editor.chart_top_values)
expect(assigns(:refresh_div)).to eq("chart_div")
expect(assigns(:refresh_partial)).to eq("form_chart")
end
Expand All @@ -427,19 +427,19 @@
chosen_graph = "<No chart>"
controller.params = {:chosen_graph => chosen_graph}
edit = assigns(:edit)
edit[:current] = {:graph_count => ReportController::Reports::Editor::GRAPH_MAX_COUNT, :graph_other => true}
edit[:current] = {:graph_count => ReportController::Reports::Editor.chart_top_values, :graph_other => true}
controller.instance_variable_set(:@edit, edit)
controller.send(:gfv_charts)
edit_new = assigns(:edit)[:new]
expect(edit_new[:graph_type]).to be_nil
expect(edit_new[:graph_other]).to be_truthy
expect(edit_new[:graph_count]).to eq(ReportController::Reports::Editor::GRAPH_MAX_COUNT)
expect(edit_new[:graph_count]).to eq(ReportController::Reports::Editor.chart_top_values)
expect(assigns(:refresh_div)).to eq("chart_div")
expect(assigns(:refresh_partial)).to eq("form_chart")
end

it "sets top values to show" do
top_val = "3"
top_val = 3
controller.params = {:chosen_count => top_val}
controller.send(:gfv_charts)
expect(assigns(:edit)[:new][:graph_count]).to eq(top_val)
Expand Down