Skip to content

Commit

Permalink
chore(core/help): make help field work in ng2
Browse files Browse the repository at this point in the history
* add code to make the help field component work in ng2 components.
* create framework for wiring in upgraded ng1 components.
  • Loading branch information
icfantv committed Mar 17, 2017
1 parent 6aa2123 commit 4b52f70
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 8 deletions.
5 changes: 3 additions & 2 deletions app/scripts/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {BrowserModule} from '@angular/platform-browser';
import {UpgradeModule, downgradeInjectable, downgradeComponent} from '@angular/upgrade/static';
declare let angular: any;

import {SPINNAKER_DOWNGRADES, SPINNAKER_COMPONENT_DOWNGRADES} from './modules';
import {SPINNAKER_DOWNGRADES, SPINNAKER_COMPONENT_DOWNGRADES, SPINNAKER_DIRECTIVE_UPGRADES} from './modules';

const providers: Type<any>[] = [];
export const DOWNGRADED_MODULE_NAMES: string[] = [];
Expand Down Expand Up @@ -39,7 +39,8 @@ SPINNAKER_COMPONENT_DOWNGRADES.forEach((item) => {
UpgradeModule
],
declarations: [
...declarations
...declarations,
...SPINNAKER_DIRECTIVE_UPGRADES
],
entryComponents: [
...declarations
Expand Down
37 changes: 35 additions & 2 deletions app/scripts/modules/core/help/helpField.component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Directive, ElementRef, Injector, Input} from '@angular/core';
import {UpgradeComponent} from '@angular/upgrade/static';
import {module} from 'angular';

import {HELP_CONTENTS_REGISTRY, HelpContentsRegistry} from './helpContents.registry';
Expand All @@ -22,7 +24,9 @@ class HelpFieldCtrl implements ng.IComponentController {
private popoverShownStart: number;
private popoverClose: ng.IPromise<void>;

static get $inject() { return ['$timeout', '$analytics', 'helpContents', 'helpContentsRegistry']; }
static get $inject() {
return ['$timeout', '$analytics', 'helpContents', 'helpContentsRegistry'];
}

constructor(private $timeout: ng.ITimeoutService,
private $analytics: any,
Expand Down Expand Up @@ -120,9 +124,38 @@ class HelpFieldComponent implements ng.IComponentOptions {
`;
}

const selector = 'helpField';
export const HELP_FIELD_COMPONENT = 'spinnaker.core.help.helpField.component';
module(HELP_FIELD_COMPONENT, [
HELP_CONTENTS_REGISTRY,
require('./helpContents'),
require('angulartics'),
]).component('helpField', new HelpFieldComponent());
]).component(selector, new HelpFieldComponent());

@Directive({
selector: 'help-field'
})
export class HelpFieldComponentDirective extends UpgradeComponent {

@Input()
public key: string;

@Input()
public fallback: string;

@Input()
public content: string;

@Input()
public placement: string;

@Input()
public expand: boolean;

@Input()
public label: string;

constructor(elementRef: ElementRef, injector: Injector) {
super(selector, elementRef, injector);
}
}
7 changes: 7 additions & 0 deletions app/scripts/modules/core/help/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {Type} from '@angular/core';

import {HelpFieldComponentDirective} from './helpField.component';

export const HELP_DIRECTIVE_UPGRADES: Type<any>[] = [
HelpFieldComponentDirective
];
9 changes: 8 additions & 1 deletion app/scripts/modules/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import {Type} from '@angular/core';

import {IDowngradeItem} from 'core/domain/IDowngradeItem';
import {AUTHENTICATION_MODULE_DOWNGRADES} from './authentication';
import {UPGRADE_MODULE_DOWNGRADES} from './upgrade';
import {HELP_DIRECTIVE_UPGRADES} from './help';
import {MODAL_COMPONENT_MODULE_DOWNGRADES} from './modal';
import {UPGRADE_MODULE_DOWNGRADES} from './upgrade';

export const CORE_MODULE_DOWNGRADES: IDowngradeItem[] = [
...AUTHENTICATION_MODULE_DOWNGRADES,
Expand All @@ -11,3 +14,7 @@ export const CORE_MODULE_DOWNGRADES: IDowngradeItem[] = [
export const CORE_COMPONENT_MODULE_DOWNGRADES: IDowngradeItem[] = [
...MODAL_COMPONENT_MODULE_DOWNGRADES
];

export const CORE_DIRECTIVE_UPGRADES: Type<any>[] = [
...HELP_DIRECTIVE_UPGRADES
];
10 changes: 8 additions & 2 deletions app/scripts/modules/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import {Type} from '@angular/core';

import {IDowngradeItem} from 'core/domain/IDowngradeItem';
import {CORE_MODULE_DOWNGRADES, CORE_COMPONENT_MODULE_DOWNGRADES} from './core';
import {CORE_MODULE_DOWNGRADES, CORE_COMPONENT_MODULE_DOWNGRADES, CORE_DIRECTIVE_UPGRADES} from './core';

export const SPINNAKER_DOWNGRADES: IDowngradeItem[] = [
...CORE_MODULE_DOWNGRADES
];

export const SPINNAKER_COMPONENT_DOWNGRADES: IDowngradeItem[] = [
...CORE_COMPONENT_MODULE_DOWNGRADES
...CORE_COMPONENT_MODULE_DOWNGRADES,
];

export const SPINNAKER_DIRECTIVE_UPGRADES: Type<any>[] = [
...CORE_DIRECTIVE_UPGRADES
];
2 changes: 1 addition & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"check-type"
],
"directive-selector": [
true,
false,
"attribute",
"deck",
"camelCase"
Expand Down

0 comments on commit 4b52f70

Please sign in to comment.