space/app/controllers/spaces_controller.rb

170 lines
5.3 KiB
Ruby

class SpacesController < ApplicationController
def index
params = OrbitHelper.params
page = Page.where(:page_id => params[:page_id]).first
buildings = Building.filter_by_categories.collect do |building|
floors = building.floors.desc(:title).collect do |floor|
image = (!floor.frontend_image.thumb.url.nil? ? floor.frontend_image.thumb.url : "/assets/default-floor.jpg")
link = floor.layout.nil? ? (floor.floor_units.empty? ? "#" : "/#{I18n.locale.to_s}#{page.url}/#{floor.floor_units.first.to_param}?method=unit") : OrbitHelper.url_to_show(floor.to_param)
{
"floor-title" => floor.title,
"floor-image" => image,
"alt-title" => floor.title,
"link_to_show" => link
}
end
{
"building-title" => building.title,
"building-image" => building.image.url,
"alt-title" => building.title,
"floors" => floors
}
end
{
"buildings" => buildings,
"extras" => {
}
}
end
def show
params = OrbitHelper.params
floor = Floor.where(:uid => params[:uid]).first rescue nil
thumb_image = (!floor.frontend_image.thumb.url.nil? ? floor.frontend_image.thumb.url : "/assets/default-floor.jpg")
image = (!floor.frontend_image.mobile.url.nil? ? floor.frontend_image.mobile.url : "#")
page = Page.where(:page_id => params[:page_id]).first
site = Site.first
hover_color = (site.orbit_bar_submenu_background_color rescue nil) || 'null'
bg_color = (site.orbit_bar_background_color rescue nil) || 'null'
block_color = hex2rgba((site.orbit_bar_submenu_background_color rescue nil),0.3) || 'null'
{
"floor-title" => floor.title,
"floor-frontend-image-thumb" => thumb_image,
"floor-frontend-image" => image,
"image-alt" => floor.title,
"building-back-link" => "/" + I18n.locale.to_s + page.url,
"floor-layout" => floor.layout,
"floor-id" => floor.id.to_s,
"page-id" => page.page_id,
"hover_color" => hover_color,
"bg_color" => bg_color,
"block_color" => block_color,
"style_label" => style_label(bg_color,site.orbit_bar_text_color)
}
end
def floor_units
floor = Floor.find(params[:floor_id]) rescue nil
page = Page.where(:page_id => params[:page_id]).first rescue nil
units = []
if !floor.nil?
floor.floor_units.each do |unit|
url = "/#{I18n.locale.to_s}#{page.url}/#{unit.to_param}?method=unit" rescue "#"
units << {
"id" => unit.id.to_s,
"url" => url
}
end
end
render :json => {"success" => true, "units" => units}
end
def floor_sub_units
unit = FloorUnit.find(params[:unit_id]) rescue nil
page = Page.where(:page_id => params[:page_id]).first rescue nil
units = []
if !unit.nil?
unit.floor_sub_units.each do |subunit|
url = subunit.floor_sub_unit_images.empty? ? "#" : "/#{I18n.locale.to_s}#{page.url}/#{subunit.to_param}?method=showcase&layout=false" rescue "#"
units << {
"id" => subunit.id.to_s,
"url" => url
}
end
end
render :json => {"success" => true, "sub_units" => units}
end
def unit
params = OrbitHelper.params
unit = FloorUnit.where(:uid => params[:uid]).first rescue nil
page = Page.where(:page_id => params[:page_id]).first
layout = unit.layout.nil? ? "<div id='full-layout-canvas'><img href='<%= unit.layout_image.url %>' id='layout-image'></div>" : unit.layout
backlink = unit.floor.layout.nil? ? "/" + I18n.locale.to_s + page.url : "/" + I18n.locale.to_s + page.url + "/#{unit.floor.to_param}"
site = Site.first
hover_color = (site.orbit_bar_submenu_background_color rescue nil) || 'null'
bg_color = (site.orbit_bar_background_color rescue nil) || 'null'
block_color = hex2rgba((site.orbit_bar_submenu_background_color rescue nil),0.3) || 'null'
{
"unit-title" => unit.title,
"floor-back-link" => backlink,
"unit-layout" => layout,
"unit-id" => unit.id.to_s,
"page-id" => page.page_id,
"hover_color" => hover_color,
"bg_color" => bg_color,
"block_color" => block_color,
"style_label" => style_label(bg_color,site.orbit_bar_text_color)
}
end
def showcase
params = OrbitHelper.params
unit = FloorSubUnit.where(:uid => params[:uid]).first rescue nil
images = []
unit.floor_sub_unit_images.each do |image|
images << {
"image-thumb-url" => image.image.thumb.url,
"image-url" => image.image.url,
"alt-image" => unit.title
}
end
{
"unit-images" => images,
"extras" => {
"unit-title" => unit.title,
"content" => unit.content || ''
}
}
end
private
def hex2rgba(my_hex,percent=1)
if my_hex
if my_hex[0] == '#'
my_hex = my_hex[1..-1]
end
rgb = my_hex.split(//).each_slice(my_hex.length/3).map{|v| v.join.to_i(16)}
"rgba(#{rgb[0]},#{rgb[1]},#{rgb[2]},#{percent})"
else
nil
end
end
def style_label(color1,color2)
if color1
"<style>
.s-space.show-space .selection-box-label.active{
background: #{color1} !important;
color: #{color2} !important;
}
.overlay .anchor{
border-color: #{color1} transparent transparent transparent !important;
}
</style>"
else
""
end
end
end