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

Inscription #14

Open
wants to merge 6 commits into
base: master
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
31 changes: 31 additions & 0 deletions app/controllers/subject_participant_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class SubjectParticipantController < ApplicationController
before_action :authenticate_participant!

def show
end

def create
@subject_participant = SubjectParticipant.new(subject_participant_params)

if @subject_participant.save
redirect_to subjects_path, notice: 'Votre participation a été enregistré'
else
redirect_to subjects_path
end
end

def show
end

def destroy
@subject_participant = SubjectParticipant.find(params[:id])
@subject_participant.destroy
flash[:alert] = "Participation annulée"
redirect_to subjects_path
end

def subject_participant_params
params.permit(:interested_id, :subject_id)
end

end
3 changes: 2 additions & 1 deletion app/controllers/subjects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class SubjectsController < ApplicationController
before_action :set_subject, only: [:show, :edit, :update, :destroy]

before_action :authenticate_participant!, only: [:new, :create, :edit, :update, :destroy]
# GET /subjects
# GET /subjects.json
def index
Expand All @@ -10,6 +10,7 @@ def index
# GET /subjects/1
# GET /subjects/1.json
def show
@interesteds = @subject.interested
end

# GET /subjects/new
Expand Down
4 changes: 4 additions & 0 deletions app/models/subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ class Subject < ActiveRecord::Base
has_many :interested, through: :subject_participants #interested
belongs_to :questioner, class_name: "Participant"
belongs_to :conference

def participation(current_participant)
self.subject_participants.find_by_interested_id(current_participant.id)
end
end
Copy link
Owner

@gfauredumont gfauredumont Sep 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stp, pense à fixer tes EOL (il t'en manque pas mal)... ou install un plugin Sublime pour ces aspects là (trailling ws too...)

5 changes: 3 additions & 2 deletions app/models/subject_participant.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class SubjectParticipant < ActiveRecord::Base
validates_presence_of :interested_id, :subject_id
validates :interested_id, presence: true
validates :subject_id, presence: true, uniqueness: { scope: :interested_id}
belongs_to :interested, :class_name => "Participant" #interested
belongs_to :subject
belongs_to :subject
end
1 change: 1 addition & 0 deletions app/views/subject_participant/create.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create.html.haml
1 change: 1 addition & 0 deletions app/views/subject_participant/destroy.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
destroy.html.haml
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si tu t'en sers aussi peu, je préfère ne même pas avoir de fichier ;)

1 change: 1 addition & 0 deletions app/views/subject_participant/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
show.html.haml
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si tu t'en sers aussi peu, je préfère ne même pas avoir de fichier ;)

8 changes: 8 additions & 0 deletions app/views/subjects/_inscription_button.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- if participant_signed_in?
- if subject.participation(current_participant).nil?
= link_to "Ca m'intéresse !", subject_participant_index_path(:interested_id => current_participant.id, :subject_id => subject.id), :method => :post, class:"btn btn-primary"

- else
= link_to "Ca ne m'intéresse plus !", subject_participant_path(subject.participation(current_participant).id), :method => :delete, class:"btn btn-primary"
- else
= link_to "Connectez-vous", new_participant_session_path
37 changes: 0 additions & 37 deletions app/views/subjects/index.html.erb

This file was deleted.

31 changes: 31 additions & 0 deletions app/views/subjects/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
%h1.text-center Subjects
.container
.row
%table
%thead
%tr
%th.col-sm-offset-1.col-sm-2 Title
%th.col-sm-2 Description
%th.col-sm-2 Questioner
%th.col-sm-2 Conférence
%th{:colspan => "3"}
%tbody
- @subjects.each do |subject|
%tr
%td.col-sm-offset-1.col-sm-2= subject.title
%td.col-sm-2= subject.description
%td.col-sm-2= subject.questioner.try(:name)
%td.col-sm-2= subject.conference.title
%td.col-sm-1
%td.col-sm-2.text-center
= link_to 'Show', subject
| #{link_to 'Edit', edit_subject_path(subject)} | #{link_to 'Destroy', subject, method: :delete, data: { confirm: 'Are you sure?' }}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiens, le message de warning est en Anglais... pourtant j'aurai juré que les inscriptions aux sujets sont des boutons en Français... j'ai pas suivi un truc ? (parle-moi en avant de tout changer !)


= render partial: 'inscription_button', locals: {subject: subject}

%br/
.text-center
%td
= link_to 'New Subject', new_subject_path
|
%td= link_to 'Home', root_path
24 changes: 0 additions & 24 deletions app/views/subjects/show.html.erb

This file was deleted.

23 changes: 23 additions & 0 deletions app/views/subjects/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.text-center
%h1
%strong= @subject.title
%p
%strong Description:
= @subject.description
%p
%strong Rapporteur:
= @subject.questioner.try(:name)
%p
%strong Conference:
= @subject.conference.title
%p
%strong Participant:
%ul
- @interesteds.each do |interested|
%li
= interested.email

= link_to 'Edit', edit_subject_path(@subject)
|
\#{link_to 'Back', subjects_path} |
\#{link_to 'Home', root_path}
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
resources :subjects
resources :participants
resources :conferences
resources :subject_participant
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'hésite un peu à t'en parler mais bon: est-ce que tu es sure de vouloir exposer ces nouvelles routes ?
Si non, peut-être qu'exposer juste celles qu'il te faut suffirait ?

root 'welcome#index'

# The priority is based upon order of creation: first created -> highest priority.
Expand Down