From 537c07ad4dfb005c66f13caa918f8c83ce09b872 Mon Sep 17 00:00:00 2001 From: alecmerdler Date: Wed, 1 Feb 2017 00:29:56 -0800 Subject: [PATCH] fixes based on requested changes --- karma.conf.js | 4 +- .../js/constants/injected-values.constant.ts | 2 +- static/js/constants/name-patterns.constant.ts | 2 +- static/js/constants/pages.constant.ts | 19 +++--- .../inject/inject.decorator.spec.ts | 2 +- .../js/decorators/inject/inject.decorator.ts | 2 +- static/js/quay-pages.module.ts | 2 +- static/js/quay.config.ts | 6 +- static/js/quay.module.ts | 6 +- static/js/quay.routes.ts | 3 +- static/js/quay.run.ts | 60 ++++++++++++------- 11 files changed, 60 insertions(+), 48 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 7ace21f46..98114ba2f 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -33,9 +33,7 @@ module.exports = function(config) { // Tests utils 'static/test/**/*.js', ], - exclude: [ - 'static/js/build/bundle.js', - ], + exclude: [], preprocessors: { 'static/lib/ngReact/react.ngReact.min.js': ['webpack'], 'static/lib/angular-moment.min.js': ['webpack'], diff --git a/static/js/constants/injected-values.constant.ts b/static/js/constants/injected-values.constant.ts index dcfbcbd32..f7bd2f9a4 100644 --- a/static/js/constants/injected-values.constant.ts +++ b/static/js/constants/injected-values.constant.ts @@ -13,4 +13,4 @@ export const INJECTED_ENDPOINTS: any = (window).__endpoints; /** * Features information. */ -export const INJECTED_FEATURES: any = (window).__features; \ No newline at end of file +export const INJECTED_FEATURES: any = (window).__features; diff --git a/static/js/constants/name-patterns.constant.ts b/static/js/constants/name-patterns.constant.ts index a90b027ff..422887c3e 100644 --- a/static/js/constants/name-patterns.constant.ts +++ b/static/js/constants/name-patterns.constant.ts @@ -5,4 +5,4 @@ export default { TEAM_PATTERN: '^[a-z][a-z0-9]+$', ROBOT_PATTERN: '^[a-z][a-z0-9_]{1,254}$', USERNAME_PATTERN: '^(?=.{2,255}$)([a-z0-9]+(?:[._-][a-z0-9]+)*)$', -}; \ No newline at end of file +}; diff --git a/static/js/constants/pages.constant.ts b/static/js/constants/pages.constant.ts index 57b6eb7fd..6d0452b8c 100644 --- a/static/js/constants/pages.constant.ts +++ b/static/js/constants/pages.constant.ts @@ -3,24 +3,23 @@ * TODO: Convert to class/Angular service */ export default { - '_pages': {}, + _pages: {}, /** * Create a page. * @param pageName The name of the page. * @param templateName The file name of the template. - * @param opt_controller Controller for the page. - * @param opt_flags Additional flags passed to route provider. - * @param opt_profiles Available profiles. + * @param controller Controller for the page. + * @param flags Additional flags passed to route provider. + * @param profiles Available profiles. */ - 'create': function (pageName, templateName, opt_controller, opt_flags, opt_profiles) { - var profiles = opt_profiles || ['old-layout', 'layout']; + create: function(pageName: string, templateName: string, controller?: Object, flags = {}, profiles = ['old-layout', 'layout']) { for (var i = 0; i < profiles.length; ++i) { this._pages[profiles[i] + ':' + pageName] = { 'name': pageName, - 'controller': opt_controller, + 'controller': controller, 'templateName': templateName, - 'flags': opt_flags || {} + 'flags': flags }; } }, @@ -30,7 +29,7 @@ export default { * @param pageName The name of the page. * @param profiles Available profiles to search. */ - 'get': function (pageName, profiles) { + get: function(pageName: string, profiles: any[]) { for (var i = 0; i < profiles.length; ++i) { var current = profiles[i]; var key = current.id + ':' + pageName; @@ -42,4 +41,4 @@ export default { return null; } -}; \ No newline at end of file +}; diff --git a/static/js/decorators/inject/inject.decorator.spec.ts b/static/js/decorators/inject/inject.decorator.spec.ts index 2f0a9a17b..f3f015e20 100644 --- a/static/js/decorators/inject/inject.decorator.spec.ts +++ b/static/js/decorators/inject/inject.decorator.spec.ts @@ -14,4 +14,4 @@ describe("Decorator: Inject", () => { class ValidService { constructor(@Inject('$scope') private $scope: any) {} -} \ No newline at end of file +} diff --git a/static/js/decorators/inject/inject.decorator.ts b/static/js/decorators/inject/inject.decorator.ts index 2c647a4c7..dadc20a58 100644 --- a/static/js/decorators/inject/inject.decorator.ts +++ b/static/js/decorators/inject/inject.decorator.ts @@ -5,7 +5,7 @@ */ export function Inject(value: string) { return (target: any, propertyKey: string | symbol, parameterIndex: number): void => { - target.$inject = target.$inject || []; + target.$inject = target.$inject = []; target.$inject[parameterIndex] = value; } } diff --git a/static/js/quay-pages.module.ts b/static/js/quay-pages.module.ts index 072307c58..871cb78f0 100644 --- a/static/js/quay-pages.module.ts +++ b/static/js/quay-pages.module.ts @@ -9,4 +9,4 @@ export default angular .directive('rpHeader', rpHeaderDirective) .directive('rpSidebar', rpSidebarDirective) .directive('rpBody', rpBodyDirective) - .name; \ No newline at end of file + .name; diff --git a/static/js/quay.config.ts b/static/js/quay.config.ts index fc7fc7293..af2a36af9 100644 --- a/static/js/quay.config.ts +++ b/static/js/quay.config.ts @@ -29,10 +29,8 @@ export function quayConfig( return function(element) { // Note: We only disable bs-tooltip's themselves. $tooltip is used for other things // (such as the datepicker), so we need to be specific when canceling it. - if (element.attr('bs-tooltip') == null) { + if (element !== undefined && element.attr('bs-tooltip') == null) { return existing.apply(this, arguments); - } else { - return null; } }; } @@ -66,4 +64,4 @@ export function quayConfig( }; }); } -} \ No newline at end of file +} diff --git a/static/js/quay.module.ts b/static/js/quay.module.ts index b5d17353b..c149f1ba3 100644 --- a/static/js/quay.module.ts +++ b/static/js/quay.module.ts @@ -28,7 +28,9 @@ var quayDependencies: string[] = [ 'react' ]; -if (INJECTED_CONFIG && (INJECTED_CONFIG.MIXPANEL_KEY || INJECTED_CONFIG.MUNCHKIN_KEY || INJECTED_CONFIG.GOOGLE_ANALYTICS_KEY)) { +if (INJECTED_CONFIG && (INJECTED_CONFIG.MIXPANEL_KEY || + INJECTED_CONFIG.MUNCHKIN_KEY || + INJECTED_CONFIG.GOOGLE_ANALYTICS_KEY)) { quayDependencies.push('angulartics'); } if (INJECTED_CONFIG && INJECTED_CONFIG.MIXPANEL_KEY) { @@ -54,4 +56,4 @@ export default angular .constant('INJECTED_ENDPOINTS', INJECTED_ENDPOINTS) .service('ViewArray', ViewArrayImpl) .run(quayRun) - .name; \ No newline at end of file + .name; diff --git a/static/js/quay.routes.ts b/static/js/quay.routes.ts index e458e5715..628c77dbd 100644 --- a/static/js/quay.routes.ts +++ b/static/js/quay.routes.ts @@ -1,6 +1,7 @@ import { RouteBuilderImpl } from './services/route-builder/route-builder.service.impl'; import { RouteBuilder } from './services/route-builder/route-builder.service'; import pages from './constants/pages.constant'; +import * as ng from '@types/angular'; routeConfig.$inject = [ @@ -131,4 +132,4 @@ export function routeConfig( .route('/:catch/:all', 'error-view') .route('/:catch/:all/:things', 'error-view') .route('/:catch/:all/:things/:here', 'error-view'); -} \ No newline at end of file +} diff --git a/static/js/quay.run.ts b/static/js/quay.run.ts index ac28801b6..9ebcfd262 100644 --- a/static/js/quay.run.ts +++ b/static/js/quay.run.ts @@ -1,4 +1,5 @@ import * as $ from 'jquery'; +import * as ng from '@types/angular'; quayRun.$inject = [ @@ -18,42 +19,45 @@ quayRun.$inject = [ ]; export default function quayRun( - $location, - $rootScope, - Restangular, - UserService, - PlanService, - $http, - $timeout, - CookieService, - Features, - $anchorScroll, - UtilService, - MetaService, - INJECTED_CONFIG) { + $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) { var defaultTitle = INJECTED_CONFIG['REGISTRY_TITLE'] || 'Quay Container Registry'; // Handle session security. - Restangular.setDefaultRequestParams(['post', 'put', 'remove', 'delete'], {'_csrf_token': (window).__token || ''}); + Restangular.setDefaultRequestParams(['post', 'put', 'remove', 'delete'], + {'_csrf_token': (window).__token || ''}); // Handle session expiration. Restangular.setErrorInterceptor(function(response) { - if (response.status == 503) { + if (response !== undefined && response.status == 503) { ($('#cannotContactService')).modal({}); return false; } - if (response.status == 500) { + if (response !== undefined && response.status == 500) { window.location.href = '/500'; return false; } - if (!response.data) { + if (response !== undefined && !response.data) { return true; } var invalid_token = response.data['title'] == 'invalid_token' || response.data['error_type'] == 'invalid_token'; - if (response.status == 401 && invalid_token && response.data['session_required'] !== false) { + if (response !== undefined && response.status == 401 && + invalid_token && + response.data['session_required'] !== false) { ($('#sessionexpiredModal')).modal({}); return false; } @@ -73,9 +77,10 @@ export default function quayRun( return; } - $rootScope.$watch('description', function(description) { + $rootScope.$watch('description', function(description: string) { if (!description) { - description = 'Hosted private docker repositories. Includes full user management and history. Free for public repositories.'; + 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 @@ -87,9 +92,7 @@ export default function quayRun( // Listen for scope changes and update the title and description accordingly. $rootScope.$watch(function() { var title = MetaService.getTitle($rootScope.currentPage) || defaultTitle; - if ($rootScope.title != title) { - $rootScope.title = title; - } + $rootScope.title = title; var description = MetaService.getDescription($rootScope.currentPage) || ''; if ($rootScope.description != description) { @@ -126,4 +129,15 @@ export default function quayRun( } return $http.pendingRequests.length > 0; }; +} + + +interface QuayRunScope extends ng.IRootScopeService { + currentPage: any; + current: any; + title: any; + description: string, + pageClass: any; + newLayout: any; + fixFooter: any; } \ No newline at end of file