|
|
@ -6,17 +6,15 @@ |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
import { Component, EventEmitter, Input, Output } from '@angular/core'; |
|
|
import { Component, EventEmitter, Input, Output } from '@angular/core'; |
|
|
import { FormBuilder, Validators } from '@angular/forms'; |
|
|
import { FormBuilder } from '@angular/forms'; |
|
|
|
|
|
|
|
|
import { |
|
|
import { |
|
|
ApiUrlConfig, |
|
|
ApiUrlConfig, |
|
|
AppsState, |
|
|
AppsState, |
|
|
CreateAppDto, |
|
|
CreateAppDto, |
|
|
ValidatorsEx |
|
|
CreateAppForm |
|
|
} from '@app/shared/internal'; |
|
|
} from '@app/shared/internal'; |
|
|
|
|
|
|
|
|
const FALLBACK_NAME = 'my-app'; |
|
|
|
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
|
selector: 'sqx-app-form', |
|
|
selector: 'sqx-app-form', |
|
|
styleUrls: ['./app-form.component.scss'], |
|
|
styleUrls: ['./app-form.component.scss'], |
|
|
@ -29,22 +27,7 @@ export class AppFormComponent { |
|
|
@Input() |
|
|
@Input() |
|
|
public template = ''; |
|
|
public template = ''; |
|
|
|
|
|
|
|
|
public createFormError = ''; |
|
|
public createForm = new CreateAppForm(this.formBuilder); |
|
|
public createFormSubmitted = false; |
|
|
|
|
|
public createForm = |
|
|
|
|
|
this.formBuilder.group({ |
|
|
|
|
|
name: ['', |
|
|
|
|
|
[ |
|
|
|
|
|
Validators.required, |
|
|
|
|
|
Validators.maxLength(40), |
|
|
|
|
|
ValidatorsEx.pattern('[a-z0-9]+(\-[a-z0-9]+)*', 'Name can contain lower case letters (a-z), numbers and dashes (not at the end).') |
|
|
|
|
|
] |
|
|
|
|
|
] |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
public appName = |
|
|
|
|
|
this.createForm.controls['name'].valueChanges.map(n => n || FALLBACK_NAME) |
|
|
|
|
|
.startWith(FALLBACK_NAME); |
|
|
|
|
|
|
|
|
|
|
|
constructor(public readonly apiUrl: ApiUrlConfig, |
|
|
constructor(public readonly apiUrl: ApiUrlConfig, |
|
|
private readonly appsStore: AppsState, |
|
|
private readonly appsStore: AppsState, |
|
|
@ -57,25 +40,17 @@ export class AppFormComponent { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public createApp() { |
|
|
public createApp() { |
|
|
this.createFormSubmitted = true; |
|
|
const value = this.createForm.submit(); |
|
|
|
|
|
|
|
|
if (this.createForm.valid) { |
|
|
|
|
|
this.createForm.disable(); |
|
|
|
|
|
|
|
|
|
|
|
const request = new CreateAppDto(this.createForm.controls['name'].value, this.template); |
|
|
if (value) { |
|
|
|
|
|
const request = new CreateAppDto(value.name, this.template); |
|
|
|
|
|
|
|
|
this.appsStore.createApp(request) |
|
|
this.appsStore.createApp(request) |
|
|
.subscribe(dto => { |
|
|
.subscribe(dto => { |
|
|
this.complete(); |
|
|
this.complete(); |
|
|
}, error => { |
|
|
}, error => { |
|
|
this.enableCreateForm(error.displayMessage); |
|
|
this.createForm.submitFailed(error); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private enableCreateForm(message: string) { |
|
|
|
|
|
this.createForm.enable(); |
|
|
|
|
|
this.createFormSubmitted = false; |
|
|
|
|
|
this.createFormError = message; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |