From 7c0295d9d83313a4f6300f2e2ab33f69081cbada Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Tue, 13 Oct 2015 18:55:18 +0800 Subject: [PATCH] space module mods --- app/controllers/admin/spaces_controller.rb | 15 +++++++++++++++ app/controllers/spaces_controller.rb | 6 ++++-- app/models/building.rb | 1 + app/views/admin/spaces/_building.html.erb | 2 +- app/views/admin/spaces/_form.html.erb | 11 ++++++++++- app/views/admin/spaces/edit.html.erb | 5 +++++ lib/space/engine.rb | 9 +++++++++ 7 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 app/views/admin/spaces/edit.html.erb diff --git a/app/controllers/admin/spaces_controller.rb b/app/controllers/admin/spaces_controller.rb index 61bc34c..e0c3a39 100644 --- a/app/controllers/admin/spaces_controller.rb +++ b/app/controllers/admin/spaces_controller.rb @@ -8,12 +8,27 @@ class Admin::SpacesController < OrbitAdminController @building = Building.new end + def edit + uid = params[:id].split("-").last + @building = Building.find_by(:uid => uid) rescue nil + end + def create building = Building.new(building_params) building.save redirect_to admin_spaces_path end + def update + uid = params[:id].split("-").last + building = Building.find_by(:uid => uid) rescue nil + if !building.nil? + building.update_attributes(building_params) + building.save + end + redirect_to admin_spaces_path + end + def floors uid = params[:space_id].split("-").last @building = Building.find_by(:uid => uid) rescue nil diff --git a/app/controllers/spaces_controller.rb b/app/controllers/spaces_controller.rb index 3d4e479..3c7fc8f 100644 --- a/app/controllers/spaces_controller.rb +++ b/app/controllers/spaces_controller.rb @@ -1,13 +1,15 @@ class SpacesController < ApplicationController def index - buildings = Building.all.collect do |building| + 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" => OrbitHelper.url_to_show(floor.to_param) + "link_to_show" => link } end { diff --git a/app/models/building.rb b/app/models/building.rb index 3948135..eadb93c 100644 --- a/app/models/building.rb +++ b/app/models/building.rb @@ -1,6 +1,7 @@ class Building include Mongoid::Document include Mongoid::Timestamps + include OrbitCategory::Categorizable include Slug field :title, as: :slug_title, localize: true diff --git a/app/views/admin/spaces/_building.html.erb b/app/views/admin/spaces/_building.html.erb index 12700e4..1738c7b 100644 --- a/app/views/admin/spaces/_building.html.erb +++ b/app/views/admin/spaces/_building.html.erb @@ -5,6 +5,6 @@

<%= building.title %>

- Edit | Delete + Edit | Delete
\ No newline at end of file diff --git a/app/views/admin/spaces/_form.html.erb b/app/views/admin/spaces/_form.html.erb index feee94a..8bd5f61 100644 --- a/app/views/admin/spaces/_form.html.erb +++ b/app/views/admin/spaces/_form.html.erb @@ -20,11 +20,20 @@
<%= f.label :title.to_s + " (" + locale.to_s + ")", :class => "control-label muted" %>
- <%= f.text_field locale, placeholder: t("space.building_name") %> + <%= f.text_field locale, placeholder: t("space.building_name"), :value => @building.title_translations[locale.to_s] %>
<% end %> <% end %> + + +
+ +
+ <%= select_category(f, ModuleApp.find_by_key("space")) %> +
+
+
diff --git a/app/views/admin/spaces/edit.html.erb b/app/views/admin/spaces/edit.html.erb new file mode 100644 index 0000000..33d26b6 --- /dev/null +++ b/app/views/admin/spaces/edit.html.erb @@ -0,0 +1,5 @@ +<%= form_for @building, url: admin_space_path(@building), html: {class: "form-horizontal main-forms"} do |f| %> +
+ <%= render :partial => "form", locals: {f: f} %> +
+<% end %> \ No newline at end of file diff --git a/lib/space/engine.rb b/lib/space/engine.rb index a82d2f9..69921c3 100644 --- a/lib/space/engine.rb +++ b/lib/space/engine.rb @@ -5,6 +5,7 @@ module Space module_label "space.space" base_url File.expand_path File.dirname(__FILE__) frontend_enabled + categorizable side_bar do head_label_i18n 'space.space', icon_class: "icons-leaf" available_for "users" @@ -16,6 +17,14 @@ module Space :priority=>1, :active_for_action=>{'admin/spaces'=>'index'}, :available_for => 'users' + + context_link 'categories', + :link_path=>"admin_module_app_categories_path" , + :link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'space').id}", + :priority=>3, + :active_for_action=>{'admin/spaces'=>'categories'}, + :active_for_category => 'Announcement', + :available_for => 'managers' end end end