Sort branches by age
authorJoachim Breitner <mail@joachim-breitner.de>
Thu, 31 Mar 2016 21:06:44 +0000 (23:06 +0200)
committerJoachim Breitner <mail@joachim-breitner.de>
Tue, 5 Apr 2016 21:11:25 +0000 (23:11 +0200)
site/index.html
site/js/gipeda.js

index e8e3a90..a2786ba 100644 (file)
@@ -262,7 +262,7 @@ html {
 <script id="branches"  type="text/x-handlebars-template">
   <h2>Branches</h2>
   <table class="table branch-table">
-   {{#each_unnaturally branches}}
+   {{#each_branch branches}}
      {{#with (lookup ../revisions this)}}
       {{#with this.summary}}
       <tr
@@ -308,7 +308,7 @@ html {
        </td>
       </tr>
      {{/with}}
-   {{/each_unnaturally}}
+   {{/each_branch}}
   </table>
 </script>
 
index 2d7fa3d..a45e9c1 100644 (file)
@@ -226,7 +226,6 @@ Handlebars.registerHelper('humanDate', function(timestamp) {
 Handlebars.registerHelper('each_naturally', function(context,options){
     var output = '';
     if (context) {
-       console.log(context);
        var keys = jQuery.map(context, function(v,k) {return k});
        var sorted_keys = keys.sort(naturalSort);
        sorted_keys.map(function (k,i) {
@@ -238,11 +237,8 @@ Handlebars.registerHelper('each_naturally', function(context,options){
 Handlebars.registerHelper('each_unnaturally', function(context,options){
     var output = '';
     if (context) {
-       console.log(context);
        var keys = jQuery.map(context, function(v,k) {return k});
-        // needs https://github.com/overset/javascript-natural-sort/issues/21 fixed
-       //var sorted_keys = keys.sort(naturalSort).reverse();
-       var sorted_keys = keys.sort().reverse();
+       var sorted_keys = keys.sort(naturalSort).reverse();
        sorted_keys.map(function (k,i) {
            output += options.fn(context[k], {data: {key: k, index: i}});
        });
@@ -250,6 +246,31 @@ Handlebars.registerHelper('each_unnaturally', function(context,options){
     return output;
 });
 
+// Sort by age, then by name
+Handlebars.registerHelper('each_branch', function(context,options){
+    var output = '';
+    if (context) {
+       jQuery.map(context, function (b,i) { return {branchHash: b, branchName: i}; })
+            .sort(function(a,b) {
+                revA = data.revisions[a.branchHash];
+                revB = data.revisions[b.branchHash];
+               if (revA && revB) {
+                    return revB.summary.gitDate - revA.summary.gitDate;
+                }
+               if (revA) {
+                    return -1;
+                }
+               if (revB) {
+                    return 1;
+                }
+                return naturalSort(a.branchName, b.branchName);
+            }).map(function (b,i) {
+                output += options.fn(b.branchHash, {data: {key: b.branchName, index: i}});
+            });
+    }
+    return output;
+});
+
 // We cache everything
 var jsonSeen = {};
 var jsonFetching = {};