commit
6ac503eac5
@ -0,0 +1,119 @@
|
||||
PATH
|
||||
remote: lib/seems_rateable
|
||||
specs:
|
||||
seems_rateable (1.0.13)
|
||||
jquery-rails
|
||||
rails
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
actionmailer (3.2.13)
|
||||
actionpack (= 3.2.13)
|
||||
mail (~> 2.5.3)
|
||||
actionpack (3.2.13)
|
||||
activemodel (= 3.2.13)
|
||||
activesupport (= 3.2.13)
|
||||
builder (~> 3.0.0)
|
||||
erubis (~> 2.7.0)
|
||||
journey (~> 1.0.4)
|
||||
rack (~> 1.4.5)
|
||||
rack-cache (~> 1.2)
|
||||
rack-test (~> 0.6.1)
|
||||
sprockets (~> 2.2.1)
|
||||
activemodel (3.2.13)
|
||||
activesupport (= 3.2.13)
|
||||
builder (~> 3.0.0)
|
||||
activerecord (3.2.13)
|
||||
activemodel (= 3.2.13)
|
||||
activesupport (= 3.2.13)
|
||||
arel (~> 3.0.2)
|
||||
tzinfo (~> 0.3.29)
|
||||
activeresource (3.2.13)
|
||||
activemodel (= 3.2.13)
|
||||
activesupport (= 3.2.13)
|
||||
activesupport (3.2.13)
|
||||
i18n (= 0.6.1)
|
||||
multi_json (~> 1.0)
|
||||
acts-as-taggable-on (2.4.1)
|
||||
rails (>= 3, < 5)
|
||||
arel (3.0.2)
|
||||
builder (3.0.0)
|
||||
coderay (1.0.9)
|
||||
erubis (2.7.0)
|
||||
fastercsv (1.5.0)
|
||||
hike (1.2.3)
|
||||
i18n (0.6.1)
|
||||
journey (1.0.4)
|
||||
jquery-rails (2.0.3)
|
||||
railties (>= 3.1.0, < 5.0)
|
||||
thor (~> 0.14)
|
||||
json (1.8.0)
|
||||
mail (2.5.4)
|
||||
mime-types (~> 1.16)
|
||||
treetop (~> 1.4.8)
|
||||
mime-types (1.23)
|
||||
multi_json (1.7.6)
|
||||
mysql2 (0.3.11-x86-mingw32)
|
||||
net-ldap (0.3.1)
|
||||
polyglot (0.3.3)
|
||||
rack (1.4.5)
|
||||
rack-cache (1.2)
|
||||
rack (>= 0.4)
|
||||
rack-openid (1.3.1)
|
||||
rack (>= 1.1.0)
|
||||
ruby-openid (>= 2.1.8)
|
||||
rack-ssl (1.3.3)
|
||||
rack
|
||||
rack-test (0.6.2)
|
||||
rack (>= 1.0)
|
||||
rails (3.2.13)
|
||||
actionmailer (= 3.2.13)
|
||||
actionpack (= 3.2.13)
|
||||
activerecord (= 3.2.13)
|
||||
activeresource (= 3.2.13)
|
||||
activesupport (= 3.2.13)
|
||||
bundler (~> 1.0)
|
||||
railties (= 3.2.13)
|
||||
railties (3.2.13)
|
||||
actionpack (= 3.2.13)
|
||||
activesupport (= 3.2.13)
|
||||
rack-ssl (~> 1.3.2)
|
||||
rake (>= 0.8.7)
|
||||
rdoc (~> 3.4)
|
||||
thor (>= 0.14.6, < 2.0)
|
||||
rake (10.0.4)
|
||||
rdoc (3.12.2)
|
||||
json (~> 1.4)
|
||||
ruby-openid (2.1.8)
|
||||
sprockets (2.2.2)
|
||||
hike (~> 1.2)
|
||||
multi_json (~> 1.0)
|
||||
rack (~> 1.0)
|
||||
tilt (~> 1.1, != 1.3.0)
|
||||
thor (0.18.1)
|
||||
tilt (1.4.1)
|
||||
treetop (1.4.14)
|
||||
polyglot
|
||||
polyglot (>= 0.3.1)
|
||||
tzinfo (0.3.37)
|
||||
|
||||
PLATFORMS
|
||||
x86-mingw32
|
||||
|
||||
DEPENDENCIES
|
||||
activerecord-jdbc-adapter (= 1.2.5)
|
||||
activerecord-jdbcmysql-adapter
|
||||
acts-as-taggable-on
|
||||
builder (= 3.0.0)
|
||||
coderay (~> 1.0.6)
|
||||
fastercsv (~> 1.5.0)
|
||||
i18n (~> 0.6.0)
|
||||
jquery-rails (~> 2.0.2)
|
||||
mysql2 (~> 0.3.11)
|
||||
net-ldap (~> 0.3.1)
|
||||
rack-openid
|
||||
rails (= 3.2.13)
|
||||
rdoc (>= 2.4.2)
|
||||
ruby-openid (~> 2.1.4)
|
||||
seems_rateable!
|
@ -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
|
@ -0,0 +1,6 @@
|
||||
class UserScoreController < ApplicationController
|
||||
helper :UserScore
|
||||
|
||||
|
||||
|
||||
end
|
@ -1,4 +1,6 @@
|
||||
class PraiseTread < ActiveRecord::Base
|
||||
attr_accessible :user_id,:praise_tread_object_id,:praise_tread_object_type,:praise_or_tread
|
||||
belongs_to :user
|
||||
belongs_to :praise_tread_object, polymorphic: true
|
||||
|
||||
end
|
||||
|
@ -0,0 +1,20 @@
|
||||
<div class="top-content">
|
||||
<table>
|
||||
<tr>
|
||||
<td class="info_font" style="width: 240px; color: #15bccf">创新竞赛社区</td>
|
||||
<td style="width: 430px; color: #15bccf"><strong><%= l(:label_user_location) %> : </strong></td>
|
||||
<td rowspan="2" width="250px"></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td style="padding-left: 8px"><%=link_to request.host()+"/contests", :controller=>'contests', :action=>'index' %></td>
|
||||
<td ><%=link_to l(:field_homepage), home_path %> >
|
||||
<%=link_to l(:label_contest_innovate), :controller=>'contests', :action=>'index' %> >
|
||||
<span>
|
||||
<% contest = @softapplication.contests.first %><%= contest ? link_to(contest.name, show_contest_contest_path(contest)) : '尚未加入竞赛'%>
|
||||
</span>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
@ -0,0 +1,66 @@
|
||||
<% port = ":3000" if Rails.env.development? %>
|
||||
<script type="text/javascript">
|
||||
function get_school(value){
|
||||
$.ajax({
|
||||
type :"POST",
|
||||
url :'/school/get_schoollist/'+encodeURIComponent(value),
|
||||
data :'text',
|
||||
success: function(data){
|
||||
$("#schoollist").html(data);
|
||||
|
||||
//$("#schoollist").html(data);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
)
|
||||
}
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
function test(id){
|
||||
|
||||
location.href = encodeURI('http://course.trustie.net<%=port%>?school_id='+id);
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
function ssearch(){
|
||||
//alert($("#key_word").val());
|
||||
value = $("#key_word").val();
|
||||
province = $("#province").val();
|
||||
//alert(province);
|
||||
$.ajax({
|
||||
type :"POST",
|
||||
url :'/school/search_school/?key_word='+encodeURIComponent(value)+'&province='+province,
|
||||
data :'text',
|
||||
success: function(data){
|
||||
$("#schoollist").html(data);
|
||||
|
||||
//$("#schoollist").html(data);
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<p>
|
||||
<a href="http://course.trustie.net<%=port%>?school_id=0">全部学校</a>
|
||||
<a href="http://course.trustie.net<%=port%>">我的学校</a>
|
||||
</p>
|
||||
<ul>
|
||||
<li style="width: 40%; float: left">请选择省份:<%= select_tag "province",
|
||||
options_from_collection_for_select(School.find_by_sql("select distinct province from schools"), :province, :province),
|
||||
:onclick => "get_school(this.value)" %></li>
|
||||
<li style="width: 50%; float: left"><input type="text" id="key_word" name="key_word" />
|
||||
<input type="button" class="enterprise" value="搜索" onclick="ssearch()"></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
<div>
|
||||
<ul id="schoollist" style="line-height: 25px">
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -0,0 +1 @@
|
||||
<input type="file" />
|
@ -1,64 +1,70 @@
|
||||
<%= form_for(@softapplication) do |f| %>
|
||||
<%= form_for(softapplication) do |f| %>
|
||||
|
||||
<% if @softapplication.errors.any? %>
|
||||
<% if softapplication.errors.any? %>
|
||||
<div id="error_explanation">
|
||||
<h2><%= pluralize(@softapplication.errors.count, "error") %> prohibited this softapplication from being saved:</h2>
|
||||
<h2><%= pluralize(softapplication.errors.count, "error") %> prohibited this softapplication from being saved:</h2>
|
||||
|
||||
<ul>
|
||||
<% @softapplication.errors.full_messages.each do |msg| %>
|
||||
<% softapplication.errors.full_messages.each do |msg| %>
|
||||
<li><%= msg %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<tr style="width:700px; margin-left: -10px">
|
||||
<td><%= l(:label_softapplication_name) %></td>
|
||||
<td style="require, color: #bb0000"> * </td>:
|
||||
<td ><%= f.text_field :name, :required => true, :size => 60, :style => "width:400px;" %></td>
|
||||
<td><%= l(:label_softapplication_name_condition)%></td>
|
||||
</tr></ br><br /><br />
|
||||
<fieldset class="contes-new-box">
|
||||
|
||||
<tr style="width:700px; margin-left: -10px">
|
||||
<span><%= l(:label_softapplication_name) %></span>
|
||||
<span class="contest-star"> * </span>: <td ><%= f.text_field :name, :required => true, :size => 60, :style => "width:400px;" %></td>
|
||||
<span><%= l(:label_softapplication_name_condition)%></span>
|
||||
</tr></ br>
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<tr style="width:800px;">
|
||||
<span><%= l(:label_softapplication_version_available) %></span>
|
||||
<span class="contest-star"> * </span>: <td style="width: 100px"><%= f.text_field :android_min_version_available, :required => true, :size => 60, :style => "width:400px;" %></td>
|
||||
|
||||
<tr style="width:800px;">
|
||||
<td><%= l(:label_softapplication_version_available) %></td>
|
||||
<td style="require, color: #bb0000"> * </td>:
|
||||
<td style="width: 100px"><%= f.text_field :android_min_version_available, :required => true, :size => 60, :style => "width:400px;" %></td>
|
||||
</tr></ br>
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<tr style="width:800px;">
|
||||
<span><%= l(:label_softapplication_type) %></span>
|
||||
|
||||
</tr></ br><br /><br />
|
||||
<span class="contest-star"> * </span>: <td style="width: 100px"><%= f.text_field :app_type_name, :required => true, :size => 60, :style => "width:400px;" %></td>
|
||||
|
||||
<tr style="width:800px;">
|
||||
<td><%= l(:label_softapplication_type) %></td>
|
||||
<td style="require, color: #bb0000"> * </td>:
|
||||
<td style="width: 100px"><%= f.text_field :app_type_name, :required => true, :size => 60, :style => "width:400px;" %></td>
|
||||
</tr></ br>
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<tr style="width:800px;">
|
||||
<span><%= l(:label_softapplication_description) %></span>
|
||||
<span class="contest-star"> * </span>: <td style="width: 100px"><%= f.text_field :description, :required => true, :size => 60, :style => "width:400px;" %></td>
|
||||
|
||||
</tr></ br><br /><br />
|
||||
</tr></ br>
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<tr style="width:800px;">
|
||||
<span><%= l(:label_softapplication_developers) %></span>
|
||||
<span class="contest-star"> * </span>: <td style="width: 100px"><%= f.text_field :application_developers, :required => true, :size => 60, :style => "width:400px;" %></td>
|
||||
|
||||
<tr style="width:800px;">
|
||||
<td><%= l(:label_softapplication_description) %></td>
|
||||
<td style="require, color: #bb0000"> * </td>:
|
||||
<td style="width: 100px"><%= f.text_field :description, :required => true, :size => 60, :style => "width:400px;" %></td>
|
||||
|
||||
</tr></ br><br /><br />
|
||||
|
||||
|
||||
<fieldset style="width: 600px">
|
||||
<div>
|
||||
<%=l(:label_upload_softapplication_packets)%> :<br />
|
||||
<p id="put-bid-form-partial">
|
||||
<%= render :partial => 'attachments/form' %>
|
||||
</p>
|
||||
</div>
|
||||
</fieldset></tr></ br></ br></ br></ br></ br>
|
||||
|
||||
<fieldset style="width: 600px">
|
||||
<div>
|
||||
<span><%=l(:label_upload_softapplication_photo)%> :</span>(<span style="font-size: 3px"><%=l(:label_upload_softapplication_photo_condition)%></span>)<br />
|
||||
<p id="put-bid-form-partial">
|
||||
<%= render :partial => 'attachments/form' %>
|
||||
</p>
|
||||
</div>
|
||||
</fieldset>
|
||||
</tr></ br>
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<fieldset style="width: 500px">
|
||||
<legend>上传应用软件包和应用截图</legend>
|
||||
<%= render_flash_messages %>
|
||||
<p id="put-bid-form-partial">
|
||||
<%= render :partial => 'attachments/form' %>
|
||||
</p>
|
||||
<p style="font-size: 10px">1、<%=l(:label_upload_softapplication_packets_mustpacketed)%><br>2、<%=l(:label_upload_softapplication_photo_condition)%></p>
|
||||
<p style="font-size: 10px; color: red"><%=l(:label_updated_caution)%></p>
|
||||
|
||||
</fieldset>
|
||||
</fieldset></br>
|
||||
<div class="align-center"><%= submit_tag l(:button_create), :onclick => "return true" %></div>
|
||||
<% end %>
|
||||
|
||||
|
@ -1,76 +1,5 @@
|
||||
<h3 style="font-size: 18px"><%= l(:label_release_softapplication)%></h3>
|
||||
|
||||
|
||||
<%= render partial: 'form', locals:{softapplication: @softapplication} %>
|
||||
|
||||
<div >
|
||||
<%= form_for Softapplication.new, :url => {:controller => 'softapplications', :action => 'create'}, :update => "bidding_project_list", :complete => '$("#put-bid-form").hide();', :html => {:multipart => true, :id => 'add_homework_form'} do |f| %>
|
||||
<fieldset class="contes-new-box">
|
||||
<!-- <legend>
|
||||
<%= l(:label_attachment_plural) %>
|
||||
</legend> -->
|
||||
<tr style="width:700px; margin-left: -10px">
|
||||
<span><%= l(:label_softapplication_name) %></span>
|
||||
<span class="contest-star"> * </span>: <td ><%= f.text_field :name, :required => true, :size => 60, :style => "width:400px;" %></td>
|
||||
<span><%= l(:label_softapplication_name_condition)%></span>
|
||||
</tr></ br>
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<tr style="width:800px;">
|
||||
<span><%= l(:label_softapplication_version_available) %></span>
|
||||
<span class="contest-star"> * </span>: <td style="width: 100px"><%= f.text_field :android_min_version_available, :required => true, :size => 60, :style => "width:400px;" %></td>
|
||||
|
||||
</tr></ br>
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<tr style="width:800px;">
|
||||
<span><%= l(:label_softapplication_type) %></span>
|
||||
|
||||
<span class="contest-star"> * </span>: <td style="width: 100px"><%= f.text_field :app_type_name, :required => true, :size => 60, :style => "width:400px;" %></td>
|
||||
|
||||
</tr></ br>
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<tr style="width:800px;">
|
||||
<span><%= l(:label_softapplication_description) %></span>
|
||||
<span class="contest-star"> * </span>: <td style="width: 100px"><%= f.text_field :description, :required => true, :size => 60, :style => "width:400px;" %></td>
|
||||
|
||||
</tr></ br>
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<tr style="width:800px;">
|
||||
<span><%= l(:label_softapplication_developers) %></span>
|
||||
<span class="contest-star"> * </span>: <td style="width: 100px"><%= f.text_field :application_developers, :required => true, :size => 60, :style => "width:400px;" %></td>
|
||||
|
||||
</tr></ br>
|
||||
<br />
|
||||
<br />
|
||||
<fieldset style="width: 500px">
|
||||
<legend>上传应用软件包和应用截图</legend>
|
||||
<%= render_flash_messages %>
|
||||
<p id="put-bid-form-partial">
|
||||
<%= render :partial => 'attachments/form' %>
|
||||
</p>
|
||||
<p style="font-size: 10px">(<%=l(:label_upload_softapplication_photo_condition)%>)</p>
|
||||
|
||||
</fieldset>
|
||||
</fieldset></br>
|
||||
<div class="align-center"><%= submit_tag l(:button_create), :onclick => "return true" %></div>
|
||||
<script type="text/javascript">
|
||||
function j_submit () {
|
||||
alert('start')
|
||||
var submit_homework = function(){
|
||||
$('#add_homework_form').clone().attr('action', '<%= url_for({:controller => "softapplications", :action => "create"})+".js" %>').ajaxSubmit()
|
||||
};
|
||||
alert('stop')
|
||||
$.globalEval(submit_homework());
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<% end %>
|
||||
</div>
|
@ -1,6 +1,30 @@
|
||||
<h3>test</h3>
|
||||
<%= debug request %>
|
||||
|
||||
|
||||
<% users = User.all%>
|
||||
<table>
|
||||
<tr>
|
||||
<th>name</th><th>C</th><th>I</th><th>S</th><th>filecount</th><th>issuecount</th><th>level</th>
|
||||
</tr>
|
||||
<% users.each do |user| %>
|
||||
|
||||
|
||||
|
||||
<tr>
|
||||
<td><%= user.lastname %><%= user.firstname %></td>
|
||||
<!-- <td><%= calculate_collaboration_count(user) %></td>
|
||||
<td><%= calculate_influence_count(user) %></td>
|
||||
<td><%= calculate_skill_count(user) %></td>
|
||||
<td><%= calculate_file(user) %></td>
|
||||
<td><%= calculate_issue(user) %></td>
|
||||
<td><%= calculate_level(user) %></td>
|
||||
-->
|
||||
<td><%= user.changesets.count %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<hr/>
|
||||
<%= request.host().class %>
|
||||
|
||||
<hr/>
|
||||
|
@ -0,0 +1,10 @@
|
||||
class RemoveBudgetFromContests < ActiveRecord::Migration
|
||||
def self.up
|
||||
change_column :contests, :budget, :string, :default => ""
|
||||
end
|
||||
|
||||
def self.down
|
||||
change_column :contests, :budget, :integer, :default => 0
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
class AddLogolinkToSchools < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :schools, :logo_link, :string
|
||||
end
|
||||
end
|
@ -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
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
@ -1,4 +0,0 @@
|
||||
module SeemsRateable
|
||||
class ApplicationController < ActionController::Base
|
||||
end
|
||||
end
|
@ -1,4 +0,0 @@
|
||||
module SeemsRateable
|
||||
module ApplicationHelper
|
||||
end
|
||||
end
|
@ -1,4 +0,0 @@
|
||||
module SeemsRateable
|
||||
module RatingsHelper
|
||||
end
|
||||
end
|
@ -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
|
@ -1,14 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>SeemsRateable</title>
|
||||
<%= stylesheet_link_tag "seems_rateable/application", media: "all" %>
|
||||
<%= javascript_include_tag "seems_rateable/application" %>
|
||||
<%= csrf_meta_tags %>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<%= yield %>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -1,4 +0,0 @@
|
||||
# desc "Explaining what the task does"
|
||||
# task :seems_rateable do
|
||||
# # Task goes here
|
||||
# end
|
@ -0,0 +1,17 @@
|
||||
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.md')
|
||||
rdoc.rdoc_files.include('lib/**/*.rb')
|
||||
end
|
||||
|
||||
Bundler::GemHelper.install_tasks
|
Before Width: | Height: | Size: 572 B After Width: | Height: | Size: 572 B |
Before Width: | Height: | Size: 427 B After Width: | Height: | Size: 427 B |
Before Width: | Height: | Size: 1018 B After Width: | Height: | Size: 1018 B |
@ -0,0 +1,7 @@
|
||||
module SeemsRateable
|
||||
class ApplicationController < ::ApplicationController
|
||||
rescue_from SeemsRateable::Errors::AlreadyRatedError do |exception|
|
||||
render :json => {:error => true}
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,16 @@
|
||||
require_dependency "seems_rateable/application_controller"
|
||||
|
||||
module SeemsRateable
|
||||
class RatingsController < ApplicationController
|
||||
def create
|
||||
raise Errors::NoCurrentUserInstanceError unless current_user
|
||||
obj = params[:kls].classify.constantize.find(params[:idBox])
|
||||
obj.rate(params[:rate].to_i, current_user.id, params[:dimension])
|
||||
|
||||
render :json => true
|
||||
|
||||
rescue Errors::NoCurrentUserInstanceError
|
||||
render :json => {:error => 'you must be login.'}
|
||||
end
|
||||
end
|
||||
end
|
@ -1,5 +1,5 @@
|
||||
module SeemsRateable
|
||||
class CachedRating < ActiveRecord::Base
|
||||
belongs_to :cacheable, :polymorphic => true
|
||||
belongs_to :cacheable, :polymorphic => true
|
||||
end
|
||||
end
|
@ -0,0 +1,6 @@
|
||||
module SeemsRateable
|
||||
class Rate < ActiveRecord::Base
|
||||
belongs_to :rater, :class_name => SeemsRateable::Engine.config.owner_class
|
||||
belongs_to :rateable, :polymorphic => true
|
||||
end
|
||||
end
|
@ -0,0 +1,42 @@
|
||||
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
|
||||
|
||||
def routegen
|
||||
route("seems_rateable")
|
||||
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
|
@ -0,0 +1,17 @@
|
||||
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
|
@ -1,8 +1,10 @@
|
||||
begin
|
||||
require 'rails'
|
||||
require 'rails'
|
||||
rescue LoadError
|
||||
end
|
||||
|
||||
require "jquery-rails"
|
||||
|
||||
require "seems_rateable/engine"
|
||||
require "seems_rateable/errors"
|
||||
require "seems_rateable/helpers"
|
@ -0,0 +1,16 @@
|
||||
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
|
@ -0,0 +1,21 @@
|
||||
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
|
@ -0,0 +1,27 @@
|
||||
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
|
@ -0,0 +1,91 @@
|
||||
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
|
||||
r.dimension = dimension
|
||||
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)
|
||||
r = average(dimension)
|
||||
if r.nil?
|
||||
self.rate_averages.create do |r|
|
||||
r.avg = stars
|
||||
r.dimension = dimension
|
||||
r.cnt = 1
|
||||
end
|
||||
else
|
||||
r.avg = (r.avg * r.cnt + stars) / (r.cnt+1)
|
||||
r.cnt += 1
|
||||
r.save!
|
||||
r
|
||||
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)
|
||||
rate_averages.where(dimension: dimension).first
|
||||
end
|
||||
|
||||
def rates(dimension=nil)
|
||||
rates_all.where(dimension: dimension)
|
||||
end
|
||||
|
||||
def raters(dimension=nil)
|
||||
raters_all.where('seems_rateable_rates.dimension = ?', dimension)
|
||||
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_all, :as => :rateable, :class_name => SeemsRateable::Rate, :dependent => :destroy
|
||||
has_many :raters_all, :through => :rates_all, :class_name => SeemsRateable::Engine.config.owner_class, :source => :rater
|
||||
has_many :rate_averages, :as => :cacheable, :class_name => SeemsRateable::CachedRating, :dependent => :destroy
|
||||
|
||||
self.class_variable_set(:@@permission, opts[:allow_update] ? true : false)
|
||||
|
||||
def self.can_update?
|
||||
self.class_variable_get(:@@permission)
|
||||
end
|
||||
|
||||
def self.rateable?
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
def seems_rateable_rater
|
||||
has_many :ratings_given, :class_name => SeemsRateable::Rate, :foreign_key => :rater_id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue