Skip to content

Commit

Permalink
Merge pull request #19 from srogers/develop
Browse files Browse the repository at this point in the history
Release v005
  • Loading branch information
srogers authored Jul 16, 2018
2 parents 29b3641 + e3decd5 commit 66ab71d
Show file tree
Hide file tree
Showing 24 changed files with 400 additions and 191 deletions.
4 changes: 0 additions & 4 deletions app/assets/javascripts/presentations.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,3 @@ document.addEventListener("trix-initialize", (event) ->
console.log "fixing trix buttons"
element.tabIndex = -1
)
$ ->
$('#manage_presentation_switch').on 'click', ->
$('#manage_presentation').toggle(800)

15 changes: 11 additions & 4 deletions app/controllers/activations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
class ActivationsController < ApplicationController

before_action :require_no_user

def create
@user = User.find_using_perishable_token(params[:id], 1.day)

if @user
if current_user
if @user != current_user
flash[:notice] = "This activation notice is for a different account. Your account is already active."
logger.warn "User #{ current_user.id }, #{ current_user.email } tried to activate as user ID #{ @user.id }"
end
flash[:notice] = "Your account has already been activated"
redirect_to root_url

elsif @user
if @user.active?
flash[:notice] = "Your account has already been activated"
else
@user.activate!
flash[:notice] = "Your account has been activated!"
end

if Setting.require_account_approval? && !@user.approved?
AccountCreationMailer.pending_activation_notice(@user).deliver_now
flash[:notice] = "Your email address has been confirmed - account pending administrator approval. You'll receive an email when it's ready."
Expand All @@ -24,7 +31,7 @@ def create
end
else
# TODO - maybe rate-limit or block this if it gets abused
logger.error "Request IP #{ request.ip } attempted to validate with bogus token: #{ params[:id] }"
logger.warn "Request IP #{ request.ip } attempted to validate with bogus token: #{ params[:id] }"
flash[:error] = "We're sorry-your account could not be activated. Please contact an administrator."
redirect_to root_path
end
Expand Down
20 changes: 10 additions & 10 deletions app/controllers/conference_users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ def index
end

def create
conference_user = ConferenceUser.new conference_user_params
conference_user.user_id = current_user.id unless current_user.admin? # it's all about you unless you're an admin
conference_user.creator_id = current_user.id
if conference_user.save
redirect_to conference_path(conference_user.conference_id)
@conference_user = ConferenceUser.new conference_user_params
@conference_user.user_id = current_user.id unless current_user.admin? # it's all about you unless you're an admin
@conference_user.creator_id = current_user.id
if @conference_user.save
redirect_to conference_path(@conference_user.conference_id)
else
flash[:error] = 'The user/conference association could not be saved.'
logger.debug "Conference Speaker save failed: #{ conference_user.errors.full_messages }"
logger.debug "Conference Speaker save failed: #{ @conference_user.errors.full_messages }"
redirect_to conferences_path
end
end

def destroy
conference_user = ConferenceUser.find(params[:id])
if conference_user
conference_id = conference_user.conference_id
conference_user.destroy if conference_user.user_id == current_user.id || current_user.admin?
@conference_user = ConferenceUser.find(params[:id])
if @conference_user
conference_id = @conference_user.conference_id
@conference_user.destroy if @conference_user.user_id == current_user.id || current_user.admin?
redirect_to conference_path(conference_id)
else
render body: nil
Expand Down
24 changes: 14 additions & 10 deletions app/controllers/presentation_speakers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@ class PresentationSpeakersController < ApplicationController
before_action :require_user

def create
presentation_speaker = PresentationSpeaker.new presentation_speaker_params
presentation_speaker.creator_id = current_user.id
if presentation_speaker.save
redirect_to presentation_path(presentation_speaker.presentation_id)
@presentation_speaker = PresentationSpeaker.new presentation_speaker_params
@presentation_speaker.creator_id = current_user.id
if @presentation_speaker.save
redirect_to manage_speakers_presentation_path(@presentation_speaker.presentation_id)
else
flash[:error] = 'The speaker/presentation association could not be saved.'
logger.debug "Presentation Speaker save failed: #{ presentation_speaker.errors.full_messages }"
redirect_to presentations_path
if @presentation_speaker&.presentation_id
redirect_to manage_speakers_presentation_path(@presentation_speaker.presentation_id)
else
redirect_to presentations_path
end
end
end

def destroy
presentation_speaker = PresentationSpeaker.find(params[:id])
if presentation_speaker
presentation_id = presentation_speaker.presentation_id
presentation_speaker.destroy
redirect_to presentation_path(presentation_id)
@presentation_speaker = PresentationSpeaker.find(params[:id])
if @presentation_speaker
presentation_id = @presentation_speaker.presentation_id
@presentation_speaker.destroy
redirect_to manage_speakers_presentation_path(presentation_id)
else
render body: nil
end
Expand Down
10 changes: 8 additions & 2 deletions app/controllers/presentations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ def index
end

def show
@publication = Publication.new
end

def edit
end

def manage_speakers
@presentation_speaker = PresentationSpeaker.new
@current_speaker_ids = @presentation.speakers.map{|s| s.id}.join(',')
end

def edit
def manage_publications
@publication = Publication.new
end

def new
Expand Down
39 changes: 29 additions & 10 deletions app/controllers/publications_controller.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,49 @@
class PublicationsController < ApplicationController

before_action :require_editor
before_action :get_publication, except: [:create, :new]

def create
publication = Publication.new publication_params
publication.creator_id = current_user.id
if publication.save
redirect_to presentation_path(publication.presentation_id)
@publication = Publication.new publication_params
@publication.creator_id = current_user.id
if @publication.save
redirect_to manage_publications_presentation_path(@publication.presentation_id)
else
flash[:error] = 'The publication could not be saved.'
logger.debug "Publication save failed: #{ publication.errors.full_messages }"
logger.debug "Publication save failed: #{ @publication.errors.full_messages }"
redirect_to presentations_path
end
end

def edit
@presentation = @publication.presentation
end

def update
if @publication.update_attributes publication_params
redirect_to manage_publications_presentation_path(@publication.presentation_id)
else
flash.now[:error] = 'Your publication could not be saved.'
logger.debug "Publication save failed: #{ @publication.errors.full_messages }"
@presentation = @publication.presentation
render 'edit'
end
end

def destroy
publication = Publication.find(params[:id])
if publication
presentation_id = publication.presentation_id
publication.destroy
redirect_to presentation_path(presentation_id)
if @publication
presentation_id = @publication.presentation_id
@publication.destroy
redirect_to manage_publications_presentation_path(presentation_id)
else
render body: nil
end
end

def get_publication
@publication = Publication.find params[:id]
end

def publication_params
params.require(:publication).permit(:presentation_id, :published_on, :format, :url, :notes)
end
Expand Down
7 changes: 6 additions & 1 deletion app/helpers/conferences_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ def full_name_with_date(conference)
end

def date_span(conference)
"#{pretty_date conference.start_date, style: :yearless}-#{conference.end_date.day}, #{ conference.end_date.year} "
start_text = "#{pretty_date conference.start_date, style: :yearless}"
end_text = "#{conference.end_date.day}, #{ conference.end_date.year}"
if conference.start_date.month != conference.end_date.month
end_text = "#{ I18n.l(Time.now, format: "%B") } " + end_text
end
return "#{ start_text }-#{ end_text }"
end

# Show a message appropriate for a conference where user is related to conference
Expand Down
2 changes: 1 addition & 1 deletion app/views/conferences/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
- if current_user.attended? @conference
%p
= attendance_status_message(@conference)
= link_to icon('times-circle', class: 'fa-fw'), conference_user_path(@conference_user), :method => :delete, :style => "color: #F00", :data => { :confirm => 'Remove your association with this conference?' }, :post => true
= link_to icon('trash-alt', class: 'fa-fw'), conference_user_path(@conference_user), :method => :delete, :style => "color: #F00", :data => { :confirm => 'Remove your association with this conference?' }, :post => true
- else
= simple_form_for @conference_user do |f|
= f.input :conference_id, as: :hidden, input_html: { value: @conference.id }
Expand Down
7 changes: 7 additions & 0 deletions app/views/presentations/_base_form_fields.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
= f.input :name, :autofocus => true, label: 'Presentation Name'
= f.input :conference_id, collection: [[@presentation.conference_name,@presentation.conference_id]], label: "Conference Name", input_html: { data: { delimiter: ',', placeholder: "enter a conference year...", source: conferences_path(format: :json) }, class: "select2-autocomplete", id: "conference_picker" }
= f.label :description
= f.trix_editor :description
= f.input :tag_list, label: 'Subject Areas', hint: "economics, politics, psychology, etc. - separate with commas"
= f.input :parts
= f.input :duration, hint: "total minutes"
9 changes: 0 additions & 9 deletions app/views/presentations/_form_fields.html.haml

This file was deleted.

5 changes: 1 addition & 4 deletions app/views/presentations/edit.html.haml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
.row
.col-md-12
= title "Edit Presentation Details"
.row
.col-md-12
= simple_form_for @presentation do |f|
= render :partial => "form_fields", :locals => {:f => f}
= render :partial => "base_form_fields", :locals => {:f => f}
= save_or_cancel f, presentation_path(@presentation), 'Save'
31 changes: 31 additions & 0 deletions app/views/presentations/manage_publications.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.row
.col-md-12
%h4= @presentation.name
.row
.col-md-12
%h5 Manage Publications
%ul
- if @presentation.publications.empty?
%li None Yet
- @presentation.publications.each do |publication|
%li
- if publication.url.present?
= link_to publication.format, publication.url, target: '_blank'
- else
= publication.format
= publication.published_on.year
- if publication.notes.present?
= " - #{ publication.notes }"
= link_to icon('edit', :class => 'fa-fw'), edit_publication_path(publication)
= link_to icon('trash', :class => 'fa-fw'), publication_path(publication), :method => :delete, :data => { :confirm => 'remove this publication?' }, :post => true, class: 'text-danger'

.row
.col-md-12
%h5 Add a publication
= simple_form_for @publication, :html => {:autocomplete => "off"} do |f|
= render partial: "publications/form_fields", locals: {:f => f}
%p= f.submit "Add"

.row
.col-md-12
%p= link_to "Done", presentation_path(@presentation), :class => "btn btn-primary"
25 changes: 25 additions & 0 deletions app/views/presentations/manage_speakers.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.row
.col-md-12
%h4= @presentation.name
.row
.col-md-12
%h5 Manage Speakers
%ul
- @presentation.presentation_speakers.each do |presentation_speaker|
%li
= presentation_speaker.speaker.name
=# link_to icon('edit', 'Edit', :class => 'fa-fw'), presentation_speaker_path(presentation_speaker), edit_presentation_speaker_path(presentation_speaker)
= link_to icon('trash-alt', :class => 'fa-fw'), presentation_speaker_path(presentation_speaker), :method => :delete, :data => { :confirm => 'remove this speaker?' }, :post => true, class: 'text-danger'

.row
= simple_form_for @presentation_speaker, :html => {:autocomplete => "off", id: 'new_presentation_speaker_form'} do |ps|
.col-md-6
= ps.input :presentation_id, as: :hidden, input_html: { value: @presentation.id }
= ps.input :speaker_id, collection: [['',0]], label: false, input_html: { data: { delimiter: ',', placeholder: "enter a speaker name...", width: 400, source: speakers_path(format: :json), exclude: @current_speaker_ids }, class: "select2-autocomplete" }
.col-md-6
%p= ps.submit 'Add', form: 'new_presentation_speaker_form'

.row
.col-md-12
%p= link_to "Done", presentation_path(@presentation), :class => "btn btn-primary"

8 changes: 4 additions & 4 deletions app/views/presentations/new.html.haml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.row
.col-md-12
= title "Add a New Presentation"
.row
.col-md-12
= simple_form_for @presentation, :html => {:autocomplete => "off"} do |f|
= render :partial => "form_fields", :locals => {:f => f}
= simple_fields_for :presentation_speaker do |p|
= p.input :speaker_id, collection: [['',0]], label: false, input_html: { data: { delimiter: ',', placeholder: "enter a speaker name...", source: speakers_path(format: :json) }, class: "select2-autocomplete" }, label: "Speaker"

= render :partial => "base_form_fields", :locals => {:f => f}
= save_or_cancel f, presentations_path, 'Create'
52 changes: 7 additions & 45 deletions app/views/presentations/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@

%p
Publications:
= @presentation.publications.empty? ? "Not yet available" : "Available as"
= @presentation.publications.empty? ? "Not yet available" : ""
%ul
- @presentation.publications.each do |publication|
%li= format_and_date(publication)
%li
= format_and_date(publication)
- if publication.notes.present?
= " - #{ publication.notes }"

- if can? :edit, @presentation
.row
Expand All @@ -38,56 +41,15 @@
= f.input :conference_id, collection: [['',0]], label: false, input_html: { data: { delimiter: ',', placeholder: "enter a conference year...", source: conferences_path(format: :json) }, class: "select2-autocomplete", id: "conference_picker" }
= f.submit 'Add'

.row{ style: "margin-top: 20px"}
.col-md-12
%h5#manage_presentation_switch
= link_to icon('caret-right'), '#' # make this a link for nice cursor behavior, but make the whole thing 'hot'
Manage Speakers and Pubications
.row#manage_presentation{ style: "display: none"}
.col-md-6
%h4 Speakers
%ul
- if @presentation.speakers.empty?
%li None Yet
- @presentation.presentation_speakers.each do |presentation_speaker|
%li
= presentation_speaker.speaker.name
= link_to icon('times-circle'), presentation_speaker_path(presentation_speaker), :method => :delete, :data => { :confirm => 'remove this speaker?' }, :post => true, class: 'text-danger'
%h5 Add a speaker
= simple_form_for @presentation_speaker, :html => {:autocomplete => "off"} do |f|
= f.input :presentation_id, as: :hidden, input_html: { value: @presentation.id }
= f.input :speaker_id, collection: [['',0]], label: false, input_html: { data: { delimiter: ',', placeholder: "enter a speaker name...", width: 400, source: speakers_path(format: :json), exclude: @current_speaker_ids }, class: "select2-autocomplete" }
= f.submit 'Add', id: 'new_presentation_speaker_submit'
.col-md-6
%h4 Publications
%ul
- if @presentation.publications.empty?
%li None Yet
- @presentation.publications.each do |publication|
%li
= [publication.format, publication.published_on.year, publication.url.present? ? publication.url : nil].compact.join(', ')
= link_to icon('times-circle'), publication_path(publication), :method => :delete, :data => { :confirm => 'remove this publication?' }, :post => true, class: 'text-danger'
%h5 Add a publication
= simple_form_for @publication, :html => {:autocomplete => "off"} do |f|
= f.input :presentation_id, as: :hidden, input_html: { value: @presentation.id }
= f.input :format, collection: Publication::FORMATS, include_blank: false
= f.input :published_on, as: :date, start_year: 1980, end_year: Date.today.year, order: [:year], label: "Published"
= f.input :url, label: 'URL'
= f.input :notes, hint: 'Any special clarifying info or references'
= f.submit "Add"
.row
.col-md-12
.form-actions
- if can? :edit, @presentation
= link_to "Edit", edit_presentation_path(@presentation), :class => "btn btn-secondary"
- if request.referrer.split('?').first == new_presentation_url # ignore any trailing params
= link_to "Add Another", new_presentation_path(conference_id: @presentation.conference_id), :class => "btn btn-secondary"
= link_to "Manage Speakers", manage_speakers_presentation_path(@presentation), :class => "btn btn-primary"
= link_to "Manage Publications", manage_publications_presentation_path(@presentation), :class => "btn btn-primary"
= link_to "Done", presentations_path, :class => "btn btn-primary"
.pull-right
- if can? :destroy, @presentation
Expand Down
Loading

0 comments on commit 66ab71d

Please sign in to comment.