Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class ProvidersController < ApplicationController
before_action :redirect_contributors

def index
@providers = Provider.all
@providers = Provider.includes(:regions).order(:name)
end

def show
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/regions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ class RegionsController < ApplicationController

# GET /regions
def index
@regions = Region.all
@regions = Region
.left_joins(:providers)
.select("regions.*, COUNT(providers.id) AS providers_count")
.group("regions.id")
.order(:name)
end

# GET /regions/1
Expand Down
4 changes: 2 additions & 2 deletions app/views/providers/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
</div>
</div>

<div class="col-md-4">
<!--div class="col-md-4">
<div class="form-group">
<%= form.label :file_name_prefix, style: "display: block" %>
<%= form.text_field :file_name_prefix, id: "basicInput", class: "form-control" %>
</div>
</div>
</div-->

<div class="col-md-4">
<div class="form-group">
Expand Down
4 changes: 4 additions & 0 deletions app/views/providers/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
<tr>
<th>Provider</th>
<th>Type</th>
<th>Prefix</th>
<th>Regions</th>
<th class="text-end">Provider Actions</th>
</tr>
</thead>
Expand All @@ -27,6 +29,8 @@
<tr>
<td class="text-bold-500"><%= provider.name %></td>
<td><%= provider.provider_type %></td>
<td><%= provider.file_name_prefix %></td>
<td><%= provider.regions.pluck(:name).join(", ") %></td>
<td class="text-end">
<%= link_to provider, class: "btn btn-primary btn-sm" do %>
<i class="bi bi-search"></i> View
Expand Down
2 changes: 1 addition & 1 deletion app/views/regions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<% @regions.each do |region| %>
<tr>
<td class="text-bold-500"><%= region.name %></td>
<td>1</td>
<td><%= region.providers_count %></td>
<td class="text-end">
<%= link_to region, class: "btn btn-primary btn-sm" do %>
<i class="bi bi-search"></i> View
Expand Down
7 changes: 6 additions & 1 deletion spec/views/regions/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
require "rails_helper"

RSpec.describe "regions/index", type: :view do
let!(:regions) { [ create(:region, name: "Region 1"), create(:region, name: "Region 2") ] }
before(:each) do
assign(:regions, [ create(:region, name: "Region 1"), create(:region, name: "Region 2") ])
assign :regions, Region
.left_joins(:providers)
.select("regions.*, COUNT(providers.id) AS providers_count")
.group("regions.id")
.order(:name)
end

it "renders a list of regions" do
Expand Down