Skip to content

Commit

Permalink
add batch editing for events
Browse files Browse the repository at this point in the history
  • Loading branch information
elad-eyal committed Oct 20, 2019
1 parent 9c88a10 commit 062a9f2
Show file tree
Hide file tree
Showing 12 changed files with 437 additions and 2 deletions.
66 changes: 66 additions & 0 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ def start_review
def batch_actions
if params[:bulk_email]
bulk_send_email
elsif params[:bulk_set]
bulk_set
elsif params[:bulk_add_person]
bulk_add_person
else
redirect_to events_path, alert: :illegal
end
Expand All @@ -141,7 +145,69 @@ def bulk_send_email
redirect_back(notice: t('emails_module.notice_mails_delivered'), fallback_location: root_path)
end
end

def bulk_set
authorize @conference, :orga?
events = search @conference.events_with_review_averages

total_successful = 0
total_skipped = 0
total_failed = 0
events.each do |event|
if event.try(params[:bulk_set_attribute]) == params[:bulk_set_value]
total_skipped +=1
elsif event.update( params[:bulk_set_attribute] => params[:bulk_set_value] )
total_successful += 1
else
total_failed += 1
end
end

summary = [ t('events_module.bulk_edit.update_successful', count: total_successful),
(t('events_module.bulk_edit.update_skipped', count: total_skipped) if total_skipped > 0),
(t('events_module.bulk_edit.update_failed', count: total_failed) if total_failed > 0) ].join(' ')

if total_failed > 0
redirect_back alert: summary, fallback_location: root_path
else
redirect_back notice: summary, fallback_location: root_path
end
end

def bulk_add_person
authorize @conference, :orga?
events = search @conference.events_with_review_averages

person_id = params[:person_id]
event_role = params[:event_role]
redirect_back(alert: t('ability.denied'), fallback_location: root_path) and return if person_id.blank? or event_role.blank?

total_successful = 0
total_skipped = 0
total_failed = 0

events.each do |event|
if EventPerson.where(event: event, person_id: person_id, event_role: event_role).any?
total_skipped +=1
elsif event.update( event_people_attributes: { 'x' => { person_id: person_id,
event_role: event_role } } )
total_successful += 1
else
total_failed += 1
end
end

summary = [ t('events_module.bulk_edit.update_successful', count: total_successful),
(t('events_module.bulk_edit.update_skipped', count: total_skipped) if total_skipped > 0),
(t('events_module.bulk_edit.update_failed', count: total_failed) if total_failed > 0) ].join(' ')

if total_failed > 0
redirect_back alert: summary, fallback_location: root_path
else
redirect_back notice: summary, fallback_location: root_path
end
end

# GET /events/1
# GET /events/1.json
def show
Expand Down
4 changes: 4 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ def localized_event_type(locale = nil)
def track_name
track.try(:name)
end

def track_name=(name)
update(track: conference.tracks.find_by(name: name))
end

def end_time
start_time.since((time_slots * conference.timeslot_duration).minutes)
Expand Down
84 changes: 84 additions & 0 deletions app/views/events/_below_table.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,88 @@
id: 'bulk_email',
data: { confirm: t('notifications_module.send_unspecified_notification_confirm', count: @num_of_matching_events) },
class: 'danger'

- if policy(@conference).manage?
%p
= link_to t('events_module.bulk_edit.toggle'), "#bulk_edit", data: { function: 'toggle', args: { target: '#bulk_edit' } }
#bulk_edit{style: "display:none;"}
- if @conference.tracks.any?
= simple_form_for(:bulk_edit_track, url: batch_actions_events_path(request.query_parameters), method: :post) do |f|
= f.label t('events_module.bulk_edit.set_new_track')
= f.hidden_field 'bulk_set_attribute', value: 'track_name', name: 'bulk_set_attribute'
= select_tag 'bulk_set_value', options_for_select(@conference.tracks.map { |t| t.name.to_s }), include_blank: t('select_one'), style: "width:400px"
= f.button :submit,
t('set'),
name: 'bulk_set',
id: 'bulk_set',
data: { confirm: t('events_module.bulk_edit.set_track_confirm', count: @num_of_matching_events) },
class: 'danger'
= simple_form_for(:bulk_edit_event_type, url: batch_actions_events_path(request.query_parameters), method: :post) do |f|
= f.label t('events_module.bulk_edit.set_new_event_type')
= f.hidden_field 'bulk_set_attribute', value: 'event_type', name: 'bulk_set_attribute'
= select_tag 'bulk_set_value', options_for_select(translated_options(Event::TYPES)), include_blank: t('select_one'), style: "width:400px"
= f.button :submit,
t('set'),
name: 'bulk_set',
id: 'bulk_set',
data: { confirm: t('events_module.bulk_edit.set_events_type_confirm', count: @num_of_matching_events) },
class: 'danger'
= simple_form_for(:bulk_edit_event_state, url: batch_actions_events_path(request.query_parameters), method: :post) do |f|
= f.label t('events_module.bulk_edit.set_new_state')
= f.hidden_field 'bulk_set_attribute', value: 'state', name: 'bulk_set_attribute'
= select_tag 'bulk_set_value',
options_for_select(Event.state_machine.states.map { |st| [t(st.name.to_s, scope: 'conferences_module'), st.name.to_s] }),
include_blank: t('select_one'), style: "width:400px"
= f.button :submit,
t('set'),
name: 'bulk_set',
id: 'bulk_set',
data: { confirm: t('events_module.bulk_edit.set_events_confirm', count: @num_of_matching_events) },
class: 'danger'
= simple_form_for(:bulk_edit_add_person,
url: batch_actions_events_path(request.query_parameters),
method: :post,
data: { persons: Person.fullname_options } ) do |f|
.peoplefilter
= f.label t('events_module.bulk_edit.add_person')
= text_field_tag :filter, 'filter', style: "width:200px"
= select_tag :person_id,
options_for_select(Person.all.sort_by(&:full_name).map{|p| [p.full_name_annotated, p.id]}),
name: :person_id,
include_blank: t('select_one'),
style: "width:200px"
= select_tag :event_role,
options_for_select(translated_options(EventPerson::ROLES)),
include_blank: t('select_one'),
style: "width:200px"
= f.button :submit,
t('add'),
name: 'bulk_add_person',
id: 'bulk_add_person',
data: { confirm: t('events_module.bulk_edit.add_person_confirm', count: @num_of_matching_events) },
class: 'danger'
:javascript
attach_filter = function(set) {
form = $("form.bulk_edit_add_person");
var persons = form.data()["persons"];
var q = $(set).find('input[name=filter]');
var list = $(set).find('select[name=person_id]');

q.on('input', function(e) {
$(list).empty();
$(list).append($('<option>', { value: null, text: "" }));

$(persons).each(function(i) {
id = persons[i]["id"];
text = persons[i]["text"];

if (text.toUpperCase().indexOf(q.val().toUpperCase()) >= 0) {
$(list).append($('<option>', { value: id, text: text }));
}
});
});
}

$('div.peoplefilter').each(function(i) {
attach_filter(this);
});
29 changes: 29 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ de:
review_metric: Metrik überprüfen
room: Raum
track: Track
add: Hinzufügen
add_association: "%{name} hinzufügen"
additional_resources: Zusätzliche Ressourcen
admin: Administrator
Expand Down Expand Up @@ -961,6 +962,33 @@ de:
attachments_overview: Anhänge
average_feedback: 'Durchschnittliches Feedback:'
average_speaker_feedback: 'Durchschnittliches Feedback als Sprecher:'
bulk_edit:
add_person: Person hinzufügen
add_person_confirm:
one: Möchten Sie diesem Ereignis wirklich eine Person hinzufügen?
other: Möchten Sie wirklich allen %{count}-Ereignissen eine Person hinzufügen?
set_events_confirm:
one: Möchten Sie den Status für dieses Ereignis wirklich ändern?
other: Möchten Sie den Status für alle %{count}-Ereignisse wirklich ändern?
set_events_type_confirm:
one: Möchten Sie den Typ dieses Ereignisses wirklich ändern?
other: Möchten Sie den Typ wirklich für alle %{count}-Ereignisse ändern?
set_new_event_type: Ereignistyp ändern
set_new_state: Zustand zuweisen
set_new_track: Titel zuweisen
set_track_confirm:
one: Möchten Sie den Track dieses Events wirklich ändern?
other: Möchten Sie wirklich die Spur aller %{count}-Ereignisse ändern?
toggle: Bearbeiten Sie diese Ereignisse >>
update_failed:
one: "%{count}-Bearbeitung fehlgeschlagen."
other: "%{count} Änderungen fehlgeschlagen."
update_skipped:
one: "%{count} Bearbeitung übersprungen."
other: "%{count} Änderungen übersprungen."
update_successful:
one: "%{count} Bearbeitung erfolgreich abgeschlossen."
other: "%{count} Änderungen wurden erfolgreich abgeschlossen."
cancel_event: Event absagen
cancel_event_hint: Markieren Sie dieses Event als abgesagt. Üblicherweise bedeutet dies, dass die Referenten ihren Auftritt absagen mussten.
col_toggle_rooms: 'Räume wechseln:'
Expand Down Expand Up @@ -2045,6 +2073,7 @@ de:
login: Einloggen
signup: Anmelden
update_password: Aktualisiere mein Passwort
set: einstellen
settings: Einstellungen
show: Anzeige
show_account: Konto
Expand Down
36 changes: 34 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ en:
room: room
review_metric: Review metric
track: track
add: Add
add_association: Add %{name}
additional_resources: Additional Resources
admin: Admin
Expand Down Expand Up @@ -571,7 +572,7 @@ en:
- Fri
- Sat
abbr_month_names:
-
-
- Jan
- Feb
- Mar
Expand All @@ -597,7 +598,7 @@ en:
long: "%B %d, %Y"
short: "%b %d"
month_names:
-
-
- January
- February
- March
Expand Down Expand Up @@ -945,6 +946,36 @@ en:
ago: "%{time_ago} ago"
all_events: All events
all_rating: All ratings
bulk_edit:
add_person: Add person
add_person_confirm:
one: Are you sure you want to add a person to this event?
other: Are you sure you want to add a person to all %{count} events?
set_new_state: Assign state
set_new_track: Assign track
set_new_event_type: Change event type
set_events_confirm:
one: Are you sure you want to change state for this event?
other: Are you sure you want to change state for all %{count} events?
set_events_type_confirm:
one: Are you sure you want to modify this event's type?
other: Are you sure you want to modify the type for all %{count} events?
set_track_confirm:
one: Are you sure you want to change the track of this event?
other: Are you sure you want to change the track of all %{count} events?
set_events_confirm:
one: you sure you want to change state for this event?
other: Are you sure you want to change state for all %{count} events?
toggle: "Edit these events >>"
update_successful:
one: "%{count} edit completed successfully."
other: "%{count} edits completed successfully."
update_skipped:
one: "%{count} edit skipped."
other: "%{count} edits skipped."
update_failed:
one: "%{count} edit failed."
other: "%{count} edits failed."
predefined_title_types:
handouts: handouts
media: media
Expand Down Expand Up @@ -2026,6 +2057,7 @@ en:
login: Log in
signup: Sign up
update_password: Update my password
set: Set
settings: Settings
show: Show
show_account: Account
Expand Down
29 changes: 29 additions & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ es:
review_metric: Revisar métrica
room: sala
track: área
add: Añadir
add_association: Agregar %{name}
additional_resources: Recursos adicionales
admin: Administración
Expand Down Expand Up @@ -996,6 +997,33 @@ es:
attachments_overview: Archivos adjuntos
average_feedback: 'Comentarios promedio:'
average_speaker_feedback: 'Comentarios promedio como ponente:'
bulk_edit:
add_person: Añadir persona
add_person_confirm:
one: "¿Estás seguro de que deseas agregar una persona a este evento?"
other: "¿Está seguro de que desea agregar una persona a todos los eventos %{count}?"
set_events_confirm:
one: "¿Estás seguro de que quieres cambiar el estado de este evento?"
other: "¿Está seguro de que desea cambiar el estado de todos los eventos %{count}?"
set_events_type_confirm:
one: "¿Estás seguro de que deseas modificar el tipo de este evento?"
other: "¿Está seguro de que desea modificar el tipo para todos los eventos %{count}?"
set_new_event_type: Cambiar tipo de evento
set_new_state: Asignar estado
set_new_track: Asignar pista
set_track_confirm:
one: "¿Seguro que quieres cambiar la pista de este evento?"
other: "¿Está seguro de que desea cambiar el seguimiento de todos los eventos %{count}?"
toggle: Edita estos eventos >>
update_failed:
one: La edición %{count} falló.
other: Las ediciones %{count} fallaron.
update_skipped:
one: Edición %{count} omitida.
other: Ediciones %{count} omitidas.
update_successful:
one: Edición %{count} completada con éxito.
other: Las ediciones %{count} se completaron correctamente.
cancel_event: Cancelar evento
cancel_event_hint: Marque este evento como cancelado. Por lo general, esto significa que los oradores tuvieron que cancelar su apariencia.
col_toggle_rooms: 'Conmutar habitaciones:'
Expand Down Expand Up @@ -2083,6 +2111,7 @@ es:
login: Iniciar sesión
signup: Regístrate
update_password: Actualiza mi contraseña
set: Conjunto
settings: Personalización
show: Espectáculo
show_account: Cuenta
Expand Down
Loading

0 comments on commit 062a9f2

Please sign in to comment.