Project

General

Profile

Feature #9309 » add-query-description.patch

Takenori TAKAKI, 2024-02-15 04:02

View differences:

app/controllers/queries_controller.rb
133 133
    @query.column_names = nil if params[:default_columns]
134 134
    @query.sort_criteria = (params[:query] && params[:query][:sort_criteria]) || @query.sort_criteria
135 135
    @query.name = params[:query] && params[:query][:name]
136
    @query.description = params[:query] && params[:query][:description]
136 137
    if User.current.allowed_to?(:manage_public_queries, @query.project) || User.current.admin?
137 138
      @query.visibility = (params[:query] && params[:query][:visibility]) || Query::VISIBILITY_PRIVATE
138 139
      @query.role_ids = params[:query] && params[:query][:role_ids]
app/helpers/queries_helper.rb
502 502
          content_tag('li',
503 503
                      link_to(query.name,
504 504
                              url_params.merge(:query_id => query),
505
                              :class => css) +
505
                              :class => css,
506
                              :title => query.description) +
506 507
                        clear_link.html_safe)
507 508
        end.join("\n").html_safe,
508 509
        :class => 'queries'
app/models/query.rb
262 262

  
263 263
  validates_presence_of :name
264 264
  validates_length_of :name, :maximum => 255
265
  validates_length_of :description, :maximum => 255
265 266
  validates :visibility, :inclusion => {:in => [VISIBILITY_PUBLIC, VISIBILITY_ROLES, VISIBILITY_PRIVATE]}
266 267
  validate :validate_query_filters
267 268
  validate do |query|
app/views/admin/projects.html.erb
3 3
</div>
4 4

  
5 5
<h2><%= @query.new_record? ? l(:label_project_plural) : @query.name %></h2>
6
<%= @query.persisted? && @query.description.present? ? content_tag('p', @query.description) : '' %>
6 7

  
7 8
<%= form_tag(admin_projects_path(@project, nil), :method => :get, :id => 'query_form') do %>
8 9
<%= hidden_field_tag 'admin_projects', '1' %>
app/views/calendars/show.html.erb
1 1
<h2><%= @query.new_record? ? l(:label_calendar) : @query.name %></h2>
2
<%= @query.persisted? && @query.description.present? ? content_tag('p', @query.description) : '' %>
2 3

  
3 4
<%= form_tag({:controller => 'calendars', :action => 'show', :project_id => @project},
4 5
             :method => :get, :id => 'query_form') do %>
app/views/gantts/show.html.erb
3 3
</div>
4 4

  
5 5
<h2><%= @query.new_record? ? l(:label_gantt) : @query.name %></h2>
6
<%= @query.persisted? && @query.description.present? ? content_tag('p', @query.description) : '' %>
6 7

  
7 8
<%= form_tag({:controller => 'gantts', :action => 'show',
8 9
             :project_id => @project, :month => params[:month],
app/views/issues/index.html.erb
19 19

  
20 20
<h2><%= @query.new_record? ? l(:label_issue_plural) : @query.name %></h2>
21 21
<% html_title(@query.new_record? ? l(:label_issue_plural) : @query.name) %>
22
<%= @query.persisted? && @query.description.present? ? content_tag('p', @query.description) : '' %>
22 23

  
23 24
<%= form_tag(_project_issues_path(@project), :method => :get, :id => 'query_form') do %>
24 25
  <%= render :partial => 'queries/query_form' %>
app/views/projects/index.html.erb
5 5
</div>
6 6

  
7 7
<h2><%= @query.new_record? ? l(:label_project_plural) : @query.name %></h2>
8
<%= @query.persisted? && @query.description.present? ? content_tag('p', @query.description) : '' %>
8 9

  
9 10
<%= form_tag(projects_path(@project, nil), :method => :get, :id => 'query_form') do %>
10 11
<%= render :partial => 'queries/query_form' %>
app/views/queries/_form.html.erb
8 8

  
9 9
<p><label for="query_name"><%=l(:field_name)%></label>
10 10
<%= text_field 'query', 'name', :size => 80 %></p>
11
<p><label for="query_description"><%=l(:field_description)%></label>
12
<%= text_field 'query', 'description', :size => 80 %></p>
11 13

  
12 14
<% if User.current.admin? ||
13 15
      User.current.allowed_to?(:manage_public_queries, @query.project) %>
app/views/timelog/index.html.erb
14 14
</div>
15 15

  
16 16
<h2><%= @query.new_record? ? l(:label_spent_time) : @query.name %></h2>
17
<%= @query.persisted? && @query.description.present? ? content_tag('p', @query.description) : '' %>
17 18

  
18 19
<%= form_tag(_time_entries_path(@project, nil), :method => :get, :id => 'query_form') do %>
19 20
<%= render :partial => 'date_range' %>
app/views/users/index.html.erb
8 8
</div>
9 9

  
10 10
<h2><%= @query.new_record? ? l(:label_user_plural) : @query.name %></h2>
11
<%= @query.persisted? && @query.description.present? ? content_tag('p', @query.description) : '' %>
11 12

  
12 13
<%= form_tag(users_path, method: :get, id: 'query_form') do %>
13 14
  <%= render partial: 'queries/query_form' %>
test/fixtures/queries.yml
5 5
  project_id: 1
6 6
  visibility: 2
7 7
  name: Multiple custom fields query
8
  description: Description for Multiple custom fields query
8 9
  filters: |
9 10
    --- 
10 11
    cf_1: 
......
28 29
  project_id: 1
29 30
  visibility: 0
30 31
  name: Private query for cookbook
32
  description: Description for Private query for cookbook
31 33
  filters: |
32 34
    --- 
33 35
    tracker_id: 
......
47 49
  project_id: 
48 50
  visibility: 0
49 51
  name: Private query for all projects
52
  description: Description for Private query for all projects
50 53
  filters: |
51 54
    --- 
52 55
    tracker_id: 
......
62 65
  project_id: 
63 66
  visibility: 2
64 67
  name: Public query for all projects
68
  description: Description for Public query for all projects
65 69
  filters: |
66 70
    --- 
67 71
    tracker_id: 
......
77 81
  project_id: 
78 82
  visibility: 2
79 83
  name: Open issues by priority and tracker
84
  description: Description for Oepn issues by priority and tracker
80 85
  filters: |
81 86
    --- 
82 87
    status_id: 
......
98 103
  project_id: 
99 104
  visibility: 2
100 105
  name: Open issues grouped by tracker
106
  description: Description for Open issues grouped by tracker
101 107
  filters: |
102 108
    --- 
103 109
    status_id: 
......
118 124
  project_id: 2
119 125
  visibility: 2
120 126
  name: Public query for project 2
127
  description: Description for Public query for project 2
121 128
  filters: |
122 129
    --- 
123 130
    tracker_id: 
......
133 140
  project_id: 2
134 141
  visibility: 0
135 142
  name: Private query for project 2
143
  description: Description for Private query for project 2
136 144
  filters: |
137 145
    --- 
138 146
    tracker_id: 
......
148 156
  project_id: 
149 157
  visibility: 2
150 158
  name: Open issues grouped by list custom field
159
  description: Description for Open issues grouped by list custom field
151 160
  filters: |
152 161
    --- 
153 162
    status_id: 
......
168 177
  project_id: 1
169 178
  visibility: 2
170 179
  name: My spent time
180
  description: Description for My spent time
171 181
  filters: |
172 182
    --- 
173 183
    user_id: 
......
187 197
  type: ProjectQuery
188 198
  visibility: 2
189 199
  name: Projects as list
200
  description: Description for Projects as list
190 201
  filters: |
191 202
    ---
192 203
    id:
......
205 216
  type: ProjectQuery
206 217
  visibility: 1
207 218
  name: My bookmarks
219
  description: Description for My bookmarks
208 220
  filters: |
209 221
    ---
210 222
    id:
test/functional/calendars_controller_test.rb
155 155
  end
156 156

  
157 157
  def test_show_should_run_custom_queries
158
    @query = IssueQuery.create!(:name => 'Calendar Query', :visibility => IssueQuery::VISIBILITY_PUBLIC)
158
    query = IssueQuery.create!(:name => 'Calendar Query', :description => 'Description for Calendar Query', :visibility => IssueQuery::VISIBILITY_PUBLIC)
159 159
    get(
160 160
      :show,
161 161
      :params => {
162
        :query_id => @query.id
162
        :query_id => query.id
163 163
      }
164 164
    )
165 165
    assert_response :success
166
    assert_select 'h2', :text => 'Calendar Query'
166
    assert_select 'h2', :text => query.name
167
    assert_select '#sidebar a.query.selected[title=?]', query.description, :text => query.name
167 168
  end
168 169

  
169 170
  def test_cross_project_calendar
test/functional/gantts_controller_test.rb
118 118
    assert_response :success
119 119
  end
120 120

  
121
  def test_show_should_run_custom_query
122
    query = IssueQuery.create!(:name => 'Gantt Query', :description => 'Description for Gantt Query', :visibility => IssueQuery::VISIBILITY_PUBLIC)
123
    get(
124
      :show,
125
      :params => {
126
        :query_id => query.id
127
      }
128
    )
129
    assert_response :success
130
    assert_select 'h2', :text => query.name
131
    assert_select '#sidebar a.query.selected[title=?]', query.description, :text => query.name
132
  end
133

  
121 134
  def test_gantt_should_work_cross_project
122 135
    get :show
123 136
    assert_response :success
test/functional/issues_controller_test.rb
359 359
      assert_select 'a.query.selected', 1
360 360
      # assert link properties
361 361
      assert_select(
362
        'a.query.selected[href=?]',
362
        'a.query.selected[title=?][href=?]',
363
        'Description for Oepn issues by priority and tracker',
363 364
        '/projects/ecookbook/issues?query_id=5',
364 365
        :text => "Open issues by priority and tracker"
365 366
      )
test/functional/projects_controller_test.rb
252 252
    assert_select ".total-for-cf-#{field.id} span.value", :text => '9'
253 253
  end
254 254

  
255
  def test_index_with_query
256
    query = ProjectQuery.find(11)
257
    get :index, :params => { :query_id => query.id }
258
    assert_response :success
259
    assert_select 'h2', :text => query.name
260
    assert_select '#sidebar a.query.selected[title=?]', query.description, :text => query.name
261
  end
262

  
255 263
  def test_index_should_retrieve_default_query
256 264
    query = ProjectQuery.find(11)
257 265
    ProjectQuery.stubs(:default).returns query
......
260 268
      @request.session[:user_id] = user_id
261 269
      get :index
262 270
      assert_select 'h2', text: query.name
271
      assert_select '#sidebar a.query.selected[title=?]', query.description, :text => query.name
263 272
    end
264 273
  end
265 274

  
test/functional/queries_controller_test.rb
328 328
    assert_equal [['due_date', 'desc'], ['tracker', 'asc']], query.sort_criteria
329 329
  end
330 330

  
331
  def test_create_with_description
332
    @request.session[:user_id] = 2
333
    assert_difference '::Query.count', 1 do
334
      post(
335
        :create,
336
        :params => {
337
          :project_id => 'ecookbook',
338
          :query => {
339
            :name => 'test_new_with_description', :description => 'Description for test_new_with_description'
340
          }
341
        }
342
      )
343
    end
344
    q = Query.find_by_name("test_new_with_description")
345
    assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q
346

  
347
    assert_equal 'Description for test_new_with_description', q.description
348
  end
349

  
331 350
  def test_create_with_failure
332 351
    @request.session[:user_id] = 2
333 352
    assert_no_difference '::Query.count' do
......
659 678
    end
660 679
  end
661 680

  
681
  def test_edit_description
682
    @request.session[:user_id] = 1
683
    get(:edit, :params => {:id => 5})
684
    assert_response :success
685

  
686
    assert_select 'input[name="query[description]"][value=?]', 'Description for Oepn issues by priority and tracker'
687
  end
688

  
662 689
  def test_edit_invalid_query
663 690
    @request.session[:user_id] = 2
664 691
    get(:edit, :params => {:id => 99})
......
744 771
    assert Query.find_by_name('test_project_query_updated')
745 772
  end
746 773

  
774
  def test_update_description
775
    @request.session[:user_id] = 1
776
    q = Query.find(5)
777
    put(
778
      :update,
779
      :params => {
780
        :id => q.id,
781
        :query => {
782
          :name => q.name,
783
          :description => 'query description updated'
784
        }
785
      }
786
    )
787
    assert_redirected_to :controller => 'issues', :action => 'index', :query_id => q.id
788
    assert_equal 'query description updated',  Query.find(5).description
789
  end
790

  
747 791
  def test_update_with_failure
748 792
    @request.session[:user_id] = 1
749 793
    put(
test/functional/timelog_controller_test.rb
1682 1682
  end
1683 1683

  
1684 1684
  def test_index_with_query
1685
    query = TimeEntryQuery.new(:project_id => 1, :name => 'Time Entry Query', :visibility => 2)
1685
    query = TimeEntryQuery.new(:project_id => 1, :name => 'Time Entry Query', :description => 'Description for Time Entry Query', :visibility => 2)
1686 1686
    query.save!
1687 1687
    @request.session[:user_id] = 2
1688 1688

  
1689 1689
    get :index, :params => {:project_id => 'ecookbook', :query_id => query.id}
1690 1690
    assert_response :success
1691 1691
    assert_select 'h2', :text => query.name
1692
    assert_select '#sidebar a.selected', :text => query.name
1692
    assert_select '#sidebar a.query.selected[title=?]', query.description, :text => query.name
1693 1693
  end
1694 1694

  
1695 1695
  def test_index_atom_feed
test/functional/users_controller_test.rb
189 189
    assert_select 'tr#user-1', 1
190 190
  end
191 191

  
192
  def test_index_with_query
193
    query = UserQuery.create!(:name => 'My User Query', :description => 'Description for My User Query', :visibility => UserQuery::VISIBILITY_PUBLIC)
194
    get :index, :params => { :query_id => query.id }
195
    assert_response :success
196

  
197
    assert_select 'h2', :text => query.name
198
    assert_select '#sidebar a.query.selected[title=?]', query.description, :text => query.name
199
  end
200

  
192 201
  def test_index_csv
193 202
    with_settings :default_language => 'en' do
194 203
      user = User.logged.status(1).first
(2-2/6)