-
Notifications
You must be signed in to change notification settings - Fork 903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(artifact): Custom artifact helpers #4267
Merged
+247
−69
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this show up (given
display: none
)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, but only when
ctrl.artifact.kind
is null (if someone manually edits the JSON). Otherwise it's not an option, and disappears when something is selected.