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
def index
#check the incomming report for completeness
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
@output = "No Project Found"
flash.now[:error] = "Project Not Found"
@output = params[:app] + " is not a valid project"
else
issue_id = check_for_existing_report
if issue_id > 0
update_report(issue_id)
@output = "Updated report"
#if we get to this point, then we can try file the incomming report
#check to see if the report exists
# 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
#if we get to this point, the report doesn't exist.
#lets file a new one
issue = create_new_report
if issue.valid?
issue.save
@output = "New report filed"
flash.now[:notice] = "New report filed"
else
@output = issue.errors.full_messages
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
rescue RuntimeError
@output = "ERROR"
end
end #EOF

View File

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