diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb
new file mode 100644
index 0000000..7eb3f78
--- /dev/null
+++ b/app/controllers/templates_controller.rb
@@ -0,0 +1,69 @@
+# frozen_string_literal: true
+
+class TemplatesController < ApplicationController
+ before_action :set_template, only: %i[show edit update destroy]
+
+ # GET /templates
+ # GET /templates.json
+ def index
+ @templates = Template.order(updated_at: :desc).paginate(page: params[:page])
+ end
+
+ # GET /templates/1
+ # GET /templates/1.json
+ def show; end
+
+ # GET /templates/new
+ def new
+ @template = Template.new
+ end
+
+ # GET /templates/1/edit
+ def edit; end
+
+ # POST /templates
+ def create
+ @template = Template.new(template_params)
+ if @template.save
+ redirect_to @template, notice: 'Template was successfully created.'
+ else
+ render :new
+ end
+ end
+
+ # PATCH/PUT /templates/1
+ # PATCH/PUT /templates/1.json
+ def update
+ puts "in update, params : #{template_params}"
+ if @template.update(template_params)
+ redirect_to @template, notice: 'Template was successfully updated.'
+ else
+ render :edit
+ end
+ end
+
+ # DELETE /templates/1
+ def destroy
+ @template.destroy
+ redirect_to templates_url, notice: 'Template was successfully destroyed.'
+ end
+
+ # GET /templates/1/duplicate
+ def duplicate
+ original = Template.find(params[:template_id])
+ @template = original.dup
+ render 'new'
+ end
+
+ private
+
+ # Use callbacks to share common setup or constraints between actions.
+ def set_template
+ @template = Template.find(params[:id])
+ end
+
+ # Never trust parameters from the scary internet, only allow the white list through.
+ def template_params
+ params.require(:template).permit(:title, :description, :date, :period, { skill_ids: [] }, student_ids: [])
+ end
+end
diff --git a/app/views/shared/_header.html.erb b/app/views/shared/_header.html.erb
index baad085..1a938fd 100644
--- a/app/views/shared/_header.html.erb
+++ b/app/views/shared/_header.html.erb
@@ -34,6 +34,11 @@
Liste des séances
+
diff --git a/app/views/templates/_form.html.erb b/app/views/templates/_form.html.erb
new file mode 100644
index 0000000..6650429
--- /dev/null
+++ b/app/views/templates/_form.html.erb
@@ -0,0 +1,29 @@
+
+<%= form_with(model: template, local: true) do |form| %>
+ <% if template.errors.any? %>
+
+
<%= pluralize(template.errors.count, "error") %> prohibited this template from being saved:
+
+
+ <% template.errors.full_messages.each do |message| %>
+ - <%= message %>
+ <% end %>
+
+
+ <% end %>
+
+
+ <%= form.label :title %>
+ <%= form.text_field :title, class: "ml-2 pl-2 form-control" %>
+
+
+
+ <%= form.label :description %>
+ <%= form.text_area :description, class: "ml-2 pl-2 form-control" %>
+
+
+
+ <%= form.submit class: 'btn btn-primary btn-lg mt-3' %>
+
+<% end %>
+
diff --git a/app/views/templates/_template.html.erb b/app/views/templates/_template.html.erb
new file mode 100644
index 0000000..4928f71
--- /dev/null
+++ b/app/views/templates/_template.html.erb
@@ -0,0 +1,6 @@
+
+ <%= template.title %> |
+ <%= link_to "Voir", template_path(template.id), class: "btn btn-sm btn-outline-primary" %> |
+ <%= link_to 'Dupliquer', template_duplicate_path(template) %> |
+ <%= link_to 'Supprimer', template, method: :delete, data: { confirm: 'Cette action est irréversible, êtes-vous sûr ?' } %> |
+
diff --git a/app/views/templates/edit.html.erb b/app/views/templates/edit.html.erb
new file mode 100644
index 0000000..8743b95
--- /dev/null
+++ b/app/views/templates/edit.html.erb
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+ <%= link_to 'Show', @template, class:"mr-3" %>
+ <%= link_to 'Back', templates_path %>
+
+
+
+
diff --git a/app/views/templates/index.html.erb b/app/views/templates/index.html.erb
new file mode 100644
index 0000000..4d84f3f
--- /dev/null
+++ b/app/views/templates/index.html.erb
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+ Intitulé |
+ Date |
+ Période |
+ |
+ |
+ |
+ <% @templates.each do |f| %>
+ <%= f.collection_select :template, @templates.all, :title, :description, { class: 'chosen-select'} %> |
+ <% end %>
+
+
+
+ <%= render @templates %>
+
+
+ <%= will_paginate @templates, list_classes: %w(pagination justify-content-center) %>
+
+
+
+
+
+
diff --git a/app/views/templates/new.html.erb b/app/views/templates/new.html.erb
new file mode 100644
index 0000000..e92a243
--- /dev/null
+++ b/app/views/templates/new.html.erb
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+ <%= render 'form', template: @template %>
+
+
+
+
+ <%= link_to 'Back', templates_path %>
+
+
+
+
+
diff --git a/app/views/templates/show.html.erb b/app/views/templates/show.html.erb
new file mode 100644
index 0000000..690c5fa
--- /dev/null
+++ b/app/views/templates/show.html.erb
@@ -0,0 +1,31 @@
+
+ <%= link_to 'Retourner à la liste des séances', templates_path, class:"pl-3" %>
+
+
+
+
+
+
+
+ <%= link_to 'Editer la séance', edit_template_path(@template) %>
+
+
+
+
+ Intitulé
+ <%= @template.title %>
+
+
+
+ Description
+ <%= @template.description %>
+
+
+
+
+
+
+
+
diff --git a/config/routes.rb b/config/routes.rb
index 53f70c7..83e0ac0 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -11,6 +11,9 @@
resources :students do
collection { post :import }
end
+ resources :templates do
+ get 'duplicate'
+ end
resources :student_worksessions, only: [:destroy]
get 'report', to: 'home#report'
get 'home/index', to: "home#index"