Skip to content

Commit

Permalink
Add badge for status
Browse files Browse the repository at this point in the history
  • Loading branch information
B-Rass committed Oct 24, 2024
1 parent 65542ed commit 8d2555b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
11 changes: 11 additions & 0 deletions app/decorators/room_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,15 @@ def statuses_for_options
Room.statuses.keys.map { |status| [Room.human_attribute_name("status.#{status}"), status] }
end
end

def badge_color_for_status
case status
when "active"
"text-bg-success"
when "passive"
"text-bg-warning"
when "planned"
"text-bg-primary"
end
end
end
4 changes: 3 additions & 1 deletion app/views/rooms/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@
<% end %>
<% table.with_column(Room.human_attribute_name(:status), sort_by: :status) do |room| %>
<%= Room.human_attribute_name("status.#{room.status}") %>
<span class="badge rounded-pill <%= room.decorated.badge_color_for_status %>">
<%= Room.human_attribute_name("status.#{room.status}") %>
</span>
<% end %>
<% table.with_column(style: "min-width: 140px; width: 140px") do |room| %>
Expand Down
6 changes: 5 additions & 1 deletion app/views/rooms/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@
</dd>

<dt class="pb-2"><%= Room.human_attribute_name(:status) %></dt>
<dd class="mb-0 pb-2 ps-3"><%= Room.human_attribute_name("status.#{@room.status}") %></dd>
<dd class="mb-0 pb-2 ps-3">
<span class="badge rounded-pill <%= @room.decorated.badge_color_for_status %>">
<%= Room.human_attribute_name("status.#{@room.status}") %>
</span>
</dd>
</dl>
<% end %>
</div>
Expand Down
26 changes: 26 additions & 0 deletions spec/decorators/room_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,30 @@
describe ".statuses_for_options" do
it { expect(described_class.statuses_for_options.pluck(1)).to match_array(Room.statuses.keys) }
end

describe "#badge_color_for_status" do
let(:subject) { rooms(:one).decorated }

context "with status = active" do
it { expect(subject.badge_color_for_status).to eq "text-bg-success" }
end

context "with status = passive" do
before { rooms(:one).status = :passive }

it { expect(subject.badge_color_for_status).to eq "text-bg-warning" }
end

context "with status = planned" do
before { rooms(:one).status = :planned }

it { expect(subject.badge_color_for_status).to eq "text-bg-primary" }
end

context "with status = unknown" do
before { rooms(:one).status = :unknown }

it { expect(subject.badge_color_for_status).to be_nil }
end
end
end

0 comments on commit 8d2555b

Please sign in to comment.