Permalink
Browse files

Added ability of pull request

  • Loading branch information...
1 parent 0bba733 commit 6158b8a9c6fa61bcd0118a7ce7c62577538af2e5 @RajRoR committed Mar 20, 2013
View
44 app/controllers/forked_ideas_controller.rb
@@ -24,11 +24,7 @@ def fork
if @forked_idea.save
flash[:success] = 'Forked idea was successfully created.'
- begin
- redirect_to idea_translated_idea_forked_idea_path(params[:idea_id], translated_idea.id, @forked_idea)
- rescue Exception => e
- raise e
- end
+ redirect_to idea_translated_idea_forked_idea_path(params[:idea_id], translated_idea.id, @forked_idea)
else
flash[:error] = "Already forked or try again later."
redirect_to request.path.sub("/#{translated_idea.id}/forked_ideas/fork", '')
@@ -48,15 +44,39 @@ def update
end
end
- # DELETE /forked_ideas/1
- # DELETE /forked_ideas/1.json
- def destroy
+ def send_pull_request
@forked_idea = ForkedIdea.find(params[:id])
- @forked_idea.destroy
- respond_to do |format|
- format.html { redirect_to forked_ideas_url }
- format.json { head :no_content }
+ if @forked_idea.update_attributes(:pull_request_at => Time.now)
+ flash[:success] = 'Pull request sent successfully'
+ redirect_to pull_requests_idea_translated_idea_forked_ideas_path(params[:idea_id], params[:translated_idea_id])
+ else
+ flash[:error] = "Sorry! Please try later."
+ redirect_to idea_translated_idea_forked_ideas_path(params[:idea_id], params[:translated_idea_id])
+ end
+ end
+
+ def pull_requests
+ need_closed = (params[:closed] ? true : false)
+ translated_idea = TranslatedIdea.find(params[:translated_idea_id])
+
+ @pull_requests = translated_idea.forked_ideas.find(:all, :conditions => ['pull_request_at IS NOT NULL AND is_closed = ?', need_closed], :order => 'updated_at DESC')
+ end
+
+ def merge
+ @forked_idea = ForkedIdea.find(params[:id])
+ @translated_idea = @forked_idea.translated_idea
+ end
+
+ def close_pr
+ @forked_idea = ForkedIdea.find(params[:id])
+
+ if @forked_idea.update_attributes(:is_closed => true)
+ flash[:success] = 'Pull request sent successfully'
+ redirect_to pull_requests_idea_translated_idea_forked_ideas_path(params[:idea_id], params[:translated_idea_id], :closed => true)
+ else
+ flash[:error] = "Sorry! Please try later."
+ redirect_to idea_translated_idea_forked_ideas_path(params[:idea_id], params[:translated_idea_id])
end
end
end
View
7 app/controllers/translated_ideas_controller.rb
@@ -11,10 +11,10 @@ def create
@translated_idea = TranslatedIdea.create(params[:translated_idea])
@translated_idea.author = current_citizen
if @translated_idea.save
- redirect_to @translated_idea
+ redirect_to idea_translated_idea_path(params[:idea_id], @translated_idea)
else
@similar_idea = TranslatedIdea.where(idea_id: params[:translated_idea][:idea_id], language: params[:translated_idea][:language]).all.first
- redirect_to @similar_idea
+ redirect_to idea_translated_idea_path(params[:idea_id], @similar_idea)
end
end
@@ -31,14 +31,13 @@ def show
def edit
@translated_idea = TranslatedIdea.find(params[:id])
@idea = Idea.find(@translated_idea.idea_id)
- respond_with @translated_idea
end
def update
@translated_idea = TranslatedIdea.find(params[:id])
if @translated_idea.update_attributes(params[:translated_idea])
flash[:notice] = I18n.t("idea.updated")
end
- respond_with @translated_idea
+ redirect_to idea_translated_idea_path(params[:idea_id], @translated_idea)
end
end
View
2 app/models/forked_idea.rb
@@ -1,5 +1,5 @@
class ForkedIdea < ActiveRecord::Base
- attr_accessible :author_id, :body, :summary, :title, :translated_idea_id
+ attr_accessible :author_id, :body, :summary, :title, :translated_idea_id, :pull_request_at, :is_closed
belongs_to :translated_idea
belongs_to :author, class_name: "Citizen", foreign_key: "author_id"
View
2 app/models/translated_idea.rb
@@ -2,7 +2,7 @@ class TranslatedIdea < ActiveRecord::Base
belongs_to :idea
belongs_to :author, class_name: "Citizen", foreign_key: "author_id"
- has_many :folked_ideas, :dependent => :destroy
+ has_many :forked_ideas, :dependent => :destroy
attr_accessible :author_id, :body, :idea_id, :language, :summary, :title
validates_uniqueness_of :idea_id, :scope => [:language]
View
15 app/views/forked_ideas/index.html.haml
@@ -1,4 +1,4 @@
-%h1 Listing forked_ideas
+%h1 Listing Forked Ideas
%table{:style => 'width:100%'}
%tr
@@ -10,12 +10,15 @@
- @forked_ideas.each do |forked_idea|
%tr
- %td= forked_idea.author_id
- %td= forked_idea.title
- %td= forked_idea.body
- %td= forked_idea.summary
+ %td= forked_idea.author.name
+ %td= forked_idea.title.truncate(20)
+ %td= forked_idea.body.truncate(30)
+ %td= forked_idea.summary.truncate(30)
%td
= link_to 'Show', idea_translated_idea_forked_idea_path(params[:idea_id], params[:translated_idea_id], forked_idea)
= link_to 'Edit', edit_idea_translated_idea_forked_idea_path(params[:idea_id], params[:translated_idea_id], forked_idea)
- = link_to 'Destroy', idea_translated_idea_forked_idea_path(params[:idea_id], params[:translated_idea_id], forked_idea), :method => :delete, :data => { :confirm => 'Are you sure?' }
= link_to 'Original Translation', idea_translated_idea_path(params[:idea_id], params[:translated_idea_id])
+ - if forked_idea.author_id == current_citizen.id && !forked_idea.pull_request_at
+ = link_to 'Send Pull Request', send_pull_request_idea_translated_idea_forked_idea_path(params[:idea_id], params[:translated_idea_id], forked_idea)
+
+= link_to 'Pull Requests', pull_requests_idea_translated_idea_forked_ideas_path(params[:idea_id], params[:translated_idea_id])
View
38 app/views/forked_ideas/merge.html.haml
@@ -0,0 +1,38 @@
+%h4 You can copy from forked version and paste to master translation
+
+#forked_translated_idea_form
+ %h1= t(".master_translation")
+ = simple_form_for [Idea.find(params[:idea_id]), @translated_idea] do |f|
+ .grid_12
+ = f.input :title, label: I18n.t("title"), :input_html => { :id => "forked_translated_idea_title" }
+ .grid_8.help_cont
+ #title_help
+ %p= t('.title_help')
+ .grid_16
+ = f.input :summary, as: :text
+ .grid_8.help_cont
+ #summary_help
+ %p= t('.summary_help')
+ .grid_16
+ = f.input :body, as: :text
+ = f.label :language
+ = f.select :language, Language.all.map{ |language| [language.full_name, language.name] }, :selected => current_citizen.profile.preferred_language
+ .grid_8.help_cont
+ #body_help
+ %p= t('.body_help')
+ .grid_16
+ = f.submit I18n.t("buttons.update")
+
+#original_translated_idea
+ %h1= t(".translation_from_#{@forked_idea.author.name.underscore}")
+ .grid_12
+ %br
+ = text_field_tag :original_title, @forked_idea.title, :disabled => true
+ %br
+ .grid_16
+ %br
+ = text_area_tag :original_summary, @forked_idea.summary, :disabled => true
+ %br
+ .grid_16
+ %br
+ = text_area_tag :original_summary, @forked_idea.body, :disabled => true
View
25 app/views/forked_ideas/pull_requests.html.haml
@@ -0,0 +1,25 @@
+%h1 Listing Pull Requets
+
+%table{:style => 'width:100%'}
+ %tr
+ %th Author
+ %th Title
+ %th Body
+ %th Summary
+ %th Actions
+
+ - @pull_requests.each do |pull_request|
+ %tr
+ %td= pull_request.author.name
+ %td= pull_request.title.truncate(20)
+ %td= pull_request.body.truncate(30)
+ %td= pull_request.summary.truncate(30)
+ %td
+ = link_to 'Show', idea_translated_idea_forked_idea_path(params[:idea_id], params[:translated_idea_id], pull_request)
+
+ - unless params[:closed]
+ = link_to 'Edit', edit_idea_translated_idea_forked_idea_path(params[:idea_id], params[:translated_idea_id], pull_request)
+ = link_to 'Merge', merge_idea_translated_idea_forked_idea_path(params[:idea_id], params[:translated_idea_id], pull_request) if pull_request.author_id == current_citizen.id
+ = link_to 'Close', close_pr_idea_translated_idea_forked_idea_path(params[:idea_id], params[:translated_idea_id], pull_request) if pull_request.author_id == current_citizen.id
+
+= link_to 'Closed Pull Requests', pull_requests_idea_translated_idea_forked_ideas_path(params[:idea_id], params[:translated_idea_id], :closed => true) unless params[:closed]
View
5 app/views/forked_ideas/show.html.haml
@@ -44,7 +44,10 @@
=t('.hidden_summary_part_2')
.body
- if @forked_idea.author == current_citizen or administrator_signed_in?
- = link_to I18n.t("idea.links.edit_idea"), edit_idea_translated_idea_forked_idea_path(params[:idea_id], params[:translated_idea_id], @forked_idea)
+ - if @forked_idea.is_closed
+ = highlight('Already Closed', 'Already Closed')
+ - else
+ = link_to I18n.t("idea.links.edit_idea"), edit_idea_translated_idea_forked_idea_path(params[:idea_id], params[:translated_idea_id], @forked_idea)
= link_to 'Fork List', idea_translated_idea_forked_ideas_path(params[:idea_id], params[:translated_idea_id])
= render "ideas/share", idea: @idea
View
4 app/views/translated_ideas/_form.html.haml
@@ -1,6 +1,6 @@
#translated_idea_form
%h1= t(".translation")
- = simple_form_for @translated_idea do |f|
+ = simple_form_for [@idea, @translated_idea] do |f|
.grid_12
= f.input :title, label: I18n.t("idea.new.title")
.grid_8.help_cont
@@ -14,7 +14,7 @@
.grid_16
= f.input :body, as: :text
= f.label :language
- = f.select :language, Language.all.map{ |language| [language.full_name, language.name] }, :selected => current_citizen.profile.preferred_language
+ = f.select :language, Language.all.map{ |language| [language.full_name, language.name] }, :selected => @translated_idea.language
.grid_8.help_cont
#body_help
%p= t('.body_help')
View
3 app/views/translated_ideas/show.html.haml
@@ -45,8 +45,9 @@
.body
- if @translated_idea.author == current_citizen or administrator_signed_in?
= link_to I18n.t("idea.links.edit_idea"), edit_translated_idea_path(@translated_idea)
- = link_to 'Fork', fork_idea_translated_idea_forked_ideas_path(params[:idea_id], params[:id])
+ = link_to 'Fork', fork_idea_translated_idea_forked_ideas_path(params[:idea_id], params[:id])
= link_to 'Fork List', idea_translated_idea_forked_ideas_path(params[:idea_id], params[:id])
+ = link_to 'Pull Requests', pull_requests_idea_translated_idea_forked_ideas_path(params[:idea_id], params[:id])
= render "ideas/share", idea: @idea
View
4 config/routes.rb
@@ -53,6 +53,10 @@
resources :translated_ideas do
resources :forked_ideas do
get "fork", on: :collection
+ get "pull_requests", on: :collection
+ get "send_pull_request", on: :member
+ get "merge", on: :member
+ get "close_pr", on: :member
end
end
resources :comments
View
8 db/migrate/20130320181916_add_pull_request_at_to_forked_idea.rb
@@ -0,0 +1,8 @@
+class AddPullRequestAtToForkedIdea < ActiveRecord::Migration
+ def change
+ add_column :forked_ideas, :pull_request_at, :datetime
+ add_column :forked_ideas, :is_closed, :boolean, :default => false
+
+ add_index :forked_ideas, :pull_request_at, :name => 'inx_frkd_ideas_pr_at'
+ end
+end
View
12 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20130317180727) do
+ActiveRecord::Schema.define(:version => 20130320181916) do
create_table "administrators", :force => true do |t|
t.string "email"
@@ -186,15 +186,19 @@
end
create_table "forked_ideas", :force => true do |t|
- t.integer "translated_ideas_id"
+ t.integer "translated_idea_id"
t.integer "author_id"
t.string "title"
t.text "body"
t.text "summary"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.datetime "pull_request_at"
+ t.boolean "is_closed", :default => false
end
+ add_index "forked_ideas", ["pull_request_at"], :name => "inx_frkd_ideas_pr_at"
+
create_table "ideas", :force => true do |t|
t.string "title"
t.text "body"

0 comments on commit 6158b8a

Please sign in to comment.