Merge remote-tracking branch 'origin/master' into tagyourit

Conflicts:
	test/data/test.db
This commit is contained in:
jakedt 2014-04-01 19:09:41 -04:00
commit d768b60a3c
23 changed files with 674 additions and 134 deletions

View file

@ -185,24 +185,164 @@ quayApp = angular.module('quay', ['ngRoute', 'chieffancypants.loadingBar', 'angu
return service;
}]);
$provide.factory('UtilService', ['$sanitize', function($sanitize) {
var utilService = {};
utilService.textToSafeHtml = function(text) {
var adjusted = text.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
$provide.factory('DataFileService', [function() {
var dataFileService = {};
return $sanitize(adjusted);
dataFileService.getName_ = function(filePath) {
var parts = filePath.split('/');
return parts[parts.length - 1];
};
dataFileService.tryAsZip_ = function(buf, success, failure) {
var zip = null;
var zipFiles = null;
try {
var zip = new JSZip(buf);
zipFiles = zip.files;
} catch (e) {
failure();
return;
}
var files = [];
for (var filePath in zipFiles) {
if (zipFiles.hasOwnProperty(filePath)) {
files.push({
'name': dataFileService.getName_(filePath),
'path': filePath,
'canRead': true,
'toBlob': (function(fp) {
return function() {
return new Blob([zip.file(fp).asArrayBuffer()]);
};
}(filePath))
});
}
}
success(files);
};
dataFileService.tryAsTarGz_ = function(buf, success, failure) {
var collapsePath = function(originalPath) {
// Tar files can contain entries of the form './', so we need to collapse
// those paths down.
var parts = originalPath.split('/');
for (var i = parts.length - 1; i >= 0; i--) {
var part = parts[i];
if (part == '.') {
parts.splice(i, 1);
}
}
return parts.join('/');
};
var gunzip = new Zlib.Gunzip(buf);
var plain = gunzip.decompress();
var handler = new MultiFile();
handler.files = [];
handler.processTarChunks(dataFileService.arrayToString(plain), 0);
if (!handler.files.length) {
failure();
return;
}
var files = [];
for (var i = 0; i < handler.files.length; ++i) {
var currentFile = handler.files[i];
var path = collapsePath(currentFile.filename);
if (path == '') { continue; }
files.push({
'name': dataFileService.getName_(path),
'path': path,
'canRead': true,
'toBlob': (function(currentFile) {
return function() {
return new Blob([currentFile.data], {type: 'application/octet-binary'});
};
}(currentFile))
});
}
success(files);
};
dataFileService.blobToString = function(blob, callback) {
var reader = new FileReader();
reader.onload = function(event){
callback(reader.result);
};
reader.readAsText(blob);
};
dataFileService.arrayToString = function(buf) {
return String.fromCharCode.apply(null, new Uint16Array(buf));
};
dataFileService.readDataArrayAsPossibleArchive = function(buf, success, failure) {
dataFileService.tryAsZip_(buf, success, function() {
dataFileService.tryAsTarGz_(buf, success, failure);
});
};
dataFileService.downloadDataFileAsArrayBuffer = function($scope, url, progress, error, loaded) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.responseType = 'arraybuffer';
request.onprogress = function(e) {
$scope.$apply(function() {
var percentLoaded;
if (e.lengthComputable) {
progress(e.loaded / e.total);
}
});
};
request.onerror = function() {
$scope.$apply(function() {
error();
});
};
request.onload = function() {
if (this.status == 200) {
$scope.$apply(function() {
var uint8array = new Uint8Array(request.response);
loaded(uint8array);
});
return;
}
};
request.send();
};
return dataFileService;
}]);
$provide.factory('UtilService', ['$sanitize', function($sanitize) {
var utilService = {};
utilService.textToSafeHtml = function(text) {
var adjusted = text.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
return $sanitize(adjusted);
};
return utilService;
}]);
$provide.factory('TriggerDescriptionBuilder', ['UtilService', '$sanitize', function(UtilService, $sanitize) {
$provide.factory('TriggerDescriptionBuilder', ['UtilService', '$sanitize', function(UtilService, $sanitize) {
var builderService = {};
builderService.getDescription = function(name, config) {

View file

@ -761,7 +761,7 @@ function RepoCtrl($scope, $sanitize, Restangular, ImageMetadataService, ApiServi
loadViewInfo();
}
function BuildPackageCtrl($scope, Restangular, ApiService, $routeParams, $rootScope, $location, $timeout) {
function BuildPackageCtrl($scope, Restangular, ApiService, DataFileService, $routeParams, $rootScope, $location, $timeout) {
var namespace = $routeParams.namespace;
var name = $routeParams.name;
var buildid = $routeParams.buildid;
@ -783,100 +783,90 @@ function BuildPackageCtrl($scope, Restangular, ApiService, $routeParams, $rootSc
}, 10);
};
$scope.downloadForUser = function() {
var blob = $scope.zip.generate({type:"blob"});
saveAs(blob, $scope.repobuild['display_name'] + '.zip');
var determineDockerfilePath = function() {
var dockerfilePath = 'Dockerfile';
if ($scope.repobuild['job_config']) {
var dockerfileFolder = ($scope.repobuild['job_config']['build_subdir'] || '');
if (dockerfileFolder[0] == '/') {
dockerfileFolder = dockerfileFolder.substr(1);
}
if (dockerfileFolder && dockerfileFolder[dockerfileFolder.length - 1] != '/') {
dockerfileFolder += '/';
}
dockerfilePath = dockerfileFolder + 'Dockerfile';
}
return dockerfilePath;
};
var processBuildPack = function(response) {
// Try to load as a zip file.
var zipFiles = null;
var zip = null;
try {
var zip = new JSZip(response);
zipFiles = zip.files;
} catch (e) {
}
// Find the Dockerfile in the zip file. If there isn't any zip file, then the response
// itself (should) be the Dockerfile.
if (zipFiles && Object.keys(zipFiles).length) {
// Load the dockerfile contents.
var dockerfilePath = 'Dockerfile';
if ($scope.repobuild['job_config']) {
var dockerfileFolder = ($scope.repobuild['job_config']['build_subdir'] || '');
if (dockerfileFolder[0] == '/') {
dockerfileFolder = dockerfileFolder.substr(1);
}
if (dockerfileFolder && dockerfileFolder[dockerfileFolder.length - 1] != '/') {
dockerfileFolder += '/';
}
dockerfilePath = dockerfileFolder + 'Dockerfile';
}
var processBuildPack = function(uint8array) {
var archiveread = function(files) {
var getpath = function(file) {
return file.path;
};
var dockerfile = zip.file(dockerfilePath);
if (dockerfile) {
$scope.dockerFileContents = dockerfile.asText();
$scope.dockerFilePath = dockerfilePath;
}
var findFile = function(path) {
for (var i = 0; i < files.length; ++i) {
var file = files[i];
if (file.path == path) {
return file;
}
}
return null;
};
// Build the zip file tree.
$scope.zip = zip;
$scope.tree = new FileTree(Object.keys(zipFiles));
$scope.tree = new FileTree($.map(files, getpath));
$($scope.tree).bind('fileClicked', function(e) {
var file = zip.file(e.path);
if (file) {
var blob = new Blob([file.asArrayBuffer()]);
saveAs(blob, file.name);
var file = findFile(e.path);
if (file && file.canRead) {
saveAs(file.toBlob(), file.name);
}
});
} else {
$scope.dockerFileContents = response;
$scope.dockerFilePath = 'Dockerfile';
}
});
$scope.loaded = true;
var dockerfilePath = determineDockerfilePath();
var dockerfile = findFile(dockerfilePath);
if (dockerfile && dockerfile.canRead) {
DataFileService.blobToString(dockerfile.toBlob(), function(result) {
$scope.$apply(function() {
$scope.dockerFilePath = dockerfilePath;
$scope.dockerFileContents = result;
});
});
}
$scope.loaded = true;
};
var notarchive = function() {
$scope.dockerFileContents = DataFileService.arrayToString(uint8array);
$scope.loaded = true;
};
DataFileService.readDataArrayAsPossibleArchive(uint8array, archiveread, notarchive);
};
var downloadBuildPack = function(url) {
$scope.downloadProgress = 0;
$scope.downloading = true;
startDownload(url);
};
var startDownload = function(url) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
if (request.overrideMimeType) {
request.overrideMimeType('text/plain; charset=x-user-defined');
}
request.onprogress = function(e) {
$scope.$apply(function() {
var percentLoaded;
if (e.lengthComputable) {
$scope.downloadProgress = (e.loaded / e.total) * 100;
}
});
var onprogress = function(p) {
$scope.downloadProgress = p * 100;
};
request.onerror = function() {
$scope.$apply(function() {
$scope.downloading = false;
$scope.downloadError = true;
});
var onerror = function() {
$scope.downloading = false;
$scope.downloadError = true;
};
request.onreadystatechange = function() {
var state = request.readyState;
if (state == 4) {
$scope.$apply(function() {
$scope.downloading = false;
processBuildPack(request.responseText);
});
return;
}
var onloaded = function(uint8array) {
$scope.downloading = false;
processBuildPack(uint8array);
};
request.send();
DataFileService.downloadDataFileAsArrayBuffer($scope, url,
onprogress, onerror, onloaded);
};
var getBuildInfo = function() {