From 671f86b61277cd6b9fee6b34d15c68b2fc819f74 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 4 Sep 2012 12:31:27 +0800 Subject: [PATCH] First version of new preview. Only plain text --- Gemfile | 4 +++ Gemfile.lock | 25 +++++++++++++++++++ app/controllers/sessions_controller.rb | 2 +- app/models/preview.rb | 25 +++++++++++++++++++ lib/orbit_core_lib.rb | 13 ++++++++++ spec/factories/previews.rb | 6 +++++ spec/models/preview_spec.rb | 5 ++++ .../back_end/bulletins_controller.rb | 8 ++++++ .../announcement/app/models/bulletin.rb | 7 +----- .../back_end/news_bulletins_controller.rb | 6 ++++- .../front_end/news_bulletins_controller.rb | 3 ++- .../news/app/models/news_bulletin.rb | 2 +- .../news_bulletins/_modal_preview.html.erb | 4 +-- .../back_end/news_bulletins/preview.js.erb | 4 +-- 14 files changed, 100 insertions(+), 14 deletions(-) create mode 100644 app/models/preview.rb create mode 100644 spec/factories/previews.rb create mode 100644 spec/models/preview_spec.rb diff --git a/Gemfile b/Gemfile index a12f66dc8..37a8d319a 100644 --- a/Gemfile +++ b/Gemfile @@ -24,6 +24,10 @@ gem 'mongoid-tree', :require => 'mongoid/tree' gem "mongo_session_store-rails3" gem 'mysql2' gem 'nokogiri' + +gem 'pry', :group => :development +gem 'pry-debugger', :group => :development + gem 'radius' gem 'rake' # gem 'remotipart' diff --git a/Gemfile.lock b/Gemfile.lock index 96f07221a..cd9920498 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -69,6 +69,7 @@ GEM mongoid (~> 2.1) chinese_pinyin (0.4.1) chronic (0.6.7) + coderay (1.0.7) coffee-rails (3.1.1) coffee-script (>= 2.2.0) railties (~> 3.1.0) @@ -79,6 +80,13 @@ GEM color (1.4.1) columnize (0.3.6) database_cleaner (0.7.1) + debugger (1.1.4) + columnize (>= 0.3.1) + debugger-linecache (~> 1.1.1) + debugger-ruby_core_source (~> 1.1.3) + debugger-linecache (1.1.2) + debugger-ruby_core_source (>= 1.1.1) + debugger-ruby_core_source (1.1.3) delorean (1.2.0) chronic devise (1.5.3) @@ -118,6 +126,7 @@ GEM i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) + method_source (0.8) mime-types (1.17.2) mini_magick (3.4) subexec (~> 0.2.1) @@ -149,6 +158,18 @@ GEM progress_bar (0.4.0) highline (~> 1.6.1) options (~> 2.3.0) + pry (0.9.10) + coderay (~> 1.0.5) + method_source (~> 0.8) + slop (~> 3.3.1) + pry (0.9.10-x86-mingw32) + coderay (~> 1.0.5) + method_source (~> 0.8) + slop (~> 3.3.1) + win32console (~> 1.3) + pry-debugger (0.2.0) + debugger (~> 1.1.3) + pry (~> 0.9.9) rack (1.3.6) rack-cache (1.2) rack (>= 0.4) @@ -250,6 +271,7 @@ GEM rack (~> 1.3, >= 1.3.6) rack-protection (~> 1.2) tilt (~> 1.3, >= 1.3.3) + slop (3.3.2) social-share-button (0.0.6) spork (0.9.0) spork (0.9.0-x86-mingw32) @@ -291,6 +313,7 @@ GEM win32-api (1.4.8-x86-mingw32) win32-process (0.6.5) windows-pr (>= 1.1.2) + win32console (1.3.2-x86-mingw32) windows-api (0.4.1) win32-api (>= 1.4.5) windows-pr (1.2.1) @@ -326,6 +349,8 @@ DEPENDENCIES net-ldap (~> 0.3.1) nokogiri progress_bar + pry + pry-debugger radius rails (>= 3.1.0, < 3.2.0) rake diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 39904a1c2..b2fbc9975 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -17,7 +17,7 @@ class SessionsController < Devise::SessionsController if ($nccu_ldap_connection.bind rescue false) logger.info "=LDAP Binded password ok..." result =check_auth_with_ldap(login_uid,login_password) - if result && login_password!='' + if result #&& login_password!='' logger.info "==LDAP password passed..." nccu_id = get_nccu_id_from_mid_site(login_uid) resource = nccu_id.nil? ? nil : (User.first(conditions:{ nccu_ldap_uid: nccu_id })) diff --git a/app/models/preview.rb b/app/models/preview.rb new file mode 100644 index 000000000..fb08f675c --- /dev/null +++ b/app/models/preview.rb @@ -0,0 +1,25 @@ +class Preview + include Mongoid::Document + include Mongoid::Timestamps + + field :object, :type => Hash + field :preview_at_link + field :expired_at , :type => DateTime + field :link_args, :type => Array + field :object_class_type + + def get_arg_hash + object.slice(*link_args).inject({}){|la,(k,v)| la[k.to_sym] = v; la} + end + + def get_preview_link + ap = Rails.application.routes.url_helpers + ap.send preview_at_link,({:id=>id,:preview=>true}.merge get_arg_hash) + #func = eval("Rails.application.routes.url_helpers.#{preview_at_link}").send + end + + def get_virtual_object + eval(self.object_class_type).new object + end + +end diff --git a/lib/orbit_core_lib.rb b/lib/orbit_core_lib.rb index 8aea2b8ca..f152e3f42 100644 --- a/lib/orbit_core_lib.rb +++ b/lib/orbit_core_lib.rb @@ -1,4 +1,17 @@ module OrbitCoreLib + module Preview + def self.included(base) + base.instance_eval("field :is_preview,type: Boolean,:default => false") + base.instance_eval("scope :not_preview,where(:is_preview=>false)") + base.define_singleton_method :new_preview do |*args| + temp_obj = self.new(args.first) + temp_obj.is_preview = true + temp_obj.save(:validate => false) rescue + temp_obj + end + end + end + module BelongsToCategoryMayDisable def self.included(base) base.instance_eval("belongs_to :#{base::BelongsToCategory.to_s}") diff --git a/spec/factories/previews.rb b/spec/factories/previews.rb new file mode 100644 index 000000000..bd281c991 --- /dev/null +++ b/spec/factories/previews.rb @@ -0,0 +1,6 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :preview do + end +end diff --git a/spec/models/preview_spec.rb b/spec/models/preview_spec.rb new file mode 100644 index 000000000..86318050e --- /dev/null +++ b/spec/models/preview_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Preview do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb index c013d7f49..75c8e304e 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb @@ -11,6 +11,14 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController # before_filter :for_admin_only,:only => [:] # before_filter :for_app_manager,:only => [:index,:show,] before_filter :for_app_sub_manager,:except => [:index,:show,:get_sorted_and_filtered_bulletins] + + def preview + debugger + a=1 + + @bulletin = Bulletin.new_preview(params[:bulletin]) + end + def index # @bulletins = Bulletin.all # @bulletins = Bulletin.desc("postdate desc") diff --git a/vendor/built_in_modules/announcement/app/models/bulletin.rb b/vendor/built_in_modules/announcement/app/models/bulletin.rb index adc50101f..6e6dfb624 100644 --- a/vendor/built_in_modules/announcement/app/models/bulletin.rb +++ b/vendor/built_in_modules/announcement/app/models/bulletin.rb @@ -9,11 +9,7 @@ class Bulletin BelongsToCategory = :bulletin_category include OrbitCoreLib::BelongsToCategoryMayDisable - - # include NccuSearch - - #scope :searchable,where(:is_checked=>true,:is_hidden=>false,:is_pending=>false) - + include OrbitCoreLib::Preview is_impressionable :counter_cache => { :column_name => :view_count } field :title, localize: true @@ -36,7 +32,6 @@ class Bulletin field :is_checked, :type => Boolean, :default => false field :is_pending, :type => Boolean, :default => true field :is_rejected, :type => Boolean, :default => false - field :view_count, :type => Integer, :default => 0 field :not_checked_reason diff --git a/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletins_controller.rb b/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletins_controller.rb index a3942612d..2d365ec7f 100644 --- a/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletins_controller.rb +++ b/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletins_controller.rb @@ -10,7 +10,10 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController controller.get_unit_list end - + def preview + @preview_obj = Preview.create(:object=>params[:news_bulletin],:expired_at=>DateTime.now+30.minutes,:preview_at_link=>"panel_news_front_end_news_bulletin_path",:object_class_type=>"NewsBulletin") + end + def index # @news_bulletins = NewsBulletin.all # @news_bulletins = NewsBulletin.desc("postdate desc") @@ -117,6 +120,7 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController # POST /news_bulletins # POST /news_bulletins.xml def create + binding.pry get_tags if params[:news_bulletin_link] diff --git a/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb b/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb index 0e9f0ac31..9a05d9434 100644 --- a/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb +++ b/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb @@ -69,7 +69,8 @@ class Panel::News::FrontEnd::NewsBulletinsController < OrbitWidgetController end def preview_content - @news_bulletin = NewsBulletin.find params[:id] + @news_bulletin = NewsBulletin.find params[:id] rescue nil + @news_bulletin = Preview.find(params[:id]).get_virtual_object if @news_bulletin.nil? get_categorys end diff --git a/vendor/built_in_modules/news/app/models/news_bulletin.rb b/vendor/built_in_modules/news/app/models/news_bulletin.rb index 974d55a7f..4c31d9396 100644 --- a/vendor/built_in_modules/news/app/models/news_bulletin.rb +++ b/vendor/built_in_modules/news/app/models/news_bulletin.rb @@ -9,6 +9,7 @@ class NewsBulletin BelongsToCategory = :news_bulletin_category include OrbitCoreLib::BelongsToCategoryMayDisable + include OrbitCoreLib::Preview # include Tire::Model::Search # include Tire::Model::Callbacks # include Redis::Objects @@ -36,7 +37,6 @@ class NewsBulletin field :is_checked, :type => Boolean, :default => false field :is_pending, :type => Boolean, :default => true field :is_rejected, :type => Boolean, :default => false - field :view_count, :type => Integer, :default => 0 field :not_checked_reason diff --git a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_modal_preview.html.erb b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_modal_preview.html.erb index c5ed3abaa..5b3ec4815 100644 --- a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_modal_preview.html.erb +++ b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_modal_preview.html.erb @@ -1,11 +1,11 @@ -