From 6b904a37ad7e33c1609c2241e5aafb8d3574049d Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Fri, 31 Aug 2012 17:54:25 +0800 Subject: [PATCH 002/139] let all signed in users at NCCU upload files --- app/controllers/admin/assets_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/admin/assets_controller.rb b/app/controllers/admin/assets_controller.rb index 6a847a12..aa82583f 100644 --- a/app/controllers/admin/assets_controller.rb +++ b/app/controllers/admin/assets_controller.rb @@ -105,4 +105,8 @@ class Admin::AssetsController < OrbitBackendController render :layout => false end + def check_permission + true + end + end From 26f99c296f3ae0b61bf97b87768d93836f462651 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Fri, 31 Aug 2012 18:33:18 +0800 Subject: [PATCH 003/139] fix page blank for 403 forbidden. --- app/controllers/admin/object_auths_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/object_auths_controller.rb b/app/controllers/admin/object_auths_controller.rb index ab343360..b89a4fe6 100644 --- a/app/controllers/admin/object_auths_controller.rb +++ b/app/controllers/admin/object_auths_controller.rb @@ -91,7 +91,8 @@ private def check_if_user_can_do_object_auth unless check_permission(:manager) - render :nothing => true, :status => 403 + #render :nothing => true, :status => 403 + redirect_to '/' end end end \ No newline at end of file From fc4e2ceba565c6765f1c633fc1982a1e168e8317 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Fri, 31 Aug 2012 18:56:26 +0800 Subject: [PATCH 004/139] fix for 403 for new interface --- app/controllers/admin/object_auths_new_interface_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/object_auths_new_interface_controller.rb b/app/controllers/admin/object_auths_new_interface_controller.rb index 31c5e900..08f7496d 100644 --- a/app/controllers/admin/object_auths_new_interface_controller.rb +++ b/app/controllers/admin/object_auths_new_interface_controller.rb @@ -62,7 +62,7 @@ class Admin::ObjectAuthsNewInterfaceController < OrbitBackendController def check_if_user_can_do_object_auth unless check_permission(:manager) - render :nothing => true, :status => 403 + redirect_to '/' end end From ae1595a0081d356cdb853c2a4a0d78f8c28bd0c4 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 4 Sep 2012 09:24:12 +0800 Subject: [PATCH 005/139] view for preview --- app/assets/javascripts/inc/modal-preview.js | 20 ++++++++ .../back_end/bulletins/_form.html.erb | 1 + .../announcement/config/routes.rb | 1 + .../back_end/news_bulletins/_form.html.erb | 5 +- .../news_bulletins/_modal_preview.html.erb | 47 +++++++++++++++++++ .../back_end/news_bulletins/preview.js.erb | 5 ++ vendor/built_in_modules/news/config/routes.rb | 2 + 7 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_modal_preview.html.erb create mode 100644 vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/preview.js.erb diff --git a/app/assets/javascripts/inc/modal-preview.js b/app/assets/javascripts/inc/modal-preview.js index 959f04b2..496b2080 100644 --- a/app/assets/javascripts/inc/modal-preview.js +++ b/app/assets/javascripts/inc/modal-preview.js @@ -3,6 +3,26 @@ // <%= link_to "NewPreview", realtime_preview_admin_ad_banner_path(ad_banner_tab) , :class=>'preview_trigger'%> $(document).ready(function() { + $("a.post_preview").click(function(e){ + $("#main-wrap").after(""); + e.preventDefault(); + var form = $(this).parents("form").first() + //var cont = form["content"].value; + $.ajax({ + type: 'POST', + url: $(this).attr("href")+'?preview=true', + data: form.serialize(), + dataType: "script", + success: function (msg) { + $("#"+start_modal_with_id).modal('show'); }, + error: function(){ + alert("ERROR"); + } + }); + + return false + }); + $("a.preview_trigger").click(function(){ $("#main-wrap").after(""); $.ajax({ diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb index 23e8b82e..8c32cc6b 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb @@ -238,6 +238,7 @@
+ <%= link_to t('preview'),panel_announcement_back_end_bulletin_preview_path, :class=>"btn" %> <%= f.submit t('submit'), :class=>'btn btn-primary' %> <%= link_to t('cancel'), get_go_back, :class=>"btn" %>
diff --git a/vendor/built_in_modules/announcement/config/routes.rb b/vendor/built_in_modules/announcement/config/routes.rb index b2d8d161..48308850 100644 --- a/vendor/built_in_modules/announcement/config/routes.rb +++ b/vendor/built_in_modules/announcement/config/routes.rb @@ -15,6 +15,7 @@ Rails.application.routes.draw do get 'load_quick_edit' end collection do + post "preview" get 'delete' end match "file_quick_add/:bulletin_id" => "bulletins#file_quick_add" ,:as => :file_quick_add diff --git a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_form.html.erb b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_form.html.erb index 3460f8d8..29d75d61 100644 --- a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_form.html.erb +++ b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_form.html.erb @@ -1,5 +1,7 @@ <% # encoding: utf-8 %> - +<% content_for :page_specific_javascript do -%> + <%= javascript_include_tag "inc/modal-preview" %> +<% end -%> <%= f.error_messages %> @@ -279,6 +281,7 @@
+ <%= link_to t('preview'),preview_panel_news_back_end_news_bulletins_path, :class=>"btn post_preview",:method=>:post , :remote => true%> <%= f.submit t('submit'), :class=>'btn btn-primary' %> <%= link_to t('cancel'), get_go_back, :class=>"btn" %>
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 new file mode 100644 index 00000000..c5ed3aba --- /dev/null +++ b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_modal_preview.html.erb @@ -0,0 +1,47 @@ + \ No newline at end of file diff --git a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/preview.js.erb b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/preview.js.erb new file mode 100644 index 00000000..ff3f4e3a --- /dev/null +++ b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/preview.js.erb @@ -0,0 +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 %>"; +$("#"+start_modal_with_id).css("width","1050px"); +$("#"+start_modal_with_id).css("height","768px"); +$("#"+start_modal_with_id).css("margin","-270px 0 0 -550px"); \ No newline at end of file diff --git a/vendor/built_in_modules/news/config/routes.rb b/vendor/built_in_modules/news/config/routes.rb index 5220248c..2bab5dc3 100644 --- a/vendor/built_in_modules/news/config/routes.rb +++ b/vendor/built_in_modules/news/config/routes.rb @@ -11,10 +11,12 @@ Rails.application.routes.draw do match "approve/:news_bulletin_id" => "news_approvals#approve",:as => :approve,:via => :post match "link_quick_add/:news_bulletin_id" => "news_bulletins#link_quick_add" ,:as => :link_quick_add match "link_quick_edit/:news_bulletin_id" => "news_bulletins#link_quick_edit" ,:as => :link_quick_edit + member do get 'load_quick_edit' end collection do + post "preview" get 'delete' end match "file_quick_add/:news_bulletin_id" => "news_bulletins#file_quick_add" ,:as => :file_quick_add From ecb3b5b25c78f7b91f202e7f7be2374f86e11ea3 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 4 Sep 2012 09:34:14 +0800 Subject: [PATCH 006/139] stop saving sold files on git --- .gitignore | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 572d342f..7166a15b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,9 +8,10 @@ uploads/**/* public/panel/**/* public/index.html .DS_Store - +solr/data/**/* *.swp - +*.pid +*.lck public/assets config/application.rb 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 007/139] 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 a12f66dc..37a8d319 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 96f07221..cd992049 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 39904a1c..b2fbc997 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 00000000..fb08f675 --- /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 8aea2b8c..f152e3f4 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 00000000..bd281c99 --- /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 00000000..86318050 --- /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 c013d7f4..75c8e304 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 adc50101..6e6dfb62 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 a3942612..2d365ec7 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 0e9f0ac3..9a05d943 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 974d55a7..4c31d939 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 c5ed3aba..5b3ec481 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 @@ -