From 89b184f776829c0a17310e335fea185a657e7c55 Mon Sep 17 00:00:00 2001 From: Tocho Tochev Date: Sun, 20 Oct 2024 17:02:08 +0300 Subject: [PATCH] Enable addition of slides to event --- app/controllers/api/events_controller.rb | 2 +- .../management/events_controller.rb | 2 ++ app/controllers/public/events_controller.rb | 16 ++++++++------ app/models/event.rb | 21 ++++++++++++++++++ app/views/api/events/index.jbuilder | 1 + app/views/management/events/edit.html.slim | 7 ++++++ app/views/management/events/index.csv.erb | 4 ++-- app/views/management/events/show.html.slim | 3 +++ config/locales/bg.yml | 2 ++ config/locales/en.yml | 2 ++ lib/initfest/views/public/events/_form.slim | 22 +++++++++++-------- 11 files changed, 63 insertions(+), 19 deletions(-) diff --git a/app/controllers/api/events_controller.rb b/app/controllers/api/events_controller.rb index fca1450..cadfd33 100644 --- a/app/controllers/api/events_controller.rb +++ b/app/controllers/api/events_controller.rb @@ -4,7 +4,7 @@ class Api::EventsController < Api::ApplicationController before_action :require_current_conference! def index - @events = current_conference.events.approved.joins(:proposition).includes(:participations) + @events = current_conference.events.approved.joins(:proposition).includes(:participations).with_attached_resources_bundle end def halfnarp_friendly diff --git a/app/controllers/management/events_controller.rb b/app/controllers/management/events_controller.rb index 977641a..5b9135d 100644 --- a/app/controllers/management/events_controller.rb +++ b/app/controllers/management/events_controller.rb @@ -9,6 +9,7 @@ module Management .eager_load(:participants_with_personal_profiles, :proposition, :proposer, {track: [:translations]}, {event_type: [:translations]}, :feedbacks) + .with_attached_resources_bundle .preload(:conference), filters: params[:filters]).results # @events = @conference.events.order(:title).includes(:proposition, :proposer, :track, :event_type) @@ -76,6 +77,7 @@ module Management :abstract, :description, :notes, + :resources_bundle, :track_id, :event_type_id, participations_attributes: [ diff --git a/app/controllers/public/events_controller.rb b/app/controllers/public/events_controller.rb index 4cd4147..f3e422b 100644 --- a/app/controllers/public/events_controller.rb +++ b/app/controllers/public/events_controller.rb @@ -2,12 +2,16 @@ module Public class EventsController < Public::ApplicationController before_action :authenticate_user! + def current_user_events + Event.joins(:conference, :proposition, :participations).where(conference: current_conference).where("propositions.proposer_id = ? OR participations.participant_id = ?", current_user.id, current_user.id) + end + def index - @events = Event.joins(:conference, :proposition, :participations).where(conference: current_conference).where("propositions.proposer_id = ? OR participations.participant_id = ?", current_user.id, current_user.id) + @events = current_user_events end def edit - @event = Event.joins(:participations).find_by(id: params[:id], participations: {participant_id: current_user.id}) + @event = current_user_events.find_by(id: params[:id]) end def new @@ -30,9 +34,9 @@ module Public end def update - @event = Event.joins(:participations).find_by(id: params[:id], participations: {participant_id: current_user.id}) + @event = current_user_events.find_by(id: params[:id]) - if @event.update(event_params) + if @event.fields_editable_by_participant && @event.update(event_params.permit(@event.fields_editable_by_participant)) flash[:notice] = I18n.t("views.events.event_successfully_updated", event_type: @event.event_type.name.mb_chars.downcase) after_save_redirect else @@ -56,9 +60,7 @@ module Public def event_params params.require(:event).permit( - :title, :subtitle, :track_id, :length, :language, - :abstract, :description, :notes, :agreement, - :event_type_id + Event.new.fields_editable_by_participant ) end diff --git a/app/models/event.rb b/app/models/event.rb index 873942a..3bfa6ab 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -12,6 +12,8 @@ class Event < ActiveRecord::Base has_many :participants_with_personal_profiles, through: :approved_participations, source: :participant_with_personal_profile has_many :conflict_counts, -> { order(number_of_conflicts: :desc) }, foreign_key: :left_id + has_one_attached :resources_bundle + has_many :feedbacks, as: :feedback_receiving has_many :feedbacks_with_comment, -> { where.not(comment: [nil, ""]) }, as: :feedback_receiving, class_name: 'Feedback' include FeedbackReceiving @@ -69,6 +71,25 @@ class Event < ActiveRecord::Base } end + def fields_editable_by_participant + if not id or conference.start_date > 7.days.from_now + [ + :title, :subtitle, :track_id, :length, :language, + :abstract, :description, :notes, + :resources_bundle, + :agreement, + :event_type_id + ] + elsif conference.end_date > -14.days.from_now + [ + :resources_bundle, + :agreement, + ] + else + [] + end + end + def ranked? conference.has_vote_results? && rank.present? && number_of_votes.present? end diff --git a/app/views/api/events/index.jbuilder b/app/views/api/events/index.jbuilder index a53ef36..7b02c22 100644 --- a/app/views/api/events/index.jbuilder +++ b/app/views/api/events/index.jbuilder @@ -11,5 +11,6 @@ json.participant_user_ids event.participations.map(&:participant_id) json.feedback_url new_event_feedback_url(event_id: event.id) json.feedback_qr_code_url event_feedback_qr_code_url(event_id: event.id, format: :svg) + json.resources_bundle ((event.resources_bundle.attached? && event.conference.end_date < 0.days.from_now) ? rails_blob_url(event.resources_bundle, disposition: "attachment") : nil) end end diff --git a/app/views/management/events/edit.html.slim b/app/views/management/events/edit.html.slim index bdad53b..b525c4e 100644 --- a/app/views/management/events/edit.html.slim +++ b/app/views/management/events/edit.html.slim @@ -18,6 +18,13 @@ = f.input :abstract = f.input :description = f.input :notes + div class="form-group file optional resources_bundle" + dev class="col-sm-3 control-label text optional" + = f.label :resources_bundle + .col-sm-9 + = link_to @event.resources_bundle.filename, rails_blob_url(@event.resources_bundle.blob, disposition: "attachment") if @event.resources_bundle.attached? + = f.hidden_field :resources_bundle, value:@event.resources_bundle.signed_id if @event.resources_bundle.attached? + = f.input :resources_bundle, as: :file, wrapper: false, input_html: {direct_upload: true}, label: false hr .row .col-lg-12 diff --git a/app/views/management/events/index.csv.erb b/app/views/management/events/index.csv.erb index 2ee383c..b3da38f 100644 --- a/app/views/management/events/index.csv.erb +++ b/app/views/management/events/index.csv.erb @@ -1,5 +1,5 @@ -<%- csv_headers = %w{id title subtitle type track language paticipants length status rank number_of_votes proposer_notes} -%> +<%- csv_headers = %w{id title subtitle type track language participants length status rank number_of_votes abstract description proposer_notes resources_bundle} -%> <%= CSV.generate_line(csv_headers).html_safe -%> <%- @events.each do |event| -%> - <%= CSV.generate_line([event.id, event.title, event.subtitle, event.event_type.name, event.track.name, event.language, participant_names_with_emails(event).join(', '), event.length, event.status, event.rank, event.number_of_votes, event.notes]).html_safe -%> + <%= CSV.generate_line([event.id, event.title, event.subtitle, event.event_type.name, event.track.name, event.language, participant_names_with_emails(event).join(', '), event.length, event.status, event.rank, event.number_of_votes, event.abstract, event.description, event.notes, (rails_blob_url(event.resources_bundle, disposition: "attachment") if event.resources_bundle.attached?)]).html_safe -%> <%- end -%> diff --git a/app/views/management/events/show.html.slim b/app/views/management/events/show.html.slim index dc2fed1..9bd0e7a 100644 --- a/app/views/management/events/show.html.slim +++ b/app/views/management/events/show.html.slim @@ -36,6 +36,9 @@ - if @event.notes.present? h3 = Event.human_attribute_name :notes p = simple_format @event.notes + - if @event.resources_bundle.attached? + h3 = Event.human_attribute_name :resources_bundle + p = link_to @event.resources_bundle.filename, rails_blob_url(@event.resources_bundle.blob, disposition: "attachment") - if @conference.has_vote_results? or @conference.has_voting_endpoint? .col-md-3 .panel.panel-info.panel-rank diff --git a/config/locales/bg.yml b/config/locales/bg.yml index cb1b69a..2673720 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -84,6 +84,7 @@ bg: language: "Език" length: "Продължителност" notes: "Допълнителни бележки" + resources_bundle: "Ресурси (презентация, код, ...)" subtitle: "Подзаглавие" title: "Заглавие" track: "Поток от лекции" @@ -357,6 +358,7 @@ bg: language: "" length: "Продължителността на събитието (в минути). Продължителността на %{type} е между %{min} и %{max} минути, заедно с въпросите" notes: "Допълнителни бележки, които искате да споделите с организаторския екип" + resources_bundle: "Ресурси за посетителите - слайдове, код, записки, файл с връзки, архив... Те ще бъдат предоставени налични за сваляне от посетителите след конференцията." subtitle: "" title: "" track: "Потокът от лекции, в който искате да попадне предложението ви" diff --git a/config/locales/en.yml b/config/locales/en.yml index 233690f..7f3de65 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -84,6 +84,7 @@ en: language: "Language" length: "Length" notes: "Notes" + resources_bundle: "Resources bundle" subtitle: "Sub-title" title: "Title" track: "Track" @@ -357,6 +358,7 @@ en: language: "" length: "Length of the event (in minutes). The length of a %{type} is between %{min} and %{max} minutes" notes: "Notes that you'd like the organisation team to read" + resources_bundle: "Resources for the visitors - slides, code, notes, file with links, archive... These will be available to the visitors after the conference." subtitle: "" title: "" track: "The lecture track for your event" diff --git a/lib/initfest/views/public/events/_form.slim b/lib/initfest/views/public/events/_form.slim index e894410..25639b3 100644 --- a/lib/initfest/views/public/events/_form.slim +++ b/lib/initfest/views/public/events/_form.slim @@ -1,18 +1,22 @@ = simple_form_for @event, wrapper: :default do |form| - = form.input :event_type_id, as: :hidden, wrapper: false + = form.input :event_type_id, as: :hidden, wrapper: false, disabled: :event_type.in?(@event.fields_editable_by_participant) p = form.error_notification .form-inputs - = form.input :title, autofocus: true - = form.input :subtitle - = form.association :track, wrapper: :default, collection: current_conference.tracks.map { |track| [track.name, track.id, {title: track.description}] } - = form.input :length, hint: t('simple_form.hints.event.length', type: @event.event_type.name.mb_chars.downcase, min: @event.event_type.minimum_length, max: @event.event_type.maximum_length) - = form.input :language, as: :radio_buttons, collection: locale_collection, include_blank: false, wrapper: :default - = form.input :abstract - = form.input :description - = form.input :notes + = form.input :title, autofocus: true, disabled: !:title.in?(@event.fields_editable_by_participant) + = form.input :subtitle, disabled: !:subtitle.in?(@event.fields_editable_by_participant) + = form.association :track, wrapper: :default, collection: current_conference.tracks.map { |track| [track.name, track.id, {title: track.description}] }, disabled: !:track_id.in?(@event.fields_editable_by_participant) + = form.input :length, hint: t('simple_form.hints.event.length', type: @event.event_type.name.mb_chars.downcase, min: @event.event_type.minimum_length, max: @event.event_type.maximum_length), disabled: !:length.in?(@event.fields_editable_by_participant) + = form.input :language, as: :radio_buttons, collection: locale_collection, include_blank: false, wrapper: :default, disabled: !:language.in?(@event.fields_editable_by_participant) + = form.input :abstract, disabled: !:abstract.in?(@event.fields_editable_by_participant) + = form.input :description, disabled: !:description.in?(@event.fields_editable_by_participant) + = form.input :notes, disabled: !:notes.in?(@event.fields_editable_by_participant) + .input + = link_to @event.resources_bundle.filename, rails_blob_url(@event.resources_bundle.blob, disposition: "attachment") if @event.resources_bundle.attached? + = form.hidden_field :resources_bundle, value:@event.resources_bundle.signed_id if @event.resources_bundle.attached? + = form.input :resources_bundle, as: :file, wrapper: false, input_html: {direct_upload: true}, disabled: !:resources_bundle.in?(@event.fields_editable_by_participant) = form.input :agreement, as: :boolean, wrapper: :default -- 2.40.1