build tables for project and subproject/s views

This commit is contained in:
Stefan Tollkühn
2025-07-23 15:19:59 +02:00
parent 440750881b
commit 53e2dba32d
5 changed files with 76 additions and 35 deletions

View File

@@ -2,4 +2,8 @@ module SubprojectsHelper
def subproject_form_fields def subproject_form_fields
[:subproject_name, :project_id, :client_id, :owner_id, :builder_id] [:subproject_name, :project_id, :client_id, :owner_id, :builder_id]
end end
def subproject_view_fields
[:subproject_name, :project, :client, :owner, :builder]
end
end end

View File

@@ -1,6 +1,26 @@
<p style="color: green"><%= notice %></p> <p style="color: green"><%= notice %></p>
<%= render @project %> <% content_for :title, "Project: #{@project.name}" %>
<h1>Project: <%= @project.name %></h1>
<div id="project">
<table>
<thead>
<tr>
<% project_view_fields.each do |attrib| %>
<th><%= attrib.to_s.humanize %></th>
<% end %>
<th>Subprojects</th>
</tr>
</thead>
<tbody>
<tr>
<%= render @project %>
</tr>
</tbody>
</table>
<div>
<div> <div>
<%= link_to "Edit this project", edit_project_path(@project) %> | <%= link_to "Edit this project", edit_project_path(@project) %> |

View File

@@ -1,27 +1,14 @@
<div id="<%= dom_id subproject %>"> <% subproject_view_fields.each do |attrib| %>
<p> <td>
<strong>Subproject name:</strong> <% value = subproject.send(attrib) %>
<%= subproject.subproject_name %> <% if attrib == :subproject_name %>
</p> <%= link_to value, subproject_path(subproject) %>
<% elsif attrib == :project %>
<p> <%= link_to value.name, project_path(value) %>
<strong>Project:</strong> <% elsif attrib == :client || attrib == :owner || attrib == :builder %>
<%= subproject.project_id %> <%= link_to "#{value&.company_name} (#{value&.lastname}, #{value&.firstname})", client_path(value&.id) %>
</p> <% else %>
<%= value.is_a?(Date) ? l(value) : value %>
<p> <% end %>
<strong>Client:</strong> </td>
<%= link_to "#{subproject.client&.company_name} (#{subproject.client&.lastname}, #{subproject.client&.firstname})", client_path(subproject.client&.id) %> <% end %>
</p>
<p>
<strong>Owner:</strong>
<%= link_to "#{subproject.owner&.company_name} (#{subproject.owner&.lastname}, #{subproject.owner&.firstname})", client_path(subproject.owner&.id) %>
</p>
<p>
<strong>Builder:</strong>
<%= link_to "#{subproject.builder&.company_name} (#{subproject.builder&.lastname}, #{subproject.builder&.firstname})", client_path(subproject.builder&.id) %>
</p>
</div>

View File

@@ -5,12 +5,23 @@
<h1>Subprojects</h1> <h1>Subprojects</h1>
<div id="subprojects"> <div id="subprojects">
<% @subprojects.each do |subproject| %> <table>
<%= render subproject %> <thead>
<p> <tr>
<%= link_to "Show this subproject", subproject %> <% subproject_view_fields.each do |attrib| %>
</p> <th><%= attrib.to_s.humanize %></th>
<% end %> <% end %>
</tr>
</thead>
<tbody>
<% @subprojects.each do |subproject| %>
<tr id="<%= dom_id subproject %>">
<%= render subproject %>
</tr>
<% end %>
</tbody>
</table>
</div> </div>
<%= link_to "New subproject", new_subproject_path %> <%= link_to "New subproject", new_subproject_path %>

View File

@@ -1,6 +1,25 @@
<p style="color: green"><%= notice %></p> <p style="color: green"><%= notice %></p>
<%= render @subproject %> <% content_for :title, "Subproject: #{@subproject.subproject_name}" %>
<h1>Subproject: <%= @subproject.subproject_name %></h1>
<div id="subproject">
<table>
<thead>
<tr>
<% subproject_view_fields.each do |attrib| %>
<th><%= attrib.to_s.humanize %></th>
<% end %>
</tr>
</thead>
<tbody>
<tr>
<%= render @subproject %>
</tr>
</tbody>
</table>
</div>
<div> <div>
<%= link_to "Edit this subproject", edit_subproject_path(@subproject) %> | <%= link_to "Edit this subproject", edit_subproject_path(@subproject) %> |