From 388d6367caa8aca4c13751b7bc752bedc0a64b97 Mon Sep 17 00:00:00 2001 From: Ashley Teoh Date: Sun, 15 Apr 2018 10:17:10 -0400 Subject: [PATCH] starting out the sort function --- notebook/static/tree/js/notebooklist.js | 26 ++++++++++++++++++++++++- notebook/templates/tree.html | 6 ++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/notebook/static/tree/js/notebooklist.js b/notebook/static/tree/js/notebooklist.js index 9fadfe729..2246002ac 100644 --- a/notebook/static/tree/js/notebooklist.js +++ b/notebook/static/tree/js/notebooklist.js @@ -57,14 +57,32 @@ define([ function modified_sorter(ascending) { var order = ascending ? 1 : 0; return (function(a, b) { + if (a['type'] === 'directory') { + return (ascending) ? 1 : -1; + } return utils.datetime_sort_helper(a.last_modified, b.last_modified, order) }); } + function size_sorter(ascending) { + var order = ascending ? 1 : 0; + // directories have file size of undefined + return (function(a, b) { + if (a['type'] === 'directory') { + return (ascending) ? 1 : -1; + } + + if (a.size > b.size) { + return (ascending) ? 1 : -1; + } + }); + } + var sort_functions = { 'sort-name': name_sorter, - 'last-modified': modified_sorter + 'last-modified': modified_sorter, + 'file-size': size_sorter }; var NotebookList = function (selector, options) { @@ -520,6 +538,12 @@ define([ .addClass("item_name") .appendTo(link); + $("") + .addClass("file_size") + .addClass("pull-right") + .css("width", "50px") + .appendTo(item); + $("") .addClass("item_modified") .addClass("pull-right") diff --git a/notebook/templates/tree.html b/notebook/templates/tree.html index e37f08d3c..295bd7768 100644 --- a/notebook/templates/tree.html +++ b/notebook/templates/tree.html @@ -117,6 +117,12 @@ data-server-root="{{server_root}}" {% endfor %} +
+ + {% trans %}File size{% endtrans %} + + +
{% trans %}Last Modified{% endtrans %}