From b4209b7cc5fa145501f891c11c9552bbf98b5af9 Mon Sep 17 00:00:00 2001 From: yanxd Date: Mon, 21 Apr 2014 15:41:51 +0800 Subject: [PATCH] jrating --- Gemfile | 1 + Gemfile.lock | 6 ++- app/controllers/ratings_controller.rb | 15 ++++++ app/models/softapplication.rb | 2 + app/views/layouts/base.html.erb | 1 + app/views/softapplications/show.html.erb | 6 ++- config/routes.rb | 24 ++++----- ...0421044829_create_seems_rateable_rates.rb} | 0 ...0_create_seems_rateable_cached_ratings.rb} | 0 db/schema.rb | 2 +- .../seems_rateable/ratings_controller.rb | 17 ------ .../images/seems_rateable/bg_jRatingInfos.png | Bin 0 -> 572 bytes public/images/seems_rateable/small.png | Bin 0 -> 427 bytes public/images/seems_rateable/stars.png | Bin 0 -> 1018 bytes .../javascripts/seems_rateable/jRating.js | 8 +-- .../javascripts/seems_rateable/rateable.js | 4 +- public/stylesheets/nyan.css | 50 ++++++++++++++++++ 17 files changed, 98 insertions(+), 38 deletions(-) create mode 100644 app/controllers/ratings_controller.rb rename db/migrate/{20130806083151_create_seems_rateable_rates.rb => 20140421044829_create_seems_rateable_rates.rb} (100%) rename db/migrate/{20130806083152_create_seems_rateable_cached_ratings.rb => 20140421044830_create_seems_rateable_cached_ratings.rb} (100%) delete mode 100644 lib/plugins/seems_rateable-master/app/controllers/seems_rateable/ratings_controller.rb create mode 100644 public/images/seems_rateable/bg_jRatingInfos.png create mode 100644 public/images/seems_rateable/small.png create mode 100644 public/images/seems_rateable/stars.png rename app/assets/javascripts/rateable/jRating.js.erb => public/javascripts/seems_rateable/jRating.js (94%) rename app/assets/javascripts/rateable/rateable.js.erb => public/javascripts/seems_rateable/rateable.js (93%) diff --git a/Gemfile b/Gemfile index 63dd32df..b20c8653 100644 --- a/Gemfile +++ b/Gemfile @@ -6,6 +6,7 @@ unless RUBY_PLATFORM =~ /w32/ gem 'rubyzip' gem 'zip-zip' end +gem 'seems_rateable' gem "rails", "3.2.13" gem "jquery-rails", "~> 2.0.2" gem "i18n", "~> 0.6.0" diff --git a/Gemfile.lock b/Gemfile.lock index d60847b1..40caae26 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -75,10 +75,13 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) - rake (10.0.4) + rake (10.1.0) rdoc (3.12.2) json (~> 1.4) ruby-openid (2.1.8) + seems_rateable (1.0.13) + jquery-rails + rails sprockets (2.2.2) hike (~> 1.2) multi_json (~> 1.0) @@ -109,3 +112,4 @@ DEPENDENCIES rails (= 3.2.13) rdoc (>= 2.4.2) ruby-openid (~> 2.1.4) + seems_rateable diff --git a/app/controllers/ratings_controller.rb b/app/controllers/ratings_controller.rb new file mode 100644 index 00000000..5ae478af --- /dev/null +++ b/app/controllers/ratings_controller.rb @@ -0,0 +1,15 @@ +require_dependency "seems_rateable/application_controller" + +class RatingsController < ::ApplicationController + def create + raise NoCurrentUserInstanceError unless current_user + + obj = params[:kls].classify.constantize.find(params[:idBox]) + begin + obj.rate(params[:rate].to_i, current_user.id, params[:dimension]) + render :json => true + rescue Errors::AlreadyRatedError + render :json => {:error => true} + end + end +end diff --git a/app/models/softapplication.rb b/app/models/softapplication.rb index 71caf059..205ede48 100644 --- a/app/models/softapplication.rb +++ b/app/models/softapplication.rb @@ -1,6 +1,8 @@ class Softapplication < ActiveRecord::Base attr_accessible :android_min_version_available, :app_type_id, :app_type_name, :description, :name, :user_id, :contest_id, :application_developers acts_as_attachable + seems_rateable :allow_update => true, :dimensions => :quality + has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :contesting_softapplications, :dependent => :destroy diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erb index fe42d00e..17109b25 100644 --- a/app/views/layouts/base.html.erb +++ b/app/views/layouts/base.html.erb @@ -10,6 +10,7 @@ <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2', 'application', 'nyan', :media => 'all' %> <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %> <%= javascript_heads %> +<%= javascript_include_tag 'seems_rateable/jRating', 'seems_rateable/rateable'%> <%= heads_for_theme %> <%= call_hook :view_layouts_base_html_head %> diff --git a/app/views/softapplications/show.html.erb b/app/views/softapplications/show.html.erb index 047ecf8d..76483c7c 100644 --- a/app/views/softapplications/show.html.erb +++ b/app/views/softapplications/show.html.erb @@ -36,6 +36,10 @@ 开发人员:<%= @softapplication.application_developers %> + + 平均评分: <%= rating_for @softapplication, :static => true, dimension: :quality, class: 'rateable div_inline' %> + + @@ -64,7 +68,7 @@
软件评论:
-
+
评分: <%= rating_for @softapplication, dimension: :quality, class: 'rateable div_inline' %>
diff --git a/config/routes.rb b/config/routes.rb index 17e09f5a..54d9124f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,6 +16,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. RedmineApp::Application.routes.draw do + resources :ratings, :only => :create namespace :zipdown do match 'assort' end @@ -506,18 +507,6 @@ RedmineApp::Application.routes.draw do match 'upload_avatar', :to => 'avatar#upload', :via => :post # Endof Tao's code get 'robots.txt', :to => 'welcome#robots' - - Dir.glob File.expand_path("plugins/*", Rails.root) do |plugin_dir| - file = File.join(plugin_dir, "config/routes.rb") - if File.exists?(file) - begin - instance_eval File.read(file) - rescue Exception => e - puts "An error occurred while loading the routes definition of #{File.basename(plugin_dir)} plugin (#{file}): #{e.message}." - exit 1 - end - end - end ##############测试留言功能 fq post 'words/new', :to => 'words#new' @@ -607,5 +596,16 @@ RedmineApp::Application.routes.draw do match 'words/add_brief_introdution', :controller => 'words', :action => 'add_brief_introdution' + Dir.glob File.expand_path("plugins/*", Rails.root) do |plugin_dir| + file = File.join(plugin_dir, "config/routes.rb") + if File.exists?(file) + begin + instance_eval File.read(file) + rescue Exception => e + puts "An error occurred while loading the routes definition of #{File.basename(plugin_dir)} plugin (#{file}): #{e.message}." + exit 1 + end + end + end get ':controller(/:action(/:id))' end diff --git a/db/migrate/20130806083151_create_seems_rateable_rates.rb b/db/migrate/20140421044829_create_seems_rateable_rates.rb similarity index 100% rename from db/migrate/20130806083151_create_seems_rateable_rates.rb rename to db/migrate/20140421044829_create_seems_rateable_rates.rb diff --git a/db/migrate/20130806083152_create_seems_rateable_cached_ratings.rb b/db/migrate/20140421044830_create_seems_rateable_cached_ratings.rb similarity index 100% rename from db/migrate/20130806083152_create_seems_rateable_cached_ratings.rb rename to db/migrate/20140421044830_create_seems_rateable_cached_ratings.rb diff --git a/db/schema.rb b/db/schema.rb index bfbb7a26..3918413f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140417091429) do +ActiveRecord::Schema.define(:version => 20140421044830) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false diff --git a/lib/plugins/seems_rateable-master/app/controllers/seems_rateable/ratings_controller.rb b/lib/plugins/seems_rateable-master/app/controllers/seems_rateable/ratings_controller.rb deleted file mode 100644 index afc47d5e..00000000 --- a/lib/plugins/seems_rateable-master/app/controllers/seems_rateable/ratings_controller.rb +++ /dev/null @@ -1,17 +0,0 @@ -require_dependency "seems_rateable/application_controller" - -module SeemsRateable - class RatingsController < ::ApplicationController - def create - raise NoCurrentUserInstanceError unless current_user - - obj = params[:kls].classify.constantize.find(params[:idBox]) - begin - obj.rate(params[:rate].to_i, current_user.id, params[:dimension]) - render :json => true - rescue Errors::AlreadyRatedError - render :json => {:error => true} - end - end - end -end diff --git a/public/images/seems_rateable/bg_jRatingInfos.png b/public/images/seems_rateable/bg_jRatingInfos.png new file mode 100644 index 0000000000000000000000000000000000000000..af5bf556e15c884bc24c0ab00537123d373bbcc9 GIT binary patch literal 572 zcmV-C0>k}@P)V!IyWhyxINQN4+b0cZ8;>G@@1HMkvg zce~v)5k0ukBUEc;t(9r%=82o%)PBEzW#-ZNee4$xhXYkr1yWbm>2#vS&w{4YX-{kY zXpG6T{!M=~yc-r}S<>ulM(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pivj*8~-YX}0wT5B>9$VHC07)VQ#sI%;fa&9zVg{!%jz>&2j22y9zUu?{tLK4VvZAW0AI;BS z`C?x8NhA_;16?9qZ8Roo^E@X!vmQCGp#K~W*jBXd<1TDy4g~HvPDc6TbJmG}Z{X9~224yb7FuF<@Dij@uUc9GNnH5O^KKXdgU%x^1Bvf<7Zhqp=JQ zR6-lZ<1&vuHE{m!h2Td=<{?@uDstP^YQ4U@Tj_y-(R@B%K!(o4hiktH0@*+VlW+?! z$+Cn!M|wJ)zBuznqrPWZjpo|gV|Qd^;&MJea}^su1kYUP^=vk~h=z8*R4Ntk-Mhb$ zN=aSU<*Q?3WB(71=4Ey|CiOfaKQ}iwuW9NCL{m_96;_O%2tcW$C`xX6dOCf0IJ~*K ox_XyoyAI+m1Q(vi`&WPg02xTa4XYF-ng9R*07*qoM6N<$g5Sm5VgLXD literal 0 HcmV?d00001 diff --git a/app/assets/javascripts/rateable/jRating.js.erb b/public/javascripts/seems_rateable/jRating.js similarity index 94% rename from app/assets/javascripts/rateable/jRating.js.erb rename to public/javascripts/seems_rateable/jRating.js index 4f43a4f9..85612d06 100644 --- a/app/assets/javascripts/rateable/jRating.js.erb +++ b/public/javascripts/seems_rateable/jRating.js @@ -12,13 +12,13 @@ $.fn.jRating = function(op) { var defaults = { /** String vars **/ - bigStarsPath : '<%= image_path "seems_rateable/stars.png" %>', // path of the icon stars.png - smallStarsPath : '<%= image_path "seems_rateable/small.png" %>', // path of the icon small.png - path : '<%= SeemsRateable::Engine.routes.url_helpers.ratings_path %>', + bigStarsPath : '/images/seems_rateable/stars.png', // path of the icon stars.png + smallStarsPath : '/images/seems_rateable/small.png', // path of the icon small.png + path : '/ratings', type : 'big', // can be set to 'small' or 'big' /** Boolean vars **/ - step:false, // if true, mouseover binded star by star, + step: true, // if true, mouseover binded star by star, isDisabled:false, showRateInfo: false, canRateAgain : false, diff --git a/app/assets/javascripts/rateable/rateable.js.erb b/public/javascripts/seems_rateable/rateable.js similarity index 93% rename from app/assets/javascripts/rateable/rateable.js.erb rename to public/javascripts/seems_rateable/rateable.js index da6cc309..e926601d 100644 --- a/app/assets/javascripts/rateable/rateable.js.erb +++ b/public/javascripts/seems_rateable/rateable.js @@ -11,7 +11,7 @@ $(document).ready(function(){ //showRateInfo:false, //Rate info panel, set true to display //rateInfosX : 45, //In pixel - Absolute left position of the information box during mousemove. //rateInfosY : 5, //In pixel - Absolute top position of the information box during mousemove. - path : '<%= SeemsRateable::Engine.routes.url_helpers.ratings_path %>', + path : '/ratings', onSuccess : function(element, rate){ //something like -> //alert('success'); @@ -21,5 +21,5 @@ $(document).ready(function(){ $('You have already rated!').insertAfter(element) } }); - + }); diff --git a/public/stylesheets/nyan.css b/public/stylesheets/nyan.css index 0d426553..867f7624 100644 --- a/public/stylesheets/nyan.css +++ b/public/stylesheets/nyan.css @@ -5,6 +5,9 @@ -moz-box-sizing: border-box; -box-sizing: border-box; } +.div_inline{ + display: inline-block; +} /*文字不换行*/ .text_nowrap{ word-break:keep-all; @@ -65,7 +68,54 @@ * { font-family: Helvetica, Tahoma, Arial, "Microsoft YaHei", "微软雅黑", SimSun, "宋体", STXihei, "华文细黑", Heiti, "黑体", sans-serif; } +/* 模态窗口 +*******************************************************************************/ +/** jRating CSS **/ +/**Div containing the color of the stars */ + + +.jRatingAverage { + background-color:#f62929; + position:relative; + top:0; + left:0; + z-index:2; + height:100%; +} +.jRatingColor { + background-color:#FFD400; /* bgcolor of the stars*/ + position:relative; + top:0; + left:0; + z-index:2; + height:100%; +} + +/** Div containing the stars **/ +.jStar { + position:relative; + left:0; + z-index:3; +} + +/** P containing the rate informations **/ +p.jRatingInfos { + position: absolute; + z-index:9999; + background: transparent url('bg_jRatingInfos.png') no-repeat; + color: #CACACA; + display: none; + width: 91px; + height: 29px; + font-size:16px; + text-align:center; + padding-top:5px; +} +p.jRatingInfos span.maxRate { + color:#c9c9c9; + font-size:14px; +} /* 模态窗口 *******************************************************************************/