[dev] [nag-patch] sort in search

Francois Marier francois at nit.ca
Tue Jul 27 16:34:55 PDT 2004


Hi,

This patch fixes a bug in Nag's sorting.

More specifically, here's the bug it fixes:

- Create 3 events "abc", "def" and "ghi" with categories "Personal",
  "Personal" and "Business"
- Search for all events that contain "Personal" in the category
- Click on the "Name" column header to sort entries by name

It comes back to the task list instead of staying in the search list.

Francois
-------------- next part --------------
diff -rpuN -X ../ignorelist ../build/nag/list.php nag/list.php
--- ../build/nag/list.php	Sat Jul 24 20:34:45 2004
+++ nag/list.php	Tue Jul 27 19:26:46 2004
@@ -41,13 +41,13 @@ $title = _("My Tasks");
 switch ($actionID) {
 case 'search_tasks':
     /* Get the search parameters. */
-    $pattern = Util::getFormData('search_pattern');
+    $search_pattern = Util::getFormData('search_pattern');
     $search_name = (Util::getFormData('search_name') == 'on');
     $search_desc = (Util::getFormData('search_desc') == 'on');
     $search_category = (Util::getFormData('search_category') == 'on');
 
-    if (!empty($pattern) && ($search_name || $search_desc || $search_category)) {
-        $pattern = '/' . preg_quote($pattern, '/') . '/i';
+    if (!empty($search_pattern) && ($search_name || $search_desc || $search_category)) {
+        $pattern = '/' . preg_quote($search_pattern, '/') . '/i';
         $search_results = array();
         foreach ($tasks as $task) {
             if (($search_name && preg_match($pattern, $task['name'])) ||
@@ -84,7 +84,17 @@ if (count($tasks)) {
     $colors = $cManager->colors();
     $sortby = $prefs->getValue('sortby');
     $sortdir = $prefs->getValue('sortdir');
-    $sortbyurl = Util::addParameter('list.php', 'sortdir', abs(1 - $sortdir));
+
+    $baseurl = 'list.php';
+    if ($actionID == 'search_tasks') {
+        $baseurl = Util::addParameter($baseurl, 'actionID', 'search_tasks');
+        $baseurl = Util::addParameter($baseurl, 'search_pattern', $search_pattern);
+        $baseurl = Util::addParameter($baseurl, 'search_name', $search_name ? 'on' : 'off');
+        $baseurl = Util::addParameter($baseurl, 'search_desc', $search_desc ? 'on' : 'off');
+        $baseurl = Util::addParameter($baseurl, 'search_category', $search_category ? 'on' : 'off');
+    }
+    $sortbyurl = Util::addParameter($baseurl, 'sortdir', abs(1 - $sortdir));
+
     require NAG_TEMPLATES . '/list/task_headers.inc';
 
     foreach ($tasks as $task) {
diff -rpuN -X ../ignorelist ../build/nag/templates/list/task_headers.inc nag/templates/list/task_headers.inc
--- ../build/nag/templates/list/task_headers.inc	Sat Jul 24 20:34:45 2004
+++ nag/templates/list/task_headers.inc	Tue Jul 27 19:28:13 2004
@@ -2,31 +2,31 @@
  <tr class="item">
   <th class="<?php echo ($sortby == NAG_SORT_COMPLETION) ? 'selected' : 'item' ?>" width="2%" align="left" nowrap="nowrap">
     <?php if ($sortby == NAG_SORT_COMPLETION) echo Horde::link(Horde::applicationUrl(Util::addParameter($sortbyurl, 'sortby', NAG_SORT_COMPLETION)), _("Change sort direction"), 'widget') . Horde::img($sortdir ? 'za.gif' :  'az.gif', _("Change sort direction"), null, $registry->getParam('graphics', 'horde')) ?></a>
-    <?php echo Horde::link(Horde::applicationUrl(Util::addParameter('list.php', 'sortby', NAG_SORT_COMPLETION)), _("Sort by Completion Status"), 'widget') . Horde::img('checkbox.gif', _("Completed?")) ?></a>
+    <?php echo Horde::link(Horde::applicationUrl(Util::addParameter($baseurl, 'sortby', NAG_SORT_COMPLETION)), _("Sort by Completion Status"), 'widget') . Horde::img('checkbox.gif', _("Completed?")) ?></a>
   </th>
   <th class="<?php echo ($sortby == NAG_SORT_OWNER) ? 'selected' : 'item' ?>" width="2%" align="left" nowrap="nowrap">
     <?php if ($sortby == NAG_SORT_OWNER) echo Horde::link(Horde::applicationUrl(Util::addParameter($sortbyurl, 'sortby', NAG_SORT_OWNER)), _("Change sort direction"), 'widget') . Horde::img($sortdir ? 'za.gif' :  'az.gif', _("Change sort direction"), null, $registry->getParam('graphics', 'horde')) ?></a>
-    <?php echo Horde::widget(Horde::applicationUrl(Util::addParameter('list.php', 'sortby', NAG_SORT_OWNER)), _("Sort by User Name"), 'widget', '', '', _("_Task List")) ?></a>&nbsp;
+    <?php echo Horde::widget(Horde::applicationUrl(Util::addParameter($baseurl, 'sortby', NAG_SORT_OWNER)), _("Sort by User Name"), 'widget', '', '', _("_Task List")) ?></a>&nbsp;
   </th>
   <th class="<?php echo ($sortby == NAG_SORT_PRIORITY) ? 'selected' : 'item' ?>" width="2%" align="left" nowrap="nowrap">
     <?php if ($sortby == NAG_SORT_PRIORITY) echo Horde::link(Horde::applicationUrl(Util::addParameter($sortbyurl, 'sortby', NAG_SORT_PRIORITY)), _("Change sort direction"), 'widget') . Horde::img($sortdir ? 'za.gif' : 'az.gif', _("Change sort direction"), null, $registry->getParam('graphics', 'horde')) ?></a>
-    <?php echo Horde::widget(Horde::applicationUrl(Util::addParameter('list.php', 'sortby', NAG_SORT_PRIORITY)), _("Sort by Priority"), 'widget', '', '', _("P_ri")) ?></a>&nbsp;
+    <?php echo Horde::widget(Horde::applicationUrl(Util::addParameter($baseurl, 'sortby', NAG_SORT_PRIORITY)), _("Sort by Priority"), 'widget', '', '', _("P_ri")) ?></a>&nbsp;
   </th>
   <th width="2%">
     <?php echo Horde::img('edit.gif', _("Edit Task")) ?>
   </td>
   <th class="<?php echo ($sortby == NAG_SORT_NAME) ? 'selected' : 'item' ?>" width="60%" align="left" nowrap="nowrap">
     <?php if ($sortby == NAG_SORT_NAME) echo Horde::link(Horde::applicationUrl(Util::addParameter($sortbyurl, 'sortby', NAG_SORT_NAME)), _("Change sort direction"), 'widget') . Horde::img($sortdir ? 'za.gif' : 'az.gif', _("Change sort direction"), null, $registry->getParam('graphics', 'horde')) ?></a>
-    <?php echo Horde::widget(Horde::applicationUrl(Util::addParameter('list.php', 'sortby', NAG_SORT_NAME)), _("Sort by Name"), 'widget', '', '', _("Na_me")) ?></a>&nbsp;
+    <?php echo Horde::widget(Horde::applicationUrl(Util::addParameter($baseurl, 'sortby', NAG_SORT_NAME)), _("Sort by Name"), 'widget', '', '', _("Na_me")) ?></a>&nbsp;
   </th>
   <td width="2%"><?php echo Horde::img('note.gif', _("Task Note?")) ?></td>
   <td width="2%"><?php echo Horde::img('alarm.gif', _("Task Alarm?")) ?></td>
   <th class="<?php echo ($sortby == NAG_SORT_DUE) ? 'selected' : 'item' ?>" width="12%" align="left" nowrap="nowrap">
     <?php if ($sortby == NAG_SORT_DUE) echo Horde::link(Horde::applicationUrl(Util::addParameter($sortbyurl, 'sortby', NAG_SORT_DUE)), _("Change sort direction"), 'widget') . Horde::img($sortdir ? 'za.gif' : 'az.gif', _("Change sort direction"), null, $registry->getParam('graphics', 'horde')) ?></a>
-    <?php echo Horde::widget(Horde::applicationUrl(Util::addParameter('list.php', 'sortby', NAG_SORT_DUE)), _("Sort by Due Date"), 'widget', '', '', _("_Due Date")) ?></a>&nbsp;
+    <?php echo Horde::widget(Horde::applicationUrl(Util::addParameter($baseurl, 'sortby', NAG_SORT_DUE)), _("Sort by Due Date"), 'widget', '', '', _("_Due Date")) ?></a>&nbsp;
   </th>
   <th class="<?php echo ($sortby == NAG_SORT_CATEGORY) ? 'selected' : 'item' ?>" width="20%" align="left" nowrap="nowrap">
     <?php if ($sortby == NAG_SORT_CATEGORY) echo Horde::link(Horde::applicationUrl(Util::addParameter($sortbyurl, 'sortby', NAG_SORT_CATEGORY)), _("Change sort direction"), 'widget') . Horde::img($sortdir ? 'za.gif' : 'az.gif', _("Change sort direction"), null, $registry->getParam('graphics', 'horde')) ?></a>
-    <?php echo Horde::widget(Horde::applicationUrl(Util::addParameter('list.php', 'sortby', NAG_SORT_CATEGORY)), _("Sort by Category"), 'widget', '', '', _("Cat_egory")) ?></a>&nbsp;
+    <?php echo Horde::widget(Horde::applicationUrl(Util::addParameter($baseurl, 'sortby', NAG_SORT_CATEGORY)), _("Sort by Category"), 'widget', '', '', _("Cat_egory")) ?></a>&nbsp;
   </th>
  </tr>


More information about the dev mailing list