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
[:subproject_name, :project_id, :client_id, :owner_id, :builder_id]
end
def subproject_view_fields
[:subproject_name, :project, :client, :owner, :builder]
end
end

View File

@@ -1,6 +1,26 @@
<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>
<%= link_to "Edit this project", edit_project_path(@project) %> |

View File

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

View File

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

View File

@@ -1,6 +1,25 @@
<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>
<%= link_to "Edit this subproject", edit_subproject_path(@subproject) %> |