01_add_description_to_trackers.patch

Marius BALTEANU, 2017-05-21 21:51

Download (12.4 KB)

View differences:

app/controllers/projects_controller.rb
33 33
  helper :queries
34 34
  helper :repositories
35 35
  helper :members
36
  helper :trackers
36 37

  
37 38
  # Lists visible projects
38 39
  def index
app/helpers/issues_helper.rb
188 188
  end
189 189

  
190 190
  def trackers_options_for_select(issue)
191
    trackers = trackers_for_select(issue)
192
    trackers.collect {|t| [t.name, t.id]}
193
  end
194

  
195
  def trackers_for_select(issue)
191 196
    trackers = issue.allowed_target_trackers
192 197
    if issue.new_record? && issue.parent_issue_id.present?
193 198
      trackers = trackers.reject do |tracker|
194 199
        issue.tracker_id != tracker.id && tracker.disabled_core_fields.include?('parent_issue_id')
195 200
      end
196 201
    end
197
    trackers.collect {|t| [t.name, t.id]}
202
    trackers
198 203
  end
199 204

  
200 205
  class IssueFieldsRows
app/helpers/trackers_helper.rb
18 18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 19

  
20 20
module TrackersHelper
21

  
22
  def tracker_name_tag(tracker)
23
    title = tracker.description.presence
24
    css = title ? "field-description" : nil
25
    content_tag 'span', tracker.name, :class => css, :title => title
26
  end
21 27
end
app/models/tracker.rb
43 43
  validates_presence_of :name
44 44
  validates_uniqueness_of :name
45 45
  validates_length_of :name, :maximum => 30
46
  validates_length_of :description, :maximum => 255
46 47

  
47 48
  scope :sorted, lambda { order(:position) }
48 49
  scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
......
76 77
    'core_fields',
77 78
    'position',
78 79
    'custom_field_ids',
79
    'project_ids'
80
    'project_ids',
81
    'description'
80 82

  
81 83
  def to_s; name end
82 84

  
app/views/issues/_form.html.erb
15 15
<% end %>
16 16

  
17 17
<% if @issue.safe_attribute? 'tracker_id' %>
18
<p><%= f.select :tracker_id, trackers_options_for_select(@issue), {:required => true},
19
                :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}', this)" %></p>
18
<p>
19
  <%= f.select :tracker_id, trackers_options_for_select(@issue), {:required => true},
20
                :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}', this)",
21
                :title => @issue.tracker.description %>
22
  <%= content_tag 'a', l(:label_open_trackers_description), :class => 'icon-only icon-help', :title => l(:label_open_trackers_description), :onclick => "showModal('trackers_description', '500px'); return false;", :href => '#' if trackers_for_select(@issue).any? {|t| t.description.present? } %>
23
</p>
24
  <%= render partial: 'issues/trackers_description', locals: {trackers: trackers_for_select(@issue)} %>
20 25
<% end %>
21 26

  
22 27
<% if @issue.safe_attribute? 'subject' %>
app/views/issues/_trackers_description.html.erb
1
<% if trackers.any? {|t| t.description.present? } %>
2
  <div class="modal" id="trackers_description">
3
    <h3 class="title"><%= l(:label_trackers_description) %></h3>
4
      <dl>
5
      <% trackers.each do |tracker| %>
6
        <% if tracker.description.present? %>
7
          <dt><%= tracker.name %></dt>
8
          <dd><%= tracker.description %></dd>
9
        <% end %>
10
      <% end %>
11
      </dl>
12
  </div>
13
<% end %>
app/views/projects/_form.html.erb
54 54
<% @trackers.each do |tracker| %>
55 55
    <label class="floating">
56 56
    <%= check_box_tag 'project[tracker_ids][]', tracker.id, @project.trackers.to_a.include?(tracker), :id => nil %>
57
    <%= tracker %>
57
    <%= tracker_name_tag tracker %>
58 58
    </label>
59 59
<% end %>
60 60
<%= hidden_field_tag 'project[tracker_ids][]', '' %>
app/views/projects/show.html.erb
51 51
      <% @trackers.each do |tracker| %>
52 52
        <tr>
53 53
          <td class="name">
54
            <%= link_to tracker.name, project_issues_path(@project, :set_filter => 1, :tracker_id => tracker.id) %>
54
            <%= link_to tracker.name, project_issues_path(@project, :set_filter => 1, :tracker_id => tracker.id), :title => tracker.description %>
55 55
          </td>
56 56
          <td>
57 57
            <%= link_to @open_issues_by_tracker[tracker].to_i, project_issues_path(@project, :set_filter => 1, :tracker_id => tracker.id) %>
app/views/trackers/_form.html.erb
10 10
        :required => true %>
11 11
</p>
12 12
<p><%= f.check_box :is_in_roadmap %></p>
13
<p><%= f.text_area :description, :rows => 4 %></p>
13 14
<p>
14 15
  <label><%= l(:field_core_fields) %></label>
15 16
  <% Tracker::CORE_FIELDS.each do |field| %>
app/views/trackers/index.api.rsb
4 4
      api.id tracker.id
5 5
      api.name tracker.name
6 6
      api.default_status(:id => tracker.default_status.id, :name => tracker.default_status.name) unless tracker.default_status.nil?
7
      api.description tracker.description
7 8
    end
8 9
  end
9 10
end
app/views/trackers/index.html.erb
8 8
<table class="list trackers">
9 9
  <thead><tr>
10 10
  <th><%=l(:label_tracker)%></th>
11
  <th><%=l(:field_description)%></th>
11 12
  <th></th>
12 13
  <th></th>
13 14
  </tr></thead>
......
15 16
<% for tracker in @trackers %>
16 17
  <tr>
17 18
  <td class="name"><%= link_to tracker.name, edit_tracker_path(tracker) %></td>
19
  <td class="description"><%= tracker.description %></td>
18 20
  <td>
19 21
    <% unless tracker.workflow_rules.exists? %>
20 22
      <span class="icon icon-warning">
config/locales/en.yml
1016 1016
  label_font_monospace: Monospaced font
1017 1017
  label_font_proportional: Proportional font
1018 1018
  label_last_notes: Last notes
1019
  label_trackers_description: Trackers description
1020
  label_open_trackers_description: View all trackers description
1019 1021

  
1020 1022
  button_login: Login
1021 1023
  button_submit: Submit
db/migrate/20170503103500_add_trackers_description.rb
1
class AddTrackersDescription < ActiveRecord::Migration
2
  def self.up
3
    add_column :trackers, :description, :string, :after => :name
4
  end
5
  def self.down
6
    remove_column :trackers, :description
7
  end
8
end
public/stylesheets/application.css
466 466
#issue_tree td.checkbox, #relations td.checkbox {display:none;}
467 467
#relations td.buttons {padding:0;}
468 468

  
469
#trackers_description {display:none;}
470
#trackers_description dt {font-weight: bold; text-decoration: underline;}
471
#trackers_description dd {margin: 0; padding: 0 0 1em 0;}
472

  
469 473
fieldset.collapsible {border-width: 1px 0 0 0;}
470 474
fieldset.collapsible>legend { padding-left: 16px; background: url(../images/arrow_expanded.png) no-repeat 0% 40%; cursor:pointer; }
471 475
fieldset.collapsible.collapsed>legend { background-image: url(../images/arrow_collapsed.png); }
......
1462 1466
  height:1px;
1463 1467
  overflow:hidden;
1464 1468
}
1469

  
public/stylesheets/responsive.css
747 747
    float: none !important;
748 748
  }
749 749

  
750
  #all_attributes #issue_tracker_id {
751
    width: 90%;
752
  }
753

  
750 754
  #issue_is_private_label {
751 755
    display: inline;
752 756
  }
test/fixtures/trackers.yml
1
--- 
2
trackers_001: 
1
---
2
trackers_001:
3 3
  name: Bug
4 4
  id: 1
5 5
  is_in_chlog: true
6 6
  default_status_id: 1
7 7
  position: 1
8
trackers_002: 
8
  description: Description for Bug tracker
9
trackers_002:
9 10
  name: Feature request
10 11
  id: 2
11 12
  is_in_chlog: true
12 13
  default_status_id: 1
13 14
  position: 2
14
trackers_003: 
15
  description: Description for Feature request tracker
16
trackers_003:
15 17
  name: Support request
16 18
  id: 3
17 19
  is_in_chlog: false
test/functional/issues_controller_test.rb
2208 2208
    assert_select 'option', text: /#{t.name}/, count: 0
2209 2209
  end
2210 2210

  
2211
  def test_get_new_should_show_trackers_description
2212
    @request.session[:user_id] = 2
2213
    get :new, :project_id => 1, :tracker_id => 1
2214
    assert_response :success
2215

  
2216
    assert_select 'form#issue-form' do
2217
      assert_select 'a[title=?]', 'View all trackers description', :text => 'View all trackers description'
2218
      assert_select 'select[name=?][title=?]', 'issue[tracker_id]', 'Description for Bug tracker'
2219
    end
2220

  
2221
    assert_select 'div#trackers_description' do
2222
      assert_select 'h3', 1, :text => 'Trackers description'
2223
      # only Bug and Feature have descriptions
2224
      assert_select 'dt', 2, :text => 'Bug'
2225
      assert_select 'dd', 2, :text => 'Description for Bug tracker'
2226
    end
2227
  end
2228

  
2229
  def test_get_new_should_not_show_trackers_description_for_trackers_without_description
2230
    Tracker.update_all(:description => '')
2231

  
2232
    @request.session[:user_id] = 2
2233
    get :new, :project_id => 1, :tracker_id => 1
2234
    assert_response :success
2235

  
2236
    assert_select 'form#issue-form' do
2237
      assert_select 'a[title=?]', 'View all trackers description', 0
2238
      assert_select 'select[name=?][title=?]', 'issue[tracker_id]', ''
2239
    end
2240

  
2241
    assert_select 'div#trackers_description', 0
2242
  end
2243

  
2211 2244
  def test_update_form_for_new_issue
2212 2245
    @request.session[:user_id] = 2
2213 2246
    xhr :post, :new, :project_id => 1,
test/integration/api_test/trackers_test.rb
28 28

  
29 29
    assert_select 'trackers[type=array] tracker id', :text => '2' do
30 30
      assert_select '~ name', :text => 'Feature request'
31
      assert_select '~ description', :text => 'Description for Feature request tracker'
31 32
    end
32 33
  end
33 34
end
test/unit/tracker_test.rb
128 128
      end
129 129
    end
130 130
  end
131

  
132
  def test_tracker_should_have_description
133
    tracker = Tracker.find(1)
134
    assert tracker.respond_to?(:description)
135
    assert_equal tracker.description, "Description for Bug tracker"
136
  end
131 137
end