Have tags selected be handled universally throughout the entire repository view page.

This commit is contained in:
Joseph Schorr 2015-03-12 12:22:47 -07:00
parent ea61a68bcb
commit 347bf31f2d
9 changed files with 154 additions and 85 deletions

View file

@ -87,33 +87,32 @@ angular.module('quay').directive('repoPanelChanges', function () {
transclude: false,
restrict: 'C',
scope: {
'repository': '=repository'
'repository': '=repository',
'selectedTags': '=selectedTags',
'isEnabled': '=isEnabled'
},
controller: function($scope, $element, $location, $timeout, ApiService, UtilService, ImageMetadataService) {
controller: function($scope, $element, $timeout, ApiService, UtilService, ImageMetadataService) {
var update = function() {
if (!$scope.repository) { return; }
var tagString = $location.search()['tags'] || '';
if (!tagString) {
$scope.selectedTags = [];
return;
}
if (!$scope.repository || !$scope.selectedTags) { return; }
$scope.currentImage = null;
$scope.currentImage = null;
$scope.selectedTags = tagString.split(',');
$scope.currentTag = null;
if (!$scope.imageResource) {
if (!$scope.imagesResource) {
loadImages();
} else {
refreshTree();
}
};
$scope.$on('$routeUpdate', update);
$scope.$watch('selectedTags', update)
$scope.$watch('repository', update);
$scope.$watch('isEnabled', function(isEnabled) {
if (isEnabled) {
refreshTree();
}
});
var refreshTree = function() {
if (!$scope.repository || !$scope.images) { return; }
@ -157,10 +156,6 @@ angular.module('quay').directive('repoPanelChanges', function () {
$scope.images = resp.images;
$scope.tracker = new RepositoryImageTracker($scope.repository, $scope.images);
$scope.selectedTags = $.grep($scope.selectedTags, function(tag) {
return !!$scope.tracker.lookupTag(tag);
});
if ($scope.selectedTags && $scope.selectedTags.length) {
refreshTree();
}
@ -193,26 +188,16 @@ angular.module('quay').directive('repoPanelChanges', function () {
$scope.tracker = new RepositoryImageTracker($scope.repository, $scope.images);
data.removed.map(function(tag) {
$scope.selectedTags = $.grep($scope.selectedTags, function(cTag) {
return cTag != tag;
});
if ($scope.selectedTags.length) {
$location.search('tags', $scope.selectedTags.join(','));
} else {
$location.search('tags', null);
}
$scope.currentImage = null;
$scope.currentTag = null;
});
data.added.map(function(tag) {
$scope.selectedTags.push(tag);
$location.search('tags', $scope.selectedTags.join(','));
$scope.currentTag = tag;
});
refreshTree();
};
}
};

View file

@ -10,9 +10,9 @@ angular.module('quay').directive('repoPanelTags', function () {
restrict: 'C',
scope: {
'repository': '=repository',
'repositoryUpdated': '&repositoryUpdated'
'selectedTags': '=selectedTags'
},
controller: function($scope, $element, $filter, ApiService, UIService) {
controller: function($scope, $element, $filter, $location, ApiService, UIService) {
var orderBy = $filter('orderBy');
$scope.checkedTags = UIService.createCheckStateController([]);
@ -35,7 +35,7 @@ angular.module('quay').directive('repoPanelTags', function () {
};
var setTagState = function() {
if (!$scope.repository) { return; }
if (!$scope.repository || !$scope.selectedTags) { return; }
var tags = [];
var allTags = [];
@ -60,21 +60,29 @@ angular.module('quay').directive('repoPanelTags', function () {
}
// Sort the tags by the predicate and the reverse, and map the information.
var imageIDs = [];
var ordered = orderBy(tags, $scope.options.predicate, $scope.options.reverse);
var checked = [];
for (var i = 0; i < ordered.length; ++i) {
var tagInfo = ordered[i];
if (!imageMap[tagInfo.image_id]) {
imageMap[tagInfo.image_id] = [];
imageIDs.push(tagInfo.image_id)
}
imageMap[tagInfo.image_id].push(tagInfo);
if ($.inArray(tagInfo.name, $scope.selectedTags) >= 0) {
checked.push(tagInfo);
}
};
// Calculate the image tracks.
var colors = d3.scale.category10();
var index = 0;
for (var image_id in imageMap) {
imageIDs.sort().map(function(image_id) {
if (imageMap[image_id].length >= 2){
imageTracks.push({
'image_id': image_id,
@ -84,19 +92,34 @@ angular.module('quay').directive('repoPanelTags', function () {
});
++index;
}
}
});
$scope.imageMap = imageMap;
$scope.imageTracks = imageTracks;
$scope.tags = ordered;
$scope.checkedTags = UIService.createCheckStateController(ordered);
$scope.allTags = allTags;
$scope.iterationState = {};
$scope.checkedTags = UIService.createCheckStateController(ordered, checked);
$scope.checkedTags.listen(function(checked) {
$scope.selectedTags = checked.map(function(tag_info) {
return tag_info.name;
});
});
}
$scope.$watch('options.predicate', setTagState);
$scope.$watch('options.reverse', setTagState);
$scope.$watch('options.tagFilter', setTagState);
$scope.$watch('selectedTags', function(selectedTags) {
if (!selectedTags || !$scope.repository || !$scope.imageMap) { return; }
$scope.checkedTags.checked = selectedTags.map(function(tag) {
return $scope.repository.tags[tag];
});
}, true);
$scope.$watch('repository', function(repository) {
if (!repository) { return; }
@ -175,10 +198,8 @@ angular.module('quay').directive('repoPanelTags', function () {
return tag.image_id == image_id;
};
$scope.getCheckedTagsString = function(checked) {
return checked.map(function(tag_info) {
return tag_info.name;
}).join(',');
$scope.setTab = function(tab) {
$location.search('tab', tab);
};
}
};