]> source.dussan.org Git - redmine.git/commitdiff
Add "Assign to me" shortcut to issue edit form (#29285).
authorGo MAEDA <maeda@farend.jp>
Sat, 29 Feb 2020 06:13:24 +0000 (06:13 +0000)
committerGo MAEDA <maeda@farend.jp>
Sat, 29 Feb 2020 06:13:24 +0000 (06:13 +0000)
Patch by Marius BALTEANU.

git-svn-id: http://svn.redmine.org/redmine/trunk@19539 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/views/issues/_attributes.html.erb
app/views/issues/_form.html.erb
config/locales/en.yml
public/stylesheets/application.css
test/functional/issues_controller_test.rb

index 332ecbf19539ff636d5b4f78bb09c1f7e1ef49cf..0fc988576b2545cdf899bb0466d46643ca7f5b7b 100644 (file)
 <% end %>
 
 <% if @issue.safe_attribute? 'assigned_to_id' %>
-<p><%= f.select :assigned_to_id, principals_options_for_select(@issue.assignable_users, @issue.assigned_to),
-                :include_blank => true, :required => @issue.required_attribute?('assigned_to_id') %></p>
+<p>
+  <%= f.select :assigned_to_id, principals_options_for_select(@issue.assignable_users, @issue.assigned_to),
+                  :include_blank => true, :required => @issue.required_attribute?('assigned_to_id') %>
+  <% if @issue.assignable_users.include?(User.current) %>
+    <a class="assign-to-me-link<%= ' hidden' if @issue.assigned_to_id == User.current.id %>" href="#" data-id="<%= User.current.id %>"><%= l(:label_assign_to_me) %></a>
+  <% end %>
+</p>
 <% end %>
 
 <% if @issue.safe_attribute?('category_id') && @issue.project.issue_categories.any? %>
index fdf729140f573ad73c2f5ef6af26c4496dfedcca..214502b0a9e8b70cd5939d78de073b1b45f21930 100644 (file)
@@ -60,5 +60,25 @@ $(document).ready(function(){
   $("#issue_tracker_id, #issue_status_id").each(function(){
     $(this).val($(this).find("option[selected=selected]").val());
   });
+  $(".assign-to-me-link").click(function(event){
+    event.preventDefault();
+    var element = $(event.target);
+    $('#issue_assigned_to_id').val(element.data('id'));
+    element.hide();
+  });
+  $('#issue_assigned_to_id').change(function(event){
+    var assign_to_me_link = $(".assign-to-me-link");
+
+    if (assign_to_me_link.length > 0) {
+      var user_id = $(event.target).val();
+      var current_user_id = assign_to_me_link.data('id');
+
+      if (user_id == current_user_id) {
+        assign_to_me_link.hide();
+      } else {
+        assign_to_me_link.show();
+      }
+    }
+  });
 });
 <% end %>
index 3f0fd2d77df5b29b2620faa2de47e4e52a6dad0f..c4988e493e9847bbe2f518dafe1aaf30c9ec7303 100644 (file)
@@ -1079,6 +1079,7 @@ en:
   label_display_type_list: List
   label_display_type_board: Board
   label_my_bookmarks: My bookmarks
+  label_assign_to_me: Assign to me
 
   button_login: Login
   button_submit: Submit
index bdfccf66477700f10f60757799c4906b85940575..b3b4d9b423eb9b0f9f12950e111255332b5b129c 100644 (file)
@@ -540,6 +540,8 @@ div.issue.overdue .due-date .value { color: #c22; }
 #trackers_description dt {font-weight: bold; text-decoration: underline;}
 #trackers_description dd {margin: 0; padding: 0 0 1em 0;}
 
+#issue-form .assign-to-me-link { padding-left: 5px; }
+
 fieldset.collapsible {border-width: 1px 0 0 0;}
 fieldset.collapsible>legend { cursor:pointer; padding-left: 18px; background-position: 4px;}
 
index ec07c85772778e53971c85590c6e31f8f6c01e02..315125b913d9eac811759c215bfa154abb258eba 100644 (file)
@@ -2105,6 +2105,43 @@ class IssuesControllerTest < Redmine::ControllerTest
     end
   end
 
+  def test_update_form_should_render_assign_to_me_link_when_issue_can_be_assigned_to_the_current_user
+    @request.session[:user_id] = 1
+    get :show, :params => {
+        :id => 10
+      }
+
+    assert_select 'form#issue-form #attributes' do
+      assert_select 'a[class=?][data-id=?]', 'assign-to-me-link', '1', 1
+    end
+  end
+
+  def test_update_form_should_not_render_assign_to_me_link_when_issue_cannot_be_assigned_to_the_current_user
+    @request.session[:user_id] = 1
+    get :show, :params => {
+        :id => 2
+      }
+
+    assert_select 'form#issue-form #attributes' do
+      assert_select 'a[class=?]', 'assign-to-me-link', 0
+    end
+  end
+
+  def test_update_form_should_not_show_assign_to_me_link_when_issue_is_assigned_to_the_current_user
+    issue = Issue.find(10)
+    issue.assigned_to_id = 1
+    issue.save!
+
+    @request.session[:user_id] = 1
+    get :show, :params => {
+        :id => 10
+      }
+
+    assert_select 'form#issue-form #attributes' do
+      assert_select 'a[class=?]', 'assign-to-me-link hidden', 1
+    end
+  end
+
   def test_show_should_deny_anonymous_access_without_permission
     Role.anonymous.remove_permission!(:view_issues)
     get(:show, :params => {:id => 1})