diff --git a/app/scripts/modules/appengine/src/serverGroup/configure/wizard/configFiles.component.ts b/app/scripts/modules/appengine/src/serverGroup/configure/wizard/configFiles.component.ts index 36af314b0d6..efe9e2ce715 100644 --- a/app/scripts/modules/appengine/src/serverGroup/configure/wizard/configFiles.component.ts +++ b/app/scripts/modules/appengine/src/serverGroup/configure/wizard/configFiles.component.ts @@ -16,6 +16,25 @@ export interface IAppengineConfigFileConfigurerCtrlCommand { sourceType: string; } +class ConfigArtifact implements IArtifactAccountPair { + public $scope: IScope; + public controller: ExpectedArtifactSelectorViewController; + public delegate: NgAppengineConfigArtifactDelegate; + public id: string; + public account: string; + + constructor($scope: IScope, artifact = { id: '', account: '' }) { + const unserializable = { configurable: false, enumerable: false, writable: false }; + this.id = artifact.id; + this.account = artifact.account; + Object.defineProperty(this, '$scope', { ...unserializable, value: $scope }); + const delegate = new NgAppengineConfigArtifactDelegate(this); + const controller = new ExpectedArtifactSelectorViewController(delegate); + Object.defineProperty(this, 'delegate', { ...unserializable, value: delegate }); + Object.defineProperty(this, 'controller', { ...unserializable, value: controller }); + } +} + class AppengineConfigFileConfigurerCtrl implements IController { private artifactAccounts: IArtifactAccount[] = []; public command: IAppengineConfigFileConfigurerCtrlCommand; @@ -78,25 +97,6 @@ class AppengineConfigFileConfigurerCtrl implements IController { } } -class ConfigArtifact implements IArtifactAccountPair { - public $scope: IScope; - public controller: ExpectedArtifactSelectorViewController; - public delegate: NgAppengineConfigArtifactDelegate; - public id: string; - public account: string; - - constructor($scope: IScope, artifact = { id: '', account: '' }) { - const unserializable = { configurable: false, enumerable: false, writable: false }; - this.id = artifact.id; - this.account = artifact.account; - Object.defineProperty(this, '$scope', { ...unserializable, value: $scope }); - const delegate = new NgAppengineConfigArtifactDelegate(this); - const controller = new ExpectedArtifactSelectorViewController(delegate); - Object.defineProperty(this, 'delegate', { ...unserializable, value: delegate }); - Object.defineProperty(this, 'controller', { ...unserializable, value: controller }); - } -} - class AppengineConfigFileConfigurerComponent implements ng.IComponentOptions { public bindings: any = { command: '=' }; public controller: any = AppengineConfigFileConfigurerCtrl; diff --git a/app/scripts/modules/core/src/bootstrap/uiRouterVisualizer.toggle.ts b/app/scripts/modules/core/src/bootstrap/uiRouterVisualizer.toggle.ts index 4aefc304809..114c4c9a1fc 100644 --- a/app/scripts/modules/core/src/bootstrap/uiRouterVisualizer.toggle.ts +++ b/app/scripts/modules/core/src/bootstrap/uiRouterVisualizer.toggle.ts @@ -12,7 +12,7 @@ bootstrapModule.run(($uiRouter: UIRouter) => { let visualizerEnabled: 'true' | 'false' = 'false'; let VisualizerPlugin: { new (): UIRouterPlugin } = null; - const loadVisualizer = () => { + function loadVisualizer() { // Auto-collapse certain states with lots of children const collapseGlobs = ['home.*', 'home.*.application.*', 'home.*.application.insight.*'].map( globStr => new Glob(globStr), @@ -25,9 +25,9 @@ bootstrapModule.run(($uiRouter: UIRouter) => { return import('@uirouter/visualizer') .then((vis: any) => (VisualizerPlugin = vis.Visualizer)) .then(createVisualizer); - }; + } - const createVisualizer = () => { + function createVisualizer() { if (visualizerEnabled !== 'true') { return; } @@ -40,14 +40,14 @@ bootstrapModule.run(($uiRouter: UIRouter) => { } else { loadVisualizer(); } - }; + } - const destroyVisualizer = () => { + function destroyVisualizer() { const plugin = $uiRouter.getPlugin('visualizer'); plugin && $uiRouter.dispose(plugin); - }; + } - const toggleVisualizer = (trans: Transition) => { + function toggleVisualizer(trans: Transition) { const enabled: 'true' | 'false' = trans.paramsChanged().vis; if (enabled === undefined) { return null; @@ -66,7 +66,7 @@ bootstrapModule.run(($uiRouter: UIRouter) => { } return trans.targetState().withParams({ vis: undefined }); - }; + } (window as any).vis = createVisualizer; $uiRouter.transitionService.onStart({}, toggleVisualizer); diff --git a/app/scripts/modules/core/src/overrideRegistry/Overrides.tsx b/app/scripts/modules/core/src/overrideRegistry/Overrides.tsx index 01a0dab2a92..6bbb3ad6167 100644 --- a/app/scripts/modules/core/src/overrideRegistry/Overrides.tsx +++ b/app/scripts/modules/core/src/overrideRegistry/Overrides.tsx @@ -3,26 +3,6 @@ import * as React from 'react'; import { CloudProviderRegistry } from 'core/cloudProvider'; import { OverrideRegistry } from 'core/overrideRegistry'; -/** - * Registers a component as a replacement for some other component. - * - * This is a Class Decorator which should be applied to a React Component Class. - * The component class will be used instead of the OverridableComponent with the same key. - * - * If an (optional) cloudProvider is specified, the component override takes effect only for that cloud provider. - * If an (optional) cloudProviderVersion is specified, the component override takes effect only for a specific version of that cloud provider. - * - * @Overrides('overrideKey', "aws", "v2") - * class MyOverridingCmp extends React.Component { - * render() { return

Overridden component

} - * } - */ -export function Overrides(key: string, cloudProvider?: string, cloudProviderVersion?: string) { - return function>(targetComponent: T): void { - overrideRegistrationQueue.register(targetComponent, key, cloudProvider, cloudProviderVersion); - }; -} - /** * This queues OverrideComponent registration until the registries are ready. */ @@ -61,3 +41,23 @@ export class RegistrationQueue { } export const overrideRegistrationQueue = new RegistrationQueue(); + +/** + * Registers a component as a replacement for some other component. + * + * This is a Class Decorator which should be applied to a React Component Class. + * The component class will be used instead of the OverridableComponent with the same key. + * + * If an (optional) cloudProvider is specified, the component override takes effect only for that cloud provider. + * If an (optional) cloudProviderVersion is specified, the component override takes effect only for a specific version of that cloud provider. + * + * @Overrides('overrideKey', "aws", "v2") + * class MyOverridingCmp extends React.Component { + * render() { return

Overridden component

} + * } + */ +export function Overrides(key: string, cloudProvider?: string, cloudProviderVersion?: string) { + return function>(targetComponent: T): void { + overrideRegistrationQueue.register(targetComponent, key, cloudProvider, cloudProviderVersion); + }; +} diff --git a/app/scripts/modules/core/src/pipeline/config/stages/bakeManifest/bakeManifestConfig.controller.ts b/app/scripts/modules/core/src/pipeline/config/stages/bakeManifest/bakeManifestConfig.controller.ts index e75e8e836e3..ab40013c5a8 100644 --- a/app/scripts/modules/core/src/pipeline/config/stages/bakeManifest/bakeManifestConfig.controller.ts +++ b/app/scripts/modules/core/src/pipeline/config/stages/bakeManifest/bakeManifestConfig.controller.ts @@ -8,6 +8,25 @@ import { } from 'core/artifact'; import { UUIDGenerator } from 'core/utils'; +class InputArtifact implements IArtifactAccountPair { + public $scope: IScope; + public controller: ExpectedArtifactSelectorViewController; + public delegate: NgBakeManifestArtifactDelegate; + public id: string; + public account: string; + + constructor($scope: IScope, artifact = { id: '', account: '' }) { + const unserializable = { configurable: false, enumerable: false, writable: false }; + Object.defineProperty(this, '$scope', { ...unserializable, value: $scope }); + const delegate = new NgBakeManifestArtifactDelegate(this); + const controller = new ExpectedArtifactSelectorViewController(delegate); + Object.defineProperty(this, 'delegate', { ...unserializable, value: delegate }); + Object.defineProperty(this, 'controller', { ...unserializable, value: controller }); + this.id = artifact.id; + this.account = artifact.account; + } +} + export class BakeManifestConfigCtrl implements IController { public artifactControllers: any[]; public artifactAccounts: IArtifactAccount[] = []; @@ -105,22 +124,3 @@ export class BakeManifestConfigCtrl implements IController { ); } } - -class InputArtifact implements IArtifactAccountPair { - public $scope: IScope; - public controller: ExpectedArtifactSelectorViewController; - public delegate: NgBakeManifestArtifactDelegate; - public id: string; - public account: string; - - constructor($scope: IScope, artifact = { id: '', account: '' }) { - const unserializable = { configurable: false, enumerable: false, writable: false }; - Object.defineProperty(this, '$scope', { ...unserializable, value: $scope }); - const delegate = new NgBakeManifestArtifactDelegate(this); - const controller = new ExpectedArtifactSelectorViewController(delegate); - Object.defineProperty(this, 'delegate', { ...unserializable, value: delegate }); - Object.defineProperty(this, 'controller', { ...unserializable, value: controller }); - this.id = artifact.id; - this.account = artifact.account; - } -} diff --git a/app/scripts/modules/core/src/pipeline/config/triggers/artifacts/custom/CustomArtifactEditor.tsx b/app/scripts/modules/core/src/pipeline/config/triggers/artifacts/custom/CustomArtifactEditor.tsx index a8149f5531b..2e64f6e061d 100644 --- a/app/scripts/modules/core/src/pipeline/config/triggers/artifacts/custom/CustomArtifactEditor.tsx +++ b/app/scripts/modules/core/src/pipeline/config/triggers/artifacts/custom/CustomArtifactEditor.tsx @@ -2,14 +2,6 @@ import * as React from 'react'; import { isFinite } from 'lodash'; import { IArtifact, IArtifactEditorProps } from 'core/domain'; -export const CustomArtifactEditor = (props: IArtifactEditorProps) => { - if (props.singleColumn) { - return SingleColumnCustomArtifactEditor(props); - } else { - return MultiColumnCustomArtifactEditor(props); - } -}; - const input = (artifact: IArtifact, field: keyof IArtifact, onChange: (a: IArtifact) => void) => ( { ); }; + +export const CustomArtifactEditor = (props: IArtifactEditorProps) => { + if (props.singleColumn) { + return SingleColumnCustomArtifactEditor(props); + } else { + return MultiColumnCustomArtifactEditor(props); + } +}; diff --git a/app/scripts/modules/core/src/presentation/forms/inputs/expression/spel2js.templateParser.ts b/app/scripts/modules/core/src/presentation/forms/inputs/expression/spel2js.templateParser.ts index 9a158f0dbcc..2940a0a72f2 100644 --- a/app/scripts/modules/core/src/presentation/forms/inputs/expression/spel2js.templateParser.ts +++ b/app/scripts/modules/core/src/presentation/forms/inputs/expression/spel2js.templateParser.ts @@ -1,25 +1,5 @@ import * as spel2js from 'spel2js'; -export function parseSpelExpressions(template: string): spel2js.SpelExpression[] { - const spelExpressions = new TemplateAwareExpressionParser().parseExpressions(template); - - // A Monkey patch which adds the current context when an exception occurs - spelExpressions.forEach(expr => { - const getValue = expr._compiledExpression.getValue; - expr._compiledExpression.getValue = function() { - const state = arguments[0]; - try { - return getValue.apply(expr._compiledExpression, arguments); - } catch (err) { - err.state = state; - throw err; - } - }; - }); - - return spelExpressions; -} - const literalExpression = (literalString: string) => spel2js.SpelExpressionEvaluator.compile(`'${literalString.replace(/'/g, "''")}'`); @@ -218,13 +198,7 @@ class TemplateAwareExpressionParser { case ')': { if (!stack.length) { throw new Error( - "Found closing '" + - ch + - "' at position " + - pos + - " without an opening '" + - Bracket.theOpenBracketFor(ch) + - "'", + `Found closing '${ch}' at position ${pos} without an opening '${Bracket.theOpenBracketFor(ch)}'`, ); } @@ -268,3 +242,23 @@ class TemplateAwareExpressionParser { return pos; } } + +export function parseSpelExpressions(template: string): spel2js.SpelExpression[] { + const spelExpressions = new TemplateAwareExpressionParser().parseExpressions(template); + + // A Monkey patch which adds the current context when an exception occurs + spelExpressions.forEach(expr => { + const getValue = expr._compiledExpression.getValue; + expr._compiledExpression.getValue = function() { + const state = arguments[0]; + try { + return getValue.apply(expr._compiledExpression, arguments); + } catch (err) { + err.state = state; + throw err; + } + }; + }); + + return spelExpressions; +} diff --git a/app/scripts/modules/core/src/presentation/forms/validation/validation.ts b/app/scripts/modules/core/src/presentation/forms/validation/validation.ts index ea08493bf86..443906f64d8 100644 --- a/app/scripts/modules/core/src/presentation/forms/validation/validation.ts +++ b/app/scripts/modules/core/src/presentation/forms/validation/validation.ts @@ -74,6 +74,35 @@ const isError = (maybeError: any): boolean => { return !!maybeError; }; +const createItemBuilder = (arrayBuilder: IValidationBuilder, index: number): IArrayItemValidationBuilder => { + return { + item(itemLabel) { + return arrayBuilder.field(`[${index}]`, itemLabel); + }, + field(name, itemLabel) { + return arrayBuilder.field(`[${index}].${name}`, itemLabel); + }, + result: arrayBuilder.result, + arrayForEach: arrayBuilder.arrayForEach, + }; +}; + +// Utility to provide a builder for array items. The provided iteratee will be invoked for every array item. +const arrayForEach = (builder: (values: any) => IValidationBuilder, iteratee: IArrayItemValidator) => { + return (array: any[], arrayLabel?: string) => { + // Silently ignore non-arrays (usually undefined). If strict type checking is desired, it should be done by a previous validator. + if (!Array.isArray(array)) { + return false; + } + const arrayBuilder = builder(array); + array.forEach((item: any, index: number) => { + const itemBuilder = createItemBuilder(arrayBuilder, index); + iteratee && iteratee(itemBuilder, item, index, array, arrayLabel); + }); + return arrayBuilder.result(); + }; +}; + const buildValidatorsSync = (values: any): IValidationBuilder => { const isArray = Array.isArray(values); const synchronousErrors: INamedValidatorResult[] = []; @@ -165,35 +194,6 @@ export const buildValidators = (values: any, async?: boolean): IValidationBuilde return async ? buildValidatorsAsync(values) : buildValidatorsSync(values); }; -const createItemBuilder = (arrayBuilder: IValidationBuilder, index: number): IArrayItemValidationBuilder => { - return { - item(itemLabel) { - return arrayBuilder.field(`[${index}]`, itemLabel); - }, - field(name, itemLabel) { - return arrayBuilder.field(`[${index}].${name}`, itemLabel); - }, - result: arrayBuilder.result, - arrayForEach: arrayBuilder.arrayForEach, - }; -}; - -// Utility to provide a builder for array items. The provided iteratee will be invoked for every array item. -const arrayForEach = (builder: (values: any) => IValidationBuilder, iteratee: IArrayItemValidator) => { - return (array: any[], arrayLabel?: string) => { - // Silently ignore non-arrays (usually undefined). If strict type checking is desired, it should be done by a previous validator. - if (!Array.isArray(array)) { - return false; - } - const arrayBuilder = builder(array); - array.forEach((item: any, index: number) => { - const itemBuilder = createItemBuilder(arrayBuilder, index); - iteratee && iteratee(itemBuilder, item, index, array, arrayLabel); - }); - return arrayBuilder.result(); - }; -}; - export const composeValidators = (validators: IValidator[]): IValidator => { const validatorList = validators.filter(x => !!x); if (!validatorList.length) {