From 2530dace02df0a0253b05b8e0cf37f045be78e84 Mon Sep 17 00:00:00 2001 From: chris Date: Sun, 20 Oct 2013 18:44:04 +0800 Subject: [PATCH] Change the parser_front_end to be used in the structure for page edit, new_ui:save_pages must be run --- app/controllers/admin/pages_controller.rb | 3 +- app/controllers/pages_controller.rb | 6 ++ app/views/admin/items/_node.html.erb | 2 +- app/views/layouts/page_layout.html.erb | 15 +++++ lib/parsers/parser_common.rb | 2 +- lib/parsers/parser_front_end.rb | 70 +++++++++++++++-------- lib/tasks/new_ui.rake | 9 +++ 7 files changed, 79 insertions(+), 28 deletions(-) diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index 7a966ffe9..bbc63aebf 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -5,7 +5,8 @@ class Admin::PagesController < Admin::ItemsController def show @item = Page.find(params[:id]) @no_orbit_bar = true - render layout: 'page_layout' + @edit = true + render :text => parse_page_content(@item), :layout => 'page_layout' end def new diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index ec1008715..48261bf74 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -26,7 +26,13 @@ class PagesController < ApplicationController when 'Page' if params[:clicked_field_name] render_page({"clicked_field_name"=>params["clicked_field_name"]}) unless save_from_no_lang_for_page + elsif params[:edit] + if request.referer && request.referer.ends_with?("admin/items") + redirect_to admin_page_url(@item) else + render :file => "#{Rails.root}/public/403.html", :status => 403 + end + else render_page(params.except(:controller, :action, :page_name)) unless save_from_no_lang_for_page end when 'Link' diff --git a/app/views/admin/items/_node.html.erb b/app/views/admin/items/_node.html.erb index fd5dcda97..d60615a55 100644 --- a/app/views/admin/items/_node.html.erb +++ b/app/views/admin/items/_node.html.erb @@ -17,7 +17,7 @@ <%= link_to node.title, node.url %> <% end %>
- <%= link_to content_tag(:i, nil, class: "icon-eye-open"), eval("admin_#{node.class.to_s.downcase}_path(node)"), class: "view-page open-slide tip", title: t(:view), data: {title: node.title} if node.class.to_s.eql?('Page') %> + <%= link_to content_tag(:i, nil, class: "icon-eye-open"), "/#{node.path}?edit=true", class: "view-page open-slide tip", title: t(:view), data: {title: node.title} if node.class.to_s.eql?('Page') %> <%= link_to content_tag(:i, nil, class: "icon-edit"), eval("edit_admin_#{node.class.to_s.downcase}_path(node)"), class: "open-slide tip #{node.class.to_s.downcase} edit", title: t(:edit), data: {title: t(:edit)} %> <%= link_to content_tag(:i, nil, class: "icons-newspaper"), new_admin_page_path(:parent_id => node.id), class: "open-slide tip page", title: t(:add_page), data: {title: t(:add_page)} if node.class.to_s.eql?('Page') %> <%= link_to content_tag(:i, nil, class: "icon-link"), new_admin_link_path(:parent_id => node.id), class: "open-slide tip link", title: t(:add_link), data: {title: t(:add_link)} if node.class.to_s.eql?('Page') %> diff --git a/app/views/layouts/page_layout.html.erb b/app/views/layouts/page_layout.html.erb index 1c3dc4ee5..ea2f220b7 100644 --- a/app/views/layouts/page_layout.html.erb +++ b/app/views/layouts/page_layout.html.erb @@ -26,5 +26,20 @@ $('#myModal').modal('show') <% end -%> + <% if @edit %> + + + <% end %> diff --git a/lib/parsers/parser_common.rb b/lib/parsers/parser_common.rb index 360976abd..bb9e4a4a5 100644 --- a/lib/parsers/parser_common.rb +++ b/lib/parsers/parser_common.rb @@ -272,7 +272,7 @@ module ParserCommon part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil part_title = part.title rescue nil if edit - ret << "
" if part + ret << "
" if part ret << "' diff --git a/lib/parsers/parser_front_end.rb b/lib/parsers/parser_front_end.rb index f56a0c93f..0c83bf95b 100644 --- a/lib/parsers/parser_front_end.rb +++ b/lib/parsers/parser_front_end.rb @@ -25,6 +25,21 @@ module ParserFrontEnd # category = params[:category_id].blank? ? page[:category] : params[:category_id] body = Nokogiri::HTML(page.content) + + if @edit + body.css('.page_part').each do |page_part| + ret = '' + ret << "
" + ret << "' + ret << page_part.child.to_html rescue nil + ret << '
' + fragment = Nokogiri::HTML::DocumentFragment.new(body, ret) + page_part.swap(fragment) + end + end + body.css('orbit_front').each do |front| if front['value'] fragment = Nokogiri::HTML::DocumentFragment.new(body, "
#{eval(front['value']).to_s}
") @@ -43,6 +58,7 @@ module ParserFrontEnd end front.swap(fragment) end + body.to_html end @@ -139,34 +155,38 @@ module ParserFrontEnd ret << "
" else part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil - case part.kind - when 'text' - ret << part.content_translations[locale.to_s] rescue '' - when 'module_widget' - # url = "/panel/\#{part.module_app.key}/widget/\#{part.widget_path}?inner=true" - # options = "&part_id=\#{part.id}&category_id=\#{!part[:category].blank? ? part[:category].blank? : category}&tag_id=\#{!part[:tag].blank? ? part[:tag] : tag}&page=\#{params[:page]}&search_query=\#{params[:search_query]}&part_title=\#{Rack::Utils.escape(part_title).gsub(\"\+\", \"\%20\") rescue nil}" - # ret << "
" - url = case part.widget_path - when 'default_widget' - "/panel/orbit_app/widget/\#{part.widget_style}?inner=true" - else - "/panel/\#{part.module_app.key}/widget/\#{part.widget_path}?inner=true" - end + if part + ret << "
" + case part.kind + when 'text' + ret << part.content_translations[locale.to_s] rescue '' + when 'module_widget' + # url = "/panel/\#{part.module_app.key}/widget/\#{part.widget_path}?inner=true" + # options = "&part_id=\#{part.id}&category_id=\#{!part[:category].blank? ? part[:category].blank? : category}&tag_id=\#{!part[:tag].blank? ? part[:tag] : tag}&page=\#{params[:page]}&search_query=\#{params[:search_query]}&part_title=\#{Rack::Utils.escape(part_title).gsub(\"\+\", \"\%20\") rescue nil}" + # ret << "
" + url = case part.widget_path + when 'default_widget' + "/panel/orbit_app/widget/\#{part.widget_style}?inner=true" + else + "/panel/\#{part.module_app.key}/widget/\#{part.widget_path}?inner=true" + end - categories_str=part[:category].collect{|t| "base_category_id[]=#{t}"}.join('&') - tags_str=part[:tag].collect{|t| "base_tag_id[]=#{t}"}.join('&') - categories_str = "&#{categories_str}" unless categories_str.blank? - tags_str = "&#{tags_str}" unless tags_str.blank? + categories_str=part[:category].collect{|t| "base_category_id[]=#{t}"}.join('&') + tags_str=part[:tag].collect{|t| "base_tag_id[]=#{t}"}.join('&') + categories_str = "&#{categories_str}" unless categories_str.blank? + tags_str = "&#{tags_str}" unless tags_str.blank? - options = "&part_id=\#{part.id}#{categories_str}#{tags_str}&page=\#{params[:page]}&search_query=\#{params[:search_query]}&clicked_field_name=\#{params[:clicked_field_name]}&part_title=\#{Rack::Utils.escape(part_title).gsub(\"\+\", \"\%20\") rescue nil}&item_type=page_part&tag_id=\#{params[:tag_id]}&category_id=\#{params[:category_id]}" + options = "&part_id=\#{part.id}#{categories_str}#{tags_str}&page=\#{params[:page]}&search_query=\#{params[:search_query]}&clicked_field_name=\#{params[:clicked_field_name]}&part_title=\#{Rack::Utils.escape(part_title).gsub(\"\+\", \"\%20\") rescue nil}&item_type=page_part&tag_id=\#{params[:tag_id]}&category_id=\#{params[:category_id]}" - ret << "" - - when 'public_r_tag' - ret << send("generate_#{part.public_r_tag}s", part.public_r_tag_object_id, page) - else - '' - end if part + ret << "" + + when 'public_r_tag' + ret << send("generate_#{part.public_r_tag}s", part.public_r_tag_object_id, page) + else + '' + end + ret << "
" + end end scope = "<#{content.name}" content.attributes.each_pair do |key, value| diff --git a/lib/tasks/new_ui.rake b/lib/tasks/new_ui.rake index 86d5e8d16..d9fc6a243 100644 --- a/lib/tasks/new_ui.rake +++ b/lib/tasks/new_ui.rake @@ -24,6 +24,7 @@ namespace :new_ui do migrate_approval_on_object migrate_managers migrate_ad_images_dates + migrate_ad_banners end # :category_name is optional, depends on the naming of the category model: if no conventional, specify it @@ -47,6 +48,10 @@ namespace :new_ui do migrate_ad_banners end + task :save_pages => :environment do + save_pages + end + def migrate_categories(args = nil) if args && args[:app_key] && args[:model_name] migrate_category(args[:app_key], args[:model_name], args[:category_name]) @@ -232,4 +237,8 @@ namespace :new_ui do end end + def save_pages + Page.all(&:save) + end + end