Эх сурвалжийг харах

HUE-24. Filesize Sorting doesn't work

Marcus McLaughlin 15 жил өмнө
parent
commit
aaad889479

+ 8 - 4
apps/filebrowser/src/filebrowser/templates/listdir_components.mako

@@ -88,13 +88,17 @@ from django.template.defaultfilters import urlencode, stringformat, filesizeform
               % endif
             </div>
           </td>
+          <% 
+            if "dir" == file['type']:
+              sortValue = 0;
+            else:
+              sortValue = file['stats']['size']
+          %>
           <td class="fb-filesize">
             % if "dir" == file['type']:
-              ##this hidden zero is for sorting
-              <span style="display:none">0</span>
-              ~
+              <span data-sort-value="${sortValue}">~</span>
             % else:
-              ${file['stats']['size']|filesizeformat}
+              <span data-sort-value="${sortValue}">${file['stats']['size']|filesizeformat}</span>
             % endif
           </td>
           <td class="fb-user">${file['stats']['user']}</td>

+ 29 - 2
desktop/core/static/js/Source/JFrameFilters/CCS.JFrame.HtmlTable.js

@@ -17,12 +17,35 @@
 ---
 description: Creates instances of HtmlTable for any table with the css class .ccs-data_table with additional options for sortability and selectability.
 provides: [CCS.JFrame.HtmlTable]
-requires: [/CCS.JFrame, More/HtmlTable.Sort, More/HtmlTable.Zebra, More/HtmlTable.Select]
+requires: [/CCS.JFrame, More/HtmlTable.Sort, More/HtmlTable.Zebra, More/HtmlTable.Select, /Element.Data]
 script: CCS.JFrame.HtmlTable.js
 
 ...
 */
 
+//The newHash here is used to attach these parsers at the beginning of the HtmlTable.Parsers hash.  Otherwise, anything that begins with a number is picked up by the 'number' parser, which is not what we want.
+newHash = new Hash();
+//A parser to allow numeric sorting by any value.
+newHash.dataSortValue = {
+        match: /data-sort-value/,
+        convert: function() {
+                text = this.getElement('[data-sort-value]').get('data', 'sort-value');
+                return text.toInt();
+        },
+        number: true
+};
+//A parser to allow lexicographical sorting by any string.
+newHash.dataSortString = {
+        match: /data-sort-string/,
+        convert: function() {
+                text = this.getElement('[data-sort-string]').get('data', 'sort-string');
+                return text;
+        },
+        number: false 
+};
+newHash.combine(HtmlTable.Parsers);
+HtmlTable.Parsers = newHash;
+
 CCS.JFrame.addGlobalFilters({
 
 	htmlTable: function(container){
@@ -71,4 +94,8 @@ CCS.JFrame.addGlobalFilters({
 		}
 	}
 
-});
+});
+
+
+
+