Defect #34641

When editing an issue, the Log time and/or Add notes does not show or hide dynamically

Added by Yuichi HARADA 9 months ago. Updated 8 months ago.

Status:NewStart date:
Priority:NormalDue date:
Assignee:Marius BALTEANU% Done:

0%

Category:Issues
Target version:Candidate for next major release
Resolution: Affected version:

Description

I changed the project when editing an issue, but the Log time does not show or hide dynamically. There is a mixture of projects with the Time tracking module enabled or disabled.

34641.patch Magnifier (2.29 KB) Yuichi HARADA, 2021-01-27 02:54

34641-v2.patch Magnifier (2.59 KB) Yuichi HARADA, 2021-02-04 08:30

34641-v3.patch Magnifier (4.77 KB) Yuichi HARADA, 2021-02-09 02:22

0001-Update-log-time-and-add-notes-blocks-when-updating-t.patch Magnifier (5.46 KB) Marius BALTEANU, 2021-02-10 23:41

0002-Update-log-time-and-add-notes-blocks-when-updating-t.patch Magnifier (5.61 KB) Marius BALTEANU, 2021-02-24 19:53

History

#1 Updated by Yuichi HARADA 9 months ago

When you change the project, source:trunk/app/views/issues/edit.js.erb will be executed, so you should be able to show/hide the Log time. However, the function does not work because $('#log_time') does not exist on the issue edit form.
I created a patch like this:

diff --git a/app/views/issues/_edit.html.erb b/app/views/issues/_edit.html.erb
index 33f8352f57..766e9c78aa 100644
--- a/app/views/issues/_edit.html.erb
+++ b/app/views/issues/_edit.html.erb
@@ -9,8 +9,7 @@
         </div>
         </fieldset>
     <% end %>
-    <% if User.current.allowed_to?(:log_time, @project) %>
-        <fieldset class="tabular"><legend><%= l(:button_log_time) %></legend>
+      <fieldset id="log_time" class="tabular"><legend><%= l(:button_log_time) %></legend>
         <%= labelled_fields_for :time_entry, @time_entry do |time_entry| %>
         <div class="splitcontent">
         <div class="splitcontentleft">
@@ -25,8 +24,8 @@
           <p><%= custom_field_tag_with_label :time_entry, value %></p>
         <% end %>
         <% end %>
-    </fieldset>
-    <% end %>
+      </fieldset>
+      <%= javascript_tag("$('#log_time').hide();") unless User.current.allowed_to?(:log_time, @project) %>
     <% if @issue.notes_addable? %>
       <fieldset><legend><%= l(:field_notes) %></legend>
       <%= f.text_area :notes, :cols => 60, :rows => 10, :class => 'wiki-edit',

#2 Updated by Mischa The Evil 9 months ago

  • Target version set to Candidate for next minor release

Nice catch! It probably needs some test coverage to ensure it won't break in the future.

#3 Updated by Marius BALTEANU 9 months ago

  • Assignee set to Marius BALTEANU

Let me look a little bit on this, I don't think that we need Javascript for this.

#4 Updated by Mischa The Evil 9 months ago

Marius BALTEANU wrote:

[...] I don't think that we need Javascript for this.

That would be even nicer then...

#5 Updated by Marius BALTEANU 9 months ago

  • Subject changed from When editing an issue, the Log time does not show or hide dynamically to When editing an issue, the Log time and/or Add notes does not show or hide dynamically
  • Target version changed from Candidate for next minor release to Candidate for next major release

I've updated the subject because the same problem reproduces also for add notes block.

Looking in the code, the log time block was supposed to hide automatically (see source:trunk/app/views/issues/edit.js.erb#L3), but it doesn't work because the fieldset is missing the "log_time" id (most probably, because of r8142).

The fix to hide both blocks is quite small, just adding some ids and extra few lines of code for add notes, but it doesn't work in all cases, for example, if you edit an issue with the log time not available for the user and you change the project to one with log time available, it won't appear because the element was not rendered initially in the page.

@Yuichi HARADA, indeed, rendering the block all the time and hiding using javascript it is an option, but I still prefer to find a non javascript solution for this.

#6 Updated by Marius BALTEANU 9 months ago

For next minor release, we can deliver only the fix to hide the blocks if you find it useful.

#7 Updated by Yuichi HARADA 9 months ago

Marius BALTEANU wrote:

@Yuichi HARADA, indeed, rendering the block all the time and hiding using javascript it is an option, but I still prefer to find a non javascript solution for this.

I tried using hidden class (source:trunk/public/stylesheets/application.css#L136) like a source:trunk/app/views/issues/_attributes.html.erb#L27 . I fixed only the Log time block.

diff --git a/app/views/issues/_edit.html.erb b/app/views/issues/_edit.html.erb
index 33f8352f57..fe7dad04a8 100644
--- a/app/views/issues/_edit.html.erb
+++ b/app/views/issues/_edit.html.erb
@@ -9,8 +9,7 @@
         </div>
         </fieldset>
     <% end %>
-    <% if User.current.allowed_to?(:log_time, @project) %>
-        <fieldset class="tabular"><legend><%= l(:button_log_time) %></legend>
+      <fieldset id="log_time" class="tabular<%= ' hidden' unless User.current.allowed_to?(:log_time, @project) %>"><legend><%= l(:button_log_time) %></legend>
         <%= labelled_fields_for :time_entry, @time_entry do |time_entry| %>
         <div class="splitcontent">
         <div class="splitcontentleft">
@@ -25,8 +24,7 @@
           <p><%= custom_field_tag_with_label :time_entry, value %></p>
         <% end %>
         <% end %>
-    </fieldset>
-    <% end %>
+      </fieldset>
     <% if @issue.notes_addable? %>
       <fieldset><legend><%= l(:field_notes) %></legend>
       <%= f.text_area :notes, :cols => 60, :rows => 10, :class => 'wiki-edit',
diff --git a/app/views/issues/edit.js.erb b/app/views/issues/edit.js.erb
index 8c94aecebd..ef04553e0c 100644
--- a/app/views/issues/edit.js.erb
+++ b/app/views/issues/edit.js.erb
@@ -1,7 +1,7 @@
 replaceIssueFormWith('<%= escape_javascript(render :partial => 'form') %>');

 <% if User.current.allowed_to?(:log_time, @issue.project) %>
-  $('#log_time').show();
+  $('#log_time').removeClass('hidden');
 <% else %>
-  $('#log_time').hide();
+  $('#log_time').addClass('hidden');
 <% end %>

#8 Updated by Yuichi HARADA 8 months ago

Added system test to 34641-v2.patch.

#9 Updated by Marius BALTEANU 8 months ago

  • File 0001-Update-log-time-and-add-notes-blocks-when-updating-t.patch added

Yuichi, thanks for updating your patch.

What do you think if we update the entire "edit" form instead of only "form"? In this way, we fix this issue for all three affected blocks: log time, add notes and add attachments and we simplify the code, as well.

Beside this, the attached patch fixes another issue:
if User.current.allowed_to?(:log_time, @project) checks if the user has the log time permission on the project and not on the issue's project and because of this, you can have the case when you open an issue on a project where you have rights to log time and when you select another project where you don't have rights, the block is still displayed because @project is the same.

#10 Updated by Marius BALTEANU 8 months ago

  • File deleted (0001-Update-log-time-and-add-notes-blocks-when-updating-t.patch)

#12 Updated by Go MAEDA 8 months ago

  • Category set to Issues

#13 Updated by Yuichi HARADA 8 months ago

Marius BALTEANU wrote:

What do you think if we update the entire "edit" form instead of only "form"? In this way, we fix this issue for all three affected blocks: log time, add notes and add attachments and we simplify the code, as well.

Marius, I thought it was good. However, replaceIssueFormWith was also used in the issue creation form, and this patch broke this issue creation form.

app/views/issues/new.js.erb:1:replaceIssueFormWith('<%= escape_javascript(render :partial => 'form') %>');

#14 Updated by Marius BALTEANU 8 months ago

Yuichi HARADA wrote:

Marius BALTEANU wrote:

What do you think if we update the entire "edit" form instead of only "form"? In this way, we fix this issue for all three affected blocks: log time, add notes and add attachments and we simplify the code, as well.

Marius, I thought it was good. However, replaceIssueFormWith was also used in the issue creation form, and this patch broke this issue creation form.

[...]

Oh, such a bad patch, sorry for it. I'll post soon an updated one.

#15 Updated by Marius BALTEANU 8 months ago

Yuichi, can you test the attached patch?

#16 Updated by Yuichi HARADA 8 months ago

Marius BALTEANU wrote:

Yuichi, can you test the attached patch?

Marius, I tested your patch. I confirmed that the show or hide is dynamically switched. I think it's good.
However, I found a typo. I think it's better to fix it.

diff --git a/app/views/issues/_edit.html.erb b/app/views/issues/_edit.html.erb
index aca1ae8f4..bc881db4b 100644
--- a/app/views/issues/_edit.html.erb
+++ b/app/views/issues/_edit.html.erb
@@ -43,7 +43,7 @@
       <%= call_hook(:view_issues_edit_notes_bottom, { :issue => @issue, :notes => @notes, :form => f }) %>
       </fieldset>

-      <fieldset id="add_attachments"'><legend><%= l(:label_attachment_plural) %></legend>
+      <fieldset id="add_attachments"><legend><%= l(:label_attachment_plural) %></legend>
         <% if @issue.attachments.any? && @issue.safe_attribute?('deleted_attachment_ids') %>
         <div class="contextual"><%= link_to l(:label_edit_attachments), '#', :onclick => "$('#existing-attachments').toggle(); return false;" %></div>
         <div id="existing-attachments" style="<%= @issue.deleted_attachment_ids.blank? ? 'display:none;' : '' %>">

Also available in: Atom PDF