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 27, 2019
1 parent ba686a4 commit ed4c681
Show file tree
Hide file tree
Showing 12 changed files with 435 additions and 0 deletions.
66 changes: 66 additions & 0 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,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 @@ -150,7 +154,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(@conference.allowed_event_types_as_list)), 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 @@ -205,6 +205,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 @@ -974,6 +975,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 @@ -2084,6 +2112,7 @@ de:
login: Einloggen
signup: Anmelden
update_password: Aktualisiere mein Passwort
set: einstellen
settings: Einstellungen
show: Anzeige
show_account: Konto
Expand Down
32 changes: 32 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,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 @@ -958,6 +959,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."
attachments_overview: Attachments
average_feedback: 'Average Feedback:'
average_speaker_feedback: 'Average feedback as speaker:'
Expand Down Expand Up @@ -2065,6 +2096,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 @@ -221,6 +221,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 @@ -1008,6 +1009,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 @@ -2121,6 +2149,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
29 changes: 29 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ fr:
review_metric: Critique métrique
room: salle
track: fil
add: Ajouter
add_association: Ajouter %{name}
additional_resources: Ressources supplémentaires
admin: Admin
Expand Down Expand Up @@ -988,6 +989,33 @@ fr:
attachments_overview: Les pièces jointes
average_feedback: 'Moyenne des retours :'
average_speaker_feedback: 'Moyenne des retours par orateur :'
bulk_edit:
add_person: Ajouter une personne
add_person_confirm:
one: Êtes-vous sûr de vouloir ajouter une personne à cet événement?
other: Êtes-vous sûr de vouloir ajouter une personne à tous les événements %{count}?
set_events_confirm:
one: vous êtes sûr de vouloir changer d'état pour cet événement?
other: Êtes-vous sûr de vouloir changer d'état pour tous les événements %{count}?
set_events_type_confirm:
one: Êtes-vous sûr de vouloir modifier le type de cet événement?
other: Êtes-vous sûr de vouloir modifier le type pour tous les événements %{count}?
set_new_event_type: Changer le type d'événement
set_new_state: Attribuer l'état
set_new_track: Assigner une piste
set_track_confirm:
one: Êtes-vous sûr de vouloir changer le parcours de cet événement?
other: Êtes-vous sûr de vouloir changer le suivi de tous les événements %{count}?
toggle: Editer ces événements >>
update_failed:
one: "%{count} édition a échoué."
other: Les modifications de %{count} ont échoué.
update_skipped:
one: "%{count} édition ignorée."
other: "%{count} modifications ignorées."
update_successful:
one: "%{count} édition terminée avec succès."
other: "%{count} modifications terminées avec succès."
cancel_event: Annuler l’évènement
cancel_event_hint: |
Définit cet évènement comme annulé. Généralement, cela veut dire que l’orateur
Expand Down Expand Up @@ -2098,6 +2126,7 @@ fr:
login: Connexion
signup: Créer mon compte
update_password: Changer mon mot de passe
set: Ensemble
settings: Paramètres
show: Afficher
show_account: Compte
Expand Down
Loading

0 comments on commit ed4c681

Please sign in to comment.