mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
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:
@@ -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
|
||||
|
||||
|
||||
15
app/views/spree/admin/reports/_table.html.haml
Normal file
15
app/views/spree/admin/reports/_table.html.haml
Normal 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)
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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?"]
|
||||
|
||||
Reference in New Issue
Block a user