Changeset 207


Ignore:
Timestamp:
09/28/13 15:59:23 (5 years ago)
Author:
nhoyt
Message:

Function sortTree can now handle an arbitrary number of sortColumns (now accepts and array). For each sort column you now specify the multiplier used for greater than comparison (either 1 or -1), which facilitates secondary sorting by ascending order when primary sort order is descending, and vice versa.

In element-results.js, updated getElementResultsTable to return noResults message when rule result has no element results.

Location:
trunk/proto-14/chrome
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/proto-14/chrome/content/element-results.js

    r206 r207  
    2727  DEFAULT_COLUMN: "ainspector-elem-result-col", 
    2828  SORT_COL_2:     "ainspector-elem-result-col", 
    29   SORT_COL_3:     "ainspector-order-col", 
    30   SORT_COL_4:     "ainspector-element-col" 
     29  SORT_COL_3:     "ainspector-order-col" 
    3130} 
    3231 
     
    4645    defaultOrder:      ainspectorSidebar.elementResultConst.DEFAULT_ORDER, 
    4746    defaultColumn:     ainspectorSidebar.elementResultConst.DEFAULT_COLUMN, 
    48     sortColumn2:       ainspectorSidebar.elementResultConst.SORT_COL_2, 
    49     sortColumn3:       ainspectorSidebar.elementResultConst.SORT_COL_3, 
    50     sortColumn4:       ainspectorSidebar.elementResultConst.SORT_COL_4, 
     47    sortColumns: [ 
     48      { sortColumn: ainspectorSidebar.elementResultConst.SORT_COL_2, multiplier:  1 }, 
     49      { sortColumn: ainspectorSidebar.elementResultConst.SORT_COL_3, multiplier: -1 } 
     50    ], 
    5151    defaultSortButton: null, 
    5252    updateCallback:    null 
     
    113113    }); 
    114114  } 
     115   
     116  if (resultsCount === 0) { 
     117    var noResults = ainspectorSidebar.nlsProperties.getString("element.no-results"); 
     118    table.push({ "ainspector-element-col": noResults }); 
     119  } 
     120 
    115121  return table; 
    116122}; 
     
    161167          break; 
    162168        default: 
    163           return "?"; 
     169          return ''; 
    164170          break; 
    165171      } 
  • trunk/proto-14/chrome/content/tree-sort.js

    r206 r207  
    1313 *   defaultOrder  {String} - "ascending" or "descending" 
    1414 *   defaultColumn {String} - default primary sort column 
    15  *   sortColumn2   {String} - [can be null] 2nd column for breaking ties in primary sort column 
    16  *   sortColumn3   {String} - [can be null] 3rd column for breaking ties in 2nd sort column 
    17  *   sortColumn4   {String} - [can be null] 4th column for breaking ties in 3rd sort column 
     15 *   sortColumns {Array} - [can be null] sort column info for breaking ties in primary column 
    1816 *   defaultSortButton {Object} - [can be null] button element for default sort 
    1917 *   updateCallback  {Function} - [can be null] called after new tree view created (with tree arg) 
     
    2927  var defaultOrder      = properties.defaultOrder; 
    3028  var defaultColumn     = properties.defaultColumn; 
    31   var sortColumn2       = properties.sortColumn2; 
    32   var sortColumn3       = properties.sortColumn3; 
    33   var sortColumn4       = properties.sortColumn4; 
     29  var sortColumns       = properties.sortColumns; 
    3430  var defaultSortButton = properties.defaultSortButton; 
    3531  var updateCallback    = properties.updateCallback; 
     
    5955  function columnSort(a, b) { 
    6056 
    61     if (normalize(a[columnName]) > normalize(b[columnName])) return 1 * order; 
     57    if (normalize(a[columnName]) > normalize(b[columnName])) return  1 * order; 
    6258    if (normalize(a[columnName]) < normalize(b[columnName])) return -1 * order; 
    6359 
    64     // Tie breakers: Use additional columns, if specified, for second-, 
    65     // third- and fourth-level sorting. 
    66     if (sortColumn2 && (columnName != sortColumn2)) { 
    67       if (normalize(a[sortColumn2]) > normalize(b[sortColumn2])) return 1 * order; 
    68       if (normalize(a[sortColumn2]) < normalize(b[sortColumn2])) return -1 * order; 
    69     } 
     60    // Tie breakers: Use additional sort columns for multi-column sorting. 
     61    if (sortColumns) { 
     62      for (var i = 0; i < sortColumns.length; i++) { 
     63        var sortColumn = sortColumns[i].sortColumn; 
     64        var multiplier = sortColumns[i].multiplier; 
     65        var gtmult = multiplier, ltmult = -multiplier; 
    7066 
    71     if (sortColumn3 && (columnName != sortColumn3)) { 
    72       if (normalize(a[sortColumn3]) > normalize(b[sortColumn3])) return 1 * order; 
    73       if (normalize(a[sortColumn3]) < normalize(b[sortColumn3])) return -1 * order; 
    74     } 
    75  
    76     if (sortColumn4 && (columnName != sortColumn4)) { 
    77       if (normalize(a[sortColumn4]) > normalize(b[sortColumn4])) return 1 * order; 
    78       if (normalize(a[sortColumn4]) < normalize(b[sortColumn4])) return -1 * order; 
     67        if (columnName != sortColumn) { 
     68          if (normalize(a[sortColumn]) > normalize(b[sortColumn])) return gtmult * order; 
     69          if (normalize(a[sortColumn]) < normalize(b[sortColumn])) return ltmult * order; 
     70        } 
     71      } 
    7972    } 
    8073 
  • trunk/proto-14/chrome/content/view-category.js

    r206 r207  
    3434 
    3535ainspectorSidebar.ruleResultConst = { 
    36   DEFAULT_ORDER: "descending", 
     36  DEFAULT_ORDER:  "descending", 
    3737  DEFAULT_COLUMN: "ainspector-result-col", 
    38   SORT_COL_2: "ainspector-result-col", 
    39   SORT_COL_3: "ainspector-level-col", 
    40   SORT_COL_4: "ainspector-required-col" 
     38  SORT_COL_2:     "ainspector-result-col", 
     39  SORT_COL_3:     "ainspector-level-col", 
     40  SORT_COL_4:     "ainspector-required-col" 
    4141} 
    4242 
     
    5656    defaultOrder:    ainspectorSidebar.ruleResultConst.DEFAULT_ORDER, 
    5757    defaultColumn:   ainspectorSidebar.ruleResultConst.DEFAULT_COLUMN, 
    58     sortColumn2:     ainspectorSidebar.ruleResultConst.SORT_COL_2, 
    59     sortColumn3:     ainspectorSidebar.ruleResultConst.SORT_COL_3, 
    60     sortColumn4:     ainspectorSidebar.ruleResultConst.SORT_COL_4, 
     58    sortColumns: [ 
     59      { sortColumn: ainspectorSidebar.ruleResultConst.SORT_COL_2, multiplier: 1 }, 
     60      { sortColumn: ainspectorSidebar.ruleResultConst.SORT_COL_3, multiplier: 1 }, 
     61      { sortColumn: ainspectorSidebar.ruleResultConst.SORT_COL_4, multiplier: 1 } 
     62    ], 
    6163    defaultSortButton: document.getElementById("ainspector-rc-default-sort"), 
    6264    updateCallback: ainspectorSidebar.updateSelectedRuleInfo 
  • trunk/proto-14/chrome/locale/en-US/ai-sidebar.properties

    r206 r207  
    6868element.result.hidden       = H 
    6969 
     70element.no-results = no elements 
     71 
    7072# Preference Options 
    7173 
Note: See TracChangeset for help on using the changeset viewer.