Event status management

This commit is contained in:
Petko Bordjukov 2015-10-15 19:06:41 +03:00
parent 60d84ffc7c
commit 646d61bb22
9 changed files with 111 additions and 39 deletions

View File

@ -2,7 +2,7 @@ module Management
class EventsController < ManagementController class EventsController < ManagementController
def index def index
@conference = find_conference @conference = find_conference
@events = @conference.events.approved @events = @conference.events.order(:title)
end end
def show def show

View File

@ -5,8 +5,20 @@ module Management
@events_by_proposer = @conference.events.undecided.group_by(&:proposer) @events_by_proposer = @conference.events.undecided.group_by(&:proposer)
end end
def update
@proposition = Proposition.find(params[:id])
@proposition.update(proposition_params)
redirect_to :back
end
private private
def proposition_params
params.require(:proposition).permit(:status)
end
def find_conference def find_conference
Conference.find(params[:conference_id]) Conference.find(params[:conference_id])
end end

View File

@ -5,6 +5,34 @@ module ApplicationHelper
end end
end end
def proposition_status_class(status)
{
"undecided" => "default",
"approved" => "info",
"rejected" => "danger",
"backup" => "warning"
}.with_indifferent_access[status]
end
def proposition_status_glyph(status)
{
"undecided" => "question",
"approved" => "thumbs-up",
"rejected" => "thumbs-down",
"backup" => "refresh"
}.with_indifferent_access[status]
end
def proposition_status_icon(status)
icon(proposition_status_glyph(status))
end
def proposition_status(record)
klass = record.class
output = ''
end
def action_buttons(conference, record, actions = [:index, :show, :edit, :destroy]) def action_buttons(conference, record, actions = [:index, :show, :edit, :destroy])
klass = record.class klass = record.class
output = '' output = ''
@ -34,7 +62,7 @@ module ApplicationHelper
output += link_to(icon(:trash), [:management, conference, record], { output += link_to(icon(:trash), [:management, conference, record], {
method: :delete, method: :delete,
data: {confirm: t('actions.are_you_sure')}, data: {confirm: t('actions.are_you_sure')},
title: t('actions.edit.button', model: klass.model_name.human), title: t('actions.destroy.button', model: klass.model_name.human),
class: 'btn btn-danger' class: 'btn btn-danger'
}) })
end end

View File

@ -0,0 +1,9 @@
module EventsHelper
def participant_names_or_emails(event)
event.participants.map do |participant|
participant.try(:personal_profile, current_conference).try(:name) ||
participant.personal_profiles.last.try(:name) ||
participant.email
end
end
end

View File

@ -26,6 +26,8 @@ class Event < ActiveRecord::Base
scope :confirmed, -> { where.not confirmed_at: nil } scope :confirmed, -> { where.not confirmed_at: nil }
delegate :status, to: :proposition
def proposer_profile def proposer_profile
proposer.personal_profile(conference) proposer.personal_profile(conference)
end end

View File

@ -0,0 +1,29 @@
tr
td
= event.title
- if event.subtitle.present?
br
span.small = event.subtitle
td
= participant_names_or_emails(event).join(', ')
td
= t("locales.#{event.language}")
td
= event.track.name
td
= event.event_type.name
td.action
.dropdown
button class="btn btn-sm dropdown-toggle btn-#{proposition_status_class(event.status)}" type="button" data-toggle="dropdown" title="#{t "status.#{event.status}"}"
= icon(proposition_status_glyph(event.status))
span.caret<
ul.dropdown-menu
- Proposition.statuses.each do |(status, _)|
- next if status == event.status
li
= link_to [:management, @conference, event.proposition, proposition: {status: status}], method: :patch do
= proposition_status_icon(status)
=< t "status.#{status}"
td.actions
.btn-group.btn-group-sm
= action_buttons(@conference, event, [:show, :edit])

View File

@ -1,36 +1,18 @@
.row .row
.col-lg-12 h1.page-header
.panel.panel-default = Event.model_name.human(count: 2).mb_chars.titleize
.panel-heading .row
h2.panel-title= Event.model_name.human(count: 2).mb_chars.capitalize .panel.panel-default
table.table
.panel-body thead
table.table.table-striped.table-hover.record-table tr
thead th = Event.human_attribute_name(:title)
tr th = Event.human_attribute_name(:user)
th = Event.human_attribute_name :title th = Event.human_attribute_name(:language)
th = Event.human_attribute_name :subtitle th = Track.model_name.human
th = Event.human_attribute_name :user th = Event.human_attribute_name(:type)
th = Event.human_attribute_name :length th.action
th = Event.human_attribute_name :language = Event.human_attribute_name(:status)
th.actions th.actions
tbody tbody
- @events.each do |event| = render partial: 'event', collection: @events
- proposer = event.proposer
- proposer_profile = event.proposer_profile
tr
td= event.title
td= event.subtitle
td
- if proposer_profile
= link_to proposer_profile.name, [:management, @conference, proposer_profile]
- else
| No profile for user #{proposer.email}
td #{event.length} minutes
td= event.language
td.actions
div.btn-group.btn-group-sm
= action_buttons(@conference, event, [:show, :edit, :destroy])

View File

@ -2,4 +2,9 @@ bg:
are_you_sure: Сигурен ли си? are_you_sure: Сигурен ли си?
view: Преглед view: Преглед
home: Начало home: Начало
more_about_user: "Повече информация за %{user}" more_about_user: "Повече информация за %{user}"
status:
undecided: Неопределен
approved: Одобрен
rejected: Отхвърлен
backup: Резерва

View File

@ -1,4 +1,9 @@
en: en:
are_you_sure: Are you sure? are_you_sure: Are you sure?
view: View view: View
home: Home home: Home
status:
undecided: Undecided
approved: Approved
rejected: Rejected
backup: Back-up