2022-03-11 10:53:32 -08:00
|
|
|
import { Component, EventEmitter, Input, Output } from '@angular/core'
|
|
|
|
|
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
|
2022-12-08 02:03:50 -08:00
|
|
|
import { interval, Subject, take } from 'rxjs'
|
2020-10-27 01:10:18 +01:00
|
|
|
|
|
|
|
|
@Component({
|
2020-12-13 14:28:37 +01:00
|
|
|
selector: 'app-confirm-dialog',
|
|
|
|
|
templateUrl: './confirm-dialog.component.html',
|
2022-03-11 10:53:32 -08:00
|
|
|
styleUrls: ['./confirm-dialog.component.scss'],
|
2020-10-27 01:10:18 +01:00
|
|
|
})
|
2022-02-15 23:43:02 -08:00
|
|
|
export class ConfirmDialogComponent {
|
2022-03-11 10:53:32 -08:00
|
|
|
constructor(public activeModal: NgbActiveModal) {}
|
2021-01-25 23:32:02 -08:00
|
|
|
|
2020-10-27 01:10:18 +01:00
|
|
|
@Output()
|
2020-12-13 14:28:37 +01:00
|
|
|
public confirmClicked = new EventEmitter()
|
2020-10-27 01:10:18 +01:00
|
|
|
|
2022-10-29 23:14:33 -07:00
|
|
|
@Output()
|
|
|
|
|
public alternativeClicked = new EventEmitter()
|
|
|
|
|
|
2020-10-27 01:10:18 +01:00
|
|
|
@Input()
|
2020-12-28 15:39:53 +01:00
|
|
|
title = $localize`Confirmation`
|
2020-10-27 01:10:18 +01:00
|
|
|
|
|
|
|
|
@Input()
|
2020-12-13 14:28:37 +01:00
|
|
|
messageBold
|
2020-10-27 01:10:18 +01:00
|
|
|
|
|
|
|
|
@Input()
|
2020-12-13 14:28:37 +01:00
|
|
|
message
|
2020-10-27 01:10:18 +01:00
|
|
|
|
2020-12-13 14:28:37 +01:00
|
|
|
@Input()
|
2022-03-11 10:53:32 -08:00
|
|
|
btnClass = 'btn-primary'
|
2020-12-13 14:28:37 +01:00
|
|
|
|
|
|
|
|
@Input()
|
2020-12-28 15:39:53 +01:00
|
|
|
btnCaption = $localize`Confirm`
|
2020-12-13 14:28:37 +01:00
|
|
|
|
2022-10-29 23:14:33 -07:00
|
|
|
@Input()
|
|
|
|
|
alternativeBtnClass = 'btn-secondary'
|
|
|
|
|
|
|
|
|
|
@Input()
|
|
|
|
|
alternativeBtnCaption
|
|
|
|
|
|
2021-01-03 21:44:53 +01:00
|
|
|
@Input()
|
|
|
|
|
buttonsEnabled = true
|
2021-01-25 22:44:26 -08:00
|
|
|
|
2020-12-13 15:13:43 +01:00
|
|
|
confirmButtonEnabled = true
|
2022-10-29 23:14:33 -07:00
|
|
|
alternativeButtonEnabled = true
|
2020-12-11 14:47:33 +01:00
|
|
|
seconds = 0
|
2022-03-16 13:17:08 -07:00
|
|
|
secondsTotal = 0
|
2020-12-11 14:47:33 +01:00
|
|
|
|
2022-02-15 23:43:02 -08:00
|
|
|
confirmSubject: Subject<boolean>
|
2022-10-29 23:14:33 -07:00
|
|
|
alternativeSubject: Subject<boolean>
|
2021-01-25 22:44:26 -08:00
|
|
|
|
2020-12-11 14:47:33 +01:00
|
|
|
delayConfirm(seconds: number) {
|
2022-03-16 13:17:08 -07:00
|
|
|
const refreshInterval = 0.15 // s
|
|
|
|
|
|
|
|
|
|
this.secondsTotal = seconds
|
2020-12-11 14:47:33 +01:00
|
|
|
this.seconds = seconds
|
2022-03-16 13:17:08 -07:00
|
|
|
|
|
|
|
|
interval(refreshInterval * 1000)
|
|
|
|
|
.pipe(
|
|
|
|
|
take(this.secondsTotal / refreshInterval + 2) // need 2 more for animation to complete after 0
|
|
|
|
|
)
|
|
|
|
|
.subscribe((count) => {
|
|
|
|
|
this.seconds = Math.max(
|
|
|
|
|
0,
|
|
|
|
|
this.secondsTotal - refreshInterval * (count + 1)
|
|
|
|
|
)
|
|
|
|
|
this.confirmButtonEnabled =
|
|
|
|
|
this.secondsTotal - refreshInterval * count < 0
|
|
|
|
|
})
|
2020-12-11 14:47:33 +01:00
|
|
|
}
|
|
|
|
|
|
2021-01-25 22:44:26 -08:00
|
|
|
cancel() {
|
2022-02-15 23:43:02 -08:00
|
|
|
this.confirmSubject?.next(false)
|
|
|
|
|
this.confirmSubject?.complete()
|
2020-10-27 01:10:18 +01:00
|
|
|
this.activeModal.close()
|
|
|
|
|
}
|
2021-01-25 22:44:26 -08:00
|
|
|
|
|
|
|
|
confirm() {
|
2021-01-25 23:32:02 -08:00
|
|
|
this.confirmClicked.emit()
|
2022-02-15 23:43:02 -08:00
|
|
|
this.confirmSubject?.next(true)
|
|
|
|
|
this.confirmSubject?.complete()
|
2021-01-25 22:44:26 -08:00
|
|
|
}
|
2022-10-29 23:14:33 -07:00
|
|
|
|
|
|
|
|
alternative() {
|
|
|
|
|
this.alternativeClicked.emit()
|
|
|
|
|
this.alternativeSubject?.next(true)
|
|
|
|
|
this.alternativeSubject?.complete()
|
|
|
|
|
}
|
2020-10-27 01:10:18 +01:00
|
|
|
}
|