Skip to content

Commit

Permalink
Merged in bugfix/SHIBUI-381 (pull request #12)
Browse files Browse the repository at this point in the history
Bugfix/SHIBUI-381

* SHIBUI-381: Fixed error with null or undefined string

* Cleanup: moved lists to single reference

Approved-by: Ryan Mathis <rmathis@unicon.net>
  • Loading branch information
rmathis committed Mar 13, 2018
1 parent aeb5a4c commit e7a8ec1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
aria-label="Information icon - press spacebar to read additional information for this form field"></i>
</span>
</div>
<div *ngIf="nameIdFormats.length" class="p-2">
<div class="row" *ngFor="let format of nameIdFormats.controls; let i=index; let isLast=last">
<div *ngIf="nameIdFormatList.length" class="p-2">
<div class="row" *ngFor="let format of nameIdFormatList.controls; let i=index; let isLast=last">
<label [for]="'nameIdFormat-' + i" class="col-sm-12" i18n="@@label--nameid-format-indexed">NameID Format {{ i + 1 }}</label>
<auto-complete
[id]="'nameIdFormat-' + i"
Expand Down Expand Up @@ -100,8 +100,8 @@
aria-label="Information icon - press spacebar to read additional information for this form field"></i>
</span>
</div>
<div *ngIf="authenticationMethods.length" class="p-2">
<div class="row" *ngFor="let format of authenticationMethods.controls; let i=index; let isLast=last">
<div *ngIf="authenticationMethodList.length" class="p-2">
<div class="row" *ngFor="let format of authenticationMethodList.controls; let i=index; let isLast=last">
<label [for]="'authMethod-' + i" class="col-sm-12" i18n="@@label--auth-method-indexed">Authentication Method {{ i + 1 }}</label>
<auto-complete
[id]="'authMethod-' + i"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ describe('Relying Party Form Component', () => {
fixture.detectChanges();
form.removeFormat(0);
fixture.detectChanges();
expect(form.nameIdFormats.length).toBe(0);
expect(form.nameIdFormatList.length).toBe(0);
});
});

describe('addFormat method', () => {
it('should add a new nameid format', () => {
form.addFormat();
fixture.detectChanges();
expect(form.nameIdFormats.length).toBe(1);
expect(form.nameIdFormatList.length).toBe(1);
});
});

Expand All @@ -104,15 +104,15 @@ describe('Relying Party Form Component', () => {
fixture.detectChanges();
form.removeAuthenticationMethod(0);
fixture.detectChanges();
expect(form.authenticationMethods.length).toBe(0);
expect(form.authenticationMethodList.length).toBe(0);
});
});

describe('addAuthenticationMethod method', () => {
it('should add a new auth method', () => {
form.addAuthenticationMethod();
fixture.detectChanges();
expect(form.authenticationMethods.length).toBe(1);
expect(form.authenticationMethodList.length).toBe(1);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export class RelyingPartyFormComponent extends ProviderFormFragmentComponent imp
nameIdFormatOptions = this.listValues.nameIdFormats;
authenticationMethodOptions = this.listValues.authenticationMethods;

nameIdFormatList: FormArray;
authenticationMethodList: FormArray;

constructor(
protected fb: FormBuilder,
protected statusEmitter: ProviderStatusEmitter,
Expand All @@ -31,7 +34,13 @@ export class RelyingPartyFormComponent extends ProviderFormFragmentComponent imp
super(fb, statusEmitter, valueEmitter);
}

ngOnInit(): void {
super.ngOnInit();
}

createForm(): void {
this.nameIdFormatList = this.fb.array([]);
this.authenticationMethodList = this.fb.array([]);
this.form = this.fb.group({
relyingPartyOverrides: this.fb.group({
signAssertion: false,
Expand All @@ -41,50 +50,39 @@ export class RelyingPartyFormComponent extends ProviderFormFragmentComponent imp
ignoreAuthenticationMethod: false,
omitNotBefore: false,
responderId: '',
nameIdFormats: this.fb.array([]),
authenticationMethods: this.fb.array([])
nameIdFormats: this.nameIdFormatList,
authenticationMethods: this.authenticationMethodList
})
});
}

getRequiredControl = (value: string): FormControl => this.fb.control(value, Validators.required);

setNameIdFormats(nameIdFormats: string[] = []): void {
let fcs = nameIdFormats.map(this.getRequiredControl),
list = this.fb.array(fcs),
group = this.form.get('relyingPartyOverrides') as FormGroup;
group.setControl('nameIdFormats', list);
let fcs = nameIdFormats.map(this.getRequiredControl);
fcs.forEach(ctrl => this.nameIdFormatList.push(ctrl));
}

setAuthenticationMethods(methods: string[] = []): void {
let fcs = methods.map(this.getRequiredControl),
list = this.fb.array(fcs),
group = this.form.get('relyingPartyOverrides') as FormGroup;
group.setControl('authenticationMethods', list);
}

get nameIdFormats(): FormArray {
return this.form.get('relyingPartyOverrides.nameIdFormats') as FormArray;
}

get authenticationMethods(): FormArray {
return this.form.get('relyingPartyOverrides.authenticationMethods') as FormArray;
let fcs = methods.map(this.getRequiredControl);
fcs.forEach(ctrl => this.authenticationMethodList.push(ctrl));
}

addFormat(text: string = ''): void {
this.nameIdFormats.push(this.fb.control(text, Validators.required));
this.nameIdFormatList.push(this.getRequiredControl(text));
}

addAuthenticationMethod(text: string = ''): void {
this.authenticationMethods.push(this.fb.control(text, Validators.required));
console.log(this.authenticationMethodList as FormArray);
this.authenticationMethodList.push(this.getRequiredControl(text));
}

removeFormat(index: number): void {
this.nameIdFormats.removeAt(index);
this.nameIdFormatList.removeAt(index);
}

removeAuthenticationMethod(index: number): void {
this.authenticationMethods.removeAt(index);
this.authenticationMethodList.removeAt(index);
}

ngOnChanges(): void {
Expand Down
1 change: 1 addition & 0 deletions ui/src/app/widget/autocomplete/autocomplete.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export class AutoCompleteComponent implements OnInit, OnDestroy, OnChanges, Afte
}

handleInputChange(query: string): void {
query = query || '';
const queryEmpty = query.length === 0;
const queryChanged = this.state.currentState.query.length !== query.length;
const queryLongEnough = query.length >= MIN_LENGTH;
Expand Down

0 comments on commit e7a8ec1

Please sign in to comment.