Project

General

Profile

Actions

Patch #31994

closed

Allow issue auto complete to return 10 issues when there is not search term provided

Added by Marius BĂLTEANU over 4 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Issues
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:

Description

The first patch changes the issue auto complete behaviour in order to return last ten updated issues when there is no search term provided. This will allow us to make future changes and propose to users some default issues in auto complete fields (one use case will be #31989) before they start typing a search term.

Second patch removes a view that is not used from my checks (code cleanup).


Files


Related issues

Related to Redmine - Feature #31989: Inline issue auto complete (#) in fields with text-formatting enabledClosedGo MAEDA

Actions
Actions #1

Updated by Go MAEDA over 4 years ago

  • Related to Feature #31989: Inline issue auto complete (#) in fields with text-formatting enabled added
Actions #2

Updated by Go MAEDA over 4 years ago

What do you think if the patch checks params[:status] even when the search term is empty? I think it is more consistent.

diff --git a/app/controllers/auto_completes_controller.rb b/app/controllers/auto_completes_controller.rb
index f6a1414ad..bd8ce06b0 100644
--- a/app/controllers/auto_completes_controller.rb
+++ b/app/controllers/auto_completes_controller.rb
@@ -25,11 +25,10 @@ class AutoCompletesController < ApplicationController
     q = (params[:q] || params[:term]).to_s.strip
     status = params[:status].to_s
     issue_id = params[:issue_id].to_s
+
+    scope = Issue.cross_project_scope(@project, params[:scope]).visible
+    scope = scope.open(status == 'o') if status.present?
     if q.present?
-      scope = Issue.cross_project_scope(@project, params[:scope]).visible
-      if status.present?
-        scope = scope.open(status == 'o')
-      end
       if issue_id.present?
         scope = scope.where.not(:id => issue_id.to_i)
       end
@@ -39,6 +38,8 @@ class AutoCompletesController < ApplicationController

       issues += scope.like(q).order(:id => :desc).limit(10).to_a
       issues.compact!
+    else
+      issues += scope.order(:id => :desc).limit(10).to_a
     end

     render :json => format_issues_json(issues)
Actions #3

Updated by Marius BĂLTEANU over 4 years ago

  • File deleted (0001-Issue-auto-complete-should-return-last-10-updated-is.patch)
Actions #4

Updated by Marius BĂLTEANU over 4 years ago

Go MAEDA wrote:

What do you think if the patch checks params[:status] even when the search term is empty? I think it is more consistent.

Very good idea, thanks! I've updated the patch, also params[:issue_id] should be outside.

Actions #5

Updated by Go MAEDA over 4 years ago

  • Target version set to Candidate for next major release
Actions #6

Updated by Go MAEDA over 4 years ago

  • Target version changed from Candidate for next major release to 4.1.0
Actions #7

Updated by Go MAEDA over 4 years ago

  • Assignee set to Marius BĂLTEANU

The subject says "return last 10 updated issues" but actually the patch returns last 10 created issues. Is it OK?

       issues += scope.like(q).order(:id => :desc).limit(10).to_a
Actions #8

Updated by Marius BĂLTEANU over 4 years ago

  • Subject changed from Allow issue auto complete to return last 10 updated issues when there is not search term provided to Allow issue auto complete to return last 10 created issues when there is not search term provided
  • Assignee changed from Marius BĂLTEANU to Go MAEDA

Go MAEDA wrote:

The subject says "return last 10 updated issues" but actually the patch returns last 10 created issues. Is it OK?

[...]

Indeed, my initial intention was to return the last 10 updated issues, but during the implementation, I kept the existing behaviour. I'm updating the issue subject because changing from last created to last updated (which I still consider a good idea) should be discussed in another ticket. Go Maeda, thanks for catching this.

Actions #9

Updated by Marius BĂLTEANU over 4 years ago

  • Subject changed from Allow issue auto complete to return last 10 created issues when there is not search term provided to Allow issue auto complete to return 10 issues when there is not search term provided
Actions #10

Updated by Go MAEDA over 4 years ago

Marius BALTEANU wrote:

Second patch removes a view that is not used from my checks (code cleanup).

app/views/auto_completes/issues.html.erb is no longer used after r17881 (render :layout => false was replaced with render :json => format_issues_json(issues)).

Actions #11

Updated by Go MAEDA over 4 years ago

  • Status changed from New to Closed

Committed the patches. Thank you for your contribution.

Actions #12

Updated by Mischa The Evil over 4 years ago

Marius BALTEANU wrote:

Go MAEDA wrote:

The subject says "return last 10 updated issues" but actually the patch returns last 10 created issues. Is it OK?

[...]

Indeed, my initial intention was to return the last 10 updated issues, but during the implementation, I kept the existing behaviour.

Shouldn't this change be reflected in the name of the test that is committed (test_auto_complete_without_term_should_return_last_10_updated_issues)?

Actions #13

Updated by Marius BĂLTEANU over 4 years ago

  • Status changed from Closed to Reopened

Mischa The Evil wrote:

Marius BALTEANU wrote:

Go MAEDA wrote:

The subject says "return last 10 updated issues" but actually the patch returns last 10 created issues. Is it OK?

[...]

Indeed, my initial intention was to return the last 10 updated issues, but during the implementation, I kept the existing behaviour.

Shouldn't this change be reflected in the name of the test that is committed (test_auto_complete_without_term_should_return_last_10_updated_issues)?

Indeed, it should, sorry for it.

Mariuss-MacBook-Pro:redmine mariusbalteanu$ git diff
diff --git a/test/functional/auto_completes_controller_test.rb b/test/functional/auto_completes_controller_test.rb
index 825ebf8e9..f8ed441da 100644
--- a/test/functional/auto_completes_controller_test.rb
+++ b/test/functional/auto_completes_controller_test.rb
@@ -151,7 +151,7 @@ class AutoCompletesControllerTest < Redmine::ControllerTest
     assert_include 'application/json', response.headers['Content-Type']
   end

-  def test_auto_complete_without_term_should_return_last_10_updated_issues
+  def test_auto_complete_without_term_should_return_last_10_issues
     # There are 9 issues generated by fixtures
     # and we need two more to test the 10 limit
     %w(1..2).each do

Actions #14

Updated by Go MAEDA over 4 years ago

  • Status changed from Reopened to Closed

Mischa The Evil wrote:

Shouldn't this change be reflected in the name of the test that is committed (test_auto_complete_without_term_should_return_last_10_updated_issues)?

Thank you for pointing it out. Committed the fix posted in #31994#note-12 in r18452.

Actions #15

Updated by Go MAEDA over 4 years ago

  • Related to Feature #32052: Auto-complete issues #id in search form added
Actions #16

Updated by Go MAEDA over 4 years ago

  • Related to deleted (Feature #32052: Auto-complete issues #id in search form)
Actions

Also available in: Atom PDF