diff --git a/app/assets/images/no-layout.jpg b/app/assets/images/no-layout.jpg new file mode 100644 index 0000000..c83c1a7 Binary files /dev/null and b/app/assets/images/no-layout.jpg differ diff --git a/app/assets/stylesheets/space.scss b/app/assets/stylesheets/space.scss index 70fe933..32068e3 100644 --- a/app/assets/stylesheets/space.scss +++ b/app/assets/stylesheets/space.scss @@ -70,7 +70,7 @@ ul.apartments-area { padding-bottom: 0; transition-property: left, right, top; width: 150px; - height: 150px; + height: 170px; text-align: center; .apartment-img { @@ -79,10 +79,6 @@ ul.apartments-area { height: 125px; overflow: hidden; - &:hover { - height: 145px; - margin-bottom: 5px; - } } a{ @@ -132,6 +128,10 @@ ul#layout-canvas { width: 2px; height: 2px; background-color: rgba(0, 0, 0, .4); + + .selection-box-label{ + color: #fff; + } } .make-box-permanent{ @@ -152,6 +152,10 @@ ul#layout-canvas { } } +.floor-unit-title{ + text-align: center; +} + diff --git a/app/controllers/admin/spaces_controller.rb b/app/controllers/admin/spaces_controller.rb index 4c6394b..61bc34c 100644 --- a/app/controllers/admin/spaces_controller.rb +++ b/app/controllers/admin/spaces_controller.rb @@ -41,8 +41,8 @@ class Admin::SpacesController < OrbitAdminController end def delete_floor - floor = Floor.find_by(:uid => params[:floor_id].split("-").last) - floor.destroy + floor = Floor.find_by(:uid => params[:floor_id].split("-").last) rescue nil + floor.destroy if !floor.nil? render :json => {"success" => true}.to_json end @@ -60,12 +60,122 @@ class Admin::SpacesController < OrbitAdminController end end + def edit_floor_unit + @floor_unit = FloorUnit.find_by(:uid => params[:unit_id].split("-").last) rescue nil + @floor = @floor_unit.floor + end + + def update_floor_unit + floor_unit = FloorUnit.find(params[:unit_id]) rescue nil + if !floor_unit.nil? + floor_unit.update_attributes(floor_unit_params) + floor_unit.save + end + redirect_to "/admin/spaces/#{floor_unit.floor.building.to_param}/#{floor_unit.floor.to_param}/units" + end + + def save_floor_layout + floor = Floor.find(params[:floor_id]) rescue nil + if !floor.nil? + floor.layout = params[:layout_html] + floor.save + end + render :json => {"success" => true}.to_json + end + + def delete_floor_unit + floor_unit = FloorUnit.find_by(:uid => params[:unit_id].split("-").last) rescue nil + floor = floor_unit.floor + if !floor_unit.nil? + floor_unit.destroy + end + redirect_to "/admin/spaces/#{floor.building.to_param}/#{floor.to_param}/units" + + end + def units @floor = Floor.find_by(:uid => params[:floor_id].split("-").last) end + def sub_units + @floor_unit = FloorUnit.find_by(:uid => params[:unit_id].split("-").last) + end + + def add_sub_unit + @floor_unit = FloorUnit.find_by(:uid => params[:unit_id].split("-").last) rescue nil + @sub_unit = FloorSubUnit.new + end + + def edit_sub_unit + @sub_unit = FloorSubUnit.find_by(:uid => params[:sub_unit_id].split("-").last) rescue nil + end + + def update_sub_unit + sub_unit = FloorSubUnit.find(params[:floor_sub_unit_id]) rescue nil + if !sub_unit.nil? + p = sub_unit_params + p[:floor_sub_unit_images].concat(sub_unit.floor_sub_unit_images) if p[:floor_sub_unit_images].present? + sub_unit.update_attributes(p) + sub_unit.save + end + if params[:images_to_destroy].present? + params[:images_to_destroy].each do |id| + image = FloorSubUnitImage.find(id) rescue nil + image.destroy if !image.nil? + end + end + redirect_to "/admin/spaces/#{sub_unit.floor_unit.floor.to_param}/#{sub_unit.floor_unit.to_param}/sub_units" + end + + def upload_sub_unit_image + image = FloorSubUnitImage.new(image_params) + image.save + render :json => {"success" => true,"id" => image.id.to_s}.to_json + end + + def create_sub_unit + sub_unit = FloorSubUnit.new(sub_unit_params) + sub_unit.save + respond_to do |format| + format.html {redirect_to "/admin/spaces/#{sub_unit.floor_unit.floor.to_param}/#{sub_unit.floor_unit.to_param}/sub_units"} + format.js {render :json => {"success" => true, "unit" => {"id" => sub_unit.id.to_s, "title" => sub_unit.title}}.to_json} + end + end + + def unit_layout + @floor_unit = FloorUnit.find_by(:uid => params[:unit_id].split("-").last) rescue nil + end + + def save_unit_layout + floor_unit = FloorUnit.find(params[:unit_id]) rescue nil + if !floor_unit.nil? + floor_unit.layout = params[:layout_html] + floor_unit.save + end + render :json => {"success" => true}.to_json + end + + + private + def sub_unit_params + p = params.require(:floor_sub_unit).permit! + if p[:floor_sub_unit_images].present? + images = [] + p[:floor_sub_unit_images].each do |id| + image = FloorSubUnitImage.find(id) rescue nil + images << image if !image.nil? + end + p[:floor_sub_unit_images] = images + end + p + end + + def image_params + params.require(:floor_sub_unit_image).permit! + end + def floor_params params.require(:floor).permit! end diff --git a/app/models/floor_sub_unit.rb b/app/models/floor_sub_unit.rb new file mode 100644 index 0000000..a0d8c67 --- /dev/null +++ b/app/models/floor_sub_unit.rb @@ -0,0 +1,11 @@ +class FloorSubUnit + include Mongoid::Document + include Mongoid::Timestamps + include Slug + + field :title, as: :slug_title, localize: true + + has_many :floor_sub_unit_images, :autosave => true, :dependent => :destroy + belongs_to :floor_unit + +end \ No newline at end of file diff --git a/app/models/floor_sub_unit_image.rb b/app/models/floor_sub_unit_image.rb new file mode 100644 index 0000000..de0940e --- /dev/null +++ b/app/models/floor_sub_unit_image.rb @@ -0,0 +1,9 @@ +class FloorSubUnitImage + include Mongoid::Document + include Mongoid::Timestamps + + mount_uploader :image, ImageUploader + + belongs_to :floor_sub_unit + +end \ No newline at end of file diff --git a/app/models/floor_unit.rb b/app/models/floor_unit.rb index bf8dd24..30995d4 100644 --- a/app/models/floor_unit.rb +++ b/app/models/floor_unit.rb @@ -1,11 +1,15 @@ class FloorUnit include Mongoid::Document include Mongoid::Timestamps + include Slug - field :title + field :title, as: :slug_title + field :layout + belongs_to :floor + has_many :floor_sub_units - mount_uploader :layout, ImageUploader + mount_uploader :layout_image, ImageUploader end \ No newline at end of file diff --git a/app/views/admin/spaces/_floor.html.erb b/app/views/admin/spaces/_floor.html.erb index 035b99d..98b62e9 100644 --- a/app/views/admin/spaces/_floor.html.erb +++ b/app/views/admin/spaces/_floor.html.erb @@ -1,7 +1,7 @@ <%= floor.title %> - <% if !floor.floor_units.blank? %> + <% if !floor.layout_image.url.nil? %> Floor Layout <% end %> Edit Floor diff --git a/app/views/admin/spaces/_floor_unit.html.erb b/app/views/admin/spaces/_floor_unit.html.erb index 4e1c5e8..8ad35d2 100644 --- a/app/views/admin/spaces/_floor_unit.html.erb +++ b/app/views/admin/spaces/_floor_unit.html.erb @@ -1,8 +1,12 @@
  • - +
    - " > + " >

    <%= floor_unit.title %>

    + Edit | Delete + <% if !floor_unit.layout_image.thumb.url.nil? %> + | Layout + <% end %>
  • \ No newline at end of file diff --git a/app/views/admin/spaces/_floor_unit_form.html.erb b/app/views/admin/spaces/_floor_unit_form.html.erb index afb7ac9..338426c 100644 --- a/app/views/admin/spaces/_floor_unit_form.html.erb +++ b/app/views/admin/spaces/_floor_unit_form.html.erb @@ -25,10 +25,10 @@
    -
    +
    - <% if @floor_unit.layout.file %> - <%= image_tag @floor_unit.layout %> + <% if @floor_unit.layout_image.file %> + <%= image_tag @floor_unit.layout_image %> <% else %> <% end %> @@ -37,12 +37,12 @@ <%= t(:select_image) %> <%= t(:change) %> - <%= f.file_field :layout %> + <%= f.file_field :layout_image %> <%= t(:cancel) %>
    @@ -56,7 +56,11 @@
    - <%= f.hidden_field :floor_id, value: @floor.id %> + <% if params[:action] == "add_floor_unit" %> + <%= f.hidden_field :floor_id, value: @floor.id %> + <% elsif params[:action] == "edit_floor_unit" %> + <%= hidden_field_tag :unit_id, @floor_unit.id.to_s %> + <% end %> <%= f.submit t('submit'), class: 'btn btn-primary' %> <%= link_to t('cancel'), "/admin/spaces/#{@floor.building.to_param}/#{@floor.to_param}/units", :class=>"btn" %>
    \ No newline at end of file diff --git a/app/views/admin/spaces/_sub_unit.html.erb b/app/views/admin/spaces/_sub_unit.html.erb new file mode 100644 index 0000000..40838fd --- /dev/null +++ b/app/views/admin/spaces/_sub_unit.html.erb @@ -0,0 +1,7 @@ +
  • +
    + " > +
    +

    <%= sub_unit.title %>

    + Edit | Delete +
  • \ No newline at end of file diff --git a/app/views/admin/spaces/_sub_unit_form.html.erb b/app/views/admin/spaces/_sub_unit_form.html.erb new file mode 100644 index 0000000..cba9d77 --- /dev/null +++ b/app/views/admin/spaces/_sub_unit_form.html.erb @@ -0,0 +1,83 @@ +<% content_for :page_specific_css do %> + <%= stylesheet_link_tag "lib/main-forms" %> + <%= stylesheet_link_tag "lib/main-list" %> + <%= stylesheet_link_tag "lib/dropzone" %> + <%= stylesheet_link_tag "//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" %> + <%= stylesheet_link_tag "//cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.6/animate.min.css" %> +<% end %> +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "lib/dropzone" %> + <%= javascript_include_tag "validator" %> +<% end %> + +
    + + Uploading... +
    + + +
    + +
    + + +
    + + <% @site_in_use_locales.each do |locale| %> + <%= f.fields_for :title_translations do |f| %> +
    + <%= f.label :title.to_s + " (" + locale.to_s + ")", :class => "control-label muted" %> +
    + <%= f.text_field locale, placeholder: t("space.sub_unit_name"), data: {"fv-validation" => "required;", "fv-messages" => "Cannot be empty;"}, :value => @sub_unit.title_translations[locale.to_s] %> +
    +
    + <% end %> + <% end %> + +
    + +
    + <% if params[:action] == "edit_sub_unit" %> +
    + <% @sub_unit.floor_sub_unit_images.each do |image| %> +
    +
    +
    + +
    +
    + + +
    +
    +
    + <% end %> +
    + <% end %> +
    +
    +
    + +
    +
    + +
    +
    + +
    +
    +
    + + + +
    + <% if params[:action] == "add_sub_unit" %> + <%= f.hidden_field :floor_unit, :value => @floor_unit.id %> + <% elsif params[:action] == "edit_sub_unit" %> + <%= hidden_field_tag :floor_sub_unit_id, @sub_unit.id.to_s %> + <% end %> + <%= f.submit t('submit'), class: 'btn btn-primary', :id => "floor-sub-unit-form-btn" %> +
    \ No newline at end of file diff --git a/app/views/admin/spaces/add_sub_unit.html.erb b/app/views/admin/spaces/add_sub_unit.html.erb new file mode 100644 index 0000000..f0e80a9 --- /dev/null +++ b/app/views/admin/spaces/add_sub_unit.html.erb @@ -0,0 +1,85 @@ +<%= form_for @sub_unit, url: "/admin/space/create_sub_unit", html: {class: "form-horizontal main-forms"} do |f| %> +
    + <%= render :partial => "sub_unit_form", locals: {f: f} %> +
    +<% end %> + + \ No newline at end of file diff --git a/app/views/admin/spaces/edit_floor_unit.html.erb b/app/views/admin/spaces/edit_floor_unit.html.erb new file mode 100644 index 0000000..694306e --- /dev/null +++ b/app/views/admin/spaces/edit_floor_unit.html.erb @@ -0,0 +1,5 @@ +<%= form_for @floor_unit, url: "/admin/space/update_floor_unit", html: {class: "form-horizontal main-forms"} do |f| %> +
    + <%= render :partial => "floor_unit_form", locals: {f: f} %> +
    +<% end %> \ No newline at end of file diff --git a/app/views/admin/spaces/edit_sub_unit.html.erb b/app/views/admin/spaces/edit_sub_unit.html.erb new file mode 100644 index 0000000..1bf74cd --- /dev/null +++ b/app/views/admin/spaces/edit_sub_unit.html.erb @@ -0,0 +1,85 @@ +<%= form_for @sub_unit, url: "/admin/space/update_sub_unit", html: {class: "form-horizontal main-forms edit_sub_unit_form"} do |f| %> +
    + <%= render :partial => "sub_unit_form", locals: {f: f} %> +
    +<% end %> + + \ No newline at end of file diff --git a/app/views/admin/spaces/floor_layout.html.erb b/app/views/admin/spaces/floor_layout.html.erb index 097f689..2cebf8c 100644 --- a/app/views/admin/spaces/floor_layout.html.erb +++ b/app/views/admin/spaces/floor_layout.html.erb @@ -5,26 +5,42 @@ <% content_for :page_specific_javascript do %> <%= javascript_include_tag "attrchange" %> <% end %> - -
    - -
    +
    +

    <%= @floor.title %>

    +
    +<% if @floor.layout == nil %> +
    + +
    +
    +<% else %> + <%= @floor.layout.html_safe %> +<% end %> +
    +
    + +
    +<% if !@floor.layout.nil? %> + +<% end %> diff --git a/app/views/admin/spaces/sub_units.html.erb b/app/views/admin/spaces/sub_units.html.erb new file mode 100644 index 0000000..3c196e0 --- /dev/null +++ b/app/views/admin/spaces/sub_units.html.erb @@ -0,0 +1,12 @@ +<% content_for :page_specific_css do %> + <%= stylesheet_link_tag "space" %> +<% end %> +
      + <%= render :partial => "sub_unit", :collection => @floor_unit.floor_sub_units %> +
    + + \ No newline at end of file diff --git a/app/views/admin/spaces/unit_layout.html.erb b/app/views/admin/spaces/unit_layout.html.erb new file mode 100644 index 0000000..007c5a8 --- /dev/null +++ b/app/views/admin/spaces/unit_layout.html.erb @@ -0,0 +1,306 @@ +<% content_for :page_specific_css do %> + <%= stylesheet_link_tag "https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" %> + <%= stylesheet_link_tag "space" %> +<% end %> +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "attrchange" %> +<% end %> +
    +

    <%= @floor_unit.title %>

    +
    +<% if @floor_unit.layout == nil %> +
    + +
    +
    +<% else %> + <%= @floor_unit.layout.html_safe %> +<% end %> +
    +
    + +
    +
    + +<% if !@floor_unit.layout.nil? %> + +<% end %> + + + + + + diff --git a/app/views/admin/spaces/units.html.erb b/app/views/admin/spaces/units.html.erb index 052b173..a52b029 100644 --- a/app/views/admin/spaces/units.html.erb +++ b/app/views/admin/spaces/units.html.erb @@ -2,7 +2,7 @@ <%= stylesheet_link_tag "space" %> <% end %>
      - <%= render :partial => "floor_unit", :collection => @floor.floor_units %> + <%= render :partial => "floor_unit", :collection => @floor.floor_units.asc(:title) %>
    diff --git a/config/locales/en.yml b/config/locales/en.yml index aa644fb..722cc62 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -9,4 +9,7 @@ en: simple_layout: Simple Layout detailed_layout: Detailed Layout floor_unit_name: Unit Name - save_layout: Save Layout \ No newline at end of file + save_layout: Save Layout + save_floor_layout: Save Layout + add_sub_units: Add SubUnit + sub_unit_name: SubUnit Name \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 3b65da6..4cb42a3 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -9,4 +9,7 @@ zh_tw: simple_layout: Simple Layout detailed_layout: Detailed Layout floor_unit_name: Unit Name - save_layout: Save Layout \ No newline at end of file + save_layout: Save Layout + save_floor_layout: Save Layout + add_sub_units: Add SubUnit + sub_unit_name: SubUnit Name \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index ae4f3e7..eedab94 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,10 +6,30 @@ Rails.application.routes.draw do namespace :admin do post "space/add_floor", to: 'spaces#add_floor' post "space/update_floor", to: 'spaces#update_floor' - post "space/create_floor_unit", to: 'spaces#create_floor_unit' + post "space/save_floor_layout", to: 'spaces#save_floor_layout' + + post "space/create_floor_unit", to: 'spaces#create_floor_unit' + patch "space/update_floor_unit", to: 'spaces#update_floor_unit' + patch "space/update_sub_unit", to: 'spaces#update_sub_unit' + post "space/save_unit_layout", to: 'spaces#save_unit_layout' + + post "space/upload_sub_unit_image", to: 'spaces#upload_sub_unit_image' + post "space/create_sub_unit", to: 'spaces#create_sub_unit' + + get "spaces/:building_id/:floor_id/units", to: 'spaces#units' - get "spaces/floor/:floor_id/add_floor_unit", to: 'spaces#add_floor_unit' + get "spaces/floor/:floor_id/add_floor_unit", to: 'spaces#add_floor_unit' + get "spaces/floor/:floor_id/layout", to: 'spaces#floor_layout' + get "spaces/unit/:unit_id/layout", to: 'spaces#unit_layout' + + get "spaces/unit/:unit_id/edit", to: 'spaces#edit_floor_unit' + get "spaces/:floor_id/:unit_id/sub_units", to: 'spaces#sub_units' + + get "spaces/unit/:unit_id/add_sub_unit", to: 'spaces#add_sub_unit' + get "spaces/sub_unit/:sub_unit_id/edit", to: 'spaces#edit_sub_unit' + + delete "spaces/unit/:unit_id/delete", to: 'spaces#delete_floor_unit' delete "spaces/floor/:floor_id/delete", to: 'spaces#delete_floor' resources :spaces do get "floors"