Track related fixes

Make the message in admin/Tracks form more visible by making it bold and
adding links to venue and rooms
Make papertrail track changes for all the track's attributes
Add validation to require presence of description for self-organized
tracks
Add ID column to admin/Tracks#index
Make the cfp inclusion column sortable
Show success/error flash messages after toggling cfp inclusion
This commit is contained in:
AEtherC0r3 2017-08-08 12:41:37 +03:00 committed by Stella Rouzi
parent 5f1ed7ce85
commit b717018b31
9 changed files with 114 additions and 32 deletions

View file

@ -1,18 +1,14 @@
$(function () {
$(document).ready(function() {
$('.datatable').DataTable({
// ajax: ...,
stateSave: true,
autoWidth: false,
pagingType: 'full_numbers',
"lengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]]
});
$('.datatable').DataTable({
// ajax: ...,
stateSave: true,
autoWidth: false,
pagingType: 'full_numbers',
"lengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]],
});
$('#versionstable').DataTable({
pagingType: 'full_numbers',
order: [[ 0, 'desc' ]]
});
$('#versionstable').DataTable({
pagingType: 'full_numbers',
order: [[ 0, 'desc' ]]
});
});

View file

@ -4,6 +4,9 @@ module Admin
load_and_authorize_resource :program, through: :conference, singleton: true
load_and_authorize_resource through: :program, find_by: :short_name
# Show flash message with ajax calls
after_action :prepare_unobtrusive_flash, only: :toggle_cfp_inclusion
def index; end
def show
@ -55,9 +58,13 @@ module Admin
def toggle_cfp_inclusion
@track.cfp_active = !@track.cfp_active
if @track.save
head :ok
flash[:notice] = "Successfully changed cfp inclusion of #{@track.name} to #{@track.cfp_active}"
else
head :unprocessable_entity
flash[:error] = "Failed to toggle cfp inclusion of #{@track.name} to #{@track.cfp_active}"
end
respond_to do |format|
format.js
end
end

View file

@ -9,7 +9,7 @@ class Track < ActiveRecord::Base
belongs_to :room
has_many :events, dependent: :nullify
has_paper_trail only: [:name, :description, :color], meta: { conference_id: :conference_id }
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
before_create :generate_guid
validates :name, presence: true
@ -28,6 +28,7 @@ class Track < ActiveRecord::Base
validates :end_date, presence: true, if: :self_organized_and_accepted_or_confirmed?
validates :room, presence: true, if: :self_organized_and_accepted_or_confirmed?
validates :relevance, presence: true, if: :self_organized?
validates :description, presence: true, if: :self_organized?
validate :valid_dates
validate :valid_room, if: :self_organized_and_accepted_or_confirmed?

View file

@ -14,10 +14,15 @@
= f.input :color, input_html: {size: 6, type: 'color'}, required: true
= 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', required: @track.self_organized_and_accepted_or_confirmed? }
= f.input :end_date, as: :string, input_html: { id: 'registration-period-end-datepicker', readonly: 'readonly', required: @track.self_organized_and_accepted_or_confirmed? }
- if @conference.venue
- if @conference.venue.try(:rooms)
= f.input :room, as: :select, collection: (@conference.venue.rooms).map {|room| ["#{room.name}", room.id]}, include_blank: true, label: 'Room', input_html: { class: 'select-help-toggle', required: @track.self_organized_and_accepted_or_confirmed? }
- else
Please add a venue with rooms, if you want to select a room for the track.
%b
Please add a
= link_to 'venue', admin_conference_venue_path(@conference.short_title)
with
= link_to 'rooms', admin_conference_venue_rooms_path(@conference.short_title)
, if you want to select a room for the track.
= f.input :description, input_html: {rows: 2, data: { provide: 'markdown-editable' } }, hint: markdown_hint
= f.input :cfp_active, label: 'Allow event submitters to select this track for their proposal'
= f.action :submit, as: :button, button_html: { class: 'btn btn-primary' }

View file

@ -1,3 +1,4 @@
.unobtrusive-flash-container
.row
.col-md-12
.page-header
@ -8,6 +9,7 @@
.col-md-12
%table.table.table-hover.table-striped.table-bordered.datatable#tracks
%thead
%th ID
%th Name
%th Description
%th Room
@ -20,6 +22,8 @@
%tbody
- @tracks.each do |track|
%tr
%td
= track.id
%td{style: "padding: 15px 0px 0px 10px;"}
= link_to admin_conference_program_track_path(@conference.short_title, track), class: 'btn' do
%span.label{style: "background-color: #{track.color}; color: #{ contrast_color(track.color) }"}
@ -35,7 +39,7 @@
= track.end_date.strftime('%A, %B %-d. %Y') if track.end_date
%td
= link_to track.submitter.name, admin_user_path(track.submitter) if track.self_organized?
%td.text-center
%td.text-center{ 'id' => "cfp_switch_#{track.id}", 'data-order' => track.cfp_active.to_s }
= check_box_tag "#{@conference.short_title}_#{track.short_name}", track.id, track.cfp_active,
class: 'switch-checkbox', method: :patch,
url: toggle_cfp_inclusion_admin_conference_program_track_path(@conference.short_title, id: track.short_name)+"?included=",

View file

@ -1,3 +1,4 @@
.unobtrusive-flash-container
.row
.col-md-12
.page-header

View file

@ -0,0 +1,8 @@
$('.alert').remove();
track_id = <%= @track.id %>;
track_cfp_td = $('#cfp_switch_' + track_id);
track_cfp_value = <%= @track.cfp_active %>;
track_cfp_td.attr('data-order', track_cfp_value);
$('#tracks').DataTable().cell(track_cfp_td).invalidate();