First version of new preview. Only plain text

This commit is contained in:
Matthew K. Fu JuYuan 2012-09-04 12:31:27 +08:00
parent ecb3b5b25c
commit 671f86b612
14 changed files with 100 additions and 14 deletions

View File

@ -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'

View File

@ -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

View File

@ -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 }))

25
app/models/preview.rb Normal file
View File

@ -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

View File

@ -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}")

View File

@ -0,0 +1,6 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :preview do
end
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe Preview do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -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")

View File

@ -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

View File

@ -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]

View File

@ -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

View File

@ -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

View File

@ -1,11 +1,11 @@
<div class="modal hide fade in banner-preview" id="<%= news_bulletin.id %>">
<div class="modal hide fade in banner-preview" id="<%= @preview_obj.id %>">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3><%= t("modal.preview") %></h3>
</div>
<div class="modal-body">
<p class="news_bulletin_slideshow">
<iframe src=<%= panel_news_front_end_news_bulletin_path(news_bulletin, :category_id => (news_bulletin.news_bulletin_category.id rescue ""),:preview=>true) %> style="width:1024px;height:300px" >
<iframe src=<%= @preview_obj.get_preview_link %> style="width:1024px;height:300px" >
</iframe>

View File

@ -1,5 +1,5 @@
$('#show_preview').html('<%=escape_javascript(render :partial=>"modal_preview",:locals=>{:news_bulletin => @preview_news_bulletin}) %>');
var start_modal_with_id = "<%= @preview_news_bulletin.id %>";
$('#show_preview').html('<%=escape_javascript(render :partial=>"modal_preview") %>');
var start_modal_with_id = "<%= @preview_obj.id %>";
$("#"+start_modal_with_id).css("width","1050px");
$("#"+start_modal_with_id).css("height","768px");
$("#"+start_modal_with_id).css("margin","-270px 0 0 -550px");