This repository has been archived by the owner on Jul 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: introduced lower case directive
- Loading branch information
Showing
5 changed files
with
37 additions
and
26 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
15 changes: 15 additions & 0 deletions
15
src/app/launcher/create-app/gitprovider-createapp-step/gitprovider-lowercase.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 { Directive, EventEmitter, HostListener, Output } from '@angular/core'; | ||
|
||
@Directive({ | ||
selector: '[ngModel][lowercase]' | ||
}) | ||
export class LowerCaseDirective { | ||
@Output() ngModelChange: EventEmitter<any> = new EventEmitter(); | ||
value: any; | ||
|
||
@HostListener('input', ['$event']) | ||
onInputChange($event: any) { | ||
this.value = $event.target.value.toLowerCase(); | ||
this.ngModelChange.emit(this.value); | ||
} | ||
} |
27 changes: 12 additions & 15 deletions
27
src/app/launcher/create-app/gitprovider-createapp-step/gitprovider-repository.validator.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,41 +1,38 @@ | ||
import { Directive } from '@angular/core'; | ||
import { Directive, forwardRef } from '@angular/core'; | ||
import { NG_ASYNC_VALIDATORS, Validator, ValidatorFn, AbstractControl } from '@angular/forms'; | ||
import { Observable } from 'rxjs'; | ||
|
||
import { GitProviderService } from '../../service/git-provider.service'; | ||
|
||
@Directive({ | ||
selector: '[validateRepository]', | ||
providers: [{provide: NG_ASYNC_VALIDATORS, useExisting: GitProviderRepositoryValidatorDirective, multi: true}] | ||
providers: [{ provide: NG_ASYNC_VALIDATORS, useExisting: | ||
forwardRef(() => GitProviderRepositoryValidatorDirective), multi: true }] | ||
}) | ||
export class GitProviderRepositoryValidatorDirective implements Validator { | ||
private pattern = /^[a-zA-Z0-9][a-zA-Z0-9-._]{1,63}$/; | ||
|
||
constructor(private gitProvider: GitProviderService) {} | ||
constructor(private gitProvider: GitProviderService) { } | ||
|
||
validate( control : AbstractControl ) : Observable<{[key : string] : any}> { | ||
return Observable.timer(500).switchMap(()=>{ | ||
return this.validRepositoryName(control) | ||
.mapTo(null) | ||
.catch(err=>Observable.of({availability: true})); | ||
}); | ||
validate(control: AbstractControl): Observable<{ [key: string]: any }> { | ||
return this.validRepositoryName(control).debounceTime(500).distinctUntilChanged().first(); | ||
} | ||
|
||
validRepositoryName(control: AbstractControl): Observable<{[key : string] : any}> { | ||
validRepositoryName(control: AbstractControl): Observable<{ [key: string]: any }> { | ||
return new Observable((resolve) => { | ||
const valid = this.pattern.test(control.value); | ||
const org = control.parent.get("ghOrg").value; | ||
const org = control.parent.get('ghOrg').value; | ||
if (!valid) { | ||
resolve.next(this.createError(control.value, 'pattern', valid)); | ||
resolve.next(this.createError('pattern', control.value)); | ||
} else if (org) { | ||
this.gitProvider.isGitHubRepo(org, control.value).subscribe( | ||
duplicate => resolve.next(this.createError(control.value, 'duplicate', !duplicate)) | ||
duplicate => resolve.next(duplicate ? this.createError('duplicate', control.value) : {}) | ||
); | ||
} | ||
}); | ||
} | ||
|
||
private createError(value: any, key: string, valid: boolean): any { | ||
return valid ? null : {[key]: {value: value}}; | ||
private createError(key: string, value: any): any { | ||
return { [key]: { value: value } }; | ||
} | ||
} |
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