From 9d08f52636664bdb00eca752944ee7224e57bdac Mon Sep 17 00:00:00 2001 From: chrisbr Date: Wed, 12 Nov 2014 12:12:57 +0100 Subject: [PATCH] Refactoring venue --- app/controllers/admin/venue_controller.rb | 27 ------------- app/controllers/admin/venues_controller.rb | 18 +++++++++ app/models/venue.rb | 12 +++++- .../admin/conference/_todo_list.html.haml | 2 +- app/views/admin/venue/venue_info.html.haml | 11 ------ app/views/admin/venues/_form.html.haml | 9 +++++ app/views/admin/venues/_show.html.haml | 38 +++++++++++++++++++ app/views/admin/venues/edit.html.haml | 16 ++++++++ app/views/layouts/_admin_sidebar.html.haml | 4 +- config/routes.rb | 4 +- spec/features/ability_spec.rb | 18 ++++----- .../{venue_spec.rb => venues_spec.rb} | 2 +- .../edit.html.haml_spec.rb} | 4 +- 13 files changed, 108 insertions(+), 57 deletions(-) delete mode 100644 app/controllers/admin/venue_controller.rb create mode 100644 app/controllers/admin/venues_controller.rb delete mode 100644 app/views/admin/venue/venue_info.html.haml create mode 100644 app/views/admin/venues/_form.html.haml create mode 100644 app/views/admin/venues/_show.html.haml create mode 100644 app/views/admin/venues/edit.html.haml rename spec/features/{venue_spec.rb => venues_spec.rb} (97%) rename spec/views/admin/{venue/venue_info.html.haml_spec.rb => venues/edit.html.haml_spec.rb} (84%) diff --git a/app/controllers/admin/venue_controller.rb b/app/controllers/admin/venue_controller.rb deleted file mode 100644 index f2d77495..00000000 --- a/app/controllers/admin/venue_controller.rb +++ /dev/null @@ -1,27 +0,0 @@ -module Admin - class VenueController < Admin::BaseController - load_and_authorize_resource :conference, find_by: :short_title - load_and_authorize_resource :venue, through: :conference, singleton: true - - def index; end - - def update - @venue = @conference.venue - @venue.assign_attributes(params[:venue]) - send_mail = @venue.venue_notify?(@conference) - if @venue.update_attributes(params[:venue]) - Mailbot.delay.send_email_on_venue_update(@conference) if send_mail - redirect_to(admin_conference_venue_info_path(conference_id: @conference.short_title), - notice: 'Venue was successfully updated.') - else - redirect_to(admin_conference_venue_info_path(conference_id: @conference.short_title), - notice: 'Venue Updation Failed!') - end - end - - def show - @venue = @conference.venue - render :venue_info - end - end -end diff --git a/app/controllers/admin/venues_controller.rb b/app/controllers/admin/venues_controller.rb new file mode 100644 index 00000000..1a11713a --- /dev/null +++ b/app/controllers/admin/venues_controller.rb @@ -0,0 +1,18 @@ +module Admin + class VenuesController < Admin::BaseController + load_and_authorize_resource :conference, find_by: :short_title + load_and_authorize_resource :venue, through: :conference, singleton: true + + def edit; end + + def update + if @venue.update_attributes(params[:venue]) + redirect_to(edit_admin_conference_venue_path(conference_id: @conference.short_title), + notice: 'Venue was successfully updated.') + else + flash[:error] = "Update venue failed: #{@venue.errors.full_messages.join('. ')}." + render :edit + end + end + end +end diff --git a/app/models/venue.rb b/app/models/venue.rb index 5012699f..3f9dffbd 100644 --- a/app/models/venue.rb +++ b/app/models/venue.rb @@ -12,6 +12,16 @@ class Venue < ActiveRecord::Base size: { in: 0..500.kilobytes } accepts_nested_attributes_for :lodgings, allow_destroy: true + after_update :send_mail_notification + + private + + def send_mail_notification + conferences.each do |conference| + Mailbot.delay.send_email_on_venue_update(conference) if venue_notify?(conference) + end + end + def venue_notify?(conference) (self.name_changed? || self.address_changed?) && (!self.name.blank? && !self.address.blank?) && @@ -20,8 +30,6 @@ class Venue < ActiveRecord::Base conference.email_settings.venue_update_template) end - private - # TODO: create a module to be mixed into model to perform same operation # event.rb has same functionality which can be shared # TODO: rename guid to UUID as guid is specifically Microsoft term diff --git a/app/views/admin/conference/_todo_list.html.haml b/app/views/admin/conference/_todo_list.html.haml index 272e423a..f3f64cb1 100644 --- a/app/views/admin/conference/_todo_list.html.haml +++ b/app/views/admin/conference/_todo_list.html.haml @@ -24,7 +24,7 @@ %li{'class'=>class_for_todo(conference_progress['venue'])} %span{'class'=>icon_for_todo(conference_progress['venue'])} - if can? :update, @conference.venue - = link_to 'Add venue', admin_conference_venue_info_path(conference_progress['short_title']) + = link_to 'Add venue', edit_admin_conference_venue_path(conference_progress['short_title']) - else Add venue %li{'class'=>class_for_todo(conference_progress['rooms'])} diff --git a/app/views/admin/venue/venue_info.html.haml b/app/views/admin/venue/venue_info.html.haml deleted file mode 100644 index 54c8ee70..00000000 --- a/app/views/admin/venue/venue_info.html.haml +++ /dev/null @@ -1,11 +0,0 @@ -.row - .col-md-8 - = semantic_form_for(@venue, :url => admin_conference_venue_update_path(@conference.short_title),:html => {:multipart => true}) do |f| - = f.input :name, :input_html => {:rows => 1} - = f.input :address, :input_html => {:rows => 1} - = f.input :website - = f.input :description, :input_html => { :rows => 10, :cols => 20, data: { provide: "markdown-editable" } }, hint: markdown_hint - - unless @venue.photo.blank? - = image_tag @venue.photo(:thumb) - = f.input :photo - = f.action :submit, :as => :button, :button_html => {:class => "btn btn-primary"} diff --git a/app/views/admin/venues/_form.html.haml b/app/views/admin/venues/_form.html.haml new file mode 100644 index 00000000..f94ddd7f --- /dev/null +++ b/app/views/admin/venues/_form.html.haml @@ -0,0 +1,9 @@ += semantic_form_for(@venue, url: admin_conference_venue_path(@conference.short_title)) do |f| + = f.input :name, input_html: { rows: 1 } + = f.input :address, input_html: { rows: 1 } + = f.input :website + = f.input :description, input_html: { rows: 5, cols: 20, data: { provide: 'markdown-editable' } }, hint: markdown_hint + - unless @venue.photo.blank? + = image_tag @venue.photo(:thumb) + = f.input :photo + = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/app/views/admin/venues/_show.html.haml b/app/views/admin/venues/_show.html.haml new file mode 100644 index 00000000..fa6688c6 --- /dev/null +++ b/app/views/admin/venues/_show.html.haml @@ -0,0 +1,38 @@ +.row{'style'=>'padding-top: 15px;'} + .col-md-6 + %dl.dl-horizontal + %dt + Name + %dd + = @venue.name + %dt + Address + %dd + = @venue.address + %dt + Website + %dd + = @venue.website + %dt + Description + %dd + - unless @venue.description.blank? + = markdown(@venue.description) +.row.row-flex.row-flex-wrap + .col-md-4 + .thumbnail.flex-col + %h3.text-center + Venue Logo + - if @venue.photo + = image_tag(@venue.photo(:large), class: 'img-responsive') + .caption.flex-grow + .caption + %p + %dl.dl-horizontal + %dt + Filename + %dd + = @venue.photo_file_name + -else + %h4.text-center + Not set! \ No newline at end of file diff --git a/app/views/admin/venues/edit.html.haml b/app/views/admin/venues/edit.html.haml new file mode 100644 index 00000000..d5c798a7 --- /dev/null +++ b/app/views/admin/venues/edit.html.haml @@ -0,0 +1,16 @@ +.row + .col-md-12 + %ul.nav.nav-tabs{'role'=>'tablist'} + %li.active + %a{'href'=> '#show', 'role'=>'tab', 'data-toggle'=>'tab'} + Show + %li + %a{'href'=> '#edit', 'role'=>'tab', 'data-toggle'=>'tab'} + Edit +.row + .col-md-8 + .tab-content + .tab-pane.active#show + = render partial: 'show' + .tab-pane#edit + = render partial: 'form' diff --git a/app/views/layouts/_admin_sidebar.html.haml b/app/views/layouts/_admin_sidebar.html.haml index c89c2d19..24f725b2 100644 --- a/app/views/layouts/_admin_sidebar.html.haml +++ b/app/views/layouts/_admin_sidebar.html.haml @@ -46,8 +46,8 @@ %li{:class=> active_nav_li(admin_conference_splashpage_path(@conference.short_title))} = link_to 'Splashpage', admin_conference_splashpage_path(@conference.short_title) - if can? :index, @conference.venue - %li{:class=> "#{active_nav_li(admin_conference_venue_info_path(@conference.short_title))}"} - = link_to(admin_conference_venue_info_path(@conference.short_title)) do + %li{:class=> "#{active_nav_li(edit_admin_conference_venue_path(@conference.short_title))}"} + = link_to(edit_admin_conference_venue_path(@conference.short_title)) do %span.fa.fa-road Venue %ul diff --git a/config/routes.rb b/config/routes.rb index ffa81a3e..cbc64231 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -27,8 +27,6 @@ Osem::Application.routes.draw do resource :schedule, only: [:show, :update] resources :commercials, except: [:show] get '/stats' => 'stats#index' - get '/venue' => 'venue#show', as: 'venue_info' - patch '/venue' => 'venue#update', as: 'venue_update' get '/dietary_choices' => 'dietchoices#show', as: 'dietary_list' patch '/dietary_choices' => 'dietchoices#update', as: 'dietary_update' get '/volunteers_list' => 'volunteers#show' @@ -42,6 +40,8 @@ Osem::Application.routes.draw do resource :splashpage + resource :venue, only: [:edit, :update] + resources :difficulty_levels, only: [:show, :update, :index] resources :rooms, only: [:show, :update, :index] diff --git a/spec/features/ability_spec.rb b/spec/features/ability_spec.rb index 81a21dc1..3549cc25 100644 --- a/spec/features/ability_spec.rb +++ b/spec/features/ability_spec.rb @@ -29,7 +29,7 @@ feature 'Has correct abilities' do expect(page).to have_link('Schedule', href: "/admin/conference/#{conference1.short_title}/schedule") expect(page).to have_link('Campaigns', href: "/admin/conference/#{conference1.short_title}/campaigns") expect(page).to have_link('Goals', href: "/admin/conference/#{conference1.short_title}/targets") - expect(page).to have_link('Venue', href: "/admin/conference/#{conference1.short_title}/venue") + expect(page).to have_link('Venue', href: "/admin/conference/#{conference1.short_title}/venue/edit") expect(page).to have_link('Rooms', href: "/admin/conference/#{conference1.short_title}/rooms") expect(page).to have_link('Lodgings', href: "/admin/conference/#{conference1.short_title}/lodgings") expect(page).to have_link('Sponsorship', href: "/admin/conference/#{conference1.short_title}/sponsorship_levels") @@ -64,8 +64,8 @@ feature 'Has correct abilities' do visit admin_conference_targets_path(conference1.short_title) expect(current_path).to eq(admin_conference_targets_path(conference1.short_title)) - visit admin_conference_venue_info_path(conference1.short_title) - expect(current_path).to eq(admin_conference_venue_info_path(conference1.short_title)) + visit edit_admin_conference_venue_path(conference1.short_title) + expect(current_path).to eq(edit_admin_conference_venue_path(conference1.short_title)) visit admin_conference_sponsorship_levels_path(conference1.short_title) expect(current_path).to eq(admin_conference_sponsorship_levels_path(conference1.short_title)) @@ -100,7 +100,7 @@ feature 'Has correct abilities' do expect(page).to have_link('Schedule', href: "/admin/conference/#{conference2.short_title}/schedule") expect(page).to_not have_link('Campaigns', href: "/admin/conference/#{conference2.short_title}/campaigns") expect(page).to_not have_link('Goals', href: "/admin/conference/#{conference2.short_title}/targets") - expect(page).to have_link('Venue', href: "/admin/conference/#{conference2.short_title}/venue") + expect(page).to have_link('Venue', href: "/admin/conference/#{conference2.short_title}/venue/edit") expect(page).to have_link('Rooms', href: "/admin/conference/#{conference2.short_title}/rooms") expect(page).to_not have_link('Lodgings', href: "/admin/conference/#{conference2.short_title}/lodgings") expect(page).to_not have_link('Sponsorship', href: "/admin/conference/#{conference2.short_title}/sponsorship_levels") @@ -135,7 +135,7 @@ feature 'Has correct abilities' do visit admin_conference_targets_path(conference2.short_title) expect(current_path).to eq(root_path) - visit admin_conference_venue_info_path(conference2.short_title) + visit edit_admin_conference_venue_path(conference2.short_title) expect(current_path).to eq(root_path) visit admin_conference_sponsorship_levels_path(conference2.short_title) @@ -171,7 +171,7 @@ feature 'Has correct abilities' do expect(page).to_not have_link('Schedule', href: "/admin/conference/#{conference3.short_title}/schedule") expect(page).to_not have_link('Campaigns', href: "/admin/conference/#{conference3.short_title}/campaigns") expect(page).to_not have_link('Targets', href: "/admin/conference/#{conference3.short_title}/targets") - expect(page).to_not have_link('Venue', href: "/admin/conference/#{conference3.short_title}/venue") + expect(page).to_not have_link('Venue', href: "/admin/conference/#{conference3.short_title}/venue/edit") expect(page).to_not have_link('Rooms', href: "/admin/conference/#{conference3.short_title}/rooms") expect(page).to_not have_link('Lodgings', href: "/admin/conference/#{conference3.short_title}/lodgings") expect(page).to_not have_link('Sponsorship', href: "/admin/conference/#{conference3.short_title}/sponsorship_levels") @@ -206,7 +206,7 @@ feature 'Has correct abilities' do visit admin_conference_targets_path(conference3.short_title) expect(current_path).to eq(root_path) - visit admin_conference_venue_info_path(conference3.short_title) + visit edit_admin_conference_venue_path(conference3.short_title) expect(current_path).to eq(root_path) visit admin_conference_sponsorship_levels_path(conference3.short_title) @@ -243,7 +243,7 @@ feature 'Has correct abilities' do expect(page).to_not have_link('Schedule', href: "/admin/conference/#{conference4.short_title}/schedule") expect(page).to_not have_link('Campaigns', href: "/admin/conference/#{conference4.short_title}/campaigns") expect(page).to_not have_link('Goals', href: "/admin/conference/#{conference4.short_title}/targets") - expect(page).to_not have_link('Venue', href: "/admin/conference/#{conference4.short_title}/venue") + expect(page).to_not have_link('Venue', href: "/admin/conference/#{conference4.short_title}/venue/edit") expect(page).to_not have_link('Rooms', href: "/admin/conference/#{conference4.short_title}/rooms") expect(page).to_not have_link('Lodgings', href: "/admin/conference/#{conference4.short_title}/lodgings") expect(page).to_not have_link('Sponsorship', href: "/admin/conference/#{conference4.short_title}/sponsorship_levels") @@ -278,7 +278,7 @@ feature 'Has correct abilities' do visit admin_conference_targets_path(conference4.short_title) expect(current_path).to eq(root_path) - visit admin_conference_venue_info_path(conference4.short_title) + visit edit_admin_conference_venue_path(conference4.short_title) expect(current_path).to eq(root_path) visit admin_conference_sponsorship_levels_path(conference4.short_title) diff --git a/spec/features/venue_spec.rb b/spec/features/venues_spec.rb similarity index 97% rename from spec/features/venue_spec.rb rename to spec/features/venues_spec.rb index ac28a55a..4489afea 100644 --- a/spec/features/venue_spec.rb +++ b/spec/features/venues_spec.rb @@ -10,7 +10,7 @@ feature Conference do sign_in organizer - visit admin_conference_venue_info_path( + visit edit_admin_conference_venue_path( conference_id: conference.short_title) expect(page.find("//*[@id='venue_submit_action']"). diff --git a/spec/views/admin/venue/venue_info.html.haml_spec.rb b/spec/views/admin/venues/edit.html.haml_spec.rb similarity index 84% rename from spec/views/admin/venue/venue_info.html.haml_spec.rb rename to spec/views/admin/venues/edit.html.haml_spec.rb index dd9f1922..a4bc62a4 100644 --- a/spec/views/admin/venue/venue_info.html.haml_spec.rb +++ b/spec/views/admin/venues/edit.html.haml_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' -describe 'admin/venue/venue_info' do +describe 'admin/venues/edit' do - it 'renders venue#show' do + it 'renders venues#show' do @conference = create(:conference) @venue = @conference.venue @venue.name = 'Croatia'