Add booths to non admin

This commit is contained in:
nasia 2017-07-20 14:20:46 +03:00 committed by Stella Rouzi
parent 033dbe4c40
commit 32c5af2a17
22 changed files with 426 additions and 86 deletions

View file

@ -7,9 +7,13 @@ module Admin
def show; end
def new; end
def new
@url = admin_conference_booths_path(@conference.short_title)
end
def create
@url = admin_conference_booths_path(@conference.short_title)
@booth = @conference.booths.new(booth_params)
@booth.submitter = current_user
@ -23,9 +27,13 @@ module Admin
end
end
def edit; end
def edit
@url = admin_conference_booth_path(@conference.short_title, @booth.id)
end
def update
@url = admin_conference_booth_path(@conference.short_title, @booth.id)
@booth.update_attributes(booth_params)
if @booth.save
@ -38,16 +46,6 @@ module Admin
end
end
def destroy
if @booth.destroy
redirect_to admin_conference_booths_path,
notice: 'Booth successfully destroyed.'
else
redirect_to admin_conference_booths_path,
error: "Booth couldn't be deleted. #{@booth.errors.full_messages.join('. ')}."
end
end
def accept
update_state(:accept, 'Booth accepted!')
end

View file

@ -0,0 +1,97 @@
class BoothsController < ApplicationController
before_action :authenticate_user!
load_resource :conference, find_by: :short_title
load_and_authorize_resource through: :conference
skip_authorize_resource only: [:withdraw, :confirm, :restart]
def index
@booths = current_user.booths.where(conference_id: @conference.id).uniq
end
def show; end
def new
@url = conference_booths_path(@conference.short_title)
end
def create
@url = conference_booths_path(@conference.short_title)
@booth.submitter = current_user
if @booth.save
redirect_to conference_booths_path,
notice: 'Booth successfully created.'
else
flash[:error] = "Creating booth failed. #{@booth.errors.full_messages.to_sentence}."
render :new
end
end
def edit
@url = conference_booth_path(@conference.short_title, @booth.id)
end
def update
@url = conference_booth_path(@conference.short_title, @booth.id)
@booth.update_attributes(booth_params)
if @booth.save
redirect_to conference_booths_path,
notice: 'Booth successfully updated!'
else
flash[:error] = "Booth could not be updated. #{@booth.errors.full_messages.to_sentence}."
end
end
def destroy; end
def withdraw
authorize! :update, @booth
@url = conference_booth_path(@conference.short_title, @booth.id)
@booth.withdraw!
if @booth.save
redirect_to conference_booths_path,
notice: 'Booth successfully withdrawn'
else
flash[:error] = "Booth could not be withdrawn. #{@booth.errors.full_messages.to_sentence}."
end
end
def confirm
authorize! :update, @booth
@url = conference_booth_path(@conference.short_title, @booth.id)
@booth.confirm!
if @booth.save
redirect_to conference_booths_path,
notice: 'Booth successfully confirmed'
else
flash[:error] = "Booth could not be confirmed. #{@booth.errors.full_messages.to_sentence}."
end
end
def restart
authorize! :update, @booth
@url = conference_booth_path(@conference.short_title, @booth.id)
@booth.restart!
if @booth.save
redirect_to conference_booths_path,
notice: 'Booth successfully re-submitted'
else
flash[:error] = "Booth could not be re-submitted. #{@booth.errors.full_messages.to_sentence}."
end
end
private
def booth_params
params.require(:booth).permit(:title, :description, :reasoning, :state, :picture, :conference_id,
:created_at, :updated_at, :submitter_relationship, :website_url, responsible_ids: [])
end
end

View file

@ -15,6 +15,19 @@ module FormatHelper
end
end
def booth_status_icon(booth)
case booth.state
when 'new', 'to_reject', 'to_accept'
'fa-eye'
when 'accepted'
'fa-check text-muted'
when 'confirmed'
'fa-check text-success'
when 'rejected', 'withdrawn', 'canceled'
'fa-ban'
end
end
def event_progress_color(progress)
progress = progress.to_i
if progress == 100

View file

@ -75,6 +75,12 @@ class Ability
can [:new, :create], Payment, user_id: user.id
can [:index, :show], PhysicalTicket, user: user
can [:new, :create], Booth
can [:edit, :update, :index, :show], Booth do |booth|
booth.users.include?(user)
end
can [:create, :destroy], Subscription, user_id: user.id
can [:new, :create], Event do |event|

View file

@ -35,12 +35,16 @@ class Booth < ActiveRecord::Base
state :to_reject
state :rejected
state :canceled
state :confirmed
event :restart do
transitions to: :new, from: [:withdrawn, :to_accept, :to_reject, :canceled]
transitions to: :new, from: [:withdrawn, :rejected, :canceled]
end
event :withdraw do
transitions to: :withdrawn, from: [:new, :to_accept, :accepted, :to_reject, :rejected]
transitions to: :withdrawn, from: [:new, :to_accept, :accepted, :to_reject, :rejected, :confirmed]
end
event :confirm do
transitions to: :confirmed, from: [:accepted]
end
event :to_accept do
transitions to: :to_accept, from: [:new, :to_reject]
@ -55,7 +59,7 @@ class Booth < ActiveRecord::Base
transitions to: :rejected, from: [:new, :to_reject]
end
event :cancel do
transitions to: :canceled, from: [:accepted, :rejected, :to_accept, :to_reject]
transitions to: :canceled, from: [:accepted, :rejected, :to_accept, :to_reject, :confirmed]
end
end

View file

@ -1,33 +0,0 @@
.row
.col-md-12
.page-header
%title Request a Booth
.row
.col-md-8
= semantic_form_for(@booth, url: @booth.new_record? ? admin_conference_booths_path(@conference.short_title) : admin_conference_booth_path(@conference.short_title, @booth.id), html: { multipart: true }) do |f|
= f.input :title, as: :string, autofocus: true, required: true
= f.input :description, input_html: { rows: 5, data: { provide: 'markdown-editable' } }, required: true,
hint: 'This field becomes public upon request acceptance'
= f.input :reasoning, input_html: { rows: 5, data: { provide: 'markdown-editable' } }, required: true,
label: 'How it fits the conference'
= f.input :submitter_relationship, input_html: { rows: 5, data: { provide: 'markdown-editable' } }, required: true,
label: 'Submitter\'s relation',
hint: 'e.g. employee, comunity manager, etc'
= f.input :website_url
= responsibles_selector_input f
= image_tag f.object.picture.thumb.url if f.object.picture?
= f.input :picture
%p.text-right
- if @booth.new_record?
= f.submit 'Create Booth Request', class: 'btn btn-success'
- else
= f.submit 'Update Booth Request', class: 'btn btn-success'
:javascript
$(document).ready(function() {
$('#booth_responsible_ids').selectize({
plugins: ['remove_button'],
minItems: 2
} )
});

View file

@ -2,4 +2,4 @@
Editing
= @booth.title
= render 'form'
= render 'booths/form'

View file

@ -41,8 +41,9 @@
= link_to booth.submitter.name, admin_user_path(booth.submitter) if booth.submitter
%td
.responsibles
- booth.responsibles.each do |responsible|
- booth.responsibles.each_with_index do |responsible, i|
= link_to responsible.name, admin_user_path(responsible)
= ", " unless i == booth.responsibles.length - 1
%td
.btn-group
%button{ type: 'button', class: 'btn btn-link dropdown-toggle', 'data-toggle' => 'dropdown' }
@ -51,9 +52,5 @@
%ul.dropdown-menu{ role: 'menu' }
= render 'change_state_dropdown', booth: booth
%td
.btn-group{ role: "group" }
= link_to 'Edit', edit_admin_conference_booth_path(@conference.short_title, booth.id),
class: 'btn btn-primary'
= link_to 'Delete', admin_conference_booth_path(@conference.short_title, booth.id),
method: :delete, class: 'btn btn-danger',
data: {confirm: "Do you really want to delete this booth request?"}
= link_to 'Edit', edit_admin_conference_booth_path(@conference.short_title, booth.id),
class: 'btn btn-primary'

View file

@ -1,3 +1,3 @@
%h1 New booth
= render 'form'
= render 'booths/form'

View file

@ -39,12 +39,13 @@
%td.col-md-2
%b Responsibles
%td
- @booth.responsibles.each do |responsibles|
- @booth.responsibles.each_with_index do |responsibles, i|
.responsibles
= link_to responsibles.name, admin_user_path(responsibles)
(
= responsibles.email
)
= " , " unless i == @booth.responsibles.length - 1
%tr
%td.col-md-2
%b Submitted on

View file

@ -0,0 +1,30 @@
.container
.row
.col-md-8
= semantic_form_for(@booth, url: @url, html: { multipart: true }) do |f|
= f.input :title, as: :string, autofocus: true, required: true
= f.input :description, input_html: { rows: 5, data: { provide: 'markdown-editable' } }, required: true,
hint: 'This field becomes public upon request acceptance'
= f.input :reasoning, input_html: { rows: 5, data: { provide: 'markdown-editable' } }, required: true,
label: 'How it fits the conference'
= f.input :submitter_relationship, input_html: { rows: 5, data: { provide: 'markdown-editable' } }, required: true,
label: 'Submitter\'s relation',
hint: 'e.g. employee, comunity manager, etc'
= f.input :website_url
= responsibles_selector_input f
= image_tag f.object.picture.thumb.url if f.object.picture?
= f.input :picture
%p.text-right
- if @booth.new_record?
= f.submit 'Create Booth Request', class: 'btn btn-success'
- else
= f.submit 'Update Booth Request', class: 'btn btn-success'
:javascript
$(document).ready(function() {
$('#booth_responsible_ids').selectize({
plugins: ['remove_button'],
minItems: 2
} )
});

View file

@ -0,0 +1,6 @@
.container
%h1
Editing
= @booth.title
= render 'form'

View file

@ -0,0 +1,51 @@
.container
.row
.col-md-12.page-header
%h1
Your booth requests for
= @conference.title
.row
.col-md-12
.margin-booth-table
%table.table.table-striped.table-hover
%thead
%th
%b State
%th
%b Logo
%th
%b Title
%th
%b Actions
- @booths.each do |booth|
%tr
%td{ style: "padding:20px 8px 20px 8px;" }
- if (booth.state == 'to_accept' || booth.state == 'to_reject')
- show_state = 'new'
- else
- show_state = booth.state
%span{ title: show_state, class: "fa #{booth_status_icon(booth)}" }
%td
- if booth.logo_link
= image_tag(booth.picture.thumb.url, width: '20%')
%td
= link_to booth.title, conference_booth_path(@conference.short_title, booth)
%td
-if can? :edit, booth
= link_to 'Edit', edit_conference_booth_path(@conference.short_title, booth.id),
class: 'btn btn-default'
- if booth.transition_possible? :withdraw
= link_to 'Withdraw',
withdraw_conference_booth_path(@conference.short_title, booth),
method: :patch, class: 'btn btn-mini btn-warning', id: "withdraw_booth_#{booth.id}",
data: { confirm: 'Are you sure you really want to withdraw this request?' }
- if booth.transition_possible? :confirm
= link_to 'Confirm',
confirm_conference_booth_path(@conference.short_title, booth),
method: :patch, class: 'btn btn-mini btn-success', id: "confirm_booth_#{booth.id}"
- if booth.transition_possible? :restart
= link_to 'Re-submit',
restart_conference_booth_path(@conference.short_title, booth),
method: :patch, class: 'btn btn-mini btn-success', id: "restart_booth_#{booth.id}"
.pull-right
= link_to 'Add Booth', new_conference_booth_path(@conference.short_title), class: 'button btn btn-primary'

View file

@ -0,0 +1,4 @@
.container
%h1 Request a booth
= render 'form'

View file

@ -0,0 +1,60 @@
.container
.row
.col-md-12
%h3
- if @booth.logo_link
= image_tag(@booth.picture.thumb.url, size: '20%', alt: '')
= @booth.title
.btn-group.pull-right
= link_to 'Edit', edit_admin_conference_booth_path(@conference.short_title, @booth), class: 'btn btn-mini btn-primary'
.row
.col-md-12
%table.table
%tr
%td.col-md-2
%b Description
%td
= markdown(@booth.description)
%tr
%td.col-md-2
%b Reasoning
%td
= markdown(@booth.reasoning)
%tr
%td.col-md-2
%b Website
%td
- if @booth.website_url.present?
= link_to @booth.website_url, @booth.website_url
%tr
%td.col-md-2
%b Submitter
%td
= link_to @booth.submitter.name, user_path(@booth.submitter)
%tr
%td.col-md-2
%b Submitter's relationship
%td
= @booth.submitter_relationship
%tr
%td.col-md-2
%b Responsibles
%td
- @booth.responsibles.each_with_index do |responsibles, i|
.responsibles
= link_to responsibles.name, user_path(responsibles)
(
= responsibles.email
)
= ", " unless i == @booth.responsibles.length - 1
%tr
%td.col-md-2
%b Submitted on
%td
= @booth.created_at
%tr
%td.col-md-2
%b Last updated on
%td
= @booth.updated_at