2017-01-19 08:53:38 +00:00
|
|
|
import * as $ from 'jquery';
|
2017-02-01 08:29:56 +00:00
|
|
|
import * as ng from '@types/angular';
|
2017-01-19 08:53:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
quayRun.$inject = [
|
|
|
|
'$location',
|
|
|
|
'$rootScope',
|
|
|
|
'Restangular',
|
|
|
|
'UserService',
|
|
|
|
'PlanService',
|
|
|
|
'$http',
|
|
|
|
'$timeout',
|
|
|
|
'CookieService',
|
|
|
|
'Features',
|
|
|
|
'$anchorScroll',
|
|
|
|
'UtilService',
|
|
|
|
'MetaService',
|
2017-01-23 20:34:22 +00:00
|
|
|
'INJECTED_CONFIG',
|
2017-01-19 08:53:38 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
export default function quayRun(
|
2017-02-01 08:29:56 +00:00
|
|
|
$location: ng.ILocationService,
|
|
|
|
$rootScope: QuayRunScope,
|
|
|
|
Restangular: any,
|
|
|
|
UserService: any,
|
|
|
|
PlanService: any,
|
|
|
|
$http: ng.IHttpService,
|
|
|
|
$timeout: ng.ITimeoutService,
|
|
|
|
CookieService: any,
|
|
|
|
Features: any,
|
|
|
|
$anchorScroll: ng.IAnchorScrollService,
|
|
|
|
UtilService: any,
|
|
|
|
MetaService: any,
|
|
|
|
INJECTED_CONFIG: any) {
|
2017-01-23 20:34:22 +00:00
|
|
|
var defaultTitle = INJECTED_CONFIG['REGISTRY_TITLE'] || 'Quay Container Registry';
|
2017-01-19 08:53:38 +00:00
|
|
|
|
|
|
|
// Handle session security.
|
2017-02-01 08:29:56 +00:00
|
|
|
Restangular.setDefaultRequestParams(['post', 'put', 'remove', 'delete'],
|
|
|
|
{'_csrf_token': (<any>window).__token || ''});
|
2017-01-19 08:53:38 +00:00
|
|
|
|
|
|
|
// Handle session expiration.
|
|
|
|
Restangular.setErrorInterceptor(function(response) {
|
2017-02-01 08:29:56 +00:00
|
|
|
if (response !== undefined && response.status == 503) {
|
2017-01-19 08:53:38 +00:00
|
|
|
(<any>$('#cannotContactService')).modal({});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-01 08:29:56 +00:00
|
|
|
if (response !== undefined && response.status == 500) {
|
2017-01-19 08:53:38 +00:00
|
|
|
window.location.href = '/500';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-01 08:29:56 +00:00
|
|
|
if (response !== undefined && !response.data) {
|
2017-01-19 08:53:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var invalid_token = response.data['title'] == 'invalid_token' || response.data['error_type'] == 'invalid_token';
|
2017-02-01 08:29:56 +00:00
|
|
|
if (response !== undefined && response.status == 401 &&
|
|
|
|
invalid_token &&
|
|
|
|
response.data['session_required'] !== false) {
|
2017-01-19 08:53:38 +00:00
|
|
|
(<any>$('#sessionexpiredModal')).modal({});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Check if we need to redirect based on a previously chosen plan.
|
|
|
|
var result = PlanService.handleNotedPlan();
|
|
|
|
|
|
|
|
// Check to see if we need to show a redirection page.
|
|
|
|
var redirectUrl = CookieService.get('quay.redirectAfterLoad');
|
|
|
|
CookieService.clear('quay.redirectAfterLoad');
|
|
|
|
|
|
|
|
if (!result && redirectUrl && redirectUrl.indexOf((<any>window).location.href) == 0) {
|
|
|
|
(<any>window).location = redirectUrl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-01 08:29:56 +00:00
|
|
|
$rootScope.$watch('description', function(description: string) {
|
2017-01-19 08:53:38 +00:00
|
|
|
if (!description) {
|
2017-02-01 08:29:56 +00:00
|
|
|
description = `Hosted private docker repositories. Includes full user management and history.
|
|
|
|
Free for public repositories.`;
|
2017-01-19 08:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Note: We set the content of the description tag manually here rather than using Angular binding
|
|
|
|
// because we need the <meta> tag to have a default description that is not of the form "{{ description }}",
|
|
|
|
// we read by tools that do not properly invoke the Angular code.
|
|
|
|
$('#descriptionTag').attr('content', description);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Listen for scope changes and update the title and description accordingly.
|
|
|
|
$rootScope.$watch(function() {
|
|
|
|
var title = MetaService.getTitle($rootScope.currentPage) || defaultTitle;
|
2017-02-01 08:29:56 +00:00
|
|
|
$rootScope.title = title;
|
2017-01-19 08:53:38 +00:00
|
|
|
|
|
|
|
var description = MetaService.getDescription($rootScope.currentPage) || '';
|
|
|
|
if ($rootScope.description != description) {
|
|
|
|
$rootScope.description = description;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$rootScope.$on('$routeChangeSuccess', function (event, current, previous) {
|
|
|
|
$rootScope.current = current.$$route;
|
|
|
|
$rootScope.currentPage = current;
|
|
|
|
|
|
|
|
$rootScope.pageClass = '';
|
|
|
|
|
|
|
|
if (!current.$$route) { return; }
|
|
|
|
|
|
|
|
var pageClass = current.$$route.pageClass || '';
|
|
|
|
if (typeof pageClass != 'string') {
|
|
|
|
pageClass = pageClass(Features);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$rootScope.pageClass = pageClass;
|
|
|
|
$rootScope.newLayout = !!current.$$route.newLayout;
|
|
|
|
$rootScope.fixFooter = !!current.$$route.fixFooter;
|
|
|
|
|
|
|
|
$anchorScroll();
|
|
|
|
});
|
|
|
|
|
|
|
|
var initallyChecked = false;
|
|
|
|
(<any>window).__isLoading = function() {
|
|
|
|
if (!initallyChecked) {
|
|
|
|
initallyChecked = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return $http.pendingRequests.length > 0;
|
|
|
|
};
|
2017-02-01 08:29:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
interface QuayRunScope extends ng.IRootScopeService {
|
|
|
|
currentPage: any;
|
|
|
|
current: any;
|
|
|
|
title: any;
|
|
|
|
description: string,
|
|
|
|
pageClass: any;
|
|
|
|
newLayout: any;
|
|
|
|
fixFooter: any;
|
2017-01-19 08:53:38 +00:00
|
|
|
}
|