diff --git a/app/assets/stylesheets/osem.css b/app/assets/stylesheets/osem.css index 396957dd..25f6fb68 100644 --- a/app/assets/stylesheets/osem.css +++ b/app/assets/stylesheets/osem.css @@ -83,3 +83,12 @@ body { .top-submitter img { margin: 0 auto; } + +#gallery-carousel .item img{ + height: 700px; + background-repeat: no-repeat; + background-position: center center; + width: 100%; + background-size: cover; + -webkit-background-size:cover; +} diff --git a/app/models/conference.rb b/app/models/conference.rb index 8ba0e73e..a7eaa6d0 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -10,7 +10,8 @@ class Conference < ActiveRecord::Base :difficulty_levels_attributes, :use_difficulty_levels, :use_vpositions, :use_vdays, :vdays_attributes, :vpositions_attributes, :use_volunteers, :media_id, :media_type, :color, :description, - :registration_description, :ticket_description + :registration_description, :ticket_description, + :photos_attributes has_paper_trail @@ -31,7 +32,7 @@ class Conference < ActiveRecord::Base has_many :vdays, :dependent => :destroy has_many :vpositions, :dependent => :destroy has_many :vchoices, :dependent => :destroy - + has_many :photos, dependent: :destroy belongs_to :venue accepts_nested_attributes_for :rooms, :reject_if => proc {|r| r["name"].blank?}, :allow_destroy => true @@ -46,6 +47,7 @@ class Conference < ActiveRecord::Base accepts_nested_attributes_for :questions, :allow_destroy => true accepts_nested_attributes_for :vdays, :allow_destroy => true accepts_nested_attributes_for :vpositions, :allow_destroy => true + accepts_nested_attributes_for :photos, allow_destroy: true has_attached_file :logo, :styles => {:thumb => "100x100>", :large => "300x300>" } diff --git a/app/models/photo.rb b/app/models/photo.rb new file mode 100644 index 00000000..22a8d9c2 --- /dev/null +++ b/app/models/photo.rb @@ -0,0 +1,11 @@ +class Photo < ActiveRecord::Base + attr_accessible :picture, :description + belongs_to :conference + validates_presence_of :picture + has_attached_file :picture, + styles: { thumb: '100x100>', large: '300x300>' } + + validates_attachment_content_type :picture, + content_type: [/jpg/, /jpeg/, /png/, /gif/], + size: { in: 0..500.kilobytes } +end diff --git a/app/views/admin/conference/_photo_fields.html.erb b/app/views/admin/conference/_photo_fields.html.erb new file mode 100644 index 00000000..1f590179 --- /dev/null +++ b/app/views/admin/conference/_photo_fields.html.erb @@ -0,0 +1,7 @@ +
+ <%= f.inputs do %> + <%= f.input :picture %> + <%= f.input :description, :input_html => {:rows => 2 } %> + <%= remove_association_link :photo, f %> + <% end %> +
diff --git a/app/views/admin/conference/edit.html.haml b/app/views/admin/conference/edit.html.haml index d920ba1f..90e53ef3 100644 --- a/app/views/admin/conference/edit.html.haml +++ b/app/views/admin/conference/edit.html.haml @@ -17,6 +17,8 @@ = f.input :registration_description, hint: 'This description will appear in registration segment of the splash' = f.input :ticket_description, hint: 'This will appear in the Tickets segment of the splash' + = dynamic_association :photos, "Photos", f + = f.inputs :name => "Media" do - if !@conference.logo.blank? = image_tag @conference.logo(:thumb) diff --git a/app/views/conference/_carousel.html.haml b/app/views/conference/_carousel.html.haml new file mode 100644 index 00000000..98da7299 --- /dev/null +++ b/app/views/conference/_carousel.html.haml @@ -0,0 +1,19 @@ +%div#gallery-carousel.carousel.slide{"data-ride" => "carousel"} + / Indicators + %ol.carousel-indicators + - @conference.photos.each_with_index do |p,i| + %li{"data-slide-to" => "#{i}", "data-target" => "#gallery-carousel", class: i==0 ? "active": "" } + / Wrapper for slides + .carousel-inner + - @conference.photos.each_with_index do |p,i| + %div{ class: i==0 ? "active item": "item" } + = image_tag(p.picture(:original), class: 'img-responsive') + - unless p.description.blank? + %div.carousel-caption + %p.text-center + = p.description + / Controls + %a.left.carousel-control{"data-slide" => "prev", href: "#gallery-carousel"} + %span.glyphicon.glyphicon-chevron-left + %a.right.carousel-control{"data-slide" => "next", href: "#gallery-carousel"} + %span.glyphicon.glyphicon-chevron-right diff --git a/app/views/conference/show.html.haml b/app/views/conference/show.html.haml index cbadd6d3..2f911bc4 100644 --- a/app/views/conference/show.html.haml +++ b/app/views/conference/show.html.haml @@ -1,5 +1,8 @@ = content_for :brand do = link_to @conference.title, conference_url(@conference.short_title), class: 'navbar-brand' +- unless @conference.photos.blank? + %div + = render 'carousel' %div#program = render 'program' %div#registration diff --git a/db/migrate/20140610064046_create_photos.rb b/db/migrate/20140610064046_create_photos.rb new file mode 100644 index 00000000..846b7934 --- /dev/null +++ b/db/migrate/20140610064046_create_photos.rb @@ -0,0 +1,13 @@ +class CreatePhotos < ActiveRecord::Migration + def change + create_table :photos do |t| + t.text :description + t.string :picture_file_name + t.string :picture_content_type + t.integer :picture_file_size + t.datetime :picture_updated_at + t.belongs_to :conference + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 2ef5c751..8ad51777 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140605125153) do +ActiveRecord::Schema.define(version: 20140610064046) do create_table "answers", force: true do |t| t.string "title" @@ -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" @@ -209,6 +209,17 @@ ActiveRecord::Schema.define(version: 20140605125153) do t.string "languages" end + create_table "photos", force: true do |t| + t.text "description" + t.string "picture_file_name" + t.string "picture_content_type" + t.integer "picture_file_size" + t.datetime "picture_updated_at" + t.integer "conference_id" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "qanswers", force: true do |t| t.integer "question_id" t.integer "answer_id" @@ -308,9 +319,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" diff --git a/spec/factories/photos.rb b/spec/factories/photos.rb new file mode 100644 index 00000000..aa9f0f96 --- /dev/null +++ b/spec/factories/photos.rb @@ -0,0 +1,12 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :photo do + picture_file_name 'rails.png' + picture_content_type 'image/png' + picture_file_size '1024' + picture_updated_at DateTime.now + description 'Lorem Ipsum Dolor' + conference + end +end diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb new file mode 100644 index 00000000..cf70fc7c --- /dev/null +++ b/spec/models/photo_spec.rb @@ -0,0 +1,14 @@ +require 'spec_helper' + +describe Photo do + describe 'validations' do + + it 'has a valid factory' do + expect(build(:photo)).to be_valid + end + + it 'is not valid without a picture' do + should validate_presence_of(:picture) + end + end +end