-
Notifications
You must be signed in to change notification settings - Fork 906
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(artifact): Custom artifact helpers
- Loading branch information
Lars Wander
committed
Oct 14, 2017
1 parent
180fa94
commit 7fd7653
Showing
13 changed files
with
252 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export interface IArtifact { | ||
kind: string; // json model only | ||
type: string; | ||
name: string; | ||
version: string; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export interface IArtifactKindConfig { | ||
label: string; | ||
description: string; | ||
key: string; | ||
template: string; | ||
controller: string; | ||
controllerAs?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 76 additions & 12 deletions
88
app/scripts/modules/core/src/pipeline/config/triggers/artifacts/artifact.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,84 @@ | ||
import { IComponentController, IComponentOptions, module } from 'angular'; | ||
import { | ||
ICompileService, | ||
IComponentOptions, | ||
IController, | ||
IControllerService, | ||
IRootElementService, | ||
IRootScopeService, | ||
module | ||
} from 'angular'; | ||
import { IArtifact, IArtifactKindConfig } from 'core/domain'; | ||
import { PipelineConfigProvider } from 'core/pipeline'; | ||
|
||
import { PIPELINE_CONFIG_PROVIDER } from 'core/pipeline/config/pipelineConfigProvider'; | ||
import { IArtifact } from 'core/domain/IArtifact'; | ||
|
||
class ArtifactController implements IComponentController { | ||
class ArtifactCtrl implements IController { | ||
public artifact: IArtifact; | ||
public options: IArtifactKindConfig[]; | ||
public description: string; | ||
|
||
constructor(private pipelineConfig: PipelineConfigProvider, | ||
private $controller: IControllerService, | ||
private $compile: ICompileService, | ||
private $element: IRootElementService, | ||
private $rootScope: IRootScopeService) { | ||
'nginject'; | ||
this.options = this.pipelineConfig.getArtifactKinds(); | ||
this.loadArtifactKind(); | ||
} | ||
|
||
public loadArtifactKind(): void { | ||
const kind = this.artifact.kind; | ||
if (!kind) { | ||
return; | ||
} | ||
const triggerConfig = this.options.filter(function(config) { | ||
return config.key === kind; | ||
}); | ||
|
||
if (triggerConfig.length) { | ||
const config = triggerConfig[0]; | ||
const template: Element = config.template as any; | ||
this.description = config.description; | ||
|
||
const ctrl = config.controller; | ||
const controller = this.$controller(ctrl, {artifact: this.artifact}); | ||
(controller as any).onInit(); | ||
const scope = this.$rootScope.$new(); | ||
scope[config.controllerAs] = controller; | ||
|
||
const templateBody = this.$compile(template)(scope) as any; | ||
this.$element.find('.artifact-body').html(templateBody); | ||
} | ||
} | ||
} | ||
|
||
class ArtifactComponent implements IComponentOptions { | ||
public bindings = { artifact: '=' }; | ||
public templateUrl = require('./artifact.html'); | ||
public controller = ArtifactController; | ||
public bindings: any = {artifact: '='}; | ||
public controller: any = ArtifactCtrl; | ||
public controllerAs = 'ctrl'; | ||
public template = ` | ||
<div class="form-group"> | ||
<div class="col-md-2 col-md-offset-1"> | ||
<select class="input-sm" | ||
required | ||
ng-change="ctrl.loadArtifactKind()" | ||
ng-options="option.key as option.label for option in ctrl.options" | ||
ng-model="ctrl.artifact.kind"> | ||
<option style="display:none" value="">Select a kind</option> | ||
</select> | ||
</div> | ||
<div class="col-md-9"> | ||
{{ctrl.description}} | ||
</div> | ||
</div> | ||
<hr> | ||
<div class="form-group"> | ||
<div class="col-md-12"> | ||
<div class="artifact-body"></div> | ||
</div> | ||
</div> | ||
`; | ||
} | ||
|
||
export const ARTIFACT = 'spinnaker.core.pipeline.trigger.artifact'; | ||
module(ARTIFACT, [ | ||
PIPELINE_CONFIG_PROVIDER, | ||
]).component('artifact', new ArtifactComponent()); | ||
export const ARTIFACT = 'spinnaker.core.pipeline.config.trigger.artifacts.artifact'; | ||
module(ARTIFACT, []) | ||
.component('artifact', new ArtifactComponent()); |
15 changes: 15 additions & 0 deletions
15
app/scripts/modules/core/src/pipeline/config/triggers/artifacts/artifact.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { module } from 'angular'; | ||
|
||
import { EXPECTED_ARTIFACT } from './expectedArtifact.component'; | ||
import { CUSTOM_ARTIFACT } from './custom/custom.artifact'; | ||
import { GCS_ARTIFACT } from './gcs/gcs.artifact'; | ||
import { ARTIFACT } from './artifact.component'; | ||
|
||
export const ARTIFACT_MODULE = 'spinnaker.core.pipeline.config.trigger.artifacts'; | ||
|
||
module(ARTIFACT_MODULE, [ | ||
EXPECTED_ARTIFACT, | ||
CUSTOM_ARTIFACT, | ||
GCS_ARTIFACT, | ||
ARTIFACT, | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 0 additions & 43 deletions
43
app/scripts/modules/core/src/pipeline/config/triggers/artifacts/expectedArtifact.html
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.