-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Extract reports from controller #1250
Extract reports from controller #1250
Conversation
@@ -0,0 +1,3 @@ | |||
Rails.application.config.spree.add_class("reports") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation of first line in file detected.
I like the approach! My suggestions would be:
|
<table style="table-layout: fixed"> | ||
<colgroup> | ||
<% @headers.each do |header| %> | ||
<col style="width: <%= header.values.first.length * 0.8 %>em"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't table-layout: fixed
take care of the column widths?
@mtomov: Thanks! Agree on all your points. In particular, you're right about the show method – I was too quick to assume I couldn't do it for backward compatibility reasons, but of course you're right that it's not a problem. How would you feel about simply using Also, would it be more convenient to continue with this PR, or close it while I follow up and open a new one later? |
Yes, either By all means, do continue with this one. We can squash it all at the end. |
Time.current.beginning_of_month | ||
end | ||
|
||
def parse_end_time(end_time) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused method argument - end_time
. If it's necessary, use _
or _end_time
as an argument name to indicate that it won't be used. You can also write as parse_end_time(*)
if you want the method to accept any arguments but don't care about them.
- code specific to the Sales Total report mvoed to its own class - initializer to declare which reports should be available - reports controller uses define_method metaprogramming to set up an action for each report - GET and POST routes generated for each declared report
- optional title argument for Spree::Admin::ReportsController.add_available_report! - adds Spree::Reports::OutOfStockVariants - generic view file for table-based reports
- Removes redundant title code, in favour of just using the class name - Code improvements recommended by Hound
- plus some refactoring in SalesTotal
- uses a show method in ReportsController instead of generating an action for each report - extracts Spree::Reports::Base - fixes broken translation arguments in Spree::Reports::SalesTotal - removes unnecessary colgroup in table report view
- removes unused title key from ReportsController#add_available_report - adjusts translation namespace for ReportsController#add_available_report - adjusts ReportsControllerSpec for sales_total to use show action - code style improvements
…ther Solidus namespaces
c10905a
to
fbc357f
Compare
Btw, if we are to consider an external dependency, this gem Dossier was recommended to me. |
@mtomov: Dossier looks good, but as you say it's an extra dependency, and I'd rather not add dependencies to the main Solidus distribution. However, if we go ahead with #1262 and move reports to their own |
- moves SalesTotal report specs out of controller spec - controller specs for OutOfStockVariants report - handle case where report can't be found - adjustments to SalesTotal to better match existing specs
report.content.each do |key, value| | ||
instance_variable_set("@#{key}", value) | ||
report_class = "Spree::Report::#{params[:id].camelize}".safe_constantize | ||
if report_class.present? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can just be if report_class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've always found .present?
a bit more readable, but I'm happy to match code style elsewhere in Solidus.
We want to extract reports into it's own gem like stated in #1262 |
When we have more than a handful of reports for a Solidus site, we typically end up with a long and messy decorator for the reports controller. This PR introduces a structure that allows us to extract the logic for each report into its own class, and declare which reports we want to be active in an initializer.
I appreciate this isn't ready to merge yet, but I'm opening the pull request for comment on whether this is a desirable approach. It's worked well for me with clients, but I don't know how universal my experience is. What do you think?
Notes:
Spree::ReportsController.add_available_report!
Spree::StockItem.first.set_count_on_hand(0)
.table_report
view that's intended to be generally useful for any report that generates a table.