--- /dev/null
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/
--- /dev/null
+// Place all the styles related to the Absences controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
--- /dev/null
+class AbsencesController < ApplicationController
+ before_action :set_absence, only: [:show, :edit, :update, :destroy]
+
+ # GET /absences
+ # GET /absences.json
+ def index
+ @absences = current_user.organisation.absences
+ end
+
+ # GET /absences/1
+ # GET /absences/1.json
+ def show
+ end
+
+ # GET /absences/new
+ def new
+ @absence = Absence.new
+ @absence.enfant_id = params[:enfant_id]
+ end
+
+ # GET /absences/1/edit
+ def edit
+ end
+
+ # POST /absences
+ # POST /absences.json
+ def create
+ @absence = Absence.new(absence_params)
+
+ respond_to do |format|
+ if @absence.save
+ format.html { redirect_to @absence, notice: 'Absence was successfully created.' }
+ format.json { render :show, status: :created, location: @absence }
+ else
+ format.html { render :new }
+ format.json { render json: @absence.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PATCH/PUT /absences/1
+ # PATCH/PUT /absences/1.json
+ def update
+ respond_to do |format|
+ if @absence.update(absence_params)
+ format.html { redirect_to @absence, notice: 'Absence was successfully updated.' }
+ format.json { render :show, status: :ok, location: @absence }
+ else
+ format.html { render :edit }
+ format.json { render json: @absence.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /absences/1
+ # DELETE /absences/1.json
+ def destroy
+ @absence.destroy
+ respond_to do |format|
+ format.html { redirect_to absences_url, notice: 'Absence was successfully destroyed.' }
+ format.json { head :no_content }
+ end
+ end
+
+ private
+ # Use callbacks to share common setup or constraints between actions.
+ def set_absence
+ @absence = Absence.find(params[:id])
+ end
+
+ # Never trust parameters from the scary internet, only allow the white list through.
+ def absence_params
+ params.require(:absence).permit(:enfant_id, :début, :fin, :matin, :midi, :soir)
+ end
+end
# GET /reservations
# GET /reservations.json
def index
- @reservations = @prestations = current_user.organisation.reservations
+ @reservations = current_user.organisation.reservations
end
# GET /reservations/1
# Never trust parameters from the scary internet, only allow the white list through.
def reservation_params
- params.require(:reservation).permit(:enfant_id, :prestation_type_id, :début, :fin, :lundi, :mardi, :mercredi, :jeudi, :vendredi, :matin, :midi, :soir)
+ params.require(:reservation).permit(:enfant_id, :prestation_type_id, :active, :début, :fin, :lundi, :mardi, :mercredi, :jeudi, :vendredi, :matin, :midi, :soir)
end
end
--- /dev/null
+module AbsencesHelper
+end
--- /dev/null
+class Absence < ApplicationRecord
+ belongs_to :enfant
+end
has_many :prestations
has_many :reservations
+ has_many :absences
def nom_et_prénom
"#{self.nom} #{self.prénom}"
has_many :enfants, through: :comptes
has_many :prestations, through: :enfants
has_many :reservations, through: :enfants
+ has_many :absences, through: :enfants
validates :nom, :email, presence: true
--- /dev/null
+json.extract! absence, :id, :enfant_id, :début, :fin, :matin, :midi, :soir, :created_at, :updated_at
+json.url absence_url(absence, format: :json)
--- /dev/null
+<%= bootstrap_form_with(model: absence, local: true) do |form| %>
+ <% if absence.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(absence.errors.count, "error") %> prohibited this absence from being saved:</h2>
+
+ <ul>
+ <% absence.errors.full_messages.each do |message| %>
+ <li><%= message %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <p>
+ <h2>
+ <%= @absence.enfant.nom_et_prénom %>
+ </h2>
+ </p>
+
+ <%= form.hidden_field :enfant_id %>
+ <%= form.date_select :début %>
+ <%= form.date_select :fin %>
+ <%= form.check_box :matin, custom: :switch %>
+ <%= form.check_box :midi, custom: :switch %>
+ <%= form.check_box :soir, custom: :switch %>
+ <br />
+
+ <div class="actions">
+ <%= form.submit %>
+ </div>
+<% end %>
--- /dev/null
+<h1>Editing Absence</h1>
+
+<%= render 'form', absence: @absence %>
+
+<%= link_to 'Show', @absence %> |
+<%= link_to 'Back', absences_path %>
--- /dev/null
+<h1><i class="fas fa-calendar-times"></i> Absences</h1>
+
+<table class="table table-striped">
+ <thead>
+ <tr>
+ <th>Enfant</th>
+ <th>Classe</th>
+ <th>Début</th>
+ <th>Fin</th>
+ <th>Matin</th>
+ <th>Midi</th>
+ <th>Soir</th>
+ <th colspan="3"></th>
+ </tr>
+ </thead>
+
+ <tbody>
+ <% @absences.each do |absence| %>
+ <tr>
+ <td><%= absence.enfant.nom_et_prénom %></td>
+ <td><%= absence.enfant.classroom.nom %></td>
+ <td><%= absence.début %></td>
+ <td><%= absence.fin %></td>
+ <td><%= absence.matin %></td>
+ <td><%= absence.midi %></td>
+ <td><%= absence.soir %></td>
+ <td><%= link_to 'Show', absence %></td>
+ <td><%= link_to 'Edit', edit_absence_path(absence) %></td>
+ <td><%= link_to 'Destroy', absence, method: :delete, data: { confirm: 'Are you sure?' } %></td>
+ </tr>
+ <% end %>
+ </tbody>
+</table>
+
+<br>
+
+<%= link_to 'New Absence', new_absence_path %>
--- /dev/null
+json.array! @absences, partial: "absences/absence", as: :absence
--- /dev/null
+<h1>New Absence</h1>
+
+<%= render 'form', absence: @absence %>
+
+<%= link_to 'Back', absences_path %>
--- /dev/null
+<p id="notice"><%= notice %></p>
+
+<p>
+ <strong>Enfant:</strong>
+ <%= @absence.enfant %>
+</p>
+
+<p>
+ <strong>Début:</strong>
+ <%= @absence.début %>
+</p>
+
+<p>
+ <strong>Fin:</strong>
+ <%= @absence.fin %>
+</p>
+
+<p>
+ <strong>Matin:</strong>
+ <%= @absence.matin %>
+</p>
+
+<p>
+ <strong>Midi:</strong>
+ <%= @absence.midi %>
+</p>
+
+<p>
+ <strong>Soir:</strong>
+ <%= @absence.soir %>
+</p>
+
+<%= link_to 'Edit', edit_absence_path(@absence) %> |
+<%= link_to 'Back', absences_path %>
--- /dev/null
+json.partial! "absences/absence", absence: @absence
<%= link_to "Ajouter une réservation", new_reservation_path(enfant_id: @enfant) %>
</p>
+<p>
+ <h3><i class="fas fa-calendar-times"></i> Absences</h3>
+ <table class="table table-striped">
+ <% @enfant.absences.each do |absence| %>
+ <tr>
+ <td><%= absence.début %></td>
+ <td><%= absence.fin %></td>
+ <td><%= absence.matin %></td>
+ <td><%= absence.midi %></td>
+ <td><%= absence.soir %></td>
+ </tr>
+ <% end %>
+ </table>
+
+ <%= link_to "Ajouter une absence", new_absence_path(enfant_id: @enfant) %>
+</p>
<h3><i class="fas fa-utensils"></i> Prestations</h3>
<table class="table table-striped">
</tr>
<% end %>
</table>
+
+
<li class="nav-item <%= (params[:controller]=='enfants' ? 'active' : '') %>">
<%= link_to enfants_url, class: "nav-link" do %><i class="fas fa-child"></i></span> Enfants<% end %>
</li>
- <li class="nav-item <%= (params[:controller]=='prestations' ? 'active' : '') %>">
- <%= link_to prestations_index_url, class: "nav-link" do %><i class="fas fa-utensils"></i></span> Prestations<% end %>
- </li>
<li class="nav-item <%= (params[:controller]=='reservations' ? 'active' : '') %>">
<%= link_to reservations_url, class: "nav-link" do %><i class="fas fa-calendar-alt"></i></span> Réservations<% end %>
</li>
+ <li class="nav-item <%= (params[:controller]=='absences' ? 'active' : '') %>">
+ <%= link_to absences_url, class: "nav-link" do %><i class="fas fa-calendar-times"></i></span> Absences<% end %>
+ </li>
+ <li class="nav-item <%= (params[:controller]=='prestations' ? 'active' : '') %>">
+ <%= link_to prestations_index_url, class: "nav-link" do %><i class="fas fa-utensils"></i></span> Prestations<% end %>
+ </li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
<%= form.check_box :midi, custom: :switch %>
<%= form.check_box :soir, custom: :switch %>
<br />
+ <%= form.check_box :active, custom: :switch %>
+ <br />
<div class="actions">
<%= form.submit %>
<th>Matin</th>
<th>Midi</th>
<th>Soir</th>
+ <th>Active?</th>
<th colspan="3"></th>
</tr>
</thead>
<td><%= reservation.matin %></td>
<td><%= reservation.midi %></td>
<td><%= reservation.soir %></td>
+ <td><%= reservation.active %></td>
<td><%= link_to 'Show', reservation %></td>
<td><%= link_to 'Edit', edit_reservation_path(reservation) %></td>
<td><%= link_to 'Destroy', reservation, method: :delete, data: { confirm: 'Are you sure?' } %></td>
Rails.application.routes.draw do
+ resources :absences
resources :reservations
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
--- /dev/null
+class AddActiveToReservation < ActiveRecord::Migration[5.2]
+ def change
+ add_column :reservations, :active, :boolean, default: true
+ end
+end
--- /dev/null
+class CreateAbsences < ActiveRecord::Migration[5.2]
+ def change
+ create_table :absences do |t|
+ t.references :enfant, foreign_key: true
+ t.date :début, null: false
+ t.date :fin, null: false
+ t.boolean :matin
+ t.boolean :midi
+ t.boolean :soir
+
+ t.timestamps
+ end
+ end
+end
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2019_08_29_111634) do
+ActiveRecord::Schema.define(version: 2019_08_29_140354) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
+ create_table "absences", force: :cascade do |t|
+ t.bigint "enfant_id"
+ t.date "début", null: false
+ t.date "fin", null: false
+ t.boolean "matin"
+ t.boolean "midi"
+ t.boolean "soir"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.index ["enfant_id"], name: "index_absences_on_enfant_id"
+ end
+
create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
t.boolean "soir"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
+ t.boolean "active", default: true
t.index ["enfant_id"], name: "index_reservations_on_enfant_id"
t.index ["prestation_type_id"], name: "index_reservations_on_prestation_type_id"
end
t.datetime "updated_at", null: false
end
+ add_foreign_key "absences", "enfants"
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "classrooms", "structures"
add_foreign_key "comptes", "structures"