2015-06-09 21:58:57 +00:00
|
|
|
/**
|
|
|
|
* An element which displays a table of repositories.
|
|
|
|
*/
|
|
|
|
angular.module('quay').directive('repoListTable', function () {
|
|
|
|
var directiveDefinitionObject = {
|
|
|
|
priority: 0,
|
|
|
|
templateUrl: '/static/directives/repo-list-table.html',
|
|
|
|
replace: false,
|
|
|
|
transclude: true,
|
|
|
|
restrict: 'C',
|
|
|
|
scope: {
|
|
|
|
'repositoriesResources': '=repositoriesResources',
|
2015-12-28 21:29:17 +00:00
|
|
|
'namespaces': '=namespaces',
|
|
|
|
'starToggled': '&starToggled'
|
2015-06-09 21:58:57 +00:00
|
|
|
},
|
2016-05-12 21:59:49 +00:00
|
|
|
controller: function($scope, $element, $filter, TableService) {
|
2015-06-09 21:58:57 +00:00
|
|
|
$scope.repositories = null;
|
|
|
|
$scope.orderedRepositories = [];
|
|
|
|
|
|
|
|
$scope.maxPopularity = 0;
|
|
|
|
$scope.options = {
|
2015-07-22 20:54:21 +00:00
|
|
|
'predicate': 'popularity',
|
2016-05-12 21:59:49 +00:00
|
|
|
'reverse': false,
|
|
|
|
'filter': null
|
2015-06-09 21:58:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var buildOrderedRepositories = function() {
|
|
|
|
if (!$scope.repositories) { return; }
|
|
|
|
|
2016-05-12 21:59:49 +00:00
|
|
|
$scope.orderedRepositories = TableService.buildOrderedItems($scope.repositories, $scope.options,
|
|
|
|
[], ['last_modified_datetime', 'popularity'])
|
2015-06-09 21:58:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.tablePredicateClass = function(name, predicate, reverse) {
|
|
|
|
if (name != predicate) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'current ' + (reverse ? 'reversed' : '');
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.orderBy = function(predicate) {
|
|
|
|
if (predicate == $scope.options.predicate) {
|
|
|
|
$scope.options.reverse = !$scope.options.reverse;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.options.reverse = false;
|
|
|
|
$scope.options.predicate = predicate;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.getAvatarData = function(namespace) {
|
|
|
|
var found = {};
|
|
|
|
$scope.namespaces.forEach(function(current) {
|
2015-12-28 21:29:17 +00:00
|
|
|
if (current.name == namespace || current.username == namespace) {
|
2015-06-09 21:58:57 +00:00
|
|
|
found = current.avatar;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return found;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.getStrengthClass = function(value, max, id) {
|
|
|
|
var adjusted = Math.round((value / max) * 5);
|
|
|
|
if (adjusted >= id) {
|
|
|
|
return 'active-' + adjusted;
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.$watch('options.predicate', buildOrderedRepositories);
|
|
|
|
$scope.$watch('options.reverse', buildOrderedRepositories);
|
|
|
|
|
|
|
|
$scope.$watch('repositoriesResources', function(resources) {
|
|
|
|
$scope.repositories = [];
|
|
|
|
$scope.maxPopularity = 0;
|
2015-07-22 20:59:31 +00:00
|
|
|
$scope.isLoading = false;
|
2015-06-09 21:58:57 +00:00
|
|
|
|
|
|
|
resources.forEach(function(resource) {
|
2015-07-22 20:59:31 +00:00
|
|
|
if (resource.loading) {
|
|
|
|
$scope.isLoading = true;
|
|
|
|
}
|
|
|
|
|
2015-06-09 21:58:57 +00:00
|
|
|
(resource.value || []).forEach(function(repository) {
|
|
|
|
var repositoryInfo = $.extend(repository, {
|
|
|
|
'full_name': repository.namespace + '/' + repository.name,
|
2016-05-12 21:59:49 +00:00
|
|
|
'last_modified_datetime': TableService.getReversedTimestamp(repository.last_modified),
|
2015-06-09 21:58:57 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$scope.repositories.push(repositoryInfo);
|
|
|
|
$scope.maxPopularity = Math.max($scope.maxPopularity, repository.popularity);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
buildOrderedRepositories();
|
|
|
|
}, /* deep */ true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return directiveDefinitionObject;
|
|
|
|
});
|