-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Field::HasMany with a table on show page
https://trello.com/c/NygJOCUM https://trello.com/c/TERo00zt On the `index` page, `has_many` relationships are displayed by simple text telling how many associated objects there are. On the `show` page, `has_many` relationships are displayed by an HTML table, identical to the one that appears on the associated object's `index` page. On the `form` pages, `has_many` relationships show a message saying the functionality is not yet implemented. - Extracted the common table HTMl into a partial - Extract strings to I18n - Rename index_page_attributes -> table_attributes - Rename `Page::Index` -> `Page::Table` We're now using the class to display tables both on the index page and on the other resource's show pages through the HasMany adapter. Follow-up tasks: - Implement forms for `has_many` relationships (needs discussion: https://trello.com/c/gjsGaU5W).
- Loading branch information
Showing
24 changed files
with
171 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ def attribute_types | |
} | ||
end | ||
|
||
def index_page_attributes | ||
def table_attributes | ||
attributes | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<table> | ||
<thead> | ||
<tr> | ||
<th><%= table_presenter.resource_name.titleize %></th> | ||
|
||
<% table_presenter.attribute_names.each do |attr_name| %> | ||
<th><%= attr_name.to_s.titleize %></th> | ||
<% end %> | ||
<th colspan="2"></th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
<% resources.each do |resource| %> | ||
<tr> | ||
<td><%= link_to resource.to_s, resource %></td> | ||
|
||
<% table_presenter.attributes_for(resource).each do |attribute| %> | ||
<td><%= render attribute %></td> | ||
<% end %> | ||
<td><%= link_to t("administrate.actions.edit"), [:edit, resource] %></td> | ||
<td><%= link_to( | ||
t("administrate.actions.destroy"), | ||
resource, | ||
method: :delete, | ||
data: { confirm: t("administrate.actions.confirm") } | ||
) %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Sorry, nested forms for has-many relationships are not yet supported. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= pluralize(has_many.data.count, has_many.attribute.to_s.humanize.downcase) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<%= render( | ||
"table", | ||
table_presenter: has_many.associated_table, | ||
resources: has_many.data | ||
) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
en: | ||
administrate: | ||
actions: | ||
edit: Edit | ||
destroy: Destroy | ||
confirm: Are you sure? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require_relative "base" | ||
require "pages/table" | ||
|
||
module Field | ||
class HasMany < Field::Base | ||
def associated_table | ||
Page::Table.new(associated_dashboard) | ||
end | ||
|
||
private | ||
|
||
def associated_dashboard | ||
Object.const_get("#{resource_class_name}Dashboard").new | ||
end | ||
|
||
def resource_class_name | ||
attribute.to_s.singularize.camelcase | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require "rails_helper" | ||
|
||
feature "order index page" do | ||
scenario "displays line item information" do | ||
line_item = create(:line_item) | ||
|
||
visit order_path(line_item.order) | ||
|
||
expect(page).to have_content(line_item.unit_price) | ||
expect(page).to have_content(line_item.quantity) | ||
expect(page).to have_content(line_item.total_price) | ||
expect(page).to have_link(line_item.product.to_s) | ||
end | ||
|
||
scenario "links to line items" do | ||
line_item = create(:line_item) | ||
|
||
visit order_path(line_item.order) | ||
click_on(line_item.to_s) | ||
|
||
expect(page).to have_header(line_item.to_s) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require "spec_helper" | ||
require "fields/has_many" | ||
|
||
describe Field::HasMany do | ||
describe "#to_partial_path" do | ||
it "returns a partial based on the page being rendered" do | ||
page = :show | ||
items = double | ||
field = Field::HasMany.new(:items, items, page) | ||
|
||
path = field.to_partial_path | ||
|
||
expect(path).to eq("/fields/#{page}/has_many") | ||
end | ||
end | ||
|
||
describe "#associated_table" do | ||
it "returns an index page for the dashboard of the associated attribute" do | ||
orders = [] | ||
field = Field::HasMany.new(:orders, orders, :show) | ||
|
||
page = field.associated_table | ||
|
||
expect(page).to be_instance_of(Page::Table) | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require "pages/table" | ||
|
||
describe Page::Table do | ||
end |