Redmine 2.x support - Initial work

This commit is contained in:
Davis Zanetti Cabral
2012-10-23 02:02:28 -02:00
parent 7d57f10038
commit d041809113
20 changed files with 199 additions and 161 deletions
+33 -34
View File
@@ -13,8 +13,8 @@ class DeliverablesController < ApplicationController
@deliverable_count = Deliverable.count(:conditions => { :project_id => @project.id})
@deliverable_pages = Paginator.new self, @deliverable_count, per_page_option, params['page']
@deliverables = Deliverable.find(:all,
{
@deliverables = Deliverable.find(:all,
{
:conditions => { :project_id => @project.id},
:limit => per_page_option,
:offset => @deliverable_pages.current.offset
@@ -22,7 +22,7 @@ class DeliverablesController < ApplicationController
)
@deliverables = sort_if_needed @deliverables
@deliverable = Deliverable.new
@budget = Budget.new(@project.id)
@@ -33,13 +33,12 @@ class DeliverablesController < ApplicationController
format.html { render :action => 'index', :layout => !request.xhr? }
end
end
# Action to preview the Deliverable description
def preview
@text = params[:deliverable][:description]
render :partial => 'common/preview'
end
# Saves a new Deliverable
def create
if params[:deliverable][:type] == FixedDeliverable.name
@@ -49,16 +48,16 @@ class DeliverablesController < ApplicationController
else
@deliverable = Deliverable.new(params[:deliverable])
end
@deliverable.project = @project
@budget = Budget.new(@project.id)
respond_to do |format|
if @deliverable.save
@flash = l(:notice_successful_create)
format.html { redirect_to :action => 'index' }
format.js { render :action => 'create.js.rjs'}
format.js
else
format.js { render :action => 'create_error.js.rjs'}
format.js
end
end
@@ -66,40 +65,40 @@ class DeliverablesController < ApplicationController
# Builds the edit form for the Deliverable
def edit
@deliverable = Deliverable.find_by_id_and_project_id(params[:deliverable_id], params[:id])
@deliverable = Deliverable.find_by_id_and_project_id(params[:deliverable_id], @project.id)
end
# Updates an existing Deliverable, optionally changing it's type
def update
@deliverable = Deliverable.find(params[:deliverable_id])
if params[:deliverable][:type] != @deliverable.class
@deliverable = @deliverable.change_type(params[:deliverable][:type])
end
respond_to do |format|
if @deliverable.update_attributes(params[:deliverable])
@flash = l(:notice_successful_create)
format.html { redirect_to :action => 'index', :id => @project.id }
format.html { redirect_to :action => 'index', :id => @project.identifier }
else
format.html { render :action => 'edit', :id => @project.id}
format.html { render :action => 'edit', :id => @project.identifier }
end
end
end
# Removes the Deliverable
def destroy
@deliverable = Deliverable.find_by_id_and_project_id(params[:deliverable_id], @project.id)
render_404 and return unless @deliverable
render_403 and return unless @deliverable.editable_by?(User.current)
@deliverable.destroy
flash[:notice] = l(:notice_successful_delete)
redirect_to :action => 'index', :id => @project.id
redirect_to :action => 'index', :id => @project.identifier
end
# Create a query in the session and redirects to the issue list with that query
def issues
@query = Query.new(:name => "_")
@@ -113,27 +112,27 @@ class DeliverablesController < ApplicationController
session[:query] = {:project_id => @query.project_id, :filters => @query.filters}
redirect_to :controller => 'issues', :action => 'index', :project_id => @project.id
redirect_to :controller => 'issues', :action => 'index', :project_id => @project.identifier
end
# Assigns issues to the Deliverable based on their Version
def bulk_assign_issues
@deliverable = Deliverable.find_by_id_and_project_id(params[:deliverable_id], @project.id)
render_404 and return unless @deliverable
render_403 and return unless @deliverable.editable_by?(User.current)
number_updated = @deliverable.assign_issues_by_version(params[:version][:id])
flash[:notice] = l(:message_updated_issues, number_updated)
redirect_to :action => 'index', :id => @project.id
redirect_to :action => 'index', :id => @project.identifier
end
private
def find_project
@project = Project.find(params[:id])
@project = Project.where(:identifier => params[:id]).first || Project.find(params[:id])
end
def get_settings
@settings = Setting.plugin_budget_plugin
end
@@ -146,18 +145,18 @@ class DeliverablesController < ApplicationController
return { :order => sort_clause }
end
end
# Sort +deliverables+ manually using the virtual fields
def sort_if_needed(deliverables)
if session[@sort_name] && %w(score spent progress labor_budget).include?(session[@sort_name][:key])
case session[@sort_name][:key]
when "score":
when "score" then
sorted = deliverables.sort {|a,b| a.score <=> b.score}
when "spent":
when "spent" then
sorted = deliverables.sort {|a,b| a.spent <=> b.spent}
when "progress":
when "progress" then
sorted = deliverables.sort {|a,b| a.progress <=> b.progress}
when "labor_budget":
when "labor_budget" then
sorted = deliverables.sort {|a,b| a.labor_budget <=> b.labor_budget}
end
@@ -167,5 +166,5 @@ class DeliverablesController < ApplicationController
return deliverables
end
end
end