This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/static/js/directives/ui/repo-star.js

59 lines
1.8 KiB
JavaScript
Raw Normal View History

2015-03-10 05:03:39 +00:00
/**
* An element that displays the star status of a repository and allows it to be toggled.
*/
angular.module('quay').directive('repoStar', function () {
var directiveDefinitionObject = {
priority: 0,
templateUrl: '/static/directives/repo-star.html',
replace: false,
transclude: true,
restrict: 'C',
scope: {
repository: '=repository',
starToggled: '&starToggled'
},
controller: function($scope, $element, UserService, ApiService) {
$scope.loggedIn = false;
2015-03-10 05:03:39 +00:00
// Star a repository or unstar a repository.
$scope.toggleStar = function() {
if ($scope.repository.is_starred) {
unstarRepo();
} else {
starRepo();
}
};
// Star a repository and update the UI.
var starRepo = function() {
var data = {
'namespace': $scope.repository.namespace,
'repository': $scope.repository.name
};
ApiService.createStar(data).then(function(result) {
$scope.repository.is_starred = true;
$scope.starToggled({'repository': $scope.repository});
}, ApiService.errorDisplay('Could not star repository'));
};
// Unstar a repository and update the UI.
var unstarRepo = function(repo) {
var data = {
'repository': $scope.repository.namespace + '/' + $scope.repository.name
};
ApiService.deleteStar(null, data).then(function(result) {
$scope.repository.is_starred = false;
$scope.starToggled({'repository': $scope.repository});
}, ApiService.errorDisplay('Could not unstar repository'));
};
$scope.$watch('repository', function() {
$scope.loggedIn = !UserService.currentUser().anonymous;
});
2015-03-10 05:03:39 +00:00
}
};
return directiveDefinitionObject;
});