Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template front back #113

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions app/controllers/templates_controller.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions app/views/shared/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
<i class="align-middle" data-feather="list"></i> <span class="align-middle">Liste des séances</span>
</a>
</li>
<li class="sidebar-item">
<a class="sidebar-link" href="/templates">
<i class="align-middle" data-feather="list"></i> <span class="align-middle">Liste des templates</span>
</a>
</li>
<li class="sidebar-header">
Elèves
</li>
Expand Down
29 changes: 29 additions & 0 deletions app/views/templates/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<div class="d-flex">
<%= form_with(model: template, local: true) do |form| %>
<% if template.errors.any? %>
<div id="error_explanation">
<h4><%= pluralize(template.errors.count, "error") %> prohibited this template from being saved:</h4>

<ul class="mb-4">
<% template.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="form-group mb-5 col-10">
<%= form.label :title %>
<%= form.text_field :title, class: "ml-2 pl-2 form-control" %>
</div>

<div class="form-group mb-5 col-10">
<%= form.label :description %>
<%= form.text_area :description, class: "ml-2 pl-2 form-control" %>
</div>

<div class="actions">
<%= form.submit class: 'btn btn-primary btn-lg mt-3' %>
</div>
<% end %>
</div>
6 changes: 6 additions & 0 deletions app/views/templates/_template.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<tr>
<td><%= template.title %></td>
<td><%= link_to "Voir", template_path(template.id), class: "btn btn-sm btn-outline-primary" %></td>
<td><%= link_to 'Dupliquer', template_duplicate_path(template) %></td>
<td><%= link_to 'Supprimer', template, method: :delete, data: { confirm: 'Cette action est irréversible, êtes-vous sûr ?' } %></td>
</tr>
21 changes: 21 additions & 0 deletions app/views/templates/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<main class="content">
<div class="container-fluid p-0">
<div class="row">
<div class="col-12 col-lg-10">
<div class="card animated fadeIn">
<div class="card-header">
<h1 class="mb-3">Editer le template</h1>
<div class="card-body">
<%= render 'form', template: @template %>


</div>

</div>
</div>
<%= link_to 'Show', @template, class:"mr-3" %>
<%= link_to 'Back', templates_path %>
</div>
</div>
</div>
</main>
39 changes: 39 additions & 0 deletions app/views/templates/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<main class="content">
<div class="container-fluid p-0">
<div class="row">
<div class="col-12 col-lg-8">
<div class="card animated fadeIn">
<div class="card-header d-flex justify-content-between">
<h1 class="h3 mt-2">Liste des templates</h1>
<div>
<%= link_to new_template_path, class: "btn btn-primary btn-lg" do %>
<i class="fas fa-user-plus"></i> Programmer un nouveau template
<% end %>
</div>
</div>
<div class="card-body">
<table id="datatables-basic" class="table table-striped" style="width:100%">
<thead>
<tr>
<th>Intitulé</th>
<th>Date</th>
<th>Période</th>
<th></th>
<th></th>
<th></th>
<% @templates.each do |f| %>
<th><%= f.collection_select :template, @templates.all, :title, :description, { class: 'chosen-select'} %></th>
<% end %>
</tr>
</thead>
<tbody>
<%= render @templates %>
</tbody>
</table>
<%= will_paginate @templates, list_classes: %w(pagination justify-content-center) %>
</div>
</div>
</div>
</div>
</div>
</main>
20 changes: 20 additions & 0 deletions app/views/templates/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<main class="content">
<div class="container-fluid p-0">
<div class="row">
<div class="col-12 col-lg-10">
<div class="card animated fadeIn">
<div class="card-header">
<h1 class="mb-3">Nouveau template</h1>
</div>
<div class="card-body">
<%= render 'form', template: @template %>


</div>
</div>
<%= link_to 'Back', templates_path %>
</div>

</div>
</div>
</main>
31 changes: 31 additions & 0 deletions app/views/templates/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<main class="content">
<%= link_to 'Retourner à la liste des séances', templates_path, class:"pl-3" %>

<div class="container-fluid p-0">
<div class="row">
<div class="col-12 col-lg-4">
<div class="card animated fadeIn">
<div class="card-header d-flex justify-content-between">
<h1 class="h3 mt-2">Séance</h1>
</div>

<%= link_to 'Editer la séance', edit_template_path(@template) %>

<div class="card-body">

<p>
<strong>Intitulé</strong>
<%= @template.title %>
</p>

<p>
<strong>Description</strong>
<%= @template.description %>
</p>

</div>
</div>
</div>
</div>
</div>
</main>
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down