Commit b5df8eef authored by David F.'s avatar David F.

Merge branch '88-désactiver-une-séance' into 'master'

Resolve "[club partenaire] (dés-)activer une séance"

See merge request !92
parents 4fa1e02d 94fadf80
......@@ -92,6 +92,8 @@ class MembersController < ApplicationController
member = Member.includes(:contacts).where(id: params[:id]).first
if !member.nil? && member.published? || member == current_member || admin?
@member = member
@enabled_performances = @member.performances.enabled
@disabled_performances = @member.performances.disabled
if @member.collaborating_club?
@internal_subscriptions = @member.subscriptions
@external_subscriptions = Subscription.for_performances(@member.performance_ids) - @internal_subscriptions
......
......@@ -24,7 +24,7 @@ class PerformancesController < ApplicationController
include AuthorizationsHelper
before_action :set_member
before_action :set_performance, only: [:edit, :update, :destroy]
before_action :set_performance, only: [:edit, :update, :toggle, :destroy]
before_action :authorize_member
before_action :set_available_days
before_action :set_activities
......@@ -57,6 +57,16 @@ class PerformancesController < ApplicationController
end
end
def toggle
@performance.toggle(:disabled)
done_action = (@performance.disabled? ? "désactivée" : "activée")
if @performance.save
redirect_to @member, notice: "Séance #{done_action} avec succès."
else
redirect_to @member, error: "La séance n'a pu être #{done_action}."
end
end
def destroy
@performance.destroy
redirect_to @member, notice: 'Séance supprimée avec succès.'
......
......@@ -152,7 +152,7 @@ class SubscriptionsController < ApplicationController
def set_available_performances
collaborating_clubs = Member.of_member_groups(settings.platform_collaborating_clubs)
@available_performances = Performance.where(member_id: collaborating_clubs.ids)
@available_performances = Performance.where(member_id: collaborating_clubs.ids).enabled
end
def notify_clubs_concerned_by_removal(members, removed_performance_ids)
......
......@@ -122,4 +122,19 @@ module LinksHelper
custom_link 'fa-eur', '€', path, version, options
end
def custom_disable_link(path, version = :normal, options = {})
options[:class] << 'warning'
options[:method] = :patch
(options[:data] ||= {})[:confirm] = 'Etes-vous sûr de vouloir désactiver cet élément ?'
custom_link 'fa-toggle-off', 'Désactiver', path, version, options
end
def custom_enable_link(path, version = :normal, options = {})
options[:class] << 'warning'
options[:method] = :patch
(options[:data] ||= {})[:confirm] = 'Etes-vous sûr de vouloir activer cet élément ?'
custom_link 'fa-toggle-on', 'Activer', path, version, options
end
end
......@@ -34,6 +34,8 @@ class Performance < ApplicationRecord
validate :end_at_after_start_at
scope :for_member, ->(member) { where(member: member) }
scope :disabled, -> { where(disabled: true)}
scope :enabled, -> { where.not(id: disabled)}
def full_title
"[#{activity.title}] #{I18n.t('date.day_names')[Date::DAYNAMES.index(day.camelize)].camelize} #{human_readable_range}"
......
......@@ -26,16 +26,35 @@
<p class="AdminCard-globalActions">
<%= custom_add_link "Nouvelle séance", new_member_performance_path(@member) %>
</p>
<ul>
<% @member.performances.each do |perf| %>
<li>
<span class="no_print">
<%= custom_edit_link edit_member_performance_path(@member, perf), :short, class: %w(tight) %>
<%= custom_delete_link member_performance_path(@member, perf), :short, class: %w(tight) %>
</span>
<%= perf.full_title %>
</li>
<% end %>
</ul>
<%- if @enabled_performances.present? %>
<h2><%= toggle_link "Séances actives", '#enabled' %></h2>
<ul id="enabled">
<% @enabled_performances.each do |perf| %>
<li>
<span class="no_print">
<%= custom_edit_link edit_member_performance_path(@member, perf), :short, class: %w(tight) %>
<%= custom_disable_link toggle_member_performance_path(@member, perf), :short, class: %w(tight) %>
<%= custom_delete_link member_performance_path(@member, perf), :short, class: %w(tight) %>
</span>
<%= perf.full_title %>
</li>
<% end %>
</ul>
<%- end %>
<%- if @disabled_performances.present? %>
<h2><%= toggle_link "Séances inactives", '#disabled' %></h2>
<ul id="disabled" style="display:none">
<% @disabled_performances.each do |perf| %>
<li>
<span class="no_print">
<%= custom_edit_link edit_member_performance_path(@member, perf), :short, class: %w(tight) %>
<%= custom_enable_link toggle_member_performance_path(@member, perf), :short, class: %w(tight) %>
<%= custom_delete_link member_performance_path(@member, perf), :short, class: %w(tight) %>
</span>
<%= perf.full_title %>
</li>
<% end %>
</ul>
<%- end %>
</aside>
<%- end %>
......@@ -53,7 +53,9 @@ Rails.application.routes.draw do
get :raz_pass, :on => :member
post :search_contacts, on: :collection
get :map, on: :collection
resources :performances, except: [:index, :show]
resources :performances, except: [:index, :show] do
patch :toggle, on: :member
end
resources :subscriptions do
get :option, on: :collection
get :card, on: :member
......
class AddDisabledFlagToPerformances < ActiveRecord::Migration[5.1]
def change
add_column :performances, :disabled, :boolean, default: false
end
end
......@@ -32,7 +32,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180913142206) do
ActiveRecord::Schema.define(version: 20180917093307) do
create_table "activities", force: :cascade do |t|
t.string "title", limit: 255
......@@ -348,6 +348,7 @@ ActiveRecord::Schema.define(version: 20180913142206) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "activity_id"
t.boolean "disabled", default: false
end
create_table "phone_numbers", force: :cascade do |t|
......
......@@ -47,7 +47,7 @@ feature "Manage performances" do
expect(current_path).to eq member_path(@member)
expect(page).to have_content "La séance a bien été créée."
within "aside#performances ul" do
within "aside#performances ul#enabled" do
expect(page).to have_selector("li", text: "[Athlétisme] Mardi de 11h15 à 13h45")
end
end
......@@ -72,7 +72,7 @@ feature "Manage performances" do
expect(current_path).to eq member_path(@member)
expect(page).to have_content "Séance mise à jour avec succès."
within "aside#performances ul" do
within "aside#performances ul#enabled" do
expect(page).to have_selector("li", text: "[Natation] Mardi de 10h00 à 12h00")
end
end
......@@ -88,8 +88,37 @@ feature "Manage performances" do
expect(current_path).to eq member_path(@member)
expect(page).to have_content "Séance supprimée avec succès."
within "aside#performances ul" do
expect(page).not_to have_selector("li", text: "[Natation] Mardi de 10h00 à 12h00")
expect(page).not_to have_selector("aside#performances ul#enabled")
expect(page).not_to have_selector("aside#performances ul#disabled")
end
scenario "I can disable one and reenable it", :js do
@member.activities << [athle, swim]
perf = create :performance, day: :monday, start_at: "18:00", end_at: "20:00", activity: athle, member: @member
perf = create :performance, day: :monday, start_at: "18:00", end_at: "20:00", activity: swim, member: @member
visit member_path(@member)
expect(page).not_to have_selector("aside#performances ul#disabled")
within "aside#performances ul#enabled li", text: "[Natation] Lundi" do
click_link "Désactiver"
end
expect(current_path).to eq member_path(@member)
expect(page).to have_content "Séance désactivée avec succès."
within "aside#performances ul#enabled" do
expect(page).to have_selector("li", text: "[Athlétisme] Lundi")
end
click_link "Séances inactives"
within "aside#performances ul#disabled li", text: "[Natation] Lundi" do
click_link "Activer"
end
expect(current_path).to eq member_path(@member)
expect(page).to have_content "Séance activée avec succès."
expect(page).not_to have_selector("aside#performances ul#disabled")
within "aside#performances ul#enabled" do
expect(page).to have_selector("li", text: "[Athlétisme] Lundi")
expect(page).to have_selector("li", text: "[Natation] Lundi")
end
end
end
......
......@@ -305,6 +305,7 @@ feature "Manage subscriptions" do
before { login_as_collaborating_club }
let(:athle) { create :activity, title: "Athlétisme" }
let(:swim) { create :activity, title: "Natation" }
context "I can create one", :js do
......@@ -355,8 +356,8 @@ feature "Manage subscriptions" do
expect(current_path).to eq member_path(@member)
expect(page).to have_content "L'adhésion de Jean-Charles Dupont a bien été créée."
pending "works in UI :("
within "aside#subscriptions ul#internal li", text: "Jean-Charles Dupont" do
find("i.fa-info-circle").hover
expect(page).to have_selector("span.activities", text: "Mon asso (Athlétisme)")
end
......@@ -387,8 +388,8 @@ feature "Manage subscriptions" do
expect(current_path).to eq member_path(@member)
expect(page).to have_content "L'adhésion de Jean-Charles Dupont a bien été créée."
pending "works in UI :("
within "aside#subscriptions ul#internal li", text: "Jean-Charles Dupont" do
find("i.fa-info-circle").hover
expect(page).to have_selector("span.activities", text: "Mon asso (Athlétisme)")
end
end
......@@ -400,6 +401,7 @@ feature "Manage subscriptions" do
perf1 = create :performance, member: main_club, activity: athle
perf2 = create :performance, member: other_club1, activity: athle
perf3 = create :performance, member: other_club2, activity: athle
perf4 = create :performance, member: other_club2, activity: swim, disabled: true
visit new_member_subscription_path(@member)
within "form" do
......@@ -412,6 +414,7 @@ feature "Manage subscriptions" do
check "Collaborating club - [Athlétisme] Lundi"
check "Autre asso 1 - [Athlétisme] Lundi"
check "Autre asso 2 - [Athlétisme] Lundi"
expect(page).not_to have_content "Autre asso 2 - [Natation] Lundi"
expect(page).to have_selector("div#subscription-option", text: "Formule retenue")
click_create_button
end
......@@ -428,7 +431,7 @@ feature "Manage subscriptions" do
voile = create :activity, title: "Voile"
@member.update_attribute(:name, "Mon asso")
perf1 = create :performance, member: @member, activity: athle, start_at: "18:00", end_at: "20:00"
perf2 = create :performance, member: @member, activity: parapente
perf2 = create :performance, member: @member, activity: parapente, disabled: true
external_club = create :member, name: "Les Mouettes"
perf3 = create :performance, member: external_club, activity: voile
internal_adherent = build :adherent, last_name: "Dupont", first_name: "Jean", permit_number: "123456"
......
......@@ -73,5 +73,17 @@ RSpec.describe Performance, type: :model do
perf2 = create :performance, member: member2
expect(Performance.for_member(member1)).to eq [perf1]
end
it ".disabled returns only disabled performances" do
perf1 = create :performance, disabled: false
perf2 = create :performance, disabled: true
expect(Performance.disabled).to eq [perf2]
end
it ".enabled returns only enabled performances" do
perf1 = create :performance, disabled: false
perf2 = create :performance, disabled: true
expect(Performance.enabled).to eq [perf1]
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment