diff --git a/Gemfile b/Gemfile index b20c8653a..0ea40e013 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ unless RUBY_PLATFORM =~ /w32/ gem 'rubyzip' gem 'zip-zip' end -gem 'seems_rateable' +gem 'seems_rateable', path: 'lib/seems_rateable' gem "rails", "3.2.13" gem "jquery-rails", "~> 2.0.2" gem "i18n", "~> 0.6.0" diff --git a/app/controllers/ratings_controller.rb b/app/controllers/ratings_controller.rb deleted file mode 100644 index 5ae478af8..000000000 --- a/app/controllers/ratings_controller.rb +++ /dev/null @@ -1,15 +0,0 @@ -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/config/routes.rb b/config/routes.rb index 54d9124f0..bf6f3ceee 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,7 +16,8 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. RedmineApp::Application.routes.draw do - resources :ratings, :only => :create + mount SeemsRateable::Engine => '/rateable', :as => :rateable + namespace :zipdown do match 'assort' end diff --git a/lib/plugins/seems_rateable-master/.gitignore b/lib/plugins/seems_rateable-master/.gitignore deleted file mode 100644 index f372f8d4f..000000000 --- a/lib/plugins/seems_rateable-master/.gitignore +++ /dev/null @@ -1,21 +0,0 @@ -*.gem -*.rbc -.bundle -.config -.yardoc -Gemfile.lock -InstalledFiles -_yardoc -coverage -doc/ -lib/bundler/man -pkg -rdoc -spec/reports -test/tmp -test/version_tmp -tmp -.project -.rvmrc -spec -test diff --git a/lib/plugins/seems_rateable-master/Rakefile b/lib/plugins/seems_rateable-master/Rakefile deleted file mode 100644 index c2ef03737..000000000 --- a/lib/plugins/seems_rateable-master/Rakefile +++ /dev/null @@ -1,32 +0,0 @@ -begin - require 'bundler/setup' -rescue LoadError - puts 'You must `gem install bundler` and `bundle install` to run rake tasks' -end - -require 'rdoc/task' - -RDoc::Task.new(:rdoc) do |rdoc| - rdoc.rdoc_dir = 'rdoc' - rdoc.title = 'SeemsRateable' - rdoc.options << '--line-numbers' - rdoc.rdoc_files.include('README.rdoc') - rdoc.rdoc_files.include('lib/**/*.rb') -end - -APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__) -load 'rails/tasks/engine.rake' -Bundler::GemHelper.install_tasks - -APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__) -load 'rails/tasks/engine.rake' - -Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f } -require 'rspec/core' -require 'rspec/core/rake_task' - -task :default => :spec - - - - diff --git a/lib/plugins/seems_rateable-master/app/controllers/seems_rateable/application_controller.rb b/lib/plugins/seems_rateable-master/app/controllers/seems_rateable/application_controller.rb deleted file mode 100644 index cd94242dd..000000000 --- a/lib/plugins/seems_rateable-master/app/controllers/seems_rateable/application_controller.rb +++ /dev/null @@ -1,4 +0,0 @@ -module SeemsRateable - class ApplicationController < ActionController::Base - end -end diff --git a/lib/plugins/seems_rateable-master/app/helpers/seems_rateable/application_helper.rb b/lib/plugins/seems_rateable-master/app/helpers/seems_rateable/application_helper.rb deleted file mode 100644 index 596eeb4c9..000000000 --- a/lib/plugins/seems_rateable-master/app/helpers/seems_rateable/application_helper.rb +++ /dev/null @@ -1,4 +0,0 @@ -module SeemsRateable - module ApplicationHelper - end -end diff --git a/lib/plugins/seems_rateable-master/app/helpers/seems_rateable/ratings_helper.rb b/lib/plugins/seems_rateable-master/app/helpers/seems_rateable/ratings_helper.rb deleted file mode 100644 index 91c7411c4..000000000 --- a/lib/plugins/seems_rateable-master/app/helpers/seems_rateable/ratings_helper.rb +++ /dev/null @@ -1,4 +0,0 @@ -module SeemsRateable - module RatingsHelper - end -end diff --git a/lib/plugins/seems_rateable-master/app/models/seems_rateable/rate.rb b/lib/plugins/seems_rateable-master/app/models/seems_rateable/rate.rb deleted file mode 100644 index f9db806a3..000000000 --- a/lib/plugins/seems_rateable-master/app/models/seems_rateable/rate.rb +++ /dev/null @@ -1,6 +0,0 @@ -module SeemsRateable - class Rate < ActiveRecord::Base - belongs_to :rater, :class_name => SeemsRateable::Engine.config.owner_class - belongs_to :rateable, :polymorphic => true - end -end diff --git a/lib/plugins/seems_rateable-master/app/views/layouts/seems_rateable/application.html.erb b/lib/plugins/seems_rateable-master/app/views/layouts/seems_rateable/application.html.erb deleted file mode 100644 index 3c63ba433..000000000 --- a/lib/plugins/seems_rateable-master/app/views/layouts/seems_rateable/application.html.erb +++ /dev/null @@ -1,14 +0,0 @@ - - - - SeemsRateable - <%= stylesheet_link_tag "seems_rateable/application", media: "all" %> - <%= javascript_include_tag "seems_rateable/application" %> - <%= csrf_meta_tags %> - - - -<%= yield %> - - - diff --git a/lib/plugins/seems_rateable-master/lib/generators/seems_rateable/install/install_generator.rb b/lib/plugins/seems_rateable-master/lib/generators/seems_rateable/install/install_generator.rb deleted file mode 100644 index 9a3aac0a5..000000000 --- a/lib/plugins/seems_rateable-master/lib/generators/seems_rateable/install/install_generator.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'rails/generators/migration' -require 'fileutils' - -module SeemsRateable - module Generators - class InstallGenerator < ::Rails::Generators::Base - include Rails::Generators::Migration - source_root File.expand_path('../templates', __FILE__) - - def self.next_migration_number(path) - unless @prev_migration_nr - @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i - else - @prev_migration_nr += 1 - end - @prev_migration_nr.to_s - end - - desc "generating migration files" - def copy_migrations - migration_template "rates_migration.rb", "db/migrate/create_seems_rateable_rates.rb" - migration_template "cached_ratings_migration.rb", "db/migrate/create_seems_rateable_cached_ratings.rb" - end - - desc "generating initializer" - def copy_initializer - template "initializer.rb", "config/initializers/seems_rateable.rb" - end - - desc "generating javascript files" - def copy_javascript_asset - Dir.mkdir "app/assets/javascripts/rateable" unless File.directory?("app/assets/javascripts/rateable") - copy_file "rateable.js.erb", "app/assets/javascripts/rateable/rateable.js.erb" unless File.exists?("app/assets/javascripts/rateable/rateable.js.erb") - copy_file "jRating.js.erb", "app/assets/javascripts/rateable/jRating.js.erb" unless File.exists?("app/assets/javascripts/rateable/jRating.js.erb") - end - - end - end -end diff --git a/lib/plugins/seems_rateable-master/lib/generators/seems_rateable/install/templates/cached_ratings_migration.rb b/lib/plugins/seems_rateable-master/lib/generators/seems_rateable/install/templates/cached_ratings_migration.rb deleted file mode 100644 index 1b91bdadc..000000000 --- a/lib/plugins/seems_rateable-master/lib/generators/seems_rateable/install/templates/cached_ratings_migration.rb +++ /dev/null @@ -1,17 +0,0 @@ -class CreateSeemsRateableCachedRatings < ActiveRecord::Migration - def self.up - create_table :seems_rateable_cached_ratings do |t| - t.belongs_to :cacheable, :polymorphic => true - t.float :avg, :null => false - t.integer :cnt, :null => false - t.string :dimension - t.integer :cacheable_id, :limit => 8 - t.string :cacheable_type - t.timestamps - end - end - - def self.down - drop_table :cached_ratings - end -end diff --git a/lib/plugins/seems_rateable-master/lib/seems_rateable/engine.rb b/lib/plugins/seems_rateable-master/lib/seems_rateable/engine.rb deleted file mode 100644 index 185d6f9d9..000000000 --- a/lib/plugins/seems_rateable-master/lib/seems_rateable/engine.rb +++ /dev/null @@ -1,17 +0,0 @@ -module SeemsRateable - class Engine < ::Rails::Engine - isolate_namespace SeemsRateable - - config.generators do |g| - g.test_framework :rspec, :fixture => false - g.fixture_replacement :factory_girl, :dir => 'spec/factories' - end - - initializer :seems_rateable do - ActiveRecord::Base.send :include, SeemsRateable::Model - ActionView::Base.send :include, SeemsRateable::Helpers - ActionDispatch::Routing::Mapper.send :include, SeemsRateable::Routes - end - - end -end diff --git a/lib/plugins/seems_rateable-master/lib/seems_rateable/errors.rb b/lib/plugins/seems_rateable-master/lib/seems_rateable/errors.rb deleted file mode 100644 index 8a83059ba..000000000 --- a/lib/plugins/seems_rateable-master/lib/seems_rateable/errors.rb +++ /dev/null @@ -1,21 +0,0 @@ -module SeemsRateable - module Errors - class InvalidRateableObjectError < StandardError - def to_s - "Stated object is not rateable. Add 'seems_rateable' to your object's class model." - end - end - - class NoCurrentUserInstanceError < StandardError - def to_s - "User instance current_user is not available." - end - end - - class AlreadyRatedError < StandardError - def to_s - "User has already rated an object." - end - end - end -end diff --git a/lib/plugins/seems_rateable-master/lib/seems_rateable/helpers.rb b/lib/plugins/seems_rateable-master/lib/seems_rateable/helpers.rb deleted file mode 100644 index 399f06fd8..000000000 --- a/lib/plugins/seems_rateable-master/lib/seems_rateable/helpers.rb +++ /dev/null @@ -1,27 +0,0 @@ -module SeemsRateable - module Helpers - def rating_for(obj, opts={}) - raise Errors::InvalidRateableObjectError unless obj.class.respond_to?(:rateable?) - - options = { - :dimension => nil, - :static => false, - :class => 'rateable', - :id => nil - }.update(opts) - - content_tag :div, "", "data-average" => obj.average(options[:dimension]) ? obj.average(options[:dimension]).avg : 0, :id => options[:id], - :class => "#{options[:class]}#{jdisabled?(options[:static])}", - "data-id" => obj.id, "data-kls" => obj.class.name, "data-dimension" => options[:dimension] - end - - def seems_rateable_stylesheet - stylesheet_link_tag "seems_rateable/application", media: "all", "data-turbolinks-track" => true - end - - private - def jdisabled?(option) - " jDisabled" if option || !current_user - end - end -end diff --git a/lib/plugins/seems_rateable-master/lib/seems_rateable/model.rb b/lib/plugins/seems_rateable-master/lib/seems_rateable/model.rb deleted file mode 100644 index fa1b7af11..000000000 --- a/lib/plugins/seems_rateable-master/lib/seems_rateable/model.rb +++ /dev/null @@ -1,111 +0,0 @@ -require 'active_support/concern' -module SeemsRateable - module Model - extend ActiveSupport::Concern - - def rate(stars, user_id, dimension=nil) - if !has_rated?(user_id, dimension) - self.rates.create do |r| - r.stars = stars - r.rater_id = user_id - end - update_overall_average_rating(stars, dimension) - elsif has_rated?(user_id, dimension) && can_update? - update_users_rating(stars, user_id, dimension) - else - raise Errors::AlreadyRatedError - end - end - - def update_overall_average_rating(stars, dimension=nil) - if average(dimension).nil? - CachedRating.create do |r| - r.avg = stars - r.dimension = dimension - r.cacheable_id = self.id - r.cacheable_type = self.class.name - r.cnt = 1 - end - else - r = average(dimension) - r.avg = (r.avg * r.cnt + stars) / (r.cnt+1) - r.cnt += 1 - r.save! - end - end - - def update_users_rating(stars, user_id, dimension=nil) - obj = rates(dimension).where(:rater_id => user_id).first - current_record = average(dimension) - current_record.avg = (current_record.avg*current_record.cnt - obj.stars + stars) / (current_record.cnt) - current_record.save! - obj.stars = stars - obj.save! - end - - - def average(dimension=nil) - if dimension.nil? - self.send "rate_average_without_dimension" - else - self.send "#{dimension}_average" - end - end - - def rates(dimension=nil) - if dimension.nil? - self.send "rates_without_dimension" - else - self.send "#{dimension}_rates" - end - end - - def raters(dimension=nil) - if dimension.nil? - self.send "raters_without_dimension" - else - self.send "#{dimension}_raters" - end - end - - def has_rated?(user_id, dimension=nil) - record = self.rates(dimension).where(:rater_id => user_id) - record.empty? ? false : true - end - - def can_update? - self.class.can_update? - end - - module ClassMethods - def seems_rateable(opts={}) - #has_many :rates_without_dimension, -> { where(dimension: nil) }, :as => :rateable, :class_name => SeemsRateable::Rate, :dependent => :destroy - has_many :rates_without_dimension, :conditions => { dimension: nil }, :as => :rateable, :class_name => SeemsRateable::Rate, :dependent => :destroy - has_many :raters_without_dimension, :through => :rates_without_dimension, :source => :rater - has_one :rate_average_without_dimension, :conditions => { dimension: nil }, :as => :cacheable, :class_name => SeemsRateable::CachedRating, :dependent => :destroy - - @permission = opts[:allow_update] ? true : false - - def self.can_update? - @permission - end - - def self.rateable? - true - end - - if opts[:dimensions].is_a?(Array) - opts[:dimensions].each do |dimension| - has_many :"#{dimension}_rates", :conditions => { dimension: dimension.to_s }, :dependent => :destroy, :class_name => SeemsRateable::Rate, :as => :rateable - has_many :"#{dimension}_raters", :through => :"#{dimension}_rates", :source => :rater - has_one :"#{dimension}_average", :conditions => { dimension: dimension.to_s }, :as => :cacheable, :class_name => SeemsRateable::CachedRating, :dependent => :destroy - end - end - end - - def seems_rateable_rater - has_many :ratings_given, :class_name => SeemsRateable::Rate, :foreign_key => :rater_id - end - end - end -end diff --git a/lib/plugins/seems_rateable-master/lib/tasks/seems_rateable_tasks.rake b/lib/plugins/seems_rateable-master/lib/tasks/seems_rateable_tasks.rake deleted file mode 100644 index 98c5403ac..000000000 --- a/lib/plugins/seems_rateable-master/lib/tasks/seems_rateable_tasks.rake +++ /dev/null @@ -1,4 +0,0 @@ -# desc "Explaining what the task does" -# task :seems_rateable do -# # Task goes here -# end diff --git a/lib/plugins/seems_rateable-master/Gemfile b/lib/seems_rateable/Gemfile similarity index 100% rename from lib/plugins/seems_rateable-master/Gemfile rename to lib/seems_rateable/Gemfile diff --git a/lib/plugins/seems_rateable-master/MIT-LICENSE b/lib/seems_rateable/MIT-LICENSE similarity index 100% rename from lib/plugins/seems_rateable-master/MIT-LICENSE rename to lib/seems_rateable/MIT-LICENSE diff --git a/lib/plugins/seems_rateable-master/README.md b/lib/seems_rateable/README.md similarity index 95% rename from lib/plugins/seems_rateable-master/README.md rename to lib/seems_rateable/README.md index 3e78d0250..aacc7407b 100644 --- a/lib/plugins/seems_rateable-master/README.md +++ b/lib/seems_rateable/README.md @@ -45,7 +45,7 @@ Don't forget to run $ rake db:migrate -To prepare model add seems_rateable to your rateable model file. You can also pass a hash of options to +To prepare model add seems_rateable to your rateable model file. You can also pass a hash of options to customize the functionality