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, Restangular: any, PlanService: any, $http: ng.IHttpService, CookieService: any, Features: any, $anchorScroll: ng.IAnchorScrollService, MetaService: any): void { const defaultTitle: string = INJECTED_CONFIG['REGISTRY_TITLE'] || 'Quay Container Registry'; // Handle session security. Restangular.setDefaultRequestParams(['post', 'put', 'remove', 'delete'], {'_csrf_token': (window).__token || ''}); // Handle session expiration. Restangular.setErrorInterceptor(function(response) { if (response !== undefined && response.status == 503) { ($('#cannotContactService')).modal({}); return false; } if (response !== undefined && response.status == 500) { window.location.href = '/500'; return false; } if (response !== undefined && !response.data) { return true; } const invalid_token: boolean = response.data['title'] == 'invalid_token' || response.data['error_type'] == 'invalid_token'; if (response !== undefined && response.status == 401 && invalid_token && response.data['session_required'] !== false) { ($('#sessionexpiredModal')).modal({}); return false; } return true; }); // Check if we need to redirect based on a previously chosen plan. const result: boolean = PlanService.handleNotedPlan(); // Check to see if we need to show a redirection page. const redirectUrl: string = CookieService.get('quay.redirectAfterLoad'); CookieService.clear('quay.redirectAfterLoad'); if (!result && redirectUrl && redirectUrl.indexOf((window).location.href) == 0) { (window).location = redirectUrl; return; } $rootScope.$watch('description', function(description: string) { if (!description) { description = `Hosted private docker repositories. Includes full user management and history. Free for public repositories.`; } // Note: We set the content of the description tag manually here rather than using Angular binding // because we need the 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() { const title: string = MetaService.getTitle($rootScope.currentPage) || defaultTitle; $rootScope.title = title; const description: string = 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: string | Function = 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: boolean = false; (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; description: string; pageClass: any; newLayout: any; fixFooter: any; }