space/app/controllers/spaces_controller.rb

124 lines
3.3 KiB
Ruby

class SpacesController < ApplicationController
def index
page = Page.where(:module => OrbitHelper.this_module_app.key).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(:module => OrbitHelper.this_module_app.key).first
{
"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
}
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 = "/#{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(:module => OrbitHelper.this_module_app.key).first
{
"unit-title" => unit.title,
"floor-back-link" => "/" + I18n.locale.to_s + page.url + "/#{unit.floor.to_param}",
"unit-layout" => unit.layout,
"unit-id" => unit.id.to_s,
"page-id" => page.page_id
}
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
}
}
end
end