Add SDG content section
This commit is contained in:
@@ -28,3 +28,4 @@
|
||||
@import "leaflet";
|
||||
@import "sticky_overrides";
|
||||
@import "admin/*";
|
||||
@import "sdg_management/*";
|
||||
|
||||
10
app/assets/stylesheets/sdg_management/menu.scss
Normal file
10
app/assets/stylesheets/sdg_management/menu.scss
Normal file
@@ -0,0 +1,10 @@
|
||||
.sdg-content-menu {
|
||||
|
||||
.goals-link::before {
|
||||
@extend %font-icon;
|
||||
@extend %svg-icon;
|
||||
@extend %admin-menu-icon;
|
||||
|
||||
mask-image: image-url("sdg.svg");
|
||||
}
|
||||
}
|
||||
25
app/components/sdg_management/goals/index_component.html.erb
Normal file
25
app/components/sdg_management/goals/index_component.html.erb
Normal file
@@ -0,0 +1,25 @@
|
||||
<% provide(:title) do %>
|
||||
<%= t("sdg_management.header.title") %> - <%= title %>
|
||||
<% end %>
|
||||
|
||||
<h2><%= title %></h2>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= attribute_name(:code) %></th>
|
||||
<th><%= attribute_name(:title) %></th>
|
||||
<th><%= attribute_name(:description) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% goals.each do |goal| %>
|
||||
<tr id="<%= dom_id(goal) %>" class="goal">
|
||||
<td><%= goal.code %></td>
|
||||
<td><%= goal.title %></td>
|
||||
<td><%= goal.description %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
17
app/components/sdg_management/goals/index_component.rb
Normal file
17
app/components/sdg_management/goals/index_component.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
class SDGManagement::Goals::IndexComponent < ApplicationComponent
|
||||
attr_reader :goals
|
||||
|
||||
def initialize(goals)
|
||||
@goals = goals
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def title
|
||||
SDG::Goal.model_name.human(count: 2).titleize
|
||||
end
|
||||
|
||||
def attribute_name(attribute)
|
||||
SDG::Goal.human_attribute_name(attribute)
|
||||
end
|
||||
end
|
||||
5
app/components/sdg_management/menu_component.html.erb
Normal file
5
app/components/sdg_management/menu_component.html.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<ul class="sdg-content-menu">
|
||||
<li class="<%= "is-active" if sdg? %>">
|
||||
<%= link_to t("sdg_management.menu.sdg_content"), sdg_management_goals_path, class: "goals-link" %>
|
||||
</li>
|
||||
</ul>
|
||||
7
app/components/sdg_management/menu_component.rb
Normal file
7
app/components/sdg_management/menu_component.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
class SDGManagement::MenuComponent < ApplicationComponent
|
||||
private
|
||||
|
||||
def sdg?
|
||||
controller_name == "goals"
|
||||
end
|
||||
end
|
||||
14
app/controllers/sdg_management/base_controller.rb
Normal file
14
app/controllers/sdg_management/base_controller.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
class SDGManagement::BaseController < ApplicationController
|
||||
layout "admin"
|
||||
|
||||
before_action :authenticate_user!
|
||||
before_action :verify_sdg_manager
|
||||
|
||||
skip_authorization_check
|
||||
|
||||
private
|
||||
|
||||
def verify_sdg_manager
|
||||
raise CanCan::AccessDenied unless current_user&.administrator?
|
||||
end
|
||||
end
|
||||
5
app/controllers/sdg_management/goals_controller.rb
Normal file
5
app/controllers/sdg_management/goals_controller.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class SDGManagement::GoalsController < SDGManagement::BaseController
|
||||
def index
|
||||
@goals = SDG::Goal.order(:code)
|
||||
end
|
||||
end
|
||||
@@ -42,6 +42,6 @@ module AdminHelper
|
||||
private
|
||||
|
||||
def namespace
|
||||
controller.class.name.downcase.split("::").first
|
||||
controller.class.name.split("::").first.underscore
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
<nav id="side_menu" class="admin-sidebar">
|
||||
<% if namespace == "admin" %>
|
||||
<%= render Admin::MenuComponent.new %>
|
||||
<% elsif namespace == "sdg_management" %>
|
||||
<%= render SDGManagement::MenuComponent.new %>
|
||||
<% else %>
|
||||
<%= render "/#{namespace}/menu" %>
|
||||
<% end %>
|
||||
|
||||
1
app/views/sdg_management/goals/index.html.erb
Normal file
1
app/views/sdg_management/goals/index.html.erb
Normal file
@@ -0,0 +1 @@
|
||||
<%= render SDGManagement::Goals::IndexComponent.new(@goals) %>
|
||||
@@ -32,6 +32,12 @@
|
||||
<%= link_to t("layouts.header.officing"), officing_root_path %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<% if current_user.administrator? %>
|
||||
<li>
|
||||
<%= link_to t("sdg_management.header.title"), sdg_management_root_path %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user