Unify report table rendering

There is a lot of code duplication in the report views and we would like
to change that code. So we move it into one file first.
This commit is contained in:
Maikel Linke
2018-06-06 15:23:20 +10:00
parent 86ff24b43c
commit 66567fd9e6
13 changed files with 31 additions and 149 deletions

View File

@@ -240,6 +240,8 @@ Spree::Admin::ReportsController.class_eval do
def render_report(header, table, create_csv, csv_file_name)
send_data csv_report(header, table), filename: csv_file_name if create_csv
@header = header
@table = table
# Rendering HTML is the default.
end

View File

@@ -0,0 +1,15 @@
%br
%br
%table{id: id}
%thead
%tr
- @header.each do |heading|
%th=heading
%tbody
- @table.each do |row|
%tr
- row.each do |column|
%td= column
- if @table.empty?
%tr
%td{:colspan => "2"}= t(:none)

View File

@@ -15,18 +15,5 @@
%br
%br
= button t(:search)
%br
%br
%table#listing_orders.index
%thead
%tr{'data-hook' => "orders_header"}
- @report.header.each do |heading|
%th=heading
%tbody
- @table.each do |row|
%tr
- row.each do |column|
%td= column
- if @table.empty?
%tr
%td{:colspan => "2"}= t(:none)
= render "table", id: "listing_orders"

View File

@@ -29,18 +29,4 @@
%br
= button t(:search)
%br
%br
%table#listing_customers.index
%thead
%tr{'data-hook' => "orders_header"}
- @report.header.each do |heading|
%th=heading
%tbody
- @report.table.each do |row|
%tr
- row.each do |column|
%td= column
- if @report.table.empty?
%tr
%td{:colspan => "2"}= t(:none)
= render "table", id: "listing_customers"

View File

@@ -29,18 +29,4 @@
.row
= button t(:search)
%br
%br
%table#listing_ocm_orders.index
%thead
%tr{'data-hook' => "orders_header"}
- @report.header.each do |heading|
%th=heading
%tbody
- @table.each do |row|
%tr
- row.each do |column|
%td= column
- if @table.empty?
%tr
%td{:colspan => "2"}= t(:none)
= render "table", id: "listing_ocm_orders"

View File

@@ -6,18 +6,4 @@
%br
= button t(:search)
%br
%br
%table#listing_orders.index
%thead
%tr{'data-hook' => 'orders_header'}
- @report.header.each do |heading|
%th=heading
%tbody
- @report.table.each do |row|
%tr
- row.each do |column|
%td= column
- if @report.table.empty?
%tr
%td{:colspan => "2"}= t(:none)
= render "table", id: "listing_orders"

View File

@@ -25,18 +25,4 @@
.row
= button t(:search)
%br
%br
%table#listing_orders.index
%thead
%tr{'data-hook' => "orders_header"}
- @report.header.each do |heading|
%th=heading
%tbody
- @table.each do |row|
%tr
- row.each do |column|
%td= column
- if @table.empty?
%tr
%td{:colspan => "2"}= t(:none)
= render "table", id: "listing_orders"

View File

@@ -25,18 +25,4 @@
.row
= button t(:search)
%br
%br
%table#listing_orders.index
%thead
%tr{'data-hook' => "orders_header"}
- @report.header.each do |heading|
%th=heading
%tbody
- @table.each do |row|
%tr
- row.each do |column|
%td= column
- if @table.empty?
%tr
%td{:colspan => "2"}= t(:none)
= render "table", id: "listing_orders"

View File

@@ -15,18 +15,5 @@
%br
%br
= button t(:search)
%br
%br
%table#listing_orders.index
%thead
%tr{'data-hook' => "orders_header"}
- @report.header.each do |heading|
%th=heading
%tbody
- @table.each do |row|
%tr
- row.each do |column|
%td= column
- if @table.empty?
%tr
%td{:colspan => "2"}= t(:none)
= render "table", id: "listing_orders"

View File

@@ -31,18 +31,4 @@
= label_tag :csv, t(:report_customers_csv)
%br
= button t(:search)
%br
%br
%table#listing_products.index
%thead
%tr{'data-hook' => "products_header"}
- @report.header.each do |heading|
%th=heading
%tbody
- @report.table.each do |row|
%tr
- row.each do |column|
%td= column
- if @report.table.empty?
%tr
%td{:colspan => "2"}= t(:none)
= render "table", id: "listing_products"

View File

@@ -17,18 +17,5 @@
= label_tag :csv, t(:report_customers_csv)
.row
= button t(:search)
%br
%br
%table#users_and_enterprises
%thead
%tr
- @report.header.each do |heading|
%th=heading
%tbody
- @report.table.each do |row|
%tr
- row.each do |column|
%td= column
- if @report.table.empty?
%tr
%td{:colspan => "2"}= t(:none)
= render "table", id: "users_and_enterprises"

View File

@@ -32,16 +32,4 @@
.four.columns.alpha= button t(:search)
%table#listing_invoices.index
%thead
%tr
- @report.header.each do |header|
%th= header
%tbody
- @report.table.each do |row|
%tr
- row.each do |column|
%td= column
- if @report.table.empty?
%tr
%td{:colspan => "2"}= t(:none)
= render "table", id: "listing_invoices"

View File

@@ -119,7 +119,7 @@ feature %q{
#select 'Pack By Customer', from: 'report_type'
click_button 'Search'
rows = find("table#listing_orders.index").all("thead tr")
rows = find("table#listing_orders").all("thead tr")
table = rows.map { |r| r.all("th").map { |c| c.text.strip } }
expect(table.sort).to eq([
["Hub", "Code", "First Name", "Last Name", "Supplier", "Product", "Variant", "Quantity", "TempControlled?"]