From 5b289bc1d2f08fb164db35b1218f2d1633634947 Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 3 Jan 2013 12:16:02 +0800 Subject: [PATCH 1/4] Fix old tags --- app/controllers/admin/tags_controller.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/tags_controller.rb b/app/controllers/admin/tags_controller.rb index cd5e00c9..8e8a4e6b 100644 --- a/app/controllers/admin/tags_controller.rb +++ b/app/controllers/admin/tags_controller.rb @@ -46,12 +46,16 @@ class Admin::TagsController < OrbitBackendController protected - def set_module_app - @module_app ||= ModuleApp.first(:conditions => {:key => @app_title.underscore}) rescue nil - end - def get_tags @tags = (@module_app ? @module_app.tags : Tag.all) end + + def setup_vars + @app_key = request.env['HTTP_REFERER'].split('/')[4] + if @app_key + @app_key.gsub!(/[?].*/, '') + @module_app = ModuleApp.first(conditions: {:key => @app_key}) + end + end end From fa83dbf79140f95a5abd985596fa6068af6a148f Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 3 Jan 2013 19:12:52 +0800 Subject: [PATCH 2/4] Fix order in structure --- app/models/item.rb | 4 ++-- app/models/page.rb | 11 +++-------- lib/tasks/migrate.rake | 12 ++++++++++++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/app/models/item.rb b/app/models/item.rb index 1809e2b2..6b34d8b8 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -47,10 +47,10 @@ class Item new_parent = Item.find(new_parent) current_position_sibling = find_by_parent_and_position(new_parent, position.to_i) if current_position_sibling - current_position_sibling.at_bottom? ? move_below(current_position_sibling) : move_above(current_position_sibling) + move_above(current_position_sibling) elsif self.parent != new_parent self.parent = new_parent - save! + save end end end diff --git a/app/models/page.rb b/app/models/page.rb index 5c1a7b24..bc257eaa 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -24,14 +24,12 @@ class Page < Item has_many :page_metas, :autosave => true, :dependent => :destroy accepts_nested_attributes_for :page_parts, :allow_destroy => true - before_save :delete_empty_frontend_field before_save :create_parts, if: Proc.new { |page| page.new_record? || page.design_id_changed? } - after_save :generate_html + before_save :delete_empty_frontend_field, :generate_html -# protected + protected def create_parts - page_design = self.design parent = self.parent menu_part = parent.page_parts.detect{|page_part| page_part.kind.eql?('public_r_tag') && page_part.public_r_tag.eql?('sub_menu') && page_part.public_r_tag_object_id.eql?(parent.id.to_s)} if parent @@ -73,10 +71,7 @@ class Page < Item end def generate_html - Page.without_callback(:save, :after, :generate_html) do - self.content_translations = parse_page_noko(self, Site.first) - self.save - end + self.content_translations = parse_page_noko(self, Site.first) end end diff --git a/lib/tasks/migrate.rake b/lib/tasks/migrate.rake index 74d1f53a..216a3ac1 100644 --- a/lib/tasks/migrate.rake +++ b/lib/tasks/migrate.rake @@ -350,4 +350,16 @@ namespace :migrate do ModuleApp.new.from_json(File.open("#{Rails.root}/vendor/built_in_modules/gallery/gallery.json").read).save end + task :reorder_items => :environment do + reorder_children(Item.root) + end + + def reorder_children(parent) + parent.children.each_with_index do |child, i| + child.position = i + child.save + reorder_children(child) if child.children + end + end + end From a70110f787560e128df473603f87cfdba6ec9119 Mon Sep 17 00:00:00 2001 From: Fu Matthew Date: Thu, 3 Jan 2013 19:38:14 +0800 Subject: [PATCH 3/4] make default widget works without init --- app/controllers/default_widget_controller.rb | 45 ++++++++++++++++++++ app/models/module_app.rb | 6 +++ app/views/default_widget/typeA.html.erb | 19 +++++++++ app/views/default_widget/typeB.html.erb | 22 ++++++++++ app/views/default_widget/typeC.html.erb | 15 +++++++ config/routes.rb | 3 +- lib/tasks/migrate.rake | 6 +++ 7 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 app/controllers/default_widget_controller.rb create mode 100644 app/views/default_widget/typeA.html.erb create mode 100644 app/views/default_widget/typeB.html.erb create mode 100644 app/views/default_widget/typeC.html.erb diff --git a/app/controllers/default_widget_controller.rb b/app/controllers/default_widget_controller.rb new file mode 100644 index 00000000..77887e8e --- /dev/null +++ b/app/controllers/default_widget_controller.rb @@ -0,0 +1,45 @@ +class DefaultWidgetController< OrbitWidgetController + + def front_end_available(var) + @page_part = PagePart.find params[:part_id] + @page_part.module_app.enable_frontend? + end + + def default_widget + @tag_class = nil + + @default_widget = @page_part.module_app.get_default_widget + @widget_image_field = @default_widget[:image] + data_limit = @page_part.widget_data_count.is_a?(Fixnum) ? @page_part.widget_data_count : (@page_part.widget_data_count.to_i rescue 3) + @data = eval(@default_widget[:query]).limit(data_limit).includes(@widget_image_field) + @fields = @page_part.widget_field + +# binding.pry + + case params[:type] + when "typeA" + @tag_class = 'defulat_widget_typeA' + render "typeA" + when /typeB_/ + @tag_class = "defulat_widget_#{params[:type]}" + render "typeB" + when "typeC" + @tag_class = 'defulat_widget_typeC' + render "typeC" + end + + + + # {"inner"=>"true", + # "category_id"=>"false", + # "tag_id"=>"", + # "page"=>"", + # "search_query"=>"", + # "part_title"=>"", + # "part_id"=>"50ac426f83e75219d20000a7", + # "controller"=>"default_widget", + # "action"=>"default_widget", + # "type"=>"typeA"} + end + +end diff --git a/app/models/module_app.rb b/app/models/module_app.rb index 50a6c268..b3eb4f1b 100644 --- a/app/models/module_app.rb +++ b/app/models/module_app.rb @@ -30,6 +30,12 @@ class ModuleApp before_save :set_key + #>>>>>>>>>>>>> remove after app config applied + def get_default_widget + {:query=>'Bulletin.all',:image=>nil} + end + #<<<<<<<<<<<< + def is_manager?(user) managing_users.include?(user) end diff --git a/app/views/default_widget/typeA.html.erb b/app/views/default_widget/typeA.html.erb new file mode 100644 index 00000000..22422516 --- /dev/null +++ b/app/views/default_widget/typeA.html.erb @@ -0,0 +1,19 @@ +<%= content_tag :div,:class=>@tag_class do%> +
+ + + + <% @fields.each do |field|%> + + <% end %> + + + <% @data.each do |row_data| %> + + <% @fields.each do |field|%> + + <% end %> + + <% end %> +
<%= content_tag(:span,field[0],:class=>field[1])%>
<%= content_tag(:span,row_data.send(field[0]),:class=>field[1])%>
+ <% end %> diff --git a/app/views/default_widget/typeB.html.erb b/app/views/default_widget/typeB.html.erb new file mode 100644 index 00000000..8c3cc34e --- /dev/null +++ b/app/views/default_widget/typeB.html.erb @@ -0,0 +1,22 @@ +<%= content_tag :div,:class=>@tag_class do%> +
    + + <% @data.each do |row_data| %> + <%= content_tag(:li) do %> +
    + <%= image_tag row_data.send(@widget_image_field)%> + +
    +
    + <% @fields.each do |field|%> + <%= content_tag(:span,row_data.send(field[0]),:class=>field[1])%> + <% end %> +
    + + <% end %> + <% end %> + + +
+
more
+ <% end %> diff --git a/app/views/default_widget/typeC.html.erb b/app/views/default_widget/typeC.html.erb new file mode 100644 index 00000000..4fceefc3 --- /dev/null +++ b/app/views/default_widget/typeC.html.erb @@ -0,0 +1,15 @@ +<%= content_tag :div,:class=>@tag_class do%> +
+ <%= image_tag @data.first.send(@widget_image_field)%> +
+
    + <% @data.each do |row_data| %> + <%= content_tag(:li) do %> + <% @fields.each do |field|%> + <%= content_tag(:span,row_data.send(field[0]),:class=>field[1])%> + <% end %> + <% end %> + <% end %> +
+
more
+ <% end %> diff --git a/config/routes.rb b/config/routes.rb index 2c52f6ec..f97f4ae7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -241,7 +241,8 @@ Orbit::Application.routes.draw do match 'show_sitemap' => 'front#show_sitemap', :as => :front_show_sitemap end - + match '/panel/orbit_app/widget/:type' => 'default_widget#default_widget' + match '/panel/:app_name/front_end/:app_action/:id(/:controller_action)' => 'pages#show_from_link', :constraints => lambda { |request| !request.query_string.include?("inner=true") } diff --git a/lib/tasks/migrate.rake b/lib/tasks/migrate.rake index 74d1f53a..e8032542 100644 --- a/lib/tasks/migrate.rake +++ b/lib/tasks/migrate.rake @@ -350,4 +350,10 @@ namespace :migrate do ModuleApp.new.from_json(File.open("#{Rails.root}/vendor/built_in_modules/gallery/gallery.json").read).save end + task :make_default_widget_work_config => :environment do + a = ModuleApp.where(:key=>'announcement').first + a.widgets[:default_widget] = ['typeA','typeC','typeB_style2','typeB_style3','typeB_style4'] + a.widget_fields = ["title","bulletin_category","postdate"] + a.save + end end From 49e289e0fd235c720969a638e79a4b045316b4f0 Mon Sep 17 00:00:00 2001 From: Fu Matthew Date: Thu, 3 Jan 2013 20:07:05 +0800 Subject: [PATCH 4/4] fixing default widget error when needs image --- app/models/module_app.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/module_app.rb b/app/models/module_app.rb index b3eb4f1b..d0cd8886 100644 --- a/app/models/module_app.rb +++ b/app/models/module_app.rb @@ -32,9 +32,10 @@ class ModuleApp #>>>>>>>>>>>>> remove after app config applied def get_default_widget - {:query=>'Bulletin.all',:image=>nil} + {:query=>'Bulletin.all',:image=> 'image'} end - #<<<<<<<<<<<< + #<<<<<<<<<<<<@@ + def is_manager?(user) managing_users.include?(user)