Skip to content
Snippets Groups Projects
Unverified Commit 5dfeea31 authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

wip education program roles

parent de601ac3
No related branches found
No related tags found
No related merge requests found
Showing
with 196 additions and 35 deletions
class Admin::Education::Program::RolesController < Admin::Education::Program::ApplicationController
load_and_authorize_resource class: Education::Program::Role, through: :program
def show
breadcrumb
end
def new
breadcrumb
end
def edit
breadcrumb
add_breadcrumb t('edit')
end
def create
if @role.save
redirect_to admin_education_program_role_path(@role), notice: t('admin.successfully_created_html', model: @role.to_s)
else
breadcrumb
render :new, status: :unprocessable_entity
end
end
def update
if @role.update(role_params)
redirect_to admin_education_program_role_path(@role), notice: t('admin.successfully_updated_html', model: @role.to_s)
else
breadcrumb
render :edit, status: :unprocessable_entity
add_breadcrumb t('edit')
end
end
def destroy
@role.destroy
redirect_to admin_education_program_path(@program), notice: t('admin.successfully_destroyed_html', model: @role.to_s)
end
protected
def breadcrumb
super
add_breadcrumb Education::Program::Role.model_name.human(count: 2)
breadcrumb_for @role
end
def role_params
params.require(:education_program_role)
.permit(:title)
.merge(program_id: @program.id, university_id: current_university.id)
end
end
......@@ -26,6 +26,10 @@ class Education::Program::Role < ApplicationRecord
belongs_to :university
belongs_to :program, class_name: 'Education::Program'
def to_s
"#{title}"
end
protected
def last_ordered_element
......
<%= simple_form_for [:admin, role] do |f| %>
<div class="row">
<div class="col-md-8">
<div class="card flex-fill w-100">
<div class="card-header">
<h5 class="card-title mb-0"><%= t('admin.infos') %></h5>
</div>
<div class="card-body">
<%= f.input :title %>
</div>
</div>
</div>
</div>
<% content_for :action_bar_right do %>
<%= submit f %>
<% end %>
<% end %>
<table class="table">
<thead>
<tr>
<th><%= Education::Program::Role.model_name.human %></th>
<th></th>
</tr>
</thead>
<tbody>
<% roles.each do |role| %>
<tr>
<td>
<%= link_to_if can?(:read, role),
role,
admin_education_program_role_path(role, { program_id: @program.id }) %>
</td>
<td class="text-end pe-0">
<div class="btn-group" role="group">
<%= link_to t('edit'),
edit_admin_education_program_role_path(role, { program_id: @program.id }),
class: button_classes %>
<%= link_to t('delete'),
admin_education_program_role_path(role, { program_id: @program.id }),
method: :delete,
data: { confirm: t('please_confirm') },
class: button_classes_danger %>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
<% content_for :title, @role %>
<%= render 'form', role: @role %>
<% content_for :title, Education::Program::Role.model_name.human %>
<%= render 'form', role: @role %>
<% content_for :title, @role %>
<div class="row">
<div class="col-md-4">
<div class="card flex-fill w-100">
<div class="card-header">
<h2 class="card-title mb-0 h5"><%= t('admin.infos') %></h2>
</div>
<div class="card-body">
<h3 class="h5"><%= Education::Program::Role.human_attribute_name('title') %></h3>
<%= @role.title %>
</div>
</div>
</div>
</div>
<% content_for :action_bar_right do %>
<%= edit_link @role %>
<% end %>
<table class="table">
<thead>
<tr>
<th><%= Education::Program::Teacher.model_name.human %></th>
<th><%= Education::Program::Teacher.human_attribute_name('description') %></th>
<th></th>
</tr>
</thead>
<tbody>
<% teachers.each do |teacher| %>
<tr>
<td>
<%= link_to_if can?(:read, teacher.person),
teacher.person,
admin_education_teacher_path(teacher.person) %>
</td>
<td><%= teacher.description %></td>
<td class="text-end pe-0">
<div class="btn-group" role="group">
<%= link_to t('edit'),
edit_admin_education_program_teacher_path(teacher, { program_id: @program.id }),
class: button_classes %>
<%= link_to t('delete'),
admin_education_program_teacher_path(teacher, { program_id: @program.id }),
method: :delete,
data: { confirm: t('please_confirm') },
class: button_classes_danger %>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
......@@ -93,46 +93,25 @@
<%= @program.public_send prop %>
<% i += 1 %>
<% end %>
<h3 class="h5 <%= 'mt-4' if i > 0 %>"><%= Education::Program.human_attribute_name('teachers') %></h3>
<p><%= link_to t('create'), new_admin_education_program_teacher_path(program_id: @program.id), class: 'btn btn-primary' %></p>
<table class="table">
<thead>
<tr>
<th><%= Education::Program::Teacher.model_name.human %></th>
<th><%= Education::Program::Teacher.human_attribute_name('description') %></th>
<th></th>
</tr>
</thead>
<tbody>
<% @program.teachers.includes(:person).ordered.each do |teacher| %>
<tr>
<td>
<%= link_to_if can?(:read, teacher.person),
teacher.person,
admin_education_teacher_path(teacher.person) %>
</td>
<td><%= teacher.description %></td>
<td class="text-end pe-0">
<div class="btn-group" role="group">
<%= link_to t('edit'),
edit_admin_education_program_teacher_path(teacher, { program_id: @program.id }),
class: button_classes %>
<%= link_to t('delete'),
admin_education_program_teacher_path(teacher, { program_id: @program.id }),
method: :delete,
data: { confirm: t('please_confirm') },
class: button_classes_danger %>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= render 'admin/education/program/teachers/list', teachers: @program.teachers.includes(:person).ordered %>
</div>
</div>
</div>
</div>
<div class="card flex-fill w-100">
<div class="card-header">
<h5 class="card-title mb-0"><%= Education::Program.human_attribute_name('roles') %></h5>
</div>
<div class="card-body">
<p><%= link_to t('create'), new_admin_education_program_role_path(program_id: @program.id), class: 'btn btn-primary' %></p>
<%= render 'admin/education/program/roles/list', roles: @program.roles.ordered %>
</div>
</div>
<% if @program.children.any? %>
<div class="card flex-fill w-100">
<div class="card-header">
......
......@@ -7,6 +7,9 @@ en:
education/program:
one: Program
other: Programs
education/program/role:
one: Role
other: Roles
education/program/teacher:
one: Teacher
other: Teachers
......@@ -35,9 +38,13 @@ en:
pricing: Tarifs
published: Published?
registration: Modalités et délais d’accès
roles: Roles
schools: Schools with this formation
teachers: Teachers
team: Team
education/program/role:
people: People
title: Title
education/program/teacher:
description: Description
person: Person
......
......@@ -7,9 +7,12 @@ fr:
education/program:
one: Formation
other: Formations
education/program/role:
one: Rôle
other: Rôles
education/program/teacher:
one: Enseignant
other: Enseignants
one: Enseignant·e
other: Enseignants·es
education/school:
one: École
other: Écoles
......@@ -35,9 +38,13 @@ fr:
pricing: Tarifs
published: Publiée ?
registration: Modalités et délais d’accès
roles: Rôles
schools: Écoles proposant cette formation
teachers: Enseignants·es
team: Équipe
education/program/role:
people: Personnes
title: Titre
education/program/teacher:
description: Description
person: Personne
......@@ -57,6 +64,9 @@ fr:
educational_informations: Informations pédagogiques
main_informations: Informations essentielles
useful_informations: Informations pratiques
roles:
one: Rôle
other: Rôles
teachers:
one: Enseignant·e
other: Enseignants·es
......
......@@ -2,6 +2,7 @@ namespace :education do
resources :teachers, only: [:index, :show]
resources :schools
resources :programs do
resources :roles, controller: 'program/roles', except: :index
resources :teachers, controller: 'program/teachers', except: [:index, :show]
collection do
post :reorder
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment