Skip to content

Commit a3dc62b

Browse files
xiaodotBrad van der Laan
authored andcommitted
order tags by created time
Signed-off-by: lijun <lijun@qiyi.com>
1 parent 14bd8f9 commit a3dc62b

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

app/styles/main.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,7 @@ footer img {
144144
.css-form input.ng-valid.ng-dirty {
145145
background-color: #78FA89;
146146
}
147+
148+
.caret{
149+
cursor: pointer;
150+
}

app/tag/tag-controller.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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,

app/tag/tag-list-directive.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
<tr>
1313
<th ng-class="{strike: deleted}"><span class="glyphicon glyphicon-tag"></span> Tag</th>
1414
<th ><span class="glyphicon glyphicon-qrcode"></span> Image ID</th>
15-
<th ><span class="glyphicon glyphicon-calendar"></span> Created</th>
15+
<th ng-click="sortTags()" ng-class="{dropup: orderByCreated==true, dropdown: orderByCreated==false}">
16+
<span class="glyphicon glyphicon-calendar"></span>
17+
Created
18+
<span class="caret"></span>
19+
</th>
1620
<th ><span class="glyphicon glyphicon-user"></span> Author</th>
1721
<th ><span class="glyphicon glyphicon-eye-open"></span> Docker version</th>
1822
<!-- <th ><span class="glyphicon glyphicon-arrow-up"></span> Parent's ID</th> -->

0 commit comments

Comments
 (0)