Edgewall Software

Ticket #7026: query_column_reorder_6737.diff

File query_column_reorder_6737.diff, 8.1 kB (added by hyugaricdeau@…, 5 months ago)

Some of the diffs may be from my editor removing stray whitespace, which may be annoying.

  • trac/ticket/query.py

     
    4141                            INavigationContributor, Chrome 
    4242from trac.wiki.api import IWikiSyntaxProvider, parse_args 
    4343from trac.wiki.macros import WikiMacroBase # TODO: should be moved in .api 
    44 from trac.config import Option  
     44from trac.config import Option 
    4545 
    4646class QuerySyntaxError(Exception): 
    4747    """Exception raised when a ticket query cannot be parsed from a string.""" 
     
    9494        for filter_ in filters: 
    9595            filter_ = filter_.split('=') 
    9696            if len(filter_) != 2: 
    97                 raise QuerySyntaxError('Query filter requires field and '  
     97                raise QuerySyntaxError('Query filter requires field and ' 
    9898                                       'constraints separated by a "="') 
    9999            field,values = filter_ 
    100100            if not field: 
     
    253253        # the default columns, in the same order.  That keeps the query url 
    254254        # shorter in the common case where we just want the default columns. 
    255255        if cols == self.get_default_columns(): 
    256             cols = None 
     256            cols = {} 
     257        constraints = self.constraints.copy() 
     258        constraints.update(dict(('col' + str(idx), col) 
     259                                for idx, col in enumerate(cols))) 
    257260        return href.query(report=id, 
    258261                          order=order, desc=desc and 1 or None, 
    259262                          group=self.group or None, 
    260263                          groupdesc=self.groupdesc and 1 or None, 
    261                           col=cols, 
    262264                          row=self.rows, 
    263                           format=format, **self.constraints) 
     265                          format=format, **constraints) 
    264266 
    265267    def to_string(self): 
    266268        """Return a user readable and editable representation of the query. 
     
    620622                    if val.endswith('$USER'):  
    621623                        del constraints[field]  
    622624 
    623         cols = req.args.get('col') 
    624         if isinstance(cols, basestring): 
    625             cols = [cols] 
     625        cols = self._get_ordered_cols(req) 
    626626        # Since we don't show 'id' as an option to the user, 
    627627        # we need to re-insert it here.             
    628628        if cols and 'id' not in cols:  
     
    637637                      rows, 
    638638                      req.args.get('limit')) 
    639639 
     640        for idx, col in enumerate(cols): 
     641            if 'up_' + col in req.args: 
     642                query.cols[idx] = cols[idx-1] 
     643                query.cols[idx-1] = col 
     644                req.redirect(query.get_href(req.href)) 
     645            elif 'down_' + col in req.args: 
     646                query.cols[idx] = cols[idx+1] 
     647                query.cols[idx+1] = col 
     648                req.redirect(query.get_href(req.href)) 
     649 
    640650        if 'update' in req.args: 
    641651            # Reset session vars 
    642652            for var in ('query_constraints', 'query_time', 'query_tickets'): 
     
    659669        return self.display_html(req, query) 
    660670 
    661671    # Internal methods 
     672    def _get_ordered_cols(self, req): 
     673        return [item[1] for item in 
     674                sorted([item for item in req.args.iteritems() 
     675                        if re.match(r'^col\d+', item[0])], 
     676                       key=lambda x: (len(x[0]) < 4, int(x[0][3:])))] 
    662677 
    663678    def _get_constraints(self, req): 
    664679        constraints = {} 
     
    779794        data.setdefault('description', None) 
    780795        data['title'] = title 
    781796 
    782         data['all_columns'] = query.get_all_columns() 
     797        all_columns = query.get_all_columns() 
     798        ordered_cols = self._get_ordered_cols(req) 
     799        all_columns.sort(key=lambda x: (not x in ordered_cols, 
     800                                        x in ordered_cols and  
     801                                        ordered_cols.index(x))) 
     802        data['all_columns'] = all_columns 
    783803        # Don't allow the user to remove the id column         
    784804        data['all_columns'].remove('id') 
    785805        data['all_textareas'] = query.get_all_textareas() 
  • trac/ticket/templates/query.html

     
    136136        <fieldset id="columns"> 
    137137          <legend>Columns</legend> 
    138138          <div> 
    139             <py:for each="column in all_columns"> 
    140               <label> 
    141                 <input type="checkbox" name="col" value="$column" 
    142                        checked="${any([(value == column) for value in col]) 
    143                                   and 'checked' or None}" /> 
    144                 ${labels.get(column, column or 'none')} 
    145               </label> 
    146             </py:for> 
     139            <table> 
     140              <tbody> 
     141                <tr py:for="idx, column in enumerate(all_columns)"> 
     142                  <td> 
     143                    <input type="checkbox" name="col${idx+1}" value="$column" 
     144                           checked="${any([(value == column) for value in col]) 
     145                                      and 'selected' or None}" /> 
     146                  </td> 
     147                  <td>${labels.get(column, column or 'none')}</td> 
     148                  <td> 
     149                    <input type="submit" name="up_${column}" value="Up" 
     150                           disabled="${not idx or None}" />&nbsp; 
     151                    <input type="submit" name="down_${column}" value="Down" 
     152                           disabled="${idx == len(all_columns)-1 or None}" /> 
     153                  </td> 
     154                </tr> 
     155              </tbody> 
     156            </table> 
    147157          </div> 
    148158        </fieldset> 
    149159 
  • trac/htdocs/js/query.js

     
    273273      } 
    274274      select.selectedIndex = 0; 
    275275    } 
     276 
     277    $("input[@name^='up_']").click(function() { 
     278      var row = $(this).parents('tr'); 
     279      if (row.prev().length) { 
     280        var prev = row.prev(); 
     281        if (!row.next().length) { 
     282          prev.find("input[@name^='down_']").attr("disabled", true); 
     283        } 
     284        prev.find("input[@name^='up_']").attr("disabled", false); 
     285        var row_check = row.find("input[@type='checkbox']"); 
     286        var prev_check = prev.find("input[@type='checkbox']"); 
     287        var temp = row_check.attr("name"); 
     288        row_check.attr("name", prev_check.attr("name")); 
     289        prev_check.attr("name", temp); 
     290        row.insertBefore(row.prev()); 
     291        if (!row.prev().length) { 
     292          $(this).attr("disabled", true); 
     293        } 
     294        row.find("input[@name^='down_']").attr("disabled", false); 
     295      } 
     296      return false; 
     297    }); 
     298    $("input[@name^='down_']").click(function() { 
     299      var row = $(this).parents('tr'); 
     300      if (row.next().length) { 
     301        var next = row.next(); 
     302        if (!row.prev().length) { 
     303          next.find("input[@name^='up_']").attr("disabled", true); 
     304        } 
     305        next.find("input[@name^='down_']").attr("disabled", false); 
     306        var row_check = row.find("input[@type='checkbox']"); 
     307        var next_check = next.find("input[@type='checkbox']"); 
     308        var temp = row_check.attr("name"); 
     309        row_check.attr("name", next_check.attr("name")); 
     310        next_check.attr("name", temp); 
     311        row.insertAfter(row.next()); 
     312        if (!row.next().length) { 
     313          $(this).attr("disabled", true); 
     314        } 
     315        row.find("input[@name^='up_']").attr("disabled", false); 
     316      } 
     317      return false; 
     318    }); 
    276319  } 
    277  
    278 })(jQuery); 
    279  No newline at end of file 
     320})(jQuery); 
  • trac/htdocs/css/report.css

     
    4141#filters td.filter label { padding-right: 1em } 
    4242#filters td.actions { text-align: right; white-space: nowrap } 
    4343 
     44#columns div { 
     45 height: 15em; 
     46 overflow: -moz-scrollbars-vertical; 
     47 overflow-x: hidden; 
     48 overflow-y: scroll; 
     49} 
     50 
    4451#columns div label {  
    4552 display: block; 
    4653 float: left;