--- /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 Reservations controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
# Never trust parameters from the scary internet, only allow the white list through.
def organisation_params
- params.require(:organisation).permit(:nom, :adresse, :cp, :ville, :téléphone, :email, :logo,
+ params.require(:organisation).permit(:nom, :adresse, :cp, :ville, :téléphone, :email, :logo, :zone,
structures_attributes: [:id, :nom, :_destroy])
end
end
--- /dev/null
+class ReservationsController < ApplicationController
+ before_action :set_reservation, only: [:show, :edit, :update, :destroy]
+
+ # GET /reservations
+ # GET /reservations.json
+ def index
+ @reservations = @prestations = current_user.organisation.reservations
+ end
+
+ # GET /reservations/1
+ # GET /reservations/1.json
+ def show
+ end
+
+ # GET /reservations/new
+ def new
+ @reservation = Reservation.new
+ end
+
+ # GET /reservations/1/edit
+ def edit
+ end
+
+ # POST /reservations
+ # POST /reservations.json
+ def create
+ @reservation = Reservation.new(reservation_params)
+
+ respond_to do |format|
+ if @reservation.save
+ format.html { redirect_to @reservation, notice: 'Reservation was successfully created.' }
+ format.json { render :show, status: :created, location: @reservation }
+ else
+ format.html { render :new }
+ format.json { render json: @reservation.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PATCH/PUT /reservations/1
+ # PATCH/PUT /reservations/1.json
+ def update
+ respond_to do |format|
+ if @reservation.update(reservation_params)
+ format.html { redirect_to @reservation, notice: 'Reservation was successfully updated.' }
+ format.json { render :show, status: :ok, location: @reservation }
+ else
+ format.html { render :edit }
+ format.json { render json: @reservation.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /reservations/1
+ # DELETE /reservations/1.json
+ def destroy
+ @reservation.destroy
+ respond_to do |format|
+ format.html { redirect_to reservations_url, notice: 'Reservation was successfully destroyed.' }
+ format.json { head :no_content }
+ end
+ end
+
+ private
+ # Use callbacks to share common setup or constraints between actions.
+ def set_reservation
+ @reservation = Reservation.find(params[:id])
+ end
+
+ # 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)
+ end
+end
--- /dev/null
+module ReservationsHelper
+end
belongs_to :classroom
has_many :prestations
+ has_many :reservations
end
has_many :comptes, through: :structures
has_many :enfants, through: :comptes
has_many :prestations, through: :enfants
+ has_many :reservations, through: :enfants
validates :nom, :email, presence: true
--- /dev/null
+class Reservation < ApplicationRecord
+ belongs_to :enfant
+ belongs_to :prestation_type
+end
--- /dev/null
+class Vacance < ApplicationRecord
+end
-<p id="notice"><%= notice %></p>
-
<p>
<strong>Compte:</strong>
<%= @enfant.compte.nom %>
<%= link_to 'Edit', edit_enfant_path(@enfant) %> |
<%= link_to 'Back', enfants_path %>
-<br />
+
+<br /><br />
+
+<h3>Réservations</h3>
+<table class="table table-striped">
+ <% @enfant.reservations.each do |reservation| %>
+ <tr>
+ <td><%= reservation.début %></td>
+ <td><%= reservation.fin %></td>
+ <td><%= reservation.prestation_type.nom %>
+ <td><%= reservation.lundi %>
+ <td><%= reservation.mardi %>
+ <td><%= reservation.mercredi %>
+ <td><%= reservation.jeudi %>
+ <td><%= reservation.vendredi %>
+ <td><%= reservation.matin %>
+ <td><%= reservation.midi %>
+ <td><%= reservation.soir %>
+ </tr>
+ <% end %>
+</table>
+
<h3>Prestations</h3>
<table class="table table-striped">
<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">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<ul class="navbar-nav navbar-right">
- <li class="nav-item <%= (params[:controller]=='organisations' ? 'active' : '') %>">
- <%= link_to organisation_url(current_user.organisation), class: "nav-link" do %><i class="fas fa-sitemap"></i></span> Organisation<% end %>
- </li>
+ <% if current_user %>
+ <li class="nav-item <%= (params[:controller]=='organisations' ? 'active' : '') %>">
+ <%= link_to organisation_url(current_user.organisation), class: "nav-link" do %><i class="fas fa-sitemap"></i></span> Organisation<% end %>
+ </li>
+ <% end %>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
<%= form.text_field :téléphone %>
<%= form.text_field :email %>
<%= form.file_field :logo %>
+ <%= form.select :zone, ["A", "B", "C"], { label: "Zone de vacances scolaires:", wrapper: { class: 'has-warning', data: { foo: 'bar' } } }, { class: "selectpicker" } %>
<%= form.fields_for :structures do |structure_form| %>
<p>
<strong>Email:</strong>
<%= @organisation.email %>
</p>
+
+ <p>
+ <strong>Zone:</strong>
+ <%= @organisation.zone %>
+ </p>
+
<%= link_to 'Editer', edit_organisation_path(@organisation) %>
<hr>
--- /dev/null
+<%= form_with(model: reservation, local: true) do |form| %>
+ <% if reservation.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(reservation.errors.count, "error") %> prohibited this reservation from being saved:</h2>
+
+ <ul>
+ <% reservation.errors.full_messages.each do |message| %>
+ <li><%= message %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= form.label :enfant_id %>
+ <%= form.text_field :enfant_id %>
+ </div>
+
+ <div class="field">
+ <%= form.label :prestation_type_id %>
+ <%= form.text_field :prestation_type_id %>
+ </div>
+
+ <div class="field">
+ <%= form.label :début %>
+ <%= form.date_select :début %>
+ </div>
+
+ <div class="field">
+ <%= form.label :fin %>
+ <%= form.date_select :fin %>
+ </div>
+
+ <div class="field">
+ <%= form.label :lundi %>
+ <%= form.text_field :lundi %>
+ </div>
+
+ <div class="field">
+ <%= form.label :mardi %>
+ <%= form.text_field :mardi %>
+ </div>
+
+ <div class="field">
+ <%= form.label :mercredi %>
+ <%= form.text_field :mercredi %>
+ </div>
+
+ <div class="field">
+ <%= form.label :jeudi %>
+ <%= form.text_field :jeudi %>
+ </div>
+
+ <div class="field">
+ <%= form.label :vendredi %>
+ <%= form.text_field :vendredi %>
+ </div>
+
+ <div class="field">
+ <%= form.label :matin %>
+ <%= form.check_box :matin %>
+ </div>
+
+ <div class="field">
+ <%= form.label :midi %>
+ <%= form.check_box :midi %>
+ </div>
+
+ <div class="field">
+ <%= form.label :soir %>
+ <%= form.check_box :soir %>
+ </div>
+
+ <div class="actions">
+ <%= form.submit %>
+ </div>
+<% end %>
--- /dev/null
+json.extract! reservation, :id, :enfant_id, :prestation_type_id, :début, :fin, :lundi, :mardi, :mercredi, :jeudi, :vendredi, :matin, :midi, :soir, :created_at, :updated_at
+json.url reservation_url(reservation, format: :json)
--- /dev/null
+<h1>Editing Reservation</h1>
+
+<%= render 'form', reservation: @reservation %>
+
+<%= link_to 'Show', @reservation %> |
+<%= link_to 'Back', reservations_path %>
--- /dev/null
+<h1><i class="fas fa-calendar-alt"></i> Réservations</h1>
+
+<table class="table table-striped">
+ <thead>
+ <tr>
+ <th colspan=2>Enfant</th>
+ <th>Prestation</th>
+ <th>Début</th>
+ <th>Fin</th>
+ <th>Lundi</th>
+ <th>Mardi</th>
+ <th>Mercredi</th>
+ <th>Jeudi</th>
+ <th>Vendredi</th>
+ <th>Matin</th>
+ <th>Midi</th>
+ <th>Soir</th>
+ <th colspan="3"></th>
+ </tr>
+ </thead>
+
+ <tbody>
+ <% @reservations.each do |reservation| %>
+ <tr>
+ <td><%= reservation.enfant.nom %></td>
+ <td><%= reservation.enfant.prénom %></td>
+ <td><%= reservation.prestation_type.nom %></td>
+ <td><%= reservation.début %></td>
+ <td><%= reservation.fin %></td>
+ <td><%= reservation.lundi %></td>
+ <td><%= reservation.mardi %></td>
+ <td><%= reservation.mercredi %></td>
+ <td><%= reservation.jeudi %></td>
+ <td><%= reservation.vendredi %></td>
+ <td><%= reservation.matin %></td>
+ <td><%= reservation.midi %></td>
+ <td><%= reservation.soir %></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>
+ </tr>
+ <% end %>
+ </tbody>
+</table>
+
+<br>
+
+<%= link_to 'New Reservation', new_reservation_path %>
--- /dev/null
+json.array! @reservations, partial: "reservations/reservation", as: :reservation
--- /dev/null
+<h1>New Reservation</h1>
+
+<%= render 'form', reservation: @reservation %>
+
+<%= link_to 'Back', reservations_path %>
--- /dev/null
+<p id="notice"><%= notice %></p>
+
+<p>
+ <strong>Enfant:</strong>
+ <%= @reservation.enfant %>
+</p>
+
+<p>
+ <strong>Prestation type:</strong>
+ <%= @reservation.prestation_type %>
+</p>
+
+<p>
+ <strong>Début:</strong>
+ <%= @reservation.début %>
+</p>
+
+<p>
+ <strong>Fin:</strong>
+ <%= @reservation.fin %>
+</p>
+
+<p>
+ <strong>Lundi:</strong>
+ <%= @reservation.lundi %>
+</p>
+
+<p>
+ <strong>Mardi:</strong>
+ <%= @reservation.mardi %>
+</p>
+
+<p>
+ <strong>Mercredi:</strong>
+ <%= @reservation.mercredi %>
+</p>
+
+<p>
+ <strong>Jeudi:</strong>
+ <%= @reservation.jeudi %>
+</p>
+
+<p>
+ <strong>Vendredi:</strong>
+ <%= @reservation.vendredi %>
+</p>
+
+<p>
+ <strong>Matin:</strong>
+ <%= @reservation.matin %>
+</p>
+
+<p>
+ <strong>Midi:</strong>
+ <%= @reservation.midi %>
+</p>
+
+<p>
+ <strong>Soir:</strong>
+ <%= @reservation.soir %>
+</p>
+
+<%= link_to 'Edit', edit_reservation_path(@reservation) %> |
+<%= link_to 'Back', reservations_path %>
--- /dev/null
+json.partial! "reservations/reservation", reservation: @reservation
Rails.application.routes.draw do
+ resources :reservations
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
get 'prestations/index'
--- /dev/null
+class CreateReservations < ActiveRecord::Migration[5.2]
+ def change
+ create_table :reservations do |t|
+ t.references :enfant, foreign_key: true
+ t.references :prestation_type, foreign_key: true
+ t.date :début, null: false
+ t.date :fin, null: false
+ t.decimal :lundi, :precision => 3, :scale => 2, null: false, default: 0
+ t.decimal :mardi, :precision => 3, :scale => 2, null: false, default: 0
+ t.decimal :mercredi, :precision => 3, :scale => 2, null: false, default: 0
+ t.decimal :jeudi, :precision => 3, :scale => 2, null: false, default: 0
+ t.decimal :vendredi, :precision => 3, :scale => 2, null: false, default: 0
+ t.boolean :matin
+ t.boolean :midi
+ t.boolean :soir
+
+ t.timestamps
+ end
+ end
+end
--- /dev/null
+class CreateVacances < ActiveRecord::Migration[5.2]
+ def change
+ create_table :vacances do |t|
+ t.string :zone, null: false, default: ""
+ t.string :nom, null: false, default: ""
+ t.date :début
+ t.date :fin
+
+ t.timestamps
+ end
+ end
+end
--- /dev/null
+class AddVacancesZoneToOrganisation < ActiveRecord::Migration[5.2]
+ def change
+ add_column :organisations, :zone, :string
+ end
+end
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2019_08_28_134617) do
+ActiveRecord::Schema.define(version: 2019_08_29_111634) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
t.string "email"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
+ t.string "zone"
end
create_table "prestation_types", force: :cascade do |t|
t.index ["prestation_type_id"], name: "index_prestations_on_prestation_type_id"
end
+ create_table "reservations", force: :cascade do |t|
+ t.bigint "enfant_id"
+ t.bigint "prestation_type_id"
+ t.date "début", null: false
+ t.date "fin", null: false
+ t.decimal "lundi", precision: 3, scale: 2, default: "0.0", null: false
+ t.decimal "mardi", precision: 3, scale: 2, default: "0.0", null: false
+ t.decimal "mercredi", precision: 3, scale: 2, default: "0.0", null: false
+ t.decimal "jeudi", precision: 3, scale: 2, default: "0.0", null: false
+ t.decimal "vendredi", precision: 3, scale: 2, default: "0.0", 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_reservations_on_enfant_id"
+ t.index ["prestation_type_id"], name: "index_reservations_on_prestation_type_id"
+ end
+
create_table "structure_classes", force: :cascade do |t|
t.bigint "structure_id"
t.string "nom"
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
+ create_table "vacances", force: :cascade do |t|
+ t.string "zone", default: "", null: false
+ t.string "nom", default: "", null: false
+ t.date "début"
+ t.date "fin"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "classrooms", "structures"
add_foreign_key "comptes", "structures"
add_foreign_key "prestation_types", "organisations"
add_foreign_key "prestations", "enfants"
add_foreign_key "prestations", "prestation_types"
+ add_foreign_key "reservations", "enfants"
+ add_foreign_key "reservations", "prestation_types"
add_foreign_key "structure_classes", "structures"
add_foreign_key "structures", "organisations"
add_foreign_key "tarif_types", "organisations"