mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-14 04:04:03 +00:00
Merge pull request #946 from Shriyanshagro/venue_commercial
Defined Venue has_one Commercial nice new relationship
This commit is contained in:
commit
1fdc2f8efe
7 changed files with 129 additions and 16 deletions
53
app/controllers/admin/venue_commercials_controller.rb
Normal file
53
app/controllers/admin/venue_commercials_controller.rb
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
module Admin
|
||||
class VenueCommercialsController < Admin::BaseController
|
||||
load_and_authorize_resource :conference, find_by: :short_title
|
||||
load_and_authorize_resource :venue, through: :conference, singleton: true
|
||||
load_and_authorize_resource :commercial, through: :venue, singleton: true
|
||||
|
||||
def create
|
||||
@commercial = @venue.build_commercial(commercial_params)
|
||||
authorize! :create, @commercial
|
||||
|
||||
if @commercial.save
|
||||
redirect_to admin_conference_venue_path,
|
||||
notice: 'Commercial was successfully created.'
|
||||
else
|
||||
redirect_to admin_conference_venue_path,
|
||||
error: 'An error prohibited this Commercial from being saved: '\
|
||||
"#{@commercial.errors.full_messages.join('. ')}."
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @commercial.update(commercial_params)
|
||||
redirect_to admin_conference_venue_path,
|
||||
notice: 'Commercial was successfully updated.'
|
||||
else
|
||||
redirect_to admin_conference_venue_path,
|
||||
error: 'An error prohibited this Commercial from being saved: '\
|
||||
"#{@commercial.errors.full_messages.join('. ')}."
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@commercial.destroy
|
||||
redirect_to admin_conference_venue_path, notice: 'Commercial was successfully destroyed.'
|
||||
end
|
||||
|
||||
def render_commercial
|
||||
result = Commercial.render_from_url(params[:url])
|
||||
if result[:error]
|
||||
render text: result[:error], status: 400
|
||||
else
|
||||
render text: result[:html]
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def commercial_params
|
||||
params.require(:commercial).permit(:url)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -151,6 +151,8 @@ class Ability
|
|||
can :manage, Commercial, commercialable_type: 'Event',
|
||||
commercialable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_organizer).pluck(:id)).pluck(:id)
|
||||
can :manage, Venue, conference_id: conf_ids_for_organizer
|
||||
can :manage, Commercial, commercialable_type: 'Venue',
|
||||
commercialable_id: Venue.where(conference_id: conf_ids_for_organizer).pluck(:id)
|
||||
can :manage, Lodging, conference_id: conf_ids_for_organizer
|
||||
can :manage, Room, venue: { conference_id: conf_ids_for_organizer}
|
||||
can :manage, Sponsor, conference_id: conf_ids_for_organizer
|
||||
|
|
@ -177,6 +179,7 @@ class Ability
|
|||
can :manage, EmailSettings, conference_id: conf_ids_for_cfp
|
||||
can :manage, Room, venue: { conference_id: conf_ids_for_cfp }
|
||||
can :show, Venue, conference_id: conf_ids_for_cfp
|
||||
can :show, Commercial, commercialable_type: 'Venue', commercialable_id: Venue.where(conference_id: conf_ids_for_cfp).pluck(:id)
|
||||
can :manage, Cfp, program: { conference_id: conf_ids_for_cfp }
|
||||
can :manage, Program, conference_id: conf_ids_for_cfp
|
||||
can :manage, Commercial, commercialable_type: 'Event',
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
class Venue < ActiveRecord::Base
|
||||
belongs_to :conference
|
||||
has_one :commercial, as: :commercialable, dependent: :destroy
|
||||
has_many :rooms, dependent: :destroy
|
||||
before_create :generate_guid
|
||||
|
||||
accepts_nested_attributes_for :commercial, allow_destroy: true
|
||||
validates :name, :street, :city, :country, presence: true
|
||||
validates :conference_id, presence: true, uniqueness: true
|
||||
|
||||
|
|
|
|||
|
|
@ -2,13 +2,55 @@
|
|||
.col-md-12
|
||||
.page-header
|
||||
%h1 Venue
|
||||
.row
|
||||
.col-md-8
|
||||
= semantic_form_for(@venue, url: admin_conference_venue_path(@conference.short_title)) do |f|
|
||||
= f.inputs :name, :website
|
||||
= f.input :description, input_html: { rows: 5, cols: 20, data: { provide: 'markdown-editable' } }, hint: markdown_hint
|
||||
= f.inputs :street, :postalcode, :city, :country, :latitude, :longitude
|
||||
- unless @venue.photo.blank?
|
||||
= image_tag @venue.photo(:thumb)
|
||||
= f.input :photo
|
||||
= f.action :submit, as: :button, button_html: { class: 'btn btn-primary' }
|
||||
.tabbable
|
||||
%ul.nav.nav-tabs
|
||||
%li.active
|
||||
= link_to 'Details', '#details-content', 'data-toggle' => 'tab'
|
||||
%li
|
||||
= link_to 'Commercials', '#commercials-content', 'data-toggle' => 'tab'
|
||||
|
||||
.tab-content
|
||||
#details-content.tab-pane.active
|
||||
.col-md-8
|
||||
= semantic_form_for(@venue, url: admin_conference_venue_path(@conference.short_title)) do |f|
|
||||
= f.inputs :name, :website
|
||||
= f.input :description, input_html: { rows: 5, cols: 20, data: { provide: 'markdown-editable' } }, hint: markdown_hint
|
||||
= f.inputs :street, :postalcode, :city, :country, :latitude, :longitude
|
||||
- unless @venue.photo.blank?
|
||||
= image_tag @venue.photo(:thumb)
|
||||
= f.input :photo
|
||||
= f.action :submit, as: :button, button_html: { class: 'btn btn-primary' }
|
||||
|
||||
#commercials-content.tab-pane
|
||||
- if can? :create, @venue.commercial and @venue.id
|
||||
- if @venue.commercial.nil?
|
||||
.row
|
||||
.col-md-6
|
||||
#resource-content
|
||||
#resource-placeholder{ style: 'background-color:#d3d3d3; float: left; width: 400px; height: 250px; margin: 5px; border-width: 1px; border-style: solid; border-color: rgba(0,0,0,.2);' }
|
||||
|
||||
.row
|
||||
.col-md-6
|
||||
= semantic_form_for(Commercial.new,as: :commercial, url: admin_conference_venue_venue_commercial_path(conference_id: @conference.short_title)) do |f|
|
||||
= f.input :url, label: 'URL', as: :string, input_html: { required: 'required', type: 'url' },
|
||||
hint: 'Just paste the url of your video/photo provider. Currently supported: YouTube, Vimeo, SpeakerDeck, SlideShare, Instagram, Flickr.'
|
||||
= f.action :submit, as: :button, button_html: { class: 'btn btn-primary pull-right', disabled: true }
|
||||
%hr
|
||||
- else
|
||||
- if @venue.commercial.persisted?
|
||||
.col-md-4
|
||||
.thumbnail
|
||||
.flexvideo{ id: "resource-content-#{@venue.commercial.id}"}
|
||||
= render partial: 'shared/media_item', locals: { commercial: @venue.commercial }
|
||||
.caption
|
||||
- if can? :update, @venue.commercial
|
||||
= semantic_form_for @venue.commercial, as: :commercial, url: admin_conference_venue_venue_commercial_path(conference_id: @conference.short_title, id: @venue.commercial.id) do |f|
|
||||
= f.input :url, label: 'URL', as: :string, input_html: { id: "commercial_url_#{@venue.commercial.id}", required: 'required' }, hint: 'Just paste the url of your video/photo provider'
|
||||
= f.action :submit, as: :button, button_html: { class: 'btn btn-success' }, label: 'Update'
|
||||
- if can? :destroy, @venue.commercial
|
||||
= link_to 'Delete', admin_conference_venue_venue_commercial_path(conference_id: @conference.short_title, id: @venue.commercial.id),
|
||||
method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger'
|
||||
%hr
|
||||
|
||||
- else
|
||||
First Create Venue, then update commercial
|
||||
|
|
|
|||
|
|
@ -9,10 +9,16 @@
|
|||
.col-md-6
|
||||
- if @conference.venue.location?
|
||||
= render 'conference/venue_map'
|
||||
- elsif @conference.venue.photo.blank?
|
||||
%img{ "data-src" => "holder.js/300x200?text=No Image Set", class: 'img-responsive img-rounded' }
|
||||
- elsif !@conference.venue.photo.blank?
|
||||
=image_tag(@conference.venue.photo, class: 'img-responsive img-rounded')
|
||||
-else
|
||||
- if @venue.commercial.nil?
|
||||
.row
|
||||
%img{ "data-src" => "holder.js/500x300?text=No Commercial Set", class: 'img-responsive img-rounded' }
|
||||
- else
|
||||
- if @venue.commercial.persisted?
|
||||
.thumbnail
|
||||
.flexvideo{ id: "resource-content-#{@venue.commercial.id}"}
|
||||
= render partial: 'shared/media_item', locals: { commercial: @venue.commercial }
|
||||
|
||||
.col-md-6
|
||||
%address
|
||||
%strong
|
||||
|
|
|
|||
|
|
@ -6,12 +6,17 @@
|
|||
-else
|
||||
.container
|
||||
.row
|
||||
.col-md-12
|
||||
- if @conference.venue.commercial.present? and @conference.venue.commercial.persisted?
|
||||
.col-md-5
|
||||
.thumbnail
|
||||
.flexvideo{ id: "resource-content-#{@conference.venue.commercial.id}"}
|
||||
= render partial: 'shared/media_item', locals: { commercial: @conference.venue.commercial }
|
||||
|
||||
.col-md-6
|
||||
%h2.text-center
|
||||
= "#{@conference.venue.city} / #{@conference.venue.country_name}"
|
||||
.col-md-6
|
||||
.thumbnail
|
||||
=image_tag(@conference.venue.photo, class: 'img-responsive img-rounded') unless @conference.venue.photo.blank?
|
||||
.caption
|
||||
- unless @conference.venue.description.blank?
|
||||
= markdown(@conference.venue.description)
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ Osem::Application.routes.draw do
|
|||
# Singletons
|
||||
resource :splashpage
|
||||
resource :venue do
|
||||
get 'venue_commercial/render_commercial' => 'venue_commercials#render_commercial'
|
||||
resource :venue_commercial, only: [:create, :update, :destroy]
|
||||
resources :rooms, except: [:show]
|
||||
end
|
||||
resource :registration_period
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue