-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make it so you can go to /origins/x to view that origin (doesn't check for existence or permissions yet) * Very basic validation of key pasting (but you can't save yet) * Remove some logic around "default origin" that's not being used * Fix test runner to use correct loader Signed-off-by: Nathan L Smith <[email protected]> Pull request: #674 Approved by: reset
- Loading branch information
Nathan L Smith
authored and
jtimberman
committed
Jun 12, 2016
1 parent
ab3e7bc
commit 95f535b
Showing
13 changed files
with
420 additions
and
27 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
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
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
103 changes: 103 additions & 0 deletions
103
components/builder-web/app/origin-page/KeyAddFormComponent.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,103 @@ | ||
// Copyright:: Copyright (c) 2016 The Habitat Maintainers | ||
// | ||
// The terms of the Evaluation Agreement (Habitat) between Chef Software Inc. | ||
// and the party accessing this file ("Licensee") apply to Licensee's use of | ||
// the Software until such time that the Software is made available under an | ||
// open source license such as the Apache 2.0 License. | ||
|
||
import {Component, Input, OnInit} from "angular2/core"; | ||
import {Control, ControlGroup, FormBuilder, Validators} from "angular2/common"; | ||
import {parseKey} from "../util"; | ||
|
||
@Component({ | ||
selector: "hab-key-add-form", | ||
template: ` | ||
<form class="hab-key-add-form" [ngFormModel]="form" #formValues="ngForm"> | ||
<a class="hab-key-add-form--close" href="#" (click)="onCloseClick()"> | ||
Close | ||
</a> | ||
<label class="hab-key-add-form--label" for="key">Key</label> | ||
<small> | ||
Paste your key here. Check the documentation for a guide on | ||
<a href="{{docsUrl}}/concepts-keys/"> | ||
generating keys</a>. | ||
</small> | ||
<textarea | ||
autofocus | ||
name="key" | ||
[ngFormControl]="form.controls['key']" | ||
placeholder="Begins with '{{keyFileHeaderPrefix}}'" | ||
rows=6></textarea> | ||
<div class="hab-key-add-form--submit"> | ||
<button class="hab-key-add-form--save" [disabled]="!form.valid"> | ||
Save Key | ||
</button> | ||
<div *ngIf="control.dirty && control.errors" class="hab-key-add-form--errors"> | ||
<span *ngIf="control.errors.required"> | ||
A value is required. | ||
</span> | ||
<span *ngIf="control.errors.invalidFormat"> | ||
This is not a valid key format. | ||
</span> | ||
<span *ngIf="control.errors.invalidType"> | ||
Key must begin with '{{keyFileHeaderPrefix}}'. | ||
</span> | ||
<span *ngIf="control.errors.invalidOrigin"> | ||
Key origin must match '{{originName}}'. | ||
</span> | ||
</div> | ||
</div> | ||
</form>`, | ||
}) | ||
|
||
export class KeyAddFormComponent implements OnInit { | ||
@Input() docsUrl: String; | ||
@Input() keyFileHeaderPrefix: String; | ||
@Input() onCloseClick: Function; | ||
@Input() originName: String; | ||
|
||
private form: ControlGroup; | ||
private control: Control; | ||
|
||
constructor(private formBuilder: FormBuilder) { | ||
this.form = formBuilder.group({}); | ||
} | ||
|
||
private keyFormatValidator(control) { | ||
if (parseKey(control.value).valid) { | ||
return null; | ||
} else { | ||
return { invalidFormat: true }; | ||
} | ||
} | ||
|
||
private keyTypeValidator(control) { | ||
if (parseKey(control.value).type === this.keyFileHeaderPrefix) { | ||
return null; | ||
} else { | ||
return { invalidType: true }; | ||
} | ||
} | ||
|
||
private originMatchValidator(control) { | ||
if (parseKey(control.value).origin === this.originName) { | ||
return null; | ||
} else { | ||
return { invalidOrigin: true }; | ||
} | ||
} | ||
|
||
public ngOnInit() { | ||
this.control = new Control( | ||
"", | ||
Validators.compose([ | ||
Validators.required, | ||
this.keyFormatValidator, | ||
this.keyTypeValidator.bind(this), | ||
this.originMatchValidator.bind(this), | ||
]) | ||
); | ||
|
||
this.form.addControl("key", this.control); | ||
} | ||
} |
Oops, something went wrong.