-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: better encapsulate page rendering and labware functions
- Loading branch information
1 parent
f4a5288
commit cd81fe8
Showing
8 changed files
with
225 additions
and
255 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
42 changes: 42 additions & 0 deletions
42
app/views/pipeline_progress_overview/_labware_table.html.erb
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,42 @@ | ||
<% | ||
def state_with_children_badge(labware_record) | ||
state_with_children = labware_record[:state_with_children] | ||
render partial: 'state_text_badge', locals: { state: state_with_children, text: state_with_children.humanize } | ||
end | ||
|
||
def render_header | ||
content_tag(:tr) do | ||
content_tag(:th, 'Barcode') + | ||
content_tag(:th, 'Created') + | ||
content_tag(:th, 'State') + | ||
content_tag(:th, 'Updated') | ||
end | ||
end | ||
|
||
def render_row(labware_record) | ||
content_tag(:tr) do | ||
content_tag(:td, link_to("#{labware_record.labware_barcode&.human}", url_for(labware_record))) + | ||
content_tag(:td, labware_record.created_at&.strftime('%Y-%m-%d')) + | ||
content_tag(:td, state_with_children_badge(labware_record) ) + | ||
content_tag(:td, labware_record.updated_at.strftime('%Y-%m-%d')) | ||
end | ||
end | ||
|
||
def render_table(labware) | ||
number_colums = render_header.scan(/<th>/).size | ||
|
||
content_tag(:table, class: 'table table-striped table-sm border', style: 'table-layout: fixed') do | ||
content_tag(:thead) { render_header } + | ||
content_tag(:tbody) do | ||
if labware.nil? || labware.empty? | ||
content_tag(:tr) { content_tag(:td, 'No labware found', colspan: number_colums, class: 'text-center text-muted') } | ||
else | ||
# list of labware, with a link to each | ||
labware.map { |labware_record| render_row(labware_record) }.join.html_safe | ||
end | ||
end | ||
end | ||
end | ||
%> | ||
|
||
<%= render_table(labware) %> |
17 changes: 17 additions & 0 deletions
17
app/views/pipeline_progress_overview/_purpose_card.html.erb
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,17 @@ | ||
<% | ||
# For the labware with the given purpose, groups the labware by state, and return a hash of state_with_children => count. | ||
def grouped_state_counts(purpose_name) | ||
labware_for_purpose(@labware, purpose_name).group_by(&:state_with_children).transform_values(&:size) | ||
end | ||
%> | ||
|
||
<%= card title: "#{purpose_name} (#{labware_for_purpose(@labware, purpose_name).size})", css_class: 'lightweight-card rounded-0 text-center' do %> | ||
|
||
<% grouped_state_counts(purpose_name).each do |state_with_children, count| %> | ||
<%= render partial: 'state_text_badge', locals: { state: state_with_children, text: "#{state_with_children.humanize} #{count}" } %> | ||
<% end %> | ||
|
||
<span class="float-right"> | ||
<%= link_to ">", pipeline_progress_overview_path(id: @pipeline_group_name, purpose: purpose_name, date: @from_date), class: "btn btn-sm btn-info" %> | ||
</span> | ||
<% end %> |
91 changes: 91 additions & 0 deletions
91
app/views/pipeline_progress_overview/_purpose_graph.html.erb
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,91 @@ | ||
<% | ||
# Custom component functions | ||
|
||
# Checks if a given pipeline is present in the purpose pipeline map for a specific purpose. | ||
# | ||
# @param pipeline_name [String] The name of the pipeline to check. | ||
# @param purpose_name [String] The name of the purpose to look for. | ||
# | ||
# @return [Boolean] Returns true if the pipeline is found in the keys of the purpose's pipeline map, false otherwise. | ||
def purpose_is_in_pipeline(pipeline_name, purpose_name) | ||
@purpose_pipeline_map[purpose_name].keys.include?(pipeline_name) | ||
end | ||
|
||
# Checks if the first purpose in a pipeline has occurred. | ||
# | ||
# @param pipeline_name [String] The name of the pipeline to check. | ||
# @param purpose_name [String] The name of the purpose to look for. | ||
# | ||
# @return [Boolean] Returns true if the purpose is the first in the pipeline and has occurred, false otherwise. | ||
def pipeline_first_purpose_has_occurred(pipeline_name, purpose_name) | ||
first_purpose_in_pipeline = @ordered_purposes_for_pipelines[pipeline_name].first | ||
|
||
# get list of purposes prior to the given purpose | ||
purposes_prior_to_purpose = @ordered_purpose_list[0..@ordered_purpose_list.index(purpose_name)] | ||
|
||
# has the first purpose in the pipeline occurred? | ||
purposes_prior_to_purpose.include?(first_purpose_in_pipeline) | ||
end | ||
|
||
# Checks if the last purpose in a pipeline is still to occur. | ||
# | ||
# @param pipeline_name [String] The name of the pipeline to check. | ||
# @param purpose_name [String] The name of the purpose to look for. | ||
# | ||
# @return [Boolean] Returns true if the purpose is the last in the pipeline and has not occurred, false otherwise. | ||
def pipeline_last_purpose_is_still_to_occur(pipeline_name, purpose_name) | ||
last_purpose_in_pipeline = @ordered_purposes_for_pipelines[pipeline_name].last | ||
|
||
# get list of purposes after the given purpose | ||
purposes_after_purpose = @ordered_purpose_list[@ordered_purpose_list.index(purpose_name)..-1] | ||
|
||
# has the last purpose in the pipeline occurred? | ||
purposes_after_purpose.include?(last_purpose_in_pipeline) | ||
end | ||
|
||
def show_pipeline_in_graph(pipeline_name, purpose_name) | ||
purpose_is_in_pipeline(pipeline_name, purpose_name) || | ||
pipeline_first_purpose_has_occurred(pipeline_name, purpose_name) && | ||
pipeline_last_purpose_is_still_to_occur(pipeline_name, purpose_name) | ||
end | ||
|
||
def is_first_purpose_in_pipeline(pipeline_name, purpose_name) | ||
@ordered_purposes_for_pipelines[pipeline_name].first == purpose_name | ||
end | ||
|
||
def is_last_purpose_in_pipeline(pipeline_name, purpose_name) | ||
@ordered_purposes_for_pipelines[pipeline_name].last == purpose_name | ||
end | ||
|
||
def graph_classes(pipeline_name, purpose_name) | ||
# purpose_pipeline_map is a hash of hashes, like: | ||
# "Purpose 2" => { | ||
# "Pipeline A" => { | ||
# "parent" => "Purpose 1", | ||
# "child" => "Purpose 3" | ||
# }, | ||
# "Pipeline B" => { | ||
# "parents" => "Purpose 1", | ||
# "child" => nil | ||
# } | ||
parent_purpose_name = @purpose_pipeline_map.dig(pipeline_name, purpose_name, 'parent') | ||
child_purpose_name = @purpose_pipeline_map.dig(pipeline_name, purpose_name, 'child') | ||
|
||
# provide spacing | ||
classes = ['pipeline'] | ||
# show the coloured line | ||
classes << 'pipeline-shown' if show_pipeline_in_graph(pipeline_name, purpose_name) | ||
# indicate that the purpose is part of the pipeline | ||
classes << 'pipeline-purpose' if purpose_is_in_pipeline(pipeline_name, purpose_name) | ||
# decoration for the first and last purposes in each pipeline | ||
classes << 'pipeline-start' if is_first_purpose_in_pipeline(pipeline_name, purpose_name) | ||
classes << 'pipeline-end' if is_last_purpose_in_pipeline(pipeline_name, purpose_name) | ||
|
||
classes.join(' ') | ||
end | ||
%> | ||
<%= content_tag :div, class: "stacker-graph" do %> | ||
<% @pipelines_for_group.each do |pipeline_name| %> | ||
<%= content_tag :span, '▼', class: graph_classes(pipeline_name, purpose_name) %> | ||
<% end %> | ||
<% end %> |
11 changes: 11 additions & 0 deletions
11
app/views/pipeline_progress_overview/_state_text_badge.html.erb
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,11 @@ | ||
<% | ||
@state_colours = { | ||
'pending' => 'warning', | ||
'passed' => 'success', | ||
'failed' => 'danger', | ||
'pending (parent)' => 'secondary', | ||
'passed (parent)' => 'secondary', | ||
'failed (parent)' => 'secondary' | ||
} | ||
%> | ||
<%= content_tag(:span, text, class: "badge badge-pill badge-#{@state_colours[state]}") %> |
Oops, something went wrong.