Add SDG content section

This commit is contained in:
Javi Martín
2020-11-11 13:16:37 +01:00
parent 2b6c9914dd
commit a42cb050a7
21 changed files with 166 additions and 1 deletions

View File

@@ -28,3 +28,4 @@
@import "leaflet";
@import "sticky_overrides";
@import "admin/*";
@import "sdg_management/*";

View 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");
}
}

View 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>

View 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

View 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>

View File

@@ -0,0 +1,7 @@
class SDGManagement::MenuComponent < ApplicationComponent
private
def sdg?
controller_name == "goals"
end
end

View 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

View File

@@ -0,0 +1,5 @@
class SDGManagement::GoalsController < SDGManagement::BaseController
def index
@goals = SDG::Goal.order(:code)
end
end

View File

@@ -42,6 +42,6 @@ module AdminHelper
private
def namespace
controller.class.name.downcase.split("::").first
controller.class.name.split("::").first.underscore
end
end

View File

@@ -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 %>

View File

@@ -0,0 +1 @@
<%= render SDGManagement::Goals::IndexComponent.new(@goals) %>

View File

@@ -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 %>