From b1c171cd97f71df156e8d9594949f27795f8e842 Mon Sep 17 00:00:00 2001 From: Gopesh Tulsyan Date: Mon, 2 Jun 2014 20:48:56 +0530 Subject: [PATCH] Location Component --- app/assets/stylesheets/osem.css | 14 ++++++++ app/controllers/admin/venue_controller.rb | 14 ++++---- app/models/venue.rb | 6 ++++ app/views/admin/venue/venue_info.html.haml | 3 ++ app/views/conference/_location.html.haml | 36 +++++++++++++++++++ app/views/conference/show.html.haml | 14 ++++++++ app/views/home/index.html.haml | 2 +- .../20140602140203_add_photo_to_venue.rb | 8 +++++ db/schema.rb | 25 ++++++++----- spec/factories/conferences.rb | 1 + spec/factories/venues.rb | 1 + spec/views/conference/show.html.haml_spec.rb | 14 ++++++-- 12 files changed, 119 insertions(+), 19 deletions(-) create mode 100644 app/views/conference/_location.html.haml create mode 100644 db/migrate/20140602140203_add_photo_to_venue.rb diff --git a/app/assets/stylesheets/osem.css b/app/assets/stylesheets/osem.css index 396957dd..d8f42961 100644 --- a/app/assets/stylesheets/osem.css +++ b/app/assets/stylesheets/osem.css @@ -83,3 +83,17 @@ body { .top-submitter img { margin: 0 auto; } + +#location{ + background-repeat: no-repeat; + background-position: center center; + width: 100%; + min-height: 500px; + background-size: cover; + -webkit-background-size:cover; +} + +#location li{ + display: inline-block; + margin-right: 2em; +} diff --git a/app/controllers/admin/venue_controller.rb b/app/controllers/admin/venue_controller.rb index 15156217..4c8696d6 100644 --- a/app/controllers/admin/venue_controller.rb +++ b/app/controllers/admin/venue_controller.rb @@ -6,13 +6,13 @@ class Admin::VenueController < ApplicationController def update @venue = @conference.venue - venue_params = params[:venue] - @venue.name = venue_params[:name] - @venue.address= venue_params[:address] - @venue.website = venue_params[:website] - @venue.description = venue_params[:description] - @venue.save - redirect_to(admin_conference_venue_info_path(:conference_id => @conference.short_title), :notice => 'Venue was successfully updated.') + if @venue.update_attributes!(params[:venue]) + 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 diff --git a/app/models/venue.rb b/app/models/venue.rb index e0251f7c..c63cb69b 100644 --- a/app/models/venue.rb +++ b/app/models/venue.rb @@ -1,7 +1,13 @@ class Venue < ActiveRecord::Base + attr_accessible :name, :description, :website, :address, :photo has_many :conferences before_create :generate_guid + has_attached_file :photo, + styles: { thumb: '100x100>', large: '300x300>' } + validates_attachment_content_type :photo, + content_type: [/jpg/, /jpeg/, /png/, /gif/], + size: { in: 0..500.kilobytes } private def generate_guid diff --git a/app/views/admin/venue/venue_info.html.haml b/app/views/admin/venue/venue_info.html.haml index af339af2..c576612c 100644 --- a/app/views/admin/venue/venue_info.html.haml +++ b/app/views/admin/venue/venue_info.html.haml @@ -5,4 +5,7 @@ = f.input :address, :input_html => {:rows => 1} = f.input :website = f.input :description, :input_html => { :rows => 10, :cols => 20 } + - if !@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/conference/_location.html.haml b/app/views/conference/_location.html.haml new file mode 100644 index 00000000..754b1253 --- /dev/null +++ b/app/views/conference/_location.html.haml @@ -0,0 +1,36 @@ += content_for :splash_nav do + %li + %a{ href: '#location' } Location + + +%div#location + %div.container.text-center + .div.row.col-md-12 + - if !@conference.venue.name.blank? + %h1 + %strong #{ @conference.venue.name } + - if !@conference.venue.address.blank? + %h2 + %strong #{ @conference.venue.address } + - if !@conference.venue.description.blank? + %p + %strong #{ @conference.venue.description } + %ul + - if !@conference.venue.address.blank? + %li + %b + = link_to 'View in Google Maps', "http://maps.google.com/maps?q=#{@conference.venue.address}", target: '_blank' + - if !@conference.venue.website.blank? + %li + %b + = link_to 'Visit Venue Website', @conference.venue.website, target: '_blank' + + +:javascript + $(document).ready(function(){ + var photo = "#{@conference.venue.photo}"; + if(photo) + { + $('#location').css('background-image', 'url('+photo+')'); + } + }); diff --git a/app/views/conference/show.html.haml b/app/views/conference/show.html.haml index cbadd6d3..9d2d9702 100644 --- a/app/views/conference/show.html.haml +++ b/app/views/conference/show.html.haml @@ -1,9 +1,23 @@ = content_for :brand do = link_to @conference.title, conference_url(@conference.short_title), class: 'navbar-brand' + %div#program = render 'program' %div#registration = render 'registration' %div#callforpapers = render 'call_for_papers' +%div#location + = render 'location' + + + + + + + +:javascript + $(document).ready(function(){ + $('#content').removeClass('container'); + }); diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index f9b27f71..2df959ce 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -2,4 +2,4 @@ .col-md-12.page-header %h2.text-center Upcoming Conferences - @current.each do |conference| - = render :partial => "conference_details", :locals => {:conference => conference} \ No newline at end of file + = render :partial => "conference_details", :locals => {:conference => conference} diff --git a/db/migrate/20140602140203_add_photo_to_venue.rb b/db/migrate/20140602140203_add_photo_to_venue.rb new file mode 100644 index 00000000..c2d0454c --- /dev/null +++ b/db/migrate/20140602140203_add_photo_to_venue.rb @@ -0,0 +1,8 @@ +class AddPhotoToVenue < ActiveRecord::Migration + def change + add_column :venues, :photo_file_name, :string + add_column :venues, :photo_content_type, :string + add_column :venues, :photo_file_size, :integer + add_column :venues, :photo_updated_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 2ef5c751..a347010c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -50,15 +50,15 @@ ActiveRecord::Schema.define(version: 20140605125153) do add_index "comments", ["user_id"], name: "index_comments_on_user_id" create_table "conferences", force: true do |t| - t.string "guid", null: false - t.string "title", null: false - t.string "short_title", null: false + t.string "guid", null: false + t.string "title", null: false + t.string "short_title", null: false t.string "social_tag" - t.string "contact_email", null: false - t.string "timezone", null: false + t.string "contact_email", null: false + t.string "timezone", null: false t.string "html_export_path" - t.date "start_date", null: false - t.date "end_date", null: false + t.date "start_date", null: false + t.date "end_date", null: false t.integer "venue_id" t.datetime "created_at" t.datetime "updated_at" @@ -81,6 +81,9 @@ ActiveRecord::Schema.define(version: 20140605125153) do t.text "description" t.text "registration_description" t.text "ticket_description" + t.string "facebook_url" + t.string "google_url" + t.string "twitter_url" end create_table "conferences_questions", id: false, force: true do |t| @@ -308,9 +311,9 @@ ActiveRecord::Schema.define(version: 20140605125153) do end create_table "tracks", force: true do |t| - t.string "guid", null: false + t.string "guid", null: false t.integer "conference_id" - t.string "name", null: false + t.string "name", null: false t.text "description" t.string "color" t.datetime "created_at" @@ -363,6 +366,10 @@ ActiveRecord::Schema.define(version: 20140605125153) do t.string "offline_map_bounds" t.datetime "created_at" t.datetime "updated_at" + t.string "photo_file_name" + t.string "photo_content_type" + t.integer "photo_file_size" + t.datetime "photo_updated_at" end create_table "versions", force: true do |t| diff --git a/spec/factories/conferences.rb b/spec/factories/conferences.rb index 8fdbe34d..47596648 100644 --- a/spec/factories/conferences.rb +++ b/spec/factories/conferences.rb @@ -9,5 +9,6 @@ FactoryGirl.define do contact_email 'admin@example.com' start_date Date.today end_date Date.tomorrow + venue end end diff --git a/spec/factories/venues.rb b/spec/factories/venues.rb index fca4e1f5..69eb863b 100644 --- a/spec/factories/venues.rb +++ b/spec/factories/venues.rb @@ -4,5 +4,6 @@ FactoryGirl.define do name 'Suse Office' address 'Maxfeldstrasse 5 \n90409 Nuremberg' website 'www.opensuse.org' + description 'Lorem Ipsum Dolor' end end diff --git a/spec/views/conference/show.html.haml_spec.rb b/spec/views/conference/show.html.haml_spec.rb index 8e32e586..bd98f9e2 100644 --- a/spec/views/conference/show.html.haml_spec.rb +++ b/spec/views/conference/show.html.haml_spec.rb @@ -5,13 +5,14 @@ describe 'conference/show.html.haml' do registration_start_date: Date.today, registration_end_date: Date.tomorrow, description: 'Lorem Ipsum') + @conference.venue = create(:venue) @conference.call_for_papers = create(:call_for_papers, conference: @conference) assign :conference, @conference render end it 'renders program partial' do - expect(render).to include("#{@conference.description}") + expect(rendered).to include("#{@conference.description}") expect(view).to render_template(partial: 'conference/_program') end @@ -21,6 +22,15 @@ describe 'conference/show.html.haml' do end it 'renders call_for_papers partial' do - expect(render).to include("#{@conference.call_for_papers.description}") + expect(view).to render_template(partial: 'conference/_call_for_papers') + expect(rendered).to include("#{@conference.call_for_papers.description}") + end + + it 'renders location partial' do + expect(view).to render_template(partial: 'conference/_location') + expect(rendered).to include('Suse Office') + expect(rendered).to include('Maxfeldstrasse 5 \n90409 Nuremberg') + expect(rendered).to include('www.opensuse.org') + expect(rendered).to include('Lorem Ipsum Dolor') end end