From 2bff9185563c7f174f5b59be91d87ceca4a4db9f Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Wed, 31 May 2017 21:03:15 +0300 Subject: [PATCH] Add index view for the cfp and modify existing ones Add cfp_type to the form partial Refactor Cfps#show to use partials for the different cfp types Modify the rest of the view, where the cfp was used --- .haml-lint_todo.yml | 5 +- app/controllers/admin/cfps_controller.rb | 16 ++--- app/views/admin/cfps/_events_cfp.html.haml | 38 ++++++++++++ app/views/admin/cfps/_form.html.haml | 3 +- app/views/admin/cfps/index.html.haml | 36 +++++++++++ app/views/admin/cfps/show.html.haml | 62 +++---------------- .../admin/conferences/_todo_list.html.haml | 2 +- .../versions/_object_desc_and_link.html.haml | 6 +- app/views/layouts/_admin_sidebar.html.haml | 4 +- config/routes.rb | 2 +- 10 files changed, 107 insertions(+), 67 deletions(-) create mode 100644 app/views/admin/cfps/_events_cfp.html.haml create mode 100644 app/views/admin/cfps/index.html.haml diff --git a/.haml-lint_todo.yml b/.haml-lint_todo.yml index 918178e2..0f6f5408 100644 --- a/.haml-lint_todo.yml +++ b/.haml-lint_todo.yml @@ -171,6 +171,7 @@ linters: - "app/views/tickets/index.html.haml" - "app/views/users/edit.html.haml" - "app/views/users/show.html.haml" + - "app/views/admin/cfps/index.html.haml" # Offense count: 223 InstanceVariables: @@ -229,6 +230,7 @@ linters: - "app/views/schedules/_schedule.html.haml" - "app/views/schedules/_schedule_item.html.haml" - "app/views/schedules/_schedule_tabs.html.haml" + - "app/views/admin/cfps/_events_cfp.html.haml" # Offense count: 32 IdNames: @@ -247,6 +249,7 @@ linters: - "app/views/admin/users/_event_registrations.html.haml" - "app/views/admin/users/show.html.haml" - "app/views/users/edit.html.haml" + - "app/views/admin/cfps/_events_cfp.html.haml" # Offense count: 4 UnnecessaryInterpolation: @@ -423,4 +426,4 @@ linters: exclude: - "app/views/conferences/_gallery.html.haml" - "app/views/layouts/_navigation.html.haml" - - "app/views/schedules/events.html.haml" \ No newline at end of file + - "app/views/schedules/events.html.haml" diff --git a/app/controllers/admin/cfps_controller.rb b/app/controllers/admin/cfps_controller.rb index 81fd78a9..da2723b7 100644 --- a/app/controllers/admin/cfps_controller.rb +++ b/app/controllers/admin/cfps_controller.rb @@ -4,21 +4,23 @@ module Admin load_and_authorize_resource :program, through: :conference, singleton: true load_and_authorize_resource through: :program + def index; end + def show; end def new - @cfp = @program.build_cfp + @cfp = @program.cfps.new end def edit; end def create - @cfp = @program.build_cfp(cfp_params) + @cfp = @program.cfps.new(cfp_params) send_mail_on_cfp_dates_updates = @cfp.notify_on_cfp_date_update? if @cfp.save ConferenceCfpUpdateMailJob.perform_later(@conference) if send_mail_on_cfp_dates_updates - redirect_to admin_conference_program_cfp_path, + redirect_to admin_conference_program_cfps_path, notice: 'Call for papers successfully created.' else flash.now[:error] = "Creating the call for papers failed. #{@cfp.errors.full_messages.join('. ')}." @@ -33,7 +35,7 @@ module Admin if @cfp.update_attributes(cfp_params) ConferenceCfpUpdateMailJob.perform_later(@conference) if send_mail_on_cfp_dates_updates - redirect_to admin_conference_program_cfp_path(@conference.short_title), + redirect_to admin_conference_program_cfps_path(@conference.short_title), notice: 'Call for papers successfully updated.' else flash.now[:error] = "Updating call for papers failed. #{@cfp.errors.to_a.join('. ')}." @@ -43,9 +45,9 @@ module Admin def destroy if @cfp.destroy - redirect_to admin_conference_program_cfp_path, notice: 'Call for Papers was successfully deleted.' + redirect_to admin_conference_program_cfps_path, notice: 'Call for Papers was successfully deleted.' else - redirect_to admin_conference_program_cfp_path, error: 'An error prohibited this Call for Papers from being destroyed: '\ + redirect_to admin_conference_program_cfps_path, error: 'An error prohibited this Call for Papers from being destroyed: '\ "#{@cfp.errors.full_messages.join('. ')}." end end @@ -53,7 +55,7 @@ module Admin private def cfp_params - params.require(:cfp).permit(:start_date, :end_date) + params.require(:cfp).permit(:start_date, :end_date, :cfp_type) end end end diff --git a/app/views/admin/cfps/_events_cfp.html.haml b/app/views/admin/cfps/_events_cfp.html.haml new file mode 100644 index 00000000..51bc2079 --- /dev/null +++ b/app/views/admin/cfps/_events_cfp.html.haml @@ -0,0 +1,38 @@ +%dt + Start Date: +%dd#start_date + = @cfp.start_date.strftime('%A, %B %-d. %Y') +%dt + End Date: +%dd#end_date + = @cfp.end_date.strftime('%A, %B %-d. %Y') +%dt + Days Left: +%dd + = pluralize(@cfp.remaining_days, 'day') +%dt + Event types: +%dd + = event_types(@conference) +%dt + Tracks: +%dd + = tracks(@conference) +%dt + Public Schedule +%dd#schedule_public + - if @program.schedule_public + Yes + - else + No +%dt + Schedule changeable? +%dd#schedule_changes + - if @program.schedule_fluid + Yes + - else + No +%dt + Rating Levels +%dd#rating + = @program.rating diff --git a/app/views/admin/cfps/_form.html.haml b/app/views/admin/cfps/_form.html.haml index e8110406..a02f3a02 100644 --- a/app/views/admin/cfps/_form.html.haml +++ b/app/views/admin/cfps/_form.html.haml @@ -4,8 +4,9 @@ %h1 Call for Papers .row .col-md-8 - = semantic_form_for(@cfp, url: admin_conference_program_cfp_path(@conference.short_title), html: {multipart: true}) do |f| + = semantic_form_for(@cfp, url: (@cfp.new_record? ? admin_conference_program_cfps_path : admin_conference_program_cfp_path(@conference.short_title, @cfp)), html: {multipart: true}) do |f| = f.input :start_date, as: :string, input_html: { id: 'registration-period-start-datepicker', start_date: @conference.start_date, end_date: @conference.end_date, readonly: 'readonly' } = f.input :end_date, as: :string, input_html: { id: 'registration-period-end-datepicker', readonly: 'readonly' } + = f.input :cfp_type, as: :select, collection: (@cfp.new_record? ? @program.remaining_cfp_types : [@cfp.cfp_type] + @program.remaining_cfp_types).map {|type| ["#{type.capitalize}", type]}, include_blank: false, label: 'Type', input_html: { class: 'select-help-toggle' } %p.text-right = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/app/views/admin/cfps/index.html.haml b/app/views/admin/cfps/index.html.haml new file mode 100644 index 00000000..16ab8e84 --- /dev/null +++ b/app/views/admin/cfps/index.html.haml @@ -0,0 +1,36 @@ +.row + .col-md-12 + .page-header + %h1 Call for Papers + %p.text-muted + Call for people to submit events to your conference +- if @program.cfps + .row + .col-md-12 + %table.table.table-hover.datatable#tickets + %thead + %th Type + %th Start Date + %th End Date + %th Days Left + %th Actions + %tbody + - @program.cfps.each do |cfp| + %tr + %td + = link_to(admin_conference_program_cfp_path(@conference.short_title, cfp.id)) do + = cfp.cfp_type.capitalize + %td + = cfp.start_date.strftime('%A, %B %-d. %Y') + %td + = cfp.end_date.strftime('%A, %B %-d. %Y') + %td + = pluralize(cfp.remaining_days, 'day') + %td + .btn-group + = link_to 'Edit', edit_admin_conference_program_cfp_path(@conference.short_title, cfp.id), method: :get, class: 'btn btn-primary' + = link_to 'Delete', admin_conference_program_cfp_path(@conference.short_title, cfp.id), method: 'delete', class: 'btn btn-danger', data: { confirm: 'Are you sure you want to delete the CfP?' } +- if @program.remaining_cfp_types.length > 0 + .row + .col-md-12.text-right + = link_to 'Create Call for Papers', new_admin_conference_program_cfp_path(@conference.short_title), class: 'btn btn-primary' diff --git a/app/views/admin/cfps/show.html.haml b/app/views/admin/cfps/show.html.haml index 09441508..e2a043ea 100644 --- a/app/views/admin/cfps/show.html.haml +++ b/app/views/admin/cfps/show.html.haml @@ -4,55 +4,13 @@ %h1 Call for Papers %p.text-muted Call for people to submit events to your conference -- if @cfp - .row - .col-md-8 - %dl.dl-horizontal - %dt - Start Date: - %dd#start_date - = @cfp.start_date.strftime('%A, %B %-d. %Y') - %dt - End Date: - %dd#end_date - = @cfp.end_date.strftime('%A, %B %-d. %Y') - %dt - Days Left: - %dd - = pluralize(@cfp.remaining_days, 'day') - %dt - Event types: - %dd - = event_types(@conference) - %dt - Tracks: - %dd - = tracks(@conference) - %dt - Public Schedule - %dd#schedule_public - - if @program.schedule_public - Yes - - else - No - %dt - Schedule changeable? - %dd#schedule_changes - - if @program.schedule_fluid - Yes - - else - No - %dt - Rating Levels - %dd#rating - = @program.rating - .row - .col-md-12.text-right - = link_to(edit_admin_conference_program_cfp_path(@conference.short_title), class: 'btn btn-primary') do - Edit - = link_to(admin_conference_program_cfp_path(@conference.short_title), method: 'delete', class: 'btn btn-danger', data: { confirm: 'Are you sure you want to delete the CfP?' }) do - Delete -- else - .row - .col-md-12.text-right - = link_to 'Create Call for Papers', new_admin_conference_program_cfp_path(@conference.short_title), class: 'btn btn-primary' +.row + .col-md-8 + %dl.dl-horizontal + = render "#{@cfp.cfp_type}_cfp" +.row + .col-md-12.text-right + = link_to(edit_admin_conference_program_cfp_path(@conference.short_title, @cfp.id), class: 'btn btn-primary') do + Edit + = link_to(admin_conference_program_cfp_path(@conference.short_title, @cfp.id), method: 'delete', class: 'btn btn-danger', data: { confirm: 'Are you sure you want to delete the CfP?' }) do + Delete diff --git a/app/views/admin/conferences/_todo_list.html.haml b/app/views/admin/conferences/_todo_list.html.haml index 63f4e3aa..88bb7c36 100644 --- a/app/views/admin/conferences/_todo_list.html.haml +++ b/app/views/admin/conferences/_todo_list.html.haml @@ -18,7 +18,7 @@ %li{ 'class' => "list-group-item #{hidden_if_conference_over(conference)} #{class_for_todo(conference_progress['cfp'])}" } %span{ 'class' => icon_for_todo(conference_progress['cfp']) } - if can? :update, Cfp.new(program_id: @program.id) - = link_to 'Set up call for papers', admin_conference_program_cfp_path(conference_progress['short_title']) + = link_to 'Set up call for papers', admin_conference_program_cfps_path(conference_progress['short_title']) - else Set up call for papers %li{'class'=>"list-group-item #{hidden_if_conference_over(conference)} #{class_for_todo(conference_progress['venue'])}"} diff --git a/app/views/admin/versions/_object_desc_and_link.html.haml b/app/views/admin/versions/_object_desc_and_link.html.haml index 44eedf82..1c7ed154 100644 --- a/app/views/admin/versions/_object_desc_and_link.html.haml +++ b/app/views/admin/versions/_object_desc_and_link.html.haml @@ -85,8 +85,10 @@ admin_conference_program_path(conference_id: Conference.find(version.conference_id).short_title) - when 'Cfp' - = link_if_alive version, 'cfp', - admin_conference_program_cfp_path(conference_id: Conference.find(version.conference_id).short_title) + = 'cfp' + - cfp = current_or_last_object_state(version.item_type, version.item_id) + = link_if_alive version, cfp.cfp_type, + admin_conference_program_cfp_path(conference_id: Conference.find(version.conference_id).short_title, id: version.item_id) - when 'Track' = 'track' diff --git a/app/views/layouts/_admin_sidebar.html.haml b/app/views/layouts/_admin_sidebar.html.haml index a9a2a99a..2c3eaf52 100644 --- a/app/views/layouts/_admin_sidebar.html.haml +++ b/app/views/layouts/_admin_sidebar.html.haml @@ -67,8 +67,8 @@ - if @conference.program %ul - if can? :update, Cfp.new(program_id: @conference.program.id) - %li{class: active_nav_li(admin_conference_program_cfp_path(@conference.short_title))} - = link_to 'Call for Papers', admin_conference_program_cfp_path(@conference.short_title) + %li{class: active_nav_li(admin_conference_program_cfps_path(@conference.short_title))} + = link_to 'Call for Papers', admin_conference_program_cfps_path(@conference.short_title) - if can? :update, @conference.program.events.build %li{class: active_nav_li(admin_conference_program_events_path(@conference.short_title))} = link_to 'Events', admin_conference_program_events_path(@conference.short_title) diff --git a/config/routes.rb b/config/routes.rb index 60b03f54..8fa4b857 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -53,7 +53,7 @@ Osem::Application.routes.draw do end resource :registration_period resource :program do - resource :cfp + resources :cfps resources :tracks resources :event_types resources :difficulty_levels