2017-04-05 21:14:08 +00:00
|
|
|
import { INJECTED_CONFIG } from "./constants/injected-values.constant";
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provider function for the application runtime configuration.
|
|
|
|
* See https://hotell.gitbooks.io/ng-metadata/content/docs/recipes/startup-logic.html
|
|
|
|
*/
|
|
|
|
provideRun.$inject = [
|
|
|
|
'$rootScope',
|
|
|
|
'Restangular',
|
|
|
|
'PlanService',
|
|
|
|
'$http',
|
|
|
|
'CookieService',
|
|
|
|
'Features',
|
|
|
|
'$anchorScroll',
|
|
|
|
'MetaService',
|
|
|
|
];
|
|
|
|
export function provideRun($rootScope: QuayRunScope,
|
2017-07-13 14:12:46 +00:00
|
|
|
restangular: any,
|
|
|
|
planService: any,
|
2017-04-05 21:14:08 +00:00
|
|
|
$http: ng.IHttpService,
|
2017-07-13 14:12:46 +00:00
|
|
|
cookieService: any,
|
|
|
|
features: any,
|
2017-04-05 21:14:08 +00:00
|
|
|
$anchorScroll: ng.IAnchorScrollService,
|
2017-07-13 14:12:46 +00:00
|
|
|
metaService: any): void {
|
2017-04-05 21:14:08 +00:00
|
|
|
const defaultTitle: string = INJECTED_CONFIG['REGISTRY_TITLE'] || 'Quay Container Registry';
|
|
|
|
|
|
|
|
// Handle session security.
|
2017-07-13 14:12:46 +00:00
|
|
|
restangular.setDefaultRequestParams(['post', 'put', 'remove', 'delete'],
|
2017-04-05 21:14:08 +00:00
|
|
|
{'_csrf_token': (<any>window).__token || ''});
|
|
|
|
|
|
|
|
// Handle session expiration.
|
2017-07-13 14:12:46 +00:00
|
|
|
restangular.setErrorInterceptor(function(response) {
|
2017-04-05 21:14:08 +00:00
|
|
|
if (response !== undefined && response.status == 503) {
|
|
|
|
(<any>$('#cannotContactService')).modal({});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response !== undefined && response.status == 500) {
|
|
|
|
window.location.href = '/500';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response !== undefined && !response.data) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-20 06:17:42 +00:00
|
|
|
const invalid_token: boolean = response.data['title'] == 'invalid_token' ||
|
|
|
|
response.data['error_type'] == 'invalid_token';
|
2017-04-05 21:14:08 +00:00
|
|
|
if (response !== undefined &&
|
|
|
|
response.status == 401 &&
|
|
|
|
invalid_token &&
|
|
|
|
response.data['session_required'] !== false) {
|
|
|
|
(<any>$('#sessionexpiredModal')).modal({});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Check if we need to redirect based on a previously chosen plan.
|
2017-07-13 14:12:46 +00:00
|
|
|
const result: boolean = planService.handleNotedPlan();
|
2017-04-05 21:14:08 +00:00
|
|
|
|
|
|
|
// Check to see if we need to show a redirection page.
|
2017-07-13 14:12:46 +00:00
|
|
|
const redirectUrl: string = cookieService.get('quay.redirectAfterLoad');
|
|
|
|
cookieService.clear('quay.redirectAfterLoad');
|
2017-04-05 21:14:08 +00:00
|
|
|
|
|
|
|
if (!result && redirectUrl && redirectUrl.indexOf((<any>window).location.href) == 0) {
|
|
|
|
(<any>window).location = redirectUrl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-13 14:12:46 +00:00
|
|
|
$rootScope.$watch('description', (description: string) => {
|
2017-04-05 21:14:08 +00:00
|
|
|
if (!description) {
|
2017-07-13 14:12:46 +00:00
|
|
|
description = `Hosted private Docker repositories. Includes full user management and history.
|
2017-04-05 21:14:08 +00:00
|
|
|
Free for public repositories.`;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
});
|
|
|
|
|
2017-07-13 14:12:46 +00:00
|
|
|
$rootScope.$on('$routeChangeSuccess', (event, current, previous) => {
|
2017-04-05 21:14:08 +00:00
|
|
|
$rootScope.current = current.$$route;
|
|
|
|
$rootScope.currentPage = current;
|
|
|
|
$rootScope.pageClass = '';
|
|
|
|
|
|
|
|
if (!current.$$route) { return; }
|
|
|
|
|
|
|
|
var pageClass: string | Function = current.$$route.pageClass || '';
|
|
|
|
if (typeof pageClass != 'string') {
|
2017-07-13 14:12:46 +00:00
|
|
|
pageClass = pageClass(features);
|
2017-04-05 21:14:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$rootScope.pageClass = pageClass;
|
|
|
|
$rootScope.newLayout = !!current.$$route.newLayout;
|
|
|
|
$rootScope.fixFooter = !!current.$$route.fixFooter;
|
|
|
|
|
|
|
|
$anchorScroll();
|
|
|
|
});
|
|
|
|
|
2017-07-13 14:12:46 +00:00
|
|
|
// Listen for route changes and update the title and description accordingly.
|
|
|
|
$rootScope.$on('$routeChangeSuccess', async(event, current, previous) => {
|
2017-11-08 21:14:14 +00:00
|
|
|
const title = await metaService.getTitle(current);
|
2017-07-13 14:12:46 +00:00
|
|
|
const description = await metaService.getDescription(current);
|
2017-11-08 21:14:14 +00:00
|
|
|
|
|
|
|
$rootScope.title = title || defaultTitle;
|
2017-07-13 14:12:46 +00:00
|
|
|
if ($rootScope.description != description) {
|
|
|
|
$rootScope.description = description;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-04-05 21:14:08 +00:00
|
|
|
var initallyChecked: boolean = false;
|
|
|
|
(<any>window).__isLoading = function() {
|
|
|
|
if (!initallyChecked) {
|
|
|
|
initallyChecked = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return $http.pendingRequests.length > 0;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
interface QuayRunScope extends ng.IRootScopeService {
|
|
|
|
currentPage: any;
|
|
|
|
current: any;
|
|
|
|
title: any;
|
2017-06-20 06:17:42 +00:00
|
|
|
description: string;
|
2017-04-05 21:14:08 +00:00
|
|
|
pageClass: any;
|
|
|
|
newLayout: any;
|
|
|
|
fixFooter: any;
|
|
|
|
}
|