From cb69ea5c5c75b7dcfa1770248b4cde7c3034d120 Mon Sep 17 00:00:00 2001 From: manson Date: Wed, 28 May 2014 20:05:39 +0800 Subject: [PATCH] Mobile Web --- app/controllers/application_controller.rb | 28 ++++++++- app/controllers/pages_controller.rb | 58 ++++++++++--------- app/helpers/application_helper.rb | 10 ++-- .../home/mobile/footer.html.erb | 8 +++ .../home/mobile/header.html.erb | 17 ++++++ .../home/mobile/index.html.erb | 36 ++++++++++++ .../orbit_bootstrap/home/mobile/menu.html.erb | 15 +++++ .../orbit_bootstrap/home/mobile/page.html.erb | 36 ++++++++++++ .../home/mobile/submenu.html.erb | 8 +++ .../announcement/mobile/index.html.erb | 14 +++++ .../modules/announcement/mobile/show.html.erb | 27 +++++++++ .../modules/archive/mobile/index.html.erb | 28 +++++++++ .../modules/faq/mobile/index.html.erb | 9 +++ .../modules/faq/mobile/show.html.erb | 15 +++++ .../modules/gallery/mobile/index.html.erb | 12 ++++ .../modules/gallery/mobile/show.html.erb | 11 ++++ .../web_resource/mobile/index.html.erb | 9 +++ app/uploaders/image_uploader.rb | 4 ++ config/routes.rb | 4 ++ 19 files changed, 316 insertions(+), 33 deletions(-) create mode 100644 app/templates/orbit_bootstrap/home/mobile/footer.html.erb create mode 100644 app/templates/orbit_bootstrap/home/mobile/header.html.erb create mode 100644 app/templates/orbit_bootstrap/home/mobile/index.html.erb create mode 100644 app/templates/orbit_bootstrap/home/mobile/menu.html.erb create mode 100644 app/templates/orbit_bootstrap/home/mobile/page.html.erb create mode 100644 app/templates/orbit_bootstrap/home/mobile/submenu.html.erb create mode 100644 app/templates/orbit_bootstrap/modules/announcement/mobile/index.html.erb create mode 100644 app/templates/orbit_bootstrap/modules/announcement/mobile/show.html.erb create mode 100644 app/templates/orbit_bootstrap/modules/archive/mobile/index.html.erb create mode 100644 app/templates/orbit_bootstrap/modules/faq/mobile/index.html.erb create mode 100644 app/templates/orbit_bootstrap/modules/faq/mobile/show.html.erb create mode 100644 app/templates/orbit_bootstrap/modules/gallery/mobile/index.html.erb create mode 100644 app/templates/orbit_bootstrap/modules/gallery/mobile/show.html.erb create mode 100644 app/templates/orbit_bootstrap/modules/web_resource/mobile/index.html.erb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6e686d0..8bb40e2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,7 +2,7 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. # protect_from_forgery with: :null_session - before_action :set_locale + before_action :set_locale, :set_mobile_web helper_method :current_site, :current_user def default_url_options(options={}) @@ -49,6 +49,32 @@ class ApplicationController < ActionController::Base current_user.nil? and !current_site.frontend_open end + def set_mobile_web + path = request.path.split('/') + is_mobile_path = ( (path[1].eql?("mobile") or path[2].eql?("mobile")) or params[:mobile].eql?("1") ) + + if params[:mobile].eql?("0") + session[:desktop] = true + session[:mobile] = false + $mobile= "" + redirect_to root_path if is_mobile_path + else + is_mobile_device = ( (request.user_agent =~ /iPhone|iPod|Android/) and !session[:desktop]) + $mobile = session[:mobile] ? "/mobile" : "" + + if current_site.mobile_on + if is_mobile_path or is_mobile_device + session[:desktop] = false + session[:mobile] = true + $mobile = "/mobile" + end + else + session[:mobile] = false + redirect_to root_path if is_mobile_path + end + end + end + def log_user_action unless (request.filtered_parameters['action'].eql? "system_info") and (request.filtered_parameters['controller'].eql? "admin/sites") log = UserAction.new diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 71a639f..c1a0070 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -30,12 +30,12 @@ class PagesController < ApplicationController impressionist(page) OrbitHelper.set_params params OrbitHelper.set_site_locale locale - render :html => render_final_page("home",page,true).html_safe + render :html => render_final_page("home#{$mobile}",page,true).html_safe end def show - path = request.original_fullpath.split('/') - if path.size <= 2 + path = request.path.split('/') + if path.size <= 2 or path.last.eql?("mobile") redirect_to root_path else if path.last.include? '-' @@ -174,32 +174,35 @@ class PagesController < ApplicationController parts = page.page_parts rescue [] @part_partials = {} - parts.each do |part| - subparts = part.sub_parts - partials = [] - subparts.each do |subpart| - if subpart.kind == "module_widget" - OrbitHelper.set_widget_data_count subpart.data_count - OrbitHelper.set_widget_categories subpart.categories - OrbitHelper.set_widget_module_app subpart.module - OrbitHelper.set_widget_item_url subpart - custom_value = subpart.custom_string_field || subpart.custom_array_field rescue nil - if !custom_value.nil? - OrbitHelper.set_widget_custom_value custom_value - end - partials << render_widget_for_frontend(subpart.module,subpart.widget_method,subpart.widget_type) - elsif subpart.kind == "text" - partials << subpart.content + if $mobile.blank? + parts.each do |part| + subparts = part.sub_parts + partials = [] + subparts.each do |subpart| + if subpart.kind == "module_widget" + OrbitHelper.set_widget_data_count subpart.data_count + OrbitHelper.set_widget_categories subpart.categories + OrbitHelper.set_widget_module_app subpart.module + OrbitHelper.set_widget_item_url subpart + custom_value = subpart.custom_string_field || subpart.custom_array_field rescue nil + if !custom_value.nil? + OrbitHelper.set_widget_custom_value custom_value + end + partials << render_widget_for_frontend(subpart.module,subpart.widget_method,subpart.widget_type) + elsif subpart.kind == "text" + partials << subpart.content + end end + @part_partials["data-pp='#{part.part_id}'"] = partials end - @part_partials["data-pp='#{part.part_id}'"] = partials end + @file = nil @layout_html = nil - if original_view == "home" - @file = File.join('../templates', "#{@key}", '/home/index.html.erb') + if original_view == "home#{$mobile}" + @file = File.join('../templates', "#{@key}", "/home#{$mobile}/index.html.erb") else - @file = File.join('../templates', "#{@key}", '/home/page.html.erb') + @file = File.join('../templates', "#{@key}", "/home#{$mobile}/page.html.erb") end @layout_html = render_to_string(@file) doc = Nokogiri::HTML(@layout_html, nil, "UTF-8") @@ -214,7 +217,7 @@ class PagesController < ApplicationController pp.inner_html = html_string end - if original_view != "home" + if original_view != "home#{$mobile}" viewarea = doc.css("*[data-content='true']")[0] viewarea.inner_html = render_to_string(original_view) end @@ -234,10 +237,10 @@ class PagesController < ApplicationController def get_view page = Page.find(params[:id]) rescue Page.root if page == Page.root - @view = File.join(Rails.root, 'app', 'templates', "#{@key}", 'home/index.html.erb') + @view = File.join(Rails.root, 'app', 'templates', "#{@key}", 'home#{$mobile}/index.html.erb') else module_name = page.module.downcase.singularize - @view = File.join(Rails.root, 'app', 'templates', "#{@key}", "modules/#{module_name}/index.html.erb") + @view = File.join(Rails.root, 'app', 'templates', "#{@key}", "modules#{$mobile}/#{module_name}/index.html.erb") end end @@ -263,7 +266,7 @@ class PagesController < ApplicationController if page.page_id == "" || page.page_id == nil false else - File.join("../../templates", "#{@key}", '/home/page.html.erb') + File.join("../../templates", "#{@key}", "/#{@home}#{$mobile}/page.html.erb") end # elsif request[:action] == "show" || request[:action] == "moduleShow" # File.join("../../templates", "themes", "#{@key}", '/home/page.html.erb') @@ -281,4 +284,5 @@ class PagesController < ApplicationController redirect_to '/admin/dashboards' end end + end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 025ae98..4ff629f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -19,7 +19,7 @@ module ApplicationHelper def render_header site = Site.first key = Template::KEY - header_file = File.join('../templates', "#{key}", '/home/header.html.erb') + header_file = File.join('../templates', "#{key}", "/home#{$mobile}/header.html.erb") header_file_html = render :file => header_file header = Nokogiri::HTML(header_file_html, nil, "UTF-8") sub_menu_html = site.sub_menu @@ -37,7 +37,7 @@ module ApplicationHelper def render_footer site = Site.first key = Template::KEY - footer_file = File.join('../templates', "#{key}", '/home/footer.html.erb') + footer_file = File.join('../templates', "#{key}", "/home#{$mobile}/footer.html.erb") footer_file_html = render :file => footer_file footer = Nokogiri::HTML(footer_file_html, nil, "UTF-8") html = footer.to_s @@ -74,7 +74,7 @@ module ApplicationHelper end @items = create_json(@pages) key = current_site.template - menu_file = File.open(File.join(Rails.root, 'app', 'templates', "#{key}", '/home/menu.html.erb')) + menu_file = File.open(File.join(Rails.root, 'app', 'templates', "#{key}", "/home#{$mobile}/menu.html.erb")) doc = Nokogiri::HTML(menu_file, nil, "UTF-8") menu_file.close @@ -164,7 +164,7 @@ module ApplicationHelper if params[:target_action] == "index" - file = File.open(File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', params[:target_controller].singularize, "#{params[:target_action]}.html.erb")) + file = File.open(File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', params[:target_controller].singularize+$mobile, "#{params[:target_action]}.html.erb")) doc = Nokogiri::HTML(file, nil, "UTF-8") file.close controller = "#{params[:target_controller].capitalize}_controller".classify.constantize.new @@ -186,7 +186,7 @@ module ApplicationHelper end html.html_safe elsif params[:target_action] == "show" - file = File.open(File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', params[:target_controller].singularize, "#{params[:target_action]}.html.erb")) + file = File.open(File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', params[:target_controller].singularize+$mobile, "#{params[:target_action]}.html.erb")) doc = Nokogiri::HTML(file, nil, "UTF-8") file.close controller = "#{params[:target_controller].capitalize}_controller".classify.constantize.new diff --git a/app/templates/orbit_bootstrap/home/mobile/footer.html.erb b/app/templates/orbit_bootstrap/home/mobile/footer.html.erb new file mode 100644 index 0000000..a92bb99 --- /dev/null +++ b/app/templates/orbit_bootstrap/home/mobile/footer.html.erb @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/app/templates/orbit_bootstrap/home/mobile/header.html.erb b/app/templates/orbit_bootstrap/home/mobile/header.html.erb new file mode 100644 index 0000000..3b76597 --- /dev/null +++ b/app/templates/orbit_bootstrap/home/mobile/header.html.erb @@ -0,0 +1,17 @@ +
+

THIS IS MOBILE HEADER

+
+ +
+ {{header-data}} +
+
+ <%= render_partial("menu") %> +
\ No newline at end of file diff --git a/app/templates/orbit_bootstrap/home/mobile/index.html.erb b/app/templates/orbit_bootstrap/home/mobile/index.html.erb new file mode 100644 index 0000000..9535ba7 --- /dev/null +++ b/app/templates/orbit_bootstrap/home/mobile/index.html.erb @@ -0,0 +1,36 @@ + + + + <%= render_partial("head") %> + + + <%= render_orbit_bar %> +
+ <%= render_header %> + +
+ <%#= render_widget "ad_banner/widget" %> +
+

THIS IS MOBILE PAGE

+
+
+
+
+
+
+
+
+ +
+
+ +
+
+ <%= render_footer %> +
+ + \ No newline at end of file diff --git a/app/templates/orbit_bootstrap/home/mobile/menu.html.erb b/app/templates/orbit_bootstrap/home/mobile/menu.html.erb new file mode 100644 index 0000000..c94240d --- /dev/null +++ b/app/templates/orbit_bootstrap/home/mobile/menu.html.erb @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/app/templates/orbit_bootstrap/home/mobile/page.html.erb b/app/templates/orbit_bootstrap/home/mobile/page.html.erb new file mode 100644 index 0000000..651a309 --- /dev/null +++ b/app/templates/orbit_bootstrap/home/mobile/page.html.erb @@ -0,0 +1,36 @@ + + + + <%= render_partial("head") %> + + + <%= render_orbit_bar %> +
+ <%= render_header %> + +
+ <%#= render_widget "ad_banner/widget" %> +
+

THIS IS MOBILE PAGE

+
+
+
+
+ <%= yield %> +
+
+
+ +
+
+ +
+
+ <%= render_footer %> +
+ + \ No newline at end of file diff --git a/app/templates/orbit_bootstrap/home/mobile/submenu.html.erb b/app/templates/orbit_bootstrap/home/mobile/submenu.html.erb new file mode 100644 index 0000000..7f7e5e7 --- /dev/null +++ b/app/templates/orbit_bootstrap/home/mobile/submenu.html.erb @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/app/templates/orbit_bootstrap/modules/announcement/mobile/index.html.erb b/app/templates/orbit_bootstrap/modules/announcement/mobile/index.html.erb new file mode 100644 index 0000000..47551ae --- /dev/null +++ b/app/templates/orbit_bootstrap/modules/announcement/mobile/index.html.erb @@ -0,0 +1,14 @@ +

{{widget-title}}

+

ANNOUNCEMENT MOBILE INDEX

+ \ No newline at end of file diff --git a/app/templates/orbit_bootstrap/modules/announcement/mobile/show.html.erb b/app/templates/orbit_bootstrap/modules/announcement/mobile/show.html.erb new file mode 100644 index 0000000..0bfc43e --- /dev/null +++ b/app/templates/orbit_bootstrap/modules/announcement/mobile/show.html.erb @@ -0,0 +1,27 @@ +

ANNOUNCEMENT MOBILE SHOW

+
+
+

{{title}}

+
+ +
+

+

{{body}}

+
+
+ {{file_title}}
+
+
+ {{link_title}}
+
+
\ No newline at end of file diff --git a/app/templates/orbit_bootstrap/modules/archive/mobile/index.html.erb b/app/templates/orbit_bootstrap/modules/archive/mobile/index.html.erb new file mode 100644 index 0000000..24ca79d --- /dev/null +++ b/app/templates/orbit_bootstrap/modules/archive/mobile/index.html.erb @@ -0,0 +1,28 @@ +
+

{{widget-title}}

+

ARCHIVE MOBILE INDEX

+
+
+

{{category-title}}

+
    +
  • +
    + {{archive-title}} + + {{archive-status}} + +
    +
      +
    1. + {{file-name}} + {{file-type}} +
    2. +
    +
  • +
  • + This is for test +
  • +
+
+
+
\ No newline at end of file diff --git a/app/templates/orbit_bootstrap/modules/faq/mobile/index.html.erb b/app/templates/orbit_bootstrap/modules/faq/mobile/index.html.erb new file mode 100644 index 0000000..939f704 --- /dev/null +++ b/app/templates/orbit_bootstrap/modules/faq/mobile/index.html.erb @@ -0,0 +1,9 @@ +

{{widget-title}}

+

FAQ MOBILE INDEX

+ \ No newline at end of file diff --git a/app/templates/orbit_bootstrap/modules/faq/mobile/show.html.erb b/app/templates/orbit_bootstrap/modules/faq/mobile/show.html.erb new file mode 100644 index 0000000..c3ecaf3 --- /dev/null +++ b/app/templates/orbit_bootstrap/modules/faq/mobile/show.html.erb @@ -0,0 +1,15 @@ +
+

FAQ MOBILE SHOW

+
+

{{question}}

+
+
+

{{answer}}

+
+
+ {{file_title}}
+
+
+ {{link_title}}
+
+
\ No newline at end of file diff --git a/app/templates/orbit_bootstrap/modules/gallery/mobile/index.html.erb b/app/templates/orbit_bootstrap/modules/gallery/mobile/index.html.erb new file mode 100644 index 0000000..373715d --- /dev/null +++ b/app/templates/orbit_bootstrap/modules/gallery/mobile/index.html.erb @@ -0,0 +1,12 @@ +
+

{{widget-title}}

+

GALLERY MOBILE INDEX

+ +
\ No newline at end of file diff --git a/app/templates/orbit_bootstrap/modules/gallery/mobile/show.html.erb b/app/templates/orbit_bootstrap/modules/gallery/mobile/show.html.erb new file mode 100644 index 0000000..4a656f5 --- /dev/null +++ b/app/templates/orbit_bootstrap/modules/gallery/mobile/show.html.erb @@ -0,0 +1,11 @@ +
+

{{album-title}}

+

GALLERY MOBILE SHOW

+ +
\ No newline at end of file diff --git a/app/templates/orbit_bootstrap/modules/web_resource/mobile/index.html.erb b/app/templates/orbit_bootstrap/modules/web_resource/mobile/index.html.erb new file mode 100644 index 0000000..1d41979 --- /dev/null +++ b/app/templates/orbit_bootstrap/modules/web_resource/mobile/index.html.erb @@ -0,0 +1,9 @@ +
+

{{widget-title}}

+

WEB-RESOURCE MOBILE INDEX

+ +
\ No newline at end of file diff --git a/app/uploaders/image_uploader.rb b/app/uploaders/image_uploader.rb index 1b427d7..c767b2b 100644 --- a/app/uploaders/image_uploader.rb +++ b/app/uploaders/image_uploader.rb @@ -39,6 +39,10 @@ class ImageUploader < CarrierWave::Uploader::Base process :resize_to_fit => [200, 200] end + version :mobile do + process :resize_to_limit => [1152, 768] + end + # Add a white list of extensions which are allowed to be uploaded. # For images you might use something like this: def extension_white_list diff --git a/config/routes.rb b/config/routes.rb index 05e1027..867cf1c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -188,6 +188,10 @@ Orbit::Application.routes.draw do get 'design_list' => 'designs#design_list' get 'module_store' => 'module_store#index' end + + get 'mobile', to: 'pages#home' + get 'mobile/:page(/:page)(/:page)(/:page)', to: 'pages#show', constraints: KeywordConstraint.new + get ':page(/:page)(/:page)(/:page)', to: 'pages#show', constraints: KeywordConstraint.new resources :pages end