Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

combined bounties. removed Good! button.

  • Loading branch information...
commit ef701076fbc70db7c00ef46596da41f37106cf42 1 parent fb383c8
Masaki Komagata komagata authored
52 app/controllers/bounties_controller.rb
View
@@ -1,52 +0,0 @@
-class BountiesController < ApplicationController
- before_filter :login_required => [:create, :update, :destroy]
- before_filter :find_bounty, :only => [:show]
- layout false
-
- def index
- model = Bounty
- model = model.scoped_by_task_id(params[:task_id]) if params[:task_id]
- @bounties = model.all
- end
-
- def show
- end
-
- def create
- @bounty = Bounty.new(params[:bounty])
- @bounty.user = current_user
- if @bounty.save
- render :json => @bounty, :status => :created, :location => @bounty
- else
- render :json => @bounty.errors, :status => :unprocessable_entity
- end
- end
-
- def update
- @bounty = Bounty.find_by_id_and_user_id(params[:id], current_user.id)
- if @bounty.update_attributes(params[:bounty])
- head :ok
- else
- render :json => @bounty.errors, :status => :unprocessable_entity
- end
- end
-
- def destroy
- @bounty = Bounty.find_by_id_and_user_id(params[:id], current_user.id)
- if @bounty.destroy
- head :ok
- else
- render :json => @bounty.errors, :status => :unprocessable_entity
- end
- end
-
- def total_amount
- total_bounty = Task.find(params[:task_id]).total_bounty
- render :template => 'bounties/_total_amount', :locals => {:total_amount => total_bounty}
- end
-
- private
- def find_bounty
- @bounty = Bounty.find(params[:id]) if params[:id]
- end
-end
2  app/controllers/tasks_controller.rb
View
@@ -71,8 +71,6 @@ def unsolved
end
def show
- @bounty = Bounty.new(:task_id => @task.id)
- @bounties = @task.bounties
@comments = @task.comments.by_correct_desc_and_id.paginate(
:page => params[:page],
:per_page => COMMENTS_PER_PAGE)
2  app/helpers/application_helper.rb
View
@@ -109,7 +109,7 @@ def good_attrs(object)
def task_attrs(task)
value = "task content"
value += ' solved' if task.solved?
- value += ' free' if task.total_bounty.zero?
+ value += ' free' unless task.bounty > 0
{:class => value}
end
8 app/models/bounty.rb
View
@@ -1,8 +0,0 @@
-class Bounty < ActiveRecord::Base
- include Pacecar
- belongs_to :user
- belongs_to :task
-
- validates_presence_of :amount, :task, :user
- validates_numericality_of :amount, :only_ionteger => true, :greater_than_or_equal_to => 100
-end
12 app/models/task.rb
View
@@ -6,7 +6,6 @@ class Task < ActiveRecord::Base
belongs_to :license
belongs_to :project
has_many :comments
- has_many :bounties
has_many :votes, :as => :voteable, :dependent => :destroy
validates_presence_of :title,
@@ -22,11 +21,8 @@ class Task < ActiveRecord::Base
:order => 'tasks.id DESC'
named_scope :nonfree,
- :select => '*, SUM(bounties.amount) as total_bounty',
- :joins => [:bounties],
- :group => 'tasks.id',
- :having => 'total_bounty > 0',
- :order => 'total_bounty DESC'
+ :conditions => 'bounty > 0',
+ :order => 'bounty DESC'
named_scope :count_by_language,
:select => 'COUNT(tasks.id) AS cnt, MAX(languages.name) as name',
@@ -56,8 +52,4 @@ def correct_comment
def solver
(c = correct_comment) ? c.user : nil
end
-
- def total_bounty
- self.bounties.inject(0) {|ret, b| ret + b.amount }
- end
end
18 app/models/user.rb
View
@@ -24,17 +24,19 @@ class User < TwitterAuth::GenericUser
:order => 'cnt DESC'
def total_prize
- t = Bounty.find(:first,
- :select => 'SUM(bounties.amount) AS total_bounty',
- :conditions => ['bounties.id IN (SELECT task_id FROM comments WHERE correct = ? AND user_id = ?)', true, id])
- t ? t.total_bounty.to_i : 0
+ t = Task.find(:first,
+ :select => 'SUM(bounty) AS total',
+ :joins => [:comments],
+ :conditions => ['comments.correct = ? AND comments.user_id = ?', true, id])
+ t ? t.total.to_i : 0
end
def total_payment
- t = Bounty.find(:first,
- :select => 'SUM(amount) AS total_bounty',
- :conditions => ['pay = ? AND user_id = ?', true, id])
- t ? t.total_bounty.to_i : 0
+ t = Task.find(:first,
+ :select => 'SUM(bounty) AS total',
+ :joins => [:comments],
+ :conditions => ['comments.correct = ? AND tasks.user_id = ?', true, id])
+ t ? t.total.to_i : 0
end
def vote_count
0  app/views/bounties/.empty
View
No changes.
8 app/views/layouts/application.html.haml
View
@@ -19,15 +19,10 @@
= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'
= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js'
= javascript_include_tag 'application'
-
<script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAEGshODV8YZnayVZ7tLBsVRTqLoPi9-pvDfOgHGNjNh0FSNMtrxSHFA6ff3rJtLtrq4loKeSHcbsxOQ"></script>
-
<script type="text/javascript">
-
google.setOnLoadCallback(initialize);
-
google.load("feeds", "1");
-
function initialize() {
var feedControl = new google.feeds.FeedControl();
feedControl.addFeed("http://fjord.jp/tag/code-dj/feed", "コードDJ");
@@ -35,10 +30,7 @@
feedControl.draw(document.getElementById("feedControl"));
}
google.setOnLoadCallback(initialize);
-
</script>
-
-
- header_script = yield(:header_script)
- if header_script
= header_script
18 app/views/tasks/_comment.html.haml
View
@@ -2,11 +2,6 @@
.commenter
.content
.title
- %div{good_attrs(comment)}
- %dl.good
- %dt.label
- %span Good!
- %dd.count{:id => "comment_#{comment.id}_good"}= comment.votes.size
%h4
%a.commenter{:href => user_path(comment.user)}
%span.icon= image_tag(comment.user.profile_image_url)
@@ -16,19 +11,6 @@
- form_for comment do |f|
= hidden_field_tag 'comment[correct]', true
= image_submit_tag 'choice_button.gif'
- - form_for comment.votes.new(:comment => good_comment_retweet(comment)), :html => {:id => "comment_#{comment.id}_vote_form",:class => "tweet", :style => 'display:none'} do |f|
- - if logged_in?
- .text
- = f.hidden_field :voteable_id, :id => "comment_#{comment.id}_voteable_id"
- = f.hidden_field :voteable_type, :id => "comment_#{comment.id}_voteable_type"
- = f.text_field :comment, :id => "comment_#{comment.id}_comment", :maxlength => 140
- - if logged_in?
- .input= f.submit 'tweet'
- - else
- .input= link_to 'Retweet', login_path
- %p.center tweetをすることで、このコメントにGood!ポイントが加算されます
- - else
- .please_login== tweetするには#{link_to 'Twitterでログイン', login_path}してください。
.description~markdown comment.description
- if logged_in? and comment.user.id == current_user.id
%ul.loggedin
4 app/views/tasks/_object.html.haml
View
@@ -17,11 +17,11 @@
- object.tags.each do |tag|
%li.tag=link_to h(tag.name), tasks_by_tag_path(:tag => tag.name), :class => 'button'
.sub
- - if object.total_bounty > 0
+ - if object.bounty > 0
%dl.bounty
%dt= t('Bounty')
%dd
- %span= number_to_currency object.total_bounty
+ %span= number_to_currency object.bounty
.counts
%ul.tweets
%li.count= object.votes.size
14 app/views/tasks/_object_small.html.haml
View
@@ -1,6 +1,5 @@
%li.task.clearfix{task_attrs(object_small)}
%dl
-
%dt Good!
%dd.tweets= object_small.votes.size
%dt コメント
@@ -8,18 +7,9 @@
%dt タスク名
%dd.title=link_to truncate(h(object_small.title), :length => 32), task_path(object_small)
%dt 報奨金
- - if object_small.total_bounty > 0
- %dd.bounty= number_to_currency object_small.total_bounty
+ - if object_small.bounty > 0
+ %dd.bounty= number_to_currency object_small.bounty
- else
%dd.bounty.free FREE
%dt タスク登録日
%dd.created_at== #{time_ago_in_words object_small.created_at}
-
-
-
-
-
-
-
-
-
29 app/views/tasks/_sub.html.haml
View
@@ -5,29 +5,11 @@
%ul.comments
%li.count= @task.comments.size
%li.label= t('Comment')
-
.task_data
- - if @task.total_bounty > 0
+ - if @task.bounty > 0
.section.bounty
- %dl.bounty
- %dt.bounty= t('Total bounty')
- %dd.bounty
- %span= t('Total')
- %span.total_bounty
- = number_to_currency_with_span @task.total_bounty
-
- - if logged_in?
- #add_bounty.add_bounty= ''
- - form_for @bounty do |f|
- = f.hidden_field :task_id
- = f.label :amount
- = f.text_field :amount, :size => 20
-
- - if logged_in?
- #add_bounty.add_bounty.button= t('Add Bounty')
-
-
-
+ %dl= t('Bounty')
+ %dd= number_to_currency_with_span @task.bounty
- if @task.project
.section.project
%dl
@@ -36,7 +18,6 @@
%a{:href => project_path(@task.project)}
%span.icon= 'icon'
%span.name= @task.project.name
-
.person.section
%dl.person
%dt タスク登録者
@@ -44,11 +25,9 @@
%a.person{:href => user_path(@task.user)}
%span.icon=image_tag(@task.user.profile_image_url)
%span.name=@task.user.login
-
-
.section
%dl
%dt 人気の言語
%dd
%ul
- %li aaa
+ %li FIXME!
56 app/views/tasks/show.html.haml
View
@@ -1,63 +1,9 @@
- title "#{@task.title} - #{t('application.title')}"
- bread_crumb_tag({:name => t('Home'), :url => root_path}, {:name => t('Tasks'), :url => tasks_path}, {:name => @task.title})
-- content_for :header_script do
- = javascript_include_tag 'http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js'
- = javascript_include_tag 'jquery.validator.messages_ja'
- :javascript
- $(function(){
- $('#new_bounty').dialog({
- autoOpen: false,
- title: '#{t('Add Bounty')}',
- modal: true,
- draggable: false,
- resizable: false,
- width: 500,
- buttons: {
- '#{t('Add')}': function() {
- if ($(this).valid()) $(this).submit()
- }
- },
- }).submit(function() {
- var f = $(this)
- $.post('/bounties', $(this).serialize(), function(data) {
- location.reload()
- })
- return false
- }).validate({
- rules: {
- 'bounty[amount]': {
- required: true,
- min: 100
- }
- }
- })
-
- $('#add_bounty').click(function() {
- $('#new_bounty').dialog('open')
- })
- })
%div{task_attrs(@task)}
.main
.title
- %div{good_attrs(@task)}
- %dl
- %dt
- %span= 'Good!'
- %dd.count{:id => "task_#{@task.id}_good"}= @task.votes.size
%h2= @task.title
- - form_for @task.votes.new(:comment => good_task_retweet(@task)), :html => {:id => "task_#{@task.id}_vote_form",:class => "tweet", :style => 'display:none'} do |f|
- - if logged_in?
- .text
- = f.hidden_field :voteable_id, :id => "task_#{@task.id}_voteable_id"
- = f.hidden_field :voteable_type, :id => "task_#{@task.id}_voteable_type"
- = f.text_field :comment, :id => "task_#{@task.id}_comment", :size => '140', :maxlength => 140
- - if logged_in?
- .input= f.submit 'tweet'
- - else
- .input= link_to 'Retweet', login_path
- %p.center tweetをすることでGood!ポイントが加算されます
- - else
- .please_login== tweetをするには#{link_to 'Twitterでログイン', login_path}してください。
.state
.information
%dl.license
@@ -112,5 +58,3 @@
= javascript_include_tag 'markedit/markedit.lang.ja'
= javascript_include_tag 'markedit/jquery.markedit'
= javascript_include_tag 'mk'
-
-
16 db/migrate/20100615053358_create_bounties.rb
View
@@ -1,16 +0,0 @@
-class CreateBounties < ActiveRecord::Migration
- def self.up
- create_table :bounties do |t|
- t.belongs_to :user, :null => false
- t.belongs_to :task, :null => false
- t.integer :amount, :null => false
- t.boolean :pay, :default => false
-
- t.timestamps
- end
- end
-
- def self.down
- drop_table :bounties
- end
-end
17 db/migrate/20100616094334_move_bounty_to_bounties.rb
View
@@ -1,17 +0,0 @@
-class MoveBountyToBounties < ActiveRecord::Migration
- def self.up
- Task.all.each do |task|
- if task.bounty > 0
- Bounty.create!(:amount => task.bounty,
- :task_id => task.id,
- :user_id => task.user.id)
- end
- end
-
- remove_column :tasks, :bounty
- end
-
- def self.down
- add_column :tasks, :bounty
- end
-end
1  db/seeds.rb
View
@@ -21,5 +21,4 @@ def load_fixture(fixture, dir = "db/seeds")
load_fixture :tags
load_fixture :taggings
load_fixture :projects
- load_fixture :bounties
end
24 db/seeds/bounties.yml
View
@@ -1,24 +0,0 @@
-<% $I = 0; def increment; $I += 1 end %>
-bounty_<%= increment %>:
- id: <%= $I %>
- task_id: 1
- user_id: 1
- amount: 5000
-
-bounty_<%= increment %>:
- id: <%= $I %>
- task_id: 2
- user_id: 1
- amount: 100
-
-bounty_<%= increment %>:
- id: <%= $I %>
- task_id: 3
- user_id: 1
- amount: 1230
-
-bounty_<%= increment %>:
- id: <%= $I %>
- task_id: 4
- user_id: 1
- amount: 300
4 db/seeds/tasks.yml
View
@@ -9,6 +9,7 @@ Pure Pythonで!"
language_id: 13
license_id: 4
view: 1
+ bounty: 5000
task_<%= increment %>:
id: <%= $I %>
@@ -20,6 +21,7 @@ task_<%= increment %>:
language_id: 7
license_id: 1
view: 10
+ bounty: 100
task_<%= increment %>:
id: <%= $I %>
@@ -29,6 +31,7 @@ task_<%= increment %>:
project_id: 1
language_id: 9
license_id: 4
+ bounty: 8000
view: 15
task_<%= increment %>:
@@ -40,6 +43,7 @@ task_<%= increment %>:
language_id: 9
license_id: 4
view: 1
+ bounty: 1230
source_url: "http://github.com/komagata/help-me-hackers/blob/master/app/views/tasks/_form.html.haml"
<% 20.times do |n| %>
Please sign in to comment.
Something went wrong with that request. Please try again.