mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-04 14:29:45 +00:00
rename frontend to web
This commit is contained in:
41
web/projects/ui/src/app/services/form-dialog.service.ts
Normal file
41
web/projects/ui/src/app/services/form-dialog.service.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { inject, Injectable, Injector, Type } from '@angular/core'
|
||||
import { TuiDialogOptions, TuiDialogService } from '@taiga-ui/core'
|
||||
import { TuiDialogFormService, TuiPromptData } from '@taiga-ui/kit'
|
||||
import { PolymorpheusComponent } from '@tinkoff/ng-polymorpheus'
|
||||
|
||||
const PROMPT: Partial<TuiDialogOptions<TuiPromptData>> = {
|
||||
label: 'Unsaved Changes',
|
||||
data: {
|
||||
content: 'You have unsaved changes. Are you sure you want to leave?',
|
||||
yes: 'Leave',
|
||||
no: 'Cancel',
|
||||
},
|
||||
}
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class FormDialogService {
|
||||
private readonly dialogs = inject(TuiDialogService)
|
||||
private readonly formService = new TuiDialogFormService(this.dialogs)
|
||||
private readonly prompt = this.formService.withPrompt(PROMPT)
|
||||
private readonly injector = Injector.create({
|
||||
parent: inject(Injector),
|
||||
providers: [
|
||||
{
|
||||
provide: TuiDialogFormService,
|
||||
useValue: this.formService,
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
open<T>(component: Type<any>, options: Partial<TuiDialogOptions<T>> = {}) {
|
||||
this.dialogs
|
||||
.open(new PolymorpheusComponent(component, this.injector), {
|
||||
closeable: this.prompt,
|
||||
dismissible: this.prompt,
|
||||
...options,
|
||||
})
|
||||
.subscribe({
|
||||
complete: () => this.formService.markAsPristine(),
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user