Added flash messages, and simplified code

This commit is contained in:
2012-03-29 12:11:29 -04:00
parent 23616c3d1e
commit 3e847fdacc
2 changed files with 42 additions and 25 deletions

View File

@@ -28,27 +28,49 @@ class ExceptionhandlerController < ApplicationController
include ExceptionhandlerHelper include ExceptionhandlerHelper
def index def index
#check the incomming report for completeness
if params.size < 9 if params.size < 9
@output = "<strong> not enough args </strong>" flash.now[:error] = "Not enough args"
# check to see if the reported project exists
elsif Project.find_by_name(params[:app]) == nil elsif Project.find_by_name(params[:app]) == nil
@output = "No Project Found" flash.now[:error] = "Project Not Found"
@output = params[:app] + " is not a valid project"
else else
issue_id = check_for_existing_report #if we get to this point, then we can try file the incomming report
if issue_id > 0
update_report(issue_id) #check to see if the report exists
@output = "Updated report" # if we get a report back, then let update it
issue = check_for_existing_report
if issue != nil
if update_report(issue)
flash.now[:notice] = "Updated report"
end
else else
#if we get to this point, the report doesn't exist.
#lets file a new one
issue = create_new_report issue = create_new_report
if issue.valid? if issue.valid?
issue.save issue.save
@output = "New report filed" flash.now[:notice] = "New report filed"
else else
@output = issue.errors.full_messages @output = issue.errors.full_messages
end end
#TODO generate link to issue
# link_to("My Link", {
# :controller =&gt; 'issue',
# :action =&gt; issue_id,
# :host =&gt; Setting.host_name,
# :protocol =&gt; Setting.protocol
# })
# link_to(issue)
#rescue RuntimeError
# @output = "ERROR"
end end
end end
rescue RuntimeError
@output = "ERROR"
end end
end #EOF end #EOF

View File

@@ -20,33 +20,29 @@
module ExceptionhandlerHelper module ExceptionhandlerHelper
# Checks the database for exisiting reports # Checks the database for exisiting reports
# @return id report is existing else 0 # @return existing issue report if existing
def check_for_existing_report def check_for_existing_report
bug_id = tracker.id bug_id = tracker.id
issues = Project.find_by_name(params[:app]).issues issues = Project.find_by_name(params[:app]).issues
issues.each do |issue| issues.each do |issue|
if issue.tracker_id == bug_id if issue.tracker_id == bug_id
id = check_issue(issue) if check_issue(issue)
if id > 0 return issue
return id
end end
end end
end end
return 0; return nil;
end end
# checks a specific issue agains params # checks a specific issue agains params
# @return id of report if matching, else 0 # @return true if the suppyled issue matches new report args
def check_issue(issue) def check_issue(issue)
if issue.subject == params[:msg] if issue.subject == params[:msg]
if check_issue_custom_values(issue) if check_issue_custom_values(issue)
return issue.id return true
else
return 0
end end
else
return 0
end end
return false
end end
#checks if this issue is a match for params based on it's custom values' #checks if this issue is a match for params based on it's custom values'
@@ -115,10 +111,9 @@ module ExceptionhandlerHelper
return custom_value return custom_value
end end
# retrives an issue by it's id and updates it # updates the provided issue with the incomming report
# @returns updated issue # @returns true if save is sucessful
def update_report(issue_id) def update_report(issue)
issue = Issue.find_by_id(issue_id)
if params[:description].length > 0 if params[:description].length > 0
description = issue.description description = issue.description
description += "\n\n--- New Description --- \n" description += "\n\n--- New Description --- \n"
@@ -141,7 +136,7 @@ module ExceptionhandlerHelper
value.save value.save
end end
issue.init_journal(User.anonymous, "Issue updated") issue.init_journal(User.anonymous, "Issue updated")
issue.save return issue.save
end end
# gets the prodived tracker # gets the prodived tracker