Skip to content

Commit ee3452c

Browse files
dmitrytragerdcollie2
authored andcommitted
scope visible topics to current_provider
1 parent 307446d commit ee3452c

File tree

5 files changed

+37
-34
lines changed

5 files changed

+37
-34
lines changed

app/controllers/settings_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class SettingsController < ApplicationController
22
def provider
3-
provider = provider_scope.find(provider_params[:id])
3+
provider = provider_scope.find_by(id: provider_params[:id])
44
cookies.signed[:current_provider_id] = provider.id if provider
55
redirect_to request.referer || root_path
66
end

app/controllers/topics_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def scope
7070
@scope ||= if Current.user.is_admin?
7171
Topic.all
7272
else
73-
Current.user.topics
73+
current_provider.topics
7474
end.includes(:language, :provider)
7575
end
7676
end

app/models/provider.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Provider < ApplicationRecord
1818
has_many :regions, through: :branches
1919
has_many :contributors
2020
has_many :users, through: :contributors
21+
has_many :topics
2122

2223
validates :name, :provider_type, presence: true
2324
validates :name, uniqueness: true

app/views/topics/_choose_provider.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%= form_for :provider , url: provider_settings_path, method: :put, data: { controller: "topics", topics_target: "chooseForm" } do |f| %>
1+
<%= form_for :provider , url: provider_settings_path, method: :put, data: { controller: "topics", topics_target: "chooseForm", turbo_frame: "topics", turbo_action: "advance" } do |f| %>
22
<div class="form-body">
33
<div class="row">
44
<div class="col-md-6 col-12">

app/views/topics/index.html.erb

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,42 @@
44
<div class="row" id="table-striped">
55
<div class="col-12 cold-md-12">
66
<%= render "search", providers: @providers, languages: @languages, params: search_params %>
7-
<div class="card">
8-
<div class="card-header d-flex justify-content-between align-items-center">
9-
<h2 class="card-title"><%= current_provider.name %>'s topics</h2>
10-
<%= link_to new_topic_path, class: "btn btn-primary" do %>
11-
<i class="bi bi-plus"></i> Add New Topic
12-
<% end %>
13-
</div>
14-
<div class="card-content">
15-
<div class="card-body">
16-
<% if @available_providers.any? %>
17-
<%= render "choose_provider", providers: @available_providers %>
18-
<% end %>
19-
<p class="card-text"> Some important information or instruction can be placed here.</p>
20-
<%= turbo_frame_tag "topic-list" do %>
21-
<div class="table-responsive">
22-
<table class="table table-lg table-striped mb-0">
23-
<thead>
24-
<tr>
25-
<th>Title</th>
26-
<th>Description</th>
27-
<th>UID</th>
28-
<th>Language</th>
29-
<th>Provider</th>
30-
<th>State</th>
31-
<th class="text-end">Actions</th>
32-
</tr>
33-
</thead>
34-
<%= render "list", topics: @topics %>
35-
</table>
36-
</div>
7+
<%= turbo_frame_tag "topics" do %>
8+
<div class="card">
9+
<div class="card-header d-flex justify-content-between align-items-center">
10+
<h2 class="card-title"><%= current_provider.name %>'s topics</h2>
11+
<%= link_to new_topic_path, class: "btn btn-primary" do %>
12+
<i class="bi bi-plus"></i> Add New Topic
3713
<% end %>
3814
</div>
15+
<div class="card-content">
16+
<div class="card-body">
17+
<% if @available_providers.any? %>
18+
<%= render "choose_provider", providers: @available_providers %>
19+
<% end %>
20+
<p class="card-text"> Some important information or instruction can be placed here.</p>
21+
<%= turbo_frame_tag "topic-list" do %>
22+
<div class="table-responsive">
23+
<table class="table table-lg table-striped mb-0">
24+
<thead>
25+
<tr>
26+
<th>Title</th>
27+
<th>Description</th>
28+
<th>UID</th>
29+
<th>Language</th>
30+
<th>Provider</th>
31+
<th>State</th>
32+
<th class="text-end">Actions</th>
33+
</tr>
34+
</thead>
35+
<%= render "list", topics: @topics %>
36+
</table>
37+
</div>
38+
<% end %>
39+
</div>
40+
</div>
3941
</div>
40-
</div>
42+
<% end %>
4143
</div>
4244
</div>
4345
</section>

0 commit comments

Comments
 (0)