From fe2c1a923571820d5daee54324deaf966a3d49ed Mon Sep 17 00:00:00 2001 From: manson Date: Fri, 8 Aug 2014 17:33:18 +0800 Subject: [PATCH 1/7] update dashboard for better performance --- app/helpers/application_helper.rb | 25 +++++++++++++++++-------- app/models/site.rb | 2 ++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5a29539..a1bf835 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -248,15 +248,24 @@ module ApplicationHelper end def get_month_traffic - result = [] - (0..30).each do |i| - visits = Impression.where( created_at: { - '$gte' => Time.now.beginning_of_day-i.days, - '$lte' => Time.now.end_of_day-i.days} - ).count - result.push([ Time.now.beginning_of_day-i.days, visits]) + site = Site.first + if site.month_traffic_cache.blank? or (site.month_traffic_cache['updated_at'] < (Time.now-1.day) rescue true) + site.month_traffic_cache = {} + + site.month_traffic_cache['result'] = [] + (1..30).each do |i| + visits = Impression.where( created_at: { + '$gte' => Time.now.beginning_of_day-i.days, + '$lte' => Time.now.end_of_day-i.days} + ).distinct(:request_hash).count + site.month_traffic_cache['result'].push([ Time.now.beginning_of_day-i.days, visits]) + end + + site.month_traffic_cache['updated_at'] = Time.now + site.save end - [:name=> t(:visitors_count),:data=>result] + + [:name=> t(:visitors_count),:data=>site.month_traffic_cache['result']] end # def get_today_traffic diff --git a/app/models/site.rb b/app/models/site.rb index 293ad47..11a302d 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -51,6 +51,8 @@ class Site field :store_confirmation, :type => Boolean, :default => false field :meta_viewport, :type => Boolean, :default => false + field :month_traffic_cache + belongs_to :design has_many :site_metas, :autosave => true, :dependent => :destroy validate :in_use_locales, :minimum_enabled_locales From 8d0c326bbcbe68998aa9ae1f701839a5087e8445 Mon Sep 17 00:00:00 2001 From: manson Date: Fri, 8 Aug 2014 17:52:40 +0800 Subject: [PATCH 2/7] remove distinct in dashboard monthly traffic counting --- app/helpers/application_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a1bf835..aa8d5f8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -257,7 +257,7 @@ module ApplicationHelper visits = Impression.where( created_at: { '$gte' => Time.now.beginning_of_day-i.days, '$lte' => Time.now.end_of_day-i.days} - ).distinct(:request_hash).count + ).count site.month_traffic_cache['result'].push([ Time.now.beginning_of_day-i.days, visits]) end From 13f63d4c2a7de4b6b3e46a29dee53e7806f2dcbb Mon Sep 17 00:00:00 2001 From: manson Date: Fri, 8 Aug 2014 18:05:13 +0800 Subject: [PATCH 3/7] remove page from dashboard most_visted --- app/controllers/admin/dashboards_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/dashboards_controller.rb b/app/controllers/admin/dashboards_controller.rb index 102ed76..ed2d7a1 100644 --- a/app/controllers/admin/dashboards_controller.rb +++ b/app/controllers/admin/dashboards_controller.rb @@ -11,7 +11,7 @@ class Admin::DashboardsController < OrbitBackendController check_backend_openness @module_app_contents, @module_app_contents_total = get_module_app_count('bulletin', 'page_context', 'web_link') @recent_updated = get_recently_updated('bulletin', 'page_context', 'web_link') - @most_visited = get_most_visited('bulletin', 'page_context','page') + @most_visited = get_most_visited('bulletin', 'page_context') end def reload_all_content @@ -22,7 +22,7 @@ class Admin::DashboardsController < OrbitBackendController end def reload_most_visited - @most_visited = get_most_visited('bulletin', 'page_context','page') + @most_visited = get_most_visited('bulletin', 'page_context') respond_to do |format| format.js { render 'reload', locals: {div_id: 'most_visited'} } end From 93337c10199314d65497ab5c5cb18e09bb8aa59c Mon Sep 17 00:00:00 2001 From: manson Date: Tue, 19 Aug 2014 18:00:12 +0800 Subject: [PATCH 4/7] fix preview for IE --- app/assets/javascripts/lib/modal-preview.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/lib/modal-preview.js b/app/assets/javascripts/lib/modal-preview.js index 8fe3e21..47e93df 100644 --- a/app/assets/javascripts/lib/modal-preview.js +++ b/app/assets/javascripts/lib/modal-preview.js @@ -7,7 +7,12 @@ $(function() { for ( instance in CKEDITOR.instances ) CKEDITOR.instances[instance].updateElement(); - var formData = new FormData( $('form.previewable')[0] ); + var formData; + if(typeof(FormData) == "function"){ + formData = new FormData( $('form.previewable')[0] ); + }else{ + formData = $('form.previewable').serialize() + } $.ajax({ type: "post", From 8aa5a4f7d6f1530bf7a1985a3a4d831d02628959 Mon Sep 17 00:00:00 2001 From: manson Date: Wed, 20 Aug 2014 11:47:33 +0800 Subject: [PATCH 5/7] fix slow backend index page --- app/controllers/application_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 31954e6..aff31a7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -361,7 +361,8 @@ class ApplicationController < ActionController::Base end if pagination - Kaminari.paginate_array(filter_authorized_objects(objects)).page(params[:page]).per(10) + # Kaminari.paginate_array(filter_authorized_objects(objects)).page(params[:page]).per(10) + filter_authorized_objects(objects).page(params[:page]).per(10) else filter_authorized_objects(objects) end From 51d8577774a717b690aee4e0e397ba9d51c2765f Mon Sep 17 00:00:00 2001 From: manson Date: Thu, 21 Aug 2014 11:07:08 +0800 Subject: [PATCH 6/7] fix ad_banner backend index sorting --- app/assets/javascripts/lib/ad_banner/banner_preview.js | 1 - app/controllers/admin/ad_banners_controller.rb | 2 +- app/controllers/admin/ad_images_controller.rb | 2 +- app/controllers/application_controller.rb | 10 ++++++++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/lib/ad_banner/banner_preview.js b/app/assets/javascripts/lib/ad_banner/banner_preview.js index d740ebe..5a374a7 100644 --- a/app/assets/javascripts/lib/ad_banner/banner_preview.js +++ b/app/assets/javascripts/lib/ad_banner/banner_preview.js @@ -32,7 +32,6 @@ function preview() { var resize = 500/bannerW bannerW = Math.floor(bannerW*resize); bannerH = Math.floor(bannerH*resize); - console.log(bannerW) }; if(bannerH > 300) { var resize = 300/bannerH diff --git a/app/controllers/admin/ad_banners_controller.rb b/app/controllers/admin/ad_banners_controller.rb index 780e525..8ce0211 100644 --- a/app/controllers/admin/ad_banners_controller.rb +++ b/app/controllers/admin/ad_banners_controller.rb @@ -4,7 +4,7 @@ class Admin::AdBannersController < OrbitBackendController open_for_sub_manager def index - @ad_banners = AdBanner.all.page(params[:page]).per(10) + @ad_banners = get_sorted_and_filtered("ad_banner") end def show diff --git a/app/controllers/admin/ad_images_controller.rb b/app/controllers/admin/ad_images_controller.rb index 35dc6c5..cfd44a5 100644 --- a/app/controllers/admin/ad_images_controller.rb +++ b/app/controllers/admin/ad_images_controller.rb @@ -11,7 +11,7 @@ class Admin::AdImagesController < Admin::AdBannersController end def index - @ad_images = AdImage.all.page(params[:page]).per(10) + @ad_images = get_sorted_and_filtered("ad_image") end def edit diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index aff31a7..27555cf 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -321,6 +321,8 @@ class ApplicationController < ActionController::Base sorted_objects.flatten! sorted_objects.uniq! objects = get_with_nil(objects, option, sorted_objects) + elsif option.eql?('size') + objects = objects.order_by([ [:width, params[:direction]], [:height, params[:direction]] ]) end end end @@ -361,8 +363,12 @@ class ApplicationController < ActionController::Base end if pagination - # Kaminari.paginate_array(filter_authorized_objects(objects)).page(params[:page]).per(10) - filter_authorized_objects(objects).page(params[:page]).per(10) + filtered_objects = filter_authorized_objects(objects) + if filtered_objects.is_a?(Array) + Kaminari.paginate_array(filtered_objects).page(params[:page]).per(10) + else + filter_authorized_objects(objects).page(params[:page]).per(10) + end else filter_authorized_objects(objects) end From cc82387efb319c84b6c1493aff053f121ade114c Mon Sep 17 00:00:00 2001 From: spen Date: Thu, 21 Aug 2014 14:08:29 +0800 Subject: [PATCH 7/7] update ckeditor paste From Word clean up --- Gemfile | 2 +- app/assets/javascripts/ckeditor/config.js.erb | 6 ++++++ config/application.rb | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 7dda595..d3548b2 100644 --- a/Gemfile +++ b/Gemfile @@ -109,7 +109,7 @@ group :test, :development do gem "spork" gem "capybara" #gem 'rack-mini-profiler' - gem "better_errors" + gem "better_errors", "1.1.0" # gem 'yard' # gem "bluecloth" end diff --git a/app/assets/javascripts/ckeditor/config.js.erb b/app/assets/javascripts/ckeditor/config.js.erb index 3fba3b2..269a56c 100644 --- a/app/assets/javascripts/ckeditor/config.js.erb +++ b/app/assets/javascripts/ckeditor/config.js.erb @@ -28,6 +28,8 @@ CKEDITOR.editorConfig = function( config ) { { name: 'about' } ]; + config.allowedContent = true; + config.skin = 'moono'; config.filebrowserBrowseUrl = "<%= Rails.application.routes.url_helpers.admin_assets_path(:module_app_id=>ModuleApp.where(:key=>'asset').first.id) %>"; @@ -35,6 +37,10 @@ CKEDITOR.editorConfig = function( config ) { //Font Config config.font_names = 'Arial;Comic Sans MS;Courier New;Georgia;Helvetica;Lucida Sans Unicode;Tahoma;Times New Roman;Trebuchet MS;Verdana;微軟正黑體'; + + config.enterMode = CKEDITOR.ENTER_BR; + config.shiftEnterMode = CKEDITOR.ENTER_BR; + config.pasteFromWordPromptCleanup = true; }; CKEDITOR.on('instanceReady',function(){ diff --git a/config/application.rb b/config/application.rb index 4af3206..b56da2c 100644 --- a/config/application.rb +++ b/config/application.rb @@ -56,6 +56,7 @@ module Orbit # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.default_locale = :de config.i18n.load_path += Dir[Rails.root.join('config', 'locales', 'modules', '*.{rb,yml}').to_s] + config.i18n.enforce_available_locales = false config.i18n.default_locale = :zh_tw # JavaScript files you want as :defaults (application.js is always included).