Switch landing page to read template from S3 bucket
This change uses CORS to make the Angular template request to a defined S3 bucket, falling back to the compiled login template if the bucket is not available. Fixes #1313
This commit is contained in:
parent
b7aac159ae
commit
66e09b2a95
4 changed files with 28 additions and 251 deletions
|
@ -118,54 +118,41 @@ angular.module('quay').directive('quayClasses', function(Features, Config) {
|
|||
});
|
||||
|
||||
/**
|
||||
* Adds a quay-include attribtue that adds a template solely if the expression evaluates to true.
|
||||
* Automatically adds the Features and Config services to the scope.
|
||||
* Adds a quay-static-include attribute handles adding static marketing content from a defined
|
||||
* S3 bucket. If running under QE, the local template is used.
|
||||
*
|
||||
Usage: quay-include="{'Features.BILLING': 'partials/landing-normal.html', '!Features.BILLING': 'partials/landing-login.html'}"
|
||||
* Usage: quay-static-include="{'hosted': 'index.html', 'otherwise': 'partials/landing-login.html'}"
|
||||
*/
|
||||
angular.module('quay').directive('quayInclude', function($compile, $templateCache, $http, Features, Config) {
|
||||
angular.module('quay').directive('quayStaticInclude', function($compile, $templateCache, $http, Features, Config) {
|
||||
return {
|
||||
priority: 595,
|
||||
restrict: 'A',
|
||||
link: function($scope, $element, $attr, ctrl) {
|
||||
var getTemplate = function(templateName) {
|
||||
var templateUrl = '/static/' + templateName;
|
||||
return $http.get(templateUrl, {cache: $templateCache});
|
||||
var getTemplate = function(hostedTemplateName, staticTemplateName) {
|
||||
var staticTemplateUrl = '/static/' + staticTemplateName;
|
||||
var templateUrl = staticTemplateUrl;
|
||||
if (Features.BILLING && Config['STATIC_SITE_BUCKET']) {
|
||||
templateUrl = Config['STATIC_SITE_BUCKET'] + hostedTemplateName;
|
||||
}
|
||||
|
||||
return $http.get(templateUrl, {cache: $templateCache}).catch(function(resolve, reject) {
|
||||
// Fallback to the static local URL if the hosted URL doesn't work.
|
||||
return $http.get(staticTemplateUrl, {cache: $templateCache});
|
||||
});
|
||||
};
|
||||
|
||||
var result = $scope.$eval($attr.quayInclude);
|
||||
var result = $scope.$eval($attr.quayStaticInclude);
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
|
||||
var scopeVals = {
|
||||
'Features': Features,
|
||||
'Config': Config
|
||||
};
|
||||
|
||||
var templatePath = null;
|
||||
for (var expr in result) {
|
||||
if (!result.hasOwnProperty(expr)) { continue; }
|
||||
|
||||
// Evaluate the expression with the entire features list added.
|
||||
var value = $scope.$eval(expr, scopeVals);
|
||||
if (value) {
|
||||
templatePath = result[expr];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!templatePath) {
|
||||
return;
|
||||
}
|
||||
|
||||
var promise = getTemplate(templatePath).success(function(html) {
|
||||
$element.html(html);
|
||||
}).then(function (response) {
|
||||
$element.replaceWith($compile($element.html())($scope));
|
||||
var promise = getTemplate(result['hosted'], result['otherwise']).then(function (response) {
|
||||
$element.replaceWith($compile(response['data'])($scope));
|
||||
if ($attr.onload) {
|
||||
$scope.$eval($attr.onload);
|
||||
}
|
||||
}).catch(function(err) {
|
||||
console.log(err)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
Reference in a new issue