grim/port-authority

fixed a bunch of random stuff... the none scrolling of the repo list, added a debug option, and a default title so that things aren't jumping around
var manifest = angular.module("manifest", ['ui.bootstrap'])
.config([
'$compileProvider',
function($compileProvider) {
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|chrome-extension):/);
$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|mailto|chrome-extension):/);
}
]);
manifest.factory("manifestREST", function($http) {
return {
search: function(registry, query) {
var url = registry + "/v1/search";
if(query) {
url += "?q=" + query;
}
return $http.get(url);
},
images: function(registry, repo) {
return $http.get(registry + "/v1/repositories/" + repo + "/images")
.success(function(images) {
for(var i = 0; i < images.length; i++) {
var image = images[i];
image['short_id'] = image.id.substring(0, 8);
}
return images;
});
},
tags: function(registry, repo) {
return $http.get(registry + "/v1/repositories/" + repo + "/tags");
},
info: function(registry, image) {
return $http.get(registry + "/v1/images/" + image + "/json");
}
}
});
function ManifestController($scope, manifestREST) {
$scope.debug = false;
$scope.refreshing = false;
$scope.refreshing_repo = false;
$scope.registry = "registry.hub.docker.com";
$scope.query = "busybox";
$scope.repos = null;
$scope.repo = null;
$scope.error = null;
$scope.tags = null;
$scope.clipboard = null;
/* google analytics stuff */
$scope.ga_service = analytics.getService("Port Authority Chrome");
$scope.ga_tracker = $scope.ga_service.getTracker("UA-47592312-2");
$scope.ga_tracker.sendAppView("main");
$scope.refresh = function() {
$scope.repos = null;
$scope.repo = null;
$scope.tags = null;
$scope.clipboard = null;
$scope.refreshing = true;
if($scope.registry.indexOf("http://") !== 0 && $scope.registry.indexOf("https://") !== 0) {
$scope.registry = "http://" + $scope.registry;
}
$scope.ga_tracker.sendEvent("refresh", "search param", "used", $scope.query !== "");
var timer_start = window.performance.now();
manifestREST.search($scope.registry, $scope.query)
.success(function(data, status, headers, config) {
var timer_end = window.performance.now();
$scope.ga_tracker.sendEvent("refresh", "status", "refresh success");
$scope.ga_tracker.sendTiming("refresh", "load time", timer_end - timer_start, "refresh success timing");
$scope.repos = data.results.map(function(repo) {
var library_prefix = "library/"
if(repo.name.indexOf(library_prefix) == 0) {
repo.name = repo.name.substring(library_prefix.length, repo.name.length);
}
repo.expanded = false;
$scope.refreshing = false;
return repo;
});
})
.error(function(data, status, headers, config) {
var timer_end = window.performance.now();
$scope.ga_tracker.sendEvent("refresh", "status", "refresh failed");
$scope.ga_tracker.sendTiming("refresh", "load time", timer_end - timer_start, "refresh failed timing");
$scope.refreshing = false;
console.log("Failed to get the registry list: " + status);
});
};
$scope.select_repo = function(repo) {
if(repo === $scope.repo) {
return;
}
$scope.ga_tracker.sendEvent("repo", "selected", "repo-selected");
$scope.repo = repo;
$scope.tags = null;
$scope.refreshing_repo = true;
manifestREST.tags($scope.registry, repo.name)
.success(function(data, status, headers, config) {
/* the docker registry returns a list of objects like
* [{"layer", "deadb33f", "name": "latest"}]
* and the private registry returns a dictionary of tag
* names to images. Like:
* {"latest", "deadb33f"}
* This function will normalize them into an object like
* {"deadb33f", ["latest"]}
*/
$scope.ga_tracker.sendEvent("repo", "get tags", "success");
$scope.tags = {};
if(data.constructor === Array) { /* registry.hub.docker.com */
for(var ntag in data) {
var tag = data[ntag];
$scope.tags[tag.layer] = $scope.tags[tag.layer] || [];
$scope.tags[tag.layer].push(tag.name);
}
} else if(data !== null && typeof data === 'object') { /* private registries */
for(var tag in data) {
var layer = data[tag];
$scope.tags[layer] = $scope.tags[layer] || [];
$scope.tags[layer].push(tag);
}
}
$scope.refreshing_repo = false;
})
.error(function(data, status, headers, config) {
$scope.ga_tracker.sendEvent("repo", "get tags", "failed");
console.log("Failed to get the tag list: " + status);
$scope.refreshing_repo = false;
});
};
$scope.copy_tag = function(tag) {
$scope.ga_tracker.sendEvent("copy", "clicked");
$scope.clipboard = $scope.registry + "/" + $scope.repo.name + ":" + tag;
};
}