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/resource-view.js
2015-02-26 17:45:28 -05:00

40 lines
No EOL
1 KiB
JavaScript

/**
* An element which displays either a resource (if present) or an error message if the resource
* failed to load.
*/
angular.module('quay').directive('resourceView', function () {
var directiveDefinitionObject = {
priority: 0,
templateUrl: '/static/directives/resource-view.html',
replace: false,
transclude: true,
restrict: 'C',
scope: {
'resource': '=resource',
'resources': '=resources',
'errorMessage': '=errorMessage'
},
controller: function($scope, $element) {
$scope.getState = function() {
if (!$scope.resources && !$scope.resource) {
return 'loading';
}
var resources = $scope.resources || [$scope.resource];
for (var i = 0; i < resources.length; ++i) {
var current = resources[i];
if (current.loading) {
return 'loading';
}
if (current.error) {
return 'error';
}
}
return 'ready';
};
}
};
return directiveDefinitionObject;
});