Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
218 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
module LotteryHelper | ||
def background_color_by_percentage(percentage) | ||
case percentage | ||
when 0...33 | ||
'background-color: #ffcccc;' # Light red for low percentages | ||
when 33...66 | ||
'background-color: #ffcc99;' # Light orange for medium percentages | ||
when 66..100 | ||
'background-color: #ccffcc;' # Light green for high percentages | ||
else | ||
'background-color: none;' # No background if outside range | ||
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
50 changes: 50 additions & 0 deletions
50
app/views/lottery/calculate_bidding_summary_based_on_priority.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,50 @@ | ||
<!-- Display the assignment name in the bidding summary header --> | ||
<h3>Assignment Bidding Summary by Priority: <%= @assignment.name %></h3> | ||
|
||
<!-- Define the structure of the bidding summary table --> | ||
<table class="table table-bordered table-hover"> | ||
<thead> | ||
<tr> | ||
<!-- Define the table headers with specified widths for better alignment --> | ||
<th>Topic id</th> | ||
<th>Topic name</th> | ||
<th>#1 bids</th> | ||
<th>#2 bids</th> | ||
<th>#3 bids</th> | ||
<th>Total bids</th> | ||
<!-- Set fixed width for the 'Percentage of #1 bids' column --> | ||
<th style="width: 200px;">Percentage of #1 bids</th> | ||
<!-- Set fixed width for the 'Bidding teams' column --> | ||
<th style="width: 200px;">Bidding teams</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<!-- Iterate over each topic to display its bidding information --> | ||
<% @topic_data.each do |topic| %> | ||
<tr> | ||
<!-- Display topic id, name, bid counts, total bids and bidding teams --> | ||
<td><%= topic[:id] %></td> | ||
<td><%= topic[:name] %></td> | ||
<td><%= topic[:first_bids] %></td> | ||
<td><%= topic[:second_bids] %></td> | ||
<td><%= topic[:third_bids] %></td> | ||
<td><%= topic[:total_bids] %></td> | ||
<!-- Calculate and display the percentage of first bids with tooltip and custom background --> | ||
<td title="Calculated as (#1 Bids / Total Bids) * 100"> | ||
<span style="<%= background_color_by_percentage(topic[:percentage_first]) %> font-weight: bold; padding: 3px; border-radius: 4px;"> | ||
<%= topic[:percentage_first] %> % | ||
</span> | ||
</td> | ||
<!-- List all the bidding teams for the topic --> | ||
<td> | ||
<% topic[:bidding_teams].each do |team| %> | ||
<%= team %><br> | ||
<% end %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
|
||
<!-- Link to navigate back to the previous page --> | ||
<%= link_to 'Back', :back %> |
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,27 @@ | ||
require 'rails_helper' | ||
|
||
# Assuming your helper module is in the helpers folder | ||
RSpec.describe LotteryHelper, type: :helper do | ||
# Test for low percentage range | ||
describe '#background_color_by_percentage' do | ||
it 'returns light red for low percentages' do | ||
expect(helper.background_color_by_percentage(10)).to eq('background-color: #ffcccc;') | ||
end | ||
|
||
# Test for medium percentage range | ||
it 'returns light orange for medium percentages' do | ||
expect(helper.background_color_by_percentage(50)).to eq('background-color: #ffcc99;') | ||
end | ||
|
||
# Test for high percentage range | ||
it 'returns light green for high percentages' do | ||
expect(helper.background_color_by_percentage(80)).to eq('background-color: #ccffcc;') | ||
end | ||
|
||
# Test for percentage out of range | ||
it 'returns no background for percentages out of range' do | ||
expect(helper.background_color_by_percentage(101)).to eq('background-color: none;') | ||
expect(helper.background_color_by_percentage(-1)).to eq('background-color: none;') | ||
end | ||
end | ||
end |