-
Notifications
You must be signed in to change notification settings - Fork 903
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 16, 2017
1 parent
7b14c87
commit 95be870
Showing
13 changed files
with
247 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
92 changes: 80 additions & 12 deletions
92
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,88 @@ | ||
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 artifactKindConfig = this.options.filter(function(config) { | ||
return config.key === kind; | ||
}); | ||
|
||
if (artifactKindConfig.length) { | ||
const config = artifactKindConfig[0]; | ||
const template: Element = config.template as any; | ||
this.description = config.description; | ||
|
||
const ctrl = config.controller; | ||
const controller = this.$controller(ctrl, {artifact: this.artifact}); | ||
const scope = this.$rootScope.$new(); | ||
const controllerAs = config.controllerAs; | ||
if (controllerAs) { | ||
scope[config.controllerAs] = controller; | ||
} else { | ||
scope['ctrl'] = 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.
42 changes: 42 additions & 0 deletions
42
app/scripts/modules/core/src/pipeline/config/triggers/artifacts/gcs/gcs.artifact.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,42 @@ | ||
import { IController, module } from 'angular'; | ||
|
||
import { PIPELINE_CONFIG_PROVIDER } from 'core/pipeline/config/pipelineConfigProvider'; | ||
import { IArtifact } from 'core/domain/IArtifact'; | ||
import { PipelineConfigProvider } from 'core/pipeline'; | ||
|
||
class GcsArtifactController implements IController { | ||
constructor(public artifact: IArtifact) { | ||
'ngInject'; | ||
this.artifact.type = 'gcs/object'; | ||
} | ||
} | ||
|
||
export const GCS_ARTIFACT = 'spinnaker.core.pipeline.trigger.gcs.artifact'; | ||
module(GCS_ARTIFACT, [ | ||
PIPELINE_CONFIG_PROVIDER, | ||
]).config((pipelineConfigProvider: PipelineConfigProvider) => { | ||
pipelineConfigProvider.registerArtifactKind({ | ||
label: 'GCS', | ||
description: 'A GCS object.', | ||
key: 'gcs', | ||
controller: 'gcsArtifactCtrl', | ||
controllerAs: 'ctrl', | ||
template: ` | ||
<div class="col-md-12"> | ||
<div class="form-group row"> | ||
<label class="col-md-2 sm-label-right"> | ||
Object path | ||
<help-field key="pipeline.config.expectedArtifact.gcs.name"></help-field> | ||
</label> | ||
<div class="col-md-8"> | ||
<input type="text" | ||
placeholder="gs://bucket/path/to/file" | ||
class="form-control input-sm" | ||
ng-model="ctrl.artifact.name"/> | ||
</div> | ||
</div> | ||
</div> | ||
`, | ||
}); | ||
}).controller('gcsArtifactCtrl', GcsArtifactController); | ||
|
Oops, something went wrong.