@@ -45,12 +45,12 @@ angular.module('tag-controller', ['registry-services'])
4545 if ( ! $scope . tagsCurrentPage ) {
4646 $scope . tagsCurrentPage = 1 ;
4747 } else {
48- $scope . tagsCurrentPage = parseInt ( $scope . tagsCurrentPage )
48+ $scope . tagsCurrentPage = parseInt ( $scope . tagsCurrentPage )
4949 if ( $scope . tagsCurrentPage > $scope . maxTagsPage || $scope . tagsCurrentPage < 1 ) {
50- $scope . tagsCurrentPage = 1 ;
50+ $scope . tagsCurrentPage = 1 ;
5151 }
5252 }
53- // Select wanted tags
53+ // Select wanted tags
5454 var idxShift = 0 ;
5555 $scope . displayedTags = $scope . tags ;
5656 if ( $scope . tagsPerPage ) {
@@ -68,13 +68,13 @@ angular.module('tag-controller', ['registry-services'])
6868 }
6969 }
7070 } ) ;
71-
7271
73-
72+
73+
7474 // Copy collection for rendering in a smart-table
7575 $scope . displayedTags = [ ] . concat ( $scope . tags ) ;
7676
77-
77+
7878 // selected tags
7979 $scope . selection = [ ] ;
8080
@@ -83,6 +83,29 @@ angular.module('tag-controller', ['registry-services'])
8383 return filterFilter ( $scope . displayedTags , { selected : true } ) ;
8484 } ;
8585
86+ // sort tags
87+ $scope . orderByCreated = true ;
88+
89+ function compare ( a , b ) {
90+ var at = new Date ( a . details . created ) ,
91+ bt = new Date ( b . details . created ) ;
92+
93+ return at . getTime ( ) - bt . getTime ( ) ;
94+ }
95+
96+ $scope . sortTags = function ( ) {
97+ if ( $scope . orderByCreated ) {
98+ $scope . displayedTags . sort ( compare ) ;
99+ }
100+ else {
101+ // if $scope.orderByCreated is false, that means $scope.displayedTags.sort(compare) has been invoked.
102+ // then just need to call reverse() function
103+ $scope . displayedTags . reverse ( ) ;
104+ }
105+
106+ $scope . orderByCreated = ! $scope . orderByCreated ;
107+ }
108+
86109 $scope . openConfirmTagDeletionDialog = function ( size ) {
87110 var modalInstance = $modal . open ( {
88111 animation : true ,
0 commit comments