diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 158eb23..d99edbb 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,19 +1,19 @@
module ApplicationHelper
-
-
+
+
def lighthouse_tracker? object
object.issue_tracker_type == "lighthouseapp"
end
-
+
def user_agent_graph(error)
tallies = tally(error.notices) {|notice| pretty_user_agent(notice.user_agent)}
create_percentage_table(tallies, :total => error.notices.count)
end
-
+
def pretty_user_agent(user_agent)
(user_agent.nil? || user_agent.none?) ? "N/A" : "#{user_agent.browser} #{user_agent.version}"
end
-
+
def tally(collection, &block)
collection.inject({}) do |tallies, item|
value = yield item
@@ -21,7 +21,7 @@ module ApplicationHelper
tallies
end
end
-
+
def create_percentage_table(tallies, options={})
total = (options[:total] || total_from_tallies(tallies))
percent = 100.0 / total.to_f
@@ -29,12 +29,16 @@ module ApplicationHelper
.sort {|a, b| a[0] <=> b[0]}
render :partial => "errs/tally_table", :locals => {:rows => rows}
end
-
+
def total_from_tallies(tallies)
tallies.values.inject(0) {|sum, n| sum + n}
end
private :total_from_tallies
-
+
+ def no_tracker? object
+ object.issue_tracker_type == "none"
+ end
+
def redmine_tracker? object
object.issue_tracker_type == "redmine"
end
@@ -47,3 +51,4 @@ module ApplicationHelper
object.issue_tracker_type == 'fogbugz'
end
end
+
diff --git a/app/views/apps/_fields.html.haml b/app/views/apps/_fields.html.haml
index 9542bdf..6166ae7 100644
--- a/app/views/apps/_fields.html.haml
+++ b/app/views/apps/_fields.html.haml
@@ -53,7 +53,7 @@
%div.issue_tracker.nested
%div.choose
= w.radio_button :issue_tracker_type, :none
- = label_tag :issue_tracker_type_lighthouseapp, '(None)', :for => label_for_attr(w, 'issue_tracker_type_none')
+ = label_tag :issue_tracker_type_none, '(None)', :for => label_for_attr(w, 'issue_tracker_type_none')
= w.radio_button :issue_tracker_type, :lighthouseapp
= label_tag :issue_tracker_type_lighthouseapp, 'Lighthouse', :for => label_for_attr(w, 'issue_tracker_type_lighthouseapp')
= w.radio_button :issue_tracker_type, :redmine
@@ -62,6 +62,8 @@
= label_tag :issue_tracker_type_pivotal, 'Pivotal Tracker', :for => label_for_attr(w, 'issue_tracker_type_pivotal')
= w.radio_button :issue_tracker_type, :fogbugz
= label_tag :issue_tracker_type_fogbugz, 'FogBugz', :for => label_for_attr(w, 'issue_tracker_type_fogbugz')
+ %div.tracker_params.none{:class => no_tracker?(w.object) ? 'chosen' : nil}
+ %p When no issue tracker has been configured, you will be able to leave comments on errors.
%div.tracker_params.lighthouseapp{:class => lighthouse_tracker?(w.object) ? 'chosen' : nil}
= w.label :account, "Account"
= w.text_field :account, :placeholder => "abc from abc.lighthouseapp.com"
diff --git a/app/views/errs/show.html.haml b/app/views/errs/show.html.haml
index dde396f..9eb7643 100644
--- a/app/views/errs/show.html.haml
+++ b/app/views/errs/show.html.haml
@@ -19,23 +19,25 @@
= link_to 'unlink issue', unlink_issue_app_err_path(@app, @err), :method => :delete, :confirm => "Unlink err issues?", :class => "unlink-issue"
- if @err.unresolved?
%span= link_to 'resolve', resolve_app_err_path(@app, @err), :method => :put, :confirm => err_confirm, :class => 'resolve'
-- content_for :comments do
- %h3 Comments on this Err
- - @err.comments.each do |comment|
- .window
- %table.comment
- %tr
- %th
- %span= link_to '✘'.html_safe, destroy_comment_app_err_path(@app, @err) << "?comment_id=#{comment.id}", :method => :delete, :confirm => "Are sure you don't need this comment?", :class => "destroy-comment"
- = time_ago_in_words(comment.created_at, true) << " ago by "
- = link_to comment.user.email, user_path(comment.user)
- %tr
- %td= comment.body.gsub("\n", "
").html_safe
- = form_for @comment, :url => create_comment_app_err_path(@app, @err) do |comment_form|
- %p Add a comment
- = comment_form.text_area :body, :style => "width: 420px; height: 80px;"
- = comment_form.submit "Save Comment"
+- if !@app.issue_tracker_configured? || @err.comments.any?
+ - content_for :comments do
+ %h3 Comments on this Err
+ - @err.comments.each do |comment|
+ .window
+ %table.comment
+ %tr
+ %th
+ %span= link_to '✘'.html_safe, destroy_comment_app_err_path(@app, @err) << "?comment_id=#{comment.id}", :method => :delete, :confirm => "Are sure you don't need this comment?", :class => "destroy-comment"
+ = time_ago_in_words(comment.created_at, true) << " ago by "
+ = link_to comment.user.email, user_path(comment.user)
+ %tr
+ %td= comment.body.gsub("\n", "
").html_safe
+ - unless @app.issue_tracker_configured?
+ = form_for @comment, :url => create_comment_app_err_path(@app, @err) do |comment_form|
+ %p Add a comment
+ = comment_form.text_area :body, :style => "width: 420px; height: 80px;"
+ = comment_form.submit "Save Comment"
%h4= @notice.try(:message)
diff --git a/spec/views/errs/show.html.haml_spec.rb b/spec/views/errs/show.html.haml_spec.rb
index 02a27b2..90d0f72 100644
--- a/spec/views/errs/show.html.haml_spec.rb
+++ b/spec/views/errs/show.html.haml_spec.rb
@@ -38,5 +38,38 @@ describe "errs/show.html.erb" do
end
+ describe "content_for :comments" do
+ it 'should display comments and new comment form when no issue tracker' do
+ err = Factory(:err_with_comments)
+ assign :err, err
+ assign :app, err.app
+ render
+ comments_section = String.new(view.instance_variable_get(:@_content_for)[:comments])
+ comments_section.should =~ /Test comment/
+ comments_section.should =~ /Add a comment/
+ end
+
+ context "with issue tracker" do
+ def with_issue_tracker(err)
+ err.app.issue_tracker = IssueTracker.new :issue_tracker_type => "lighthouseapp", :project_id => "1234"
+ assign :err, err
+ assign :app, err.app
+ end
+
+ it 'should not display the comments section' do
+ with_issue_tracker(Factory(:err))
+ render
+ view.instance_variable_get(:@_content_for)[:comments].should be_blank
+ end
+
+ it 'should display existing comments' do
+ with_issue_tracker(Factory(:err_with_comments))
+ render
+ comments_section = String.new(view.instance_variable_get(:@_content_for)[:comments])
+ comments_section.should =~ /Test comment/
+ comments_section.should_not =~ /Add a comment/
+ end
+ end
+ end
end
--
libgit2 0.21.2