]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1557799 - Search By Change History: date range is ignored when field is not specified
authorKohei Yoshino <kohei.yoshino@gmail.com>
Fri, 5 Jul 2019 22:49:10 +0000 (18:49 -0400)
committerGitHub <noreply@github.com>
Fri, 5 Jul 2019 22:49:10 +0000 (18:49 -0400)
extensions/BMO/web/js/advanced-search.js
js/advanced-search.js
js/field.js
qa/t/test_bug_edit.t
skins/standard/search_form.css
template/en/default/search/form.html.tmpl

index 3e5662453e344f9ff7439805fee2a559985673e6..9fa341ef018ecd02707d7871117da9afab87e16b 100644 (file)
  */
 var Bugzilla = Bugzilla || {}; // eslint-disable-line no-var
 
+/**
+ * Reference or define the BMO extension namespace.
+ * @namespace
+ */
+Bugzilla.BMO = Bugzilla.BMO || {};
+
 /**
  * Implement Advanced Search page features.
  */
-Bugzilla.AdvancedSearch = class AdvancedSearch {
+Bugzilla.BMO.AdvancedSearch = class AdvancedSearch {
   /**
    * Initialize a new AdvancedSearch instance.
    */
@@ -44,4 +50,4 @@ Bugzilla.AdvancedSearch = class AdvancedSearch {
   }
 };
 
-window.addEventListener('DOMContentLoaded', () => new Bugzilla.AdvancedSearch(), { once: true });
+window.addEventListener('DOMContentLoaded', () => new Bugzilla.BMO.AdvancedSearch(), { once: true });
index 50e673046b8ce9be052b01926e86f4863e3bd23c..8f32148152bafadb0944a5a29e349090c02253e7 100644 (file)
  */
 var Bugzilla = Bugzilla || {}; // eslint-disable-line no-var
 
+Bugzilla.AdvancedSearch = {};
+
+/**
+ * Implement features in the Search By Change History section.
+ */
+Bugzilla.AdvancedSearch.HistoryFilter = class HistoryFilter {
+  /**
+   * Initialize a new HistoryFilter instance.
+   */
+  constructor() {
+    this.$chfield = document.querySelector('#chfield');
+    this.$chfieldfrom = document.querySelector('#chfieldfrom');
+    this.$chfieldfrom_button = document.querySelector('#chfieldfrom + button');
+    this.$chfieldto = document.querySelector('#chfieldto');
+    this.$chfieldto_button = document.querySelector('#chfieldto + button');
+
+    this.$chfieldfrom.addEventListener('input', event => this.on_date_change(event));
+    this.$chfieldto.addEventListener('input', event => this.on_date_change(event));
+
+    // Use on-event handler because `field.js` will update it
+    this.$chfieldfrom_button.onclick = () => showCalendar('chfieldfrom');
+    this.$chfieldto_button.onclick = () => showCalendar('chfieldto');
+
+    createCalendar('chfieldfrom');
+    createCalendar('chfieldto');
+  }
+
+  /**
+   * Called whenever the date field value is updated.
+   * @param {InputEvent} event `input` event fired on date fields.
+   */
+  on_date_change(event) {
+    // Update the calendar when the user enters a date manually
+    if (event.isTrusted) {
+      updateCalendarFromField(event.target);
+    }
+
+    // Mark `<select>` required if the value is not empty
+    this.$chfield.required = !!this.$chfieldfrom.value.trim() || !!this.$chfieldto.value.trim();
+  }
+};
+
 /**
  * Implement Custom Search features.
  */
@@ -659,4 +701,7 @@ Bugzilla.CustomSearch.DropTarget = class CustomSearchDropTarget {
   }
 };
 
-window.addEventListener('DOMContentLoaded', () => new Bugzilla.CustomSearch(), { once: true });
+window.addEventListener('DOMContentLoaded', () => {
+  new Bugzilla.AdvancedSearch.HistoryFilter();
+  new Bugzilla.CustomSearch();
+}, { once: true });
index a3680cdf72ca1b950335c156652f1d8b1dea01e7..639484ac15eaf49f840c86877431f8c8205f4f39 100644 (file)
@@ -197,6 +197,7 @@ function setFieldFromCalendar(type, args, date_field) {
     }
 
     date_field.value = dateStr;
+    date_field.dispatchEvent(new Event('input'));
     hideCalendar(date_field.id);
 }
 
index da16d8d562536e7051065478b0dac94db27e63cc..7c972cd2afa6dd34c3d4349b6b44ff348e195c47 100644 (file)
@@ -311,7 +311,7 @@ $sel->type_ok("email2", $config->{QA_Selenium_TEST_user_login});
 screenshot_page($sel, '/app/artifacts/line271.png');
 $sel->click_ok("Search");
 check_page_load($sel,
-  q{http://HOSTNAME/buglist.cgi?emailreporter2=1&emailtype2=exact&order=Importance&list_id=__LIST_ID__&emailtype1=exact&emailcc2=1&query_format=advanced&emailassigned_to1=1&emailqa_contact2=1&email2=QA-Selenium-TEST%40mozilla.test&email1=admin%40mozilla.test&emailassigned_to2=1&product=TestProduct}
+  q{http://HOSTNAME/buglist.cgi?emailreporter2=1&order=Importance&emailtype2=exact&list_id=__LIST_ID__&emailtype1=exact&emailcc2=1&emailassigned_to1=1&query_format=advanced&emailqa_contact2=1&email2=QA-Selenium-TEST%40mozilla.test&emailassigned_to2=1&email1=admin%40mozilla.test&product=TestProduct}
 );
 $sel->title_is("Bug List");
 screenshot_page($sel, '/app/artifacts/line275.png');
index cb2d23c98f8a89d54d30f9ee0352198342ff920f..cf6574671542763295a601265abe558e960ad905 100644 (file)
   font-weight: normal;
 }
 
+.bz_search_section .field_help {
+  white-space: nowrap;
+}
+
 #bug_id_container .field_help {
-  font-size: var(--font-size-x-small);
+  display: block;
 }
 
 .search_field_row {
index 0bd57d88fdc46c024c2a0767a8a349a96974c117..5b64215bb4931f43d99327d34a2933ca361e5ed4 100644 (file)
@@ -258,7 +258,7 @@ TUI_hide_default('custom_search_query');
     <div id="bug_id_container">
       <input type="text" name="bug_id" id="bug_id"
            value="[% default.bug_id.0 FILTER html %]" size="20">
-           <div class="field_help">(comma-separated list)</div>
+           <small class="field_help">(comma-separated list)</small>
     </div>
     should be
     <select name="bug_id_type" id="bug_id_type">
@@ -391,25 +391,14 @@ TUI_hide_default('custom_search_query');
   </li>
   <li>
     <label for="chfieldfrom">between:</label>
-    <input name="chfieldfrom" id="chfieldfrom" size="10"
-           value="[% default.chfieldfrom.0 FILTER html %]" onchange="updateCalendarFromField(this)">
-           <button type="button" class="calendar_button"
-                          id="button_calendar_chfieldfrom"
-                          onclick="showCalendar('chfieldfrom')"><span>Calendar</span></button>
-           and
-           <div id="con_calendar_chfieldfrom"></div>
-          <input name="chfieldto" size="10" id="chfieldto"
-                 value="[% default.chfieldto.0 || "Now" FILTER html %]"
-                 onchange="updateCalendarFromField(this)">
-          <button type="button" class="calendar_button"
-                         id="button_calendar_chfieldto"
-                         onclick="showCalendar('chfieldto')"><span>Calendar</span></button>
-          <div id="con_calendar_chfieldto"></div>
-    (YYYY-MM-DD or relative dates)
-    <script [% script_nonce FILTER none %]>
-      createCalendar('chfieldfrom');
-      createCalendar('chfieldto');
-    </script>
+    <input name="chfieldfrom" id="chfieldfrom" size="10" value="[% default.chfieldfrom.0 FILTER html %]">
+    <button type="button" class="calendar_button" id="button_calendar_chfieldfrom"><span>Calendar</span></button>
+    and
+    <div id="con_calendar_chfieldfrom"></div>
+    <input name="chfieldto" size="10" id="chfieldto" value="[% default.chfieldto.0 FILTER html %]" placeholder="Now">
+    <button type="button" class="calendar_button" id="button_calendar_chfieldto"><span>Calendar</span></button>
+    <div id="con_calendar_chfieldto"></div>
+    <small class="field_help">(YYYY-MM-DD or <a href="[% docs_urlbase FILTER html %]using/finding.html#relative-dates">relative dates</a>)</small>
   </li>
 </ul>