Use confirm button for mail account / rule delete
This commit is contained in:
parent
3f0f89498e
commit
5bd1bf37f3
@ -32,72 +32,84 @@
|
|||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
<button *pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.MailAccount }" [disabled]="!userCanEdit(account)" class="btn btn-sm btn-outline-secondary" type="button" (click)="editMailAccount(account)">
|
<button *pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.MailAccount }" [disabled]="!userCanEdit(account)" class="btn btn-sm btn-outline-secondary" type="button" (click)="editMailAccount(account)">
|
||||||
<i-bs width="1em" height="1em" name="pencil"></i-bs> <ng-container i18n>Edit</ng-container>
|
<i-bs width="1em" height="1em" name="pencil"></i-bs> <ng-container i18n>Edit</ng-container>
|
||||||
</button>
|
</button>
|
||||||
<button *pngxIfOwner="account" class="btn btn-sm btn-outline-secondary" type="button" (click)="editPermissions(account)">
|
<button *pngxIfOwner="account" class="btn btn-sm btn-outline-secondary" type="button" (click)="editPermissions(account)">
|
||||||
<i-bs width="1em" height="1em" name="person-lock"></i-bs> <ng-container i18n>Permissions</ng-container>
|
<i-bs width="1em" height="1em" name="person-lock"></i-bs> <ng-container i18n>Permissions</ng-container>
|
||||||
</button>
|
</button>
|
||||||
<button *pngxIfPermissions="{ action: PermissionAction.Delete, type: PermissionType.MailAccount }" [disabled]="!userIsOwner(account)" class="btn btn-sm btn-outline-danger" type="button" (click)="deleteMailAccount(account)">
|
<pngx-confirm-button
|
||||||
<i-bs width="1em" height="1em" name="trash"></i-bs> <ng-container i18n>Delete</ng-container>
|
label="Delete"
|
||||||
</button>
|
i18n-label
|
||||||
</div>
|
(confirm)="deleteMailAccount(account)"
|
||||||
</div>
|
*pngxIfPermissions="{ action: PermissionAction.Delete, type: PermissionType.MailAccount }"
|
||||||
</div>
|
[disabled]="!userIsOwner(account)"
|
||||||
</li>
|
buttonClasses="btn-sm btn-outline-danger"
|
||||||
}
|
iconName="trash">
|
||||||
@if (mailAccounts.length === 0) {
|
</pngx-confirm-button>
|
||||||
<li class="list-group-item" i18n>No mail accounts defined.</li>
|
|
||||||
}
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
</ng-container>
|
|
||||||
|
|
||||||
<ng-container *pngxIfPermissions="{ action: PermissionAction.View, type: PermissionType.MailRule }">
|
|
||||||
<h4 class="mt-4">
|
|
||||||
<ng-container i18n>Mail rules</ng-container>
|
|
||||||
<button type="button" class="btn btn-sm btn-outline-primary ms-4" (click)="editMailRule()" *pngxIfPermissions="{ action: PermissionAction.Add, type: PermissionType.MailRule }">
|
|
||||||
<i-bs name="plus-circle"></i-bs> <ng-container i18n>Add Rule</ng-container>
|
|
||||||
</button>
|
|
||||||
</h4>
|
|
||||||
<ul class="list-group">
|
|
||||||
<li class="list-group-item">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col" i18n>Name</div>
|
|
||||||
<div class="col" i18n>Account</div>
|
|
||||||
<div class="col" i18n>Actions</div>
|
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
@if (mailAccounts.length === 0) {
|
||||||
|
<li class="list-group-item" i18n>No mail accounts defined.</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
|
||||||
@for (rule of mailRules; track rule) {
|
</ng-container>
|
||||||
<li class="list-group-item">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col d-flex align-items-center"><button class="btn btn-link p-0" type="button" (click)="editMailRule(rule)" [disabled]="!permissionsService.currentUserCan(PermissionAction.Change, PermissionType.MailRule)">{{rule.name}}</button></div>
|
|
||||||
<div class="col d-flex align-items-center">{{(mailAccountService.getCached(rule.account) | async)?.name}}</div>
|
|
||||||
<div class="col">
|
|
||||||
<div class="btn-group">
|
|
||||||
<button *pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.MailRule }" [disabled]="!userCanEdit(rule)" class="btn btn-sm btn-outline-secondary" type="button" (click)="editMailRule(rule)">
|
|
||||||
<i-bs width="1em" height="1em" name="pencil"></i-bs> <ng-container i18n>Edit</ng-container>
|
|
||||||
</button>
|
|
||||||
<button *pngxIfOwner="rule" class="btn btn-sm btn-outline-secondary" type="button" (click)="editPermissions(rule)">
|
|
||||||
<i-bs width="1em" height="1em" name="person-lock"></i-bs> <ng-container i18n>Permissions</ng-container>
|
|
||||||
</button>
|
|
||||||
<button *pngxIfPermissions="{ action: PermissionAction.Delete, type: PermissionType.MailRule }" [disabled]="!userIsOwner(rule)" class="btn btn-sm btn-outline-danger" type="button" (click)="deleteMailRule(rule)">
|
|
||||||
<i-bs width="1em" height="1em" name="trash"></i-bs> <ng-container i18n>Delete</ng-container>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
}
|
|
||||||
@if (mailRules.length === 0) {
|
|
||||||
<li class="list-group-item" i18n>No mail rules defined.</li>
|
|
||||||
}
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
</ng-container>
|
<ng-container *pngxIfPermissions="{ action: PermissionAction.View, type: PermissionType.MailRule }">
|
||||||
|
<h4 class="mt-4">
|
||||||
|
<ng-container i18n>Mail rules</ng-container>
|
||||||
|
<button type="button" class="btn btn-sm btn-outline-primary ms-4" (click)="editMailRule()" *pngxIfPermissions="{ action: PermissionAction.Add, type: PermissionType.MailRule }">
|
||||||
|
<i-bs name="plus-circle"></i-bs> <ng-container i18n>Add Rule</ng-container>
|
||||||
|
</button>
|
||||||
|
</h4>
|
||||||
|
<ul class="list-group">
|
||||||
|
<li class="list-group-item">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col" i18n>Name</div>
|
||||||
|
<div class="col" i18n>Account</div>
|
||||||
|
<div class="col" i18n>Actions</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
|
||||||
@if (!mailAccounts || !mailRules) {
|
@for (rule of mailRules; track rule) {
|
||||||
<div>
|
<li class="list-group-item">
|
||||||
<div class="spinner-border spinner-border-sm fw-normal ms-2 me-auto" role="status"></div>
|
<div class="row">
|
||||||
<div class="visually-hidden" i18n>Loading...</div>
|
<div class="col d-flex align-items-center"><button class="btn btn-link p-0" type="button" (click)="editMailRule(rule)" [disabled]="!permissionsService.currentUserCan(PermissionAction.Change, PermissionType.MailRule)">{{rule.name}}</button></div>
|
||||||
</div>
|
<div class="col d-flex align-items-center">{{(mailAccountService.getCached(rule.account) | async)?.name}}</div>
|
||||||
}
|
<div class="col">
|
||||||
|
<div class="btn-group">
|
||||||
|
<button *pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.MailRule }" [disabled]="!userCanEdit(rule)" class="btn btn-sm btn-outline-secondary" type="button" (click)="editMailRule(rule)">
|
||||||
|
<i-bs width="1em" height="1em" name="pencil"></i-bs> <ng-container i18n>Edit</ng-container>
|
||||||
|
</button>
|
||||||
|
<button *pngxIfOwner="rule" class="btn btn-sm btn-outline-secondary" type="button" (click)="editPermissions(rule)">
|
||||||
|
<i-bs width="1em" height="1em" name="person-lock"></i-bs> <ng-container i18n>Permissions</ng-container>
|
||||||
|
</button>
|
||||||
|
<pngx-confirm-button
|
||||||
|
label="Delete"
|
||||||
|
i18n-label
|
||||||
|
(confirm)="deleteMailRule(rule)"
|
||||||
|
*pngxIfPermissions="{ action: PermissionAction.Delete, type: PermissionType.MailRule }"
|
||||||
|
[disabled]="!userIsOwner(rule)"
|
||||||
|
buttonClasses="btn-sm btn-outline-danger"
|
||||||
|
iconName="trash">
|
||||||
|
</pngx-confirm-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
@if (mailRules.length === 0) {
|
||||||
|
<li class="list-group-item" i18n>No mail rules defined.</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
@if (!mailAccounts || !mailRules) {
|
||||||
|
<div>
|
||||||
|
<div class="spinner-border spinner-border-sm fw-normal ms-2 me-auto" role="status"></div>
|
||||||
|
<div class="visually-hidden" i18n>Loading...</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
@ -42,6 +42,8 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms'
|
|||||||
import { EditDialogMode } from '../../common/edit-dialog/edit-dialog.component'
|
import { EditDialogMode } from '../../common/edit-dialog/edit-dialog.component'
|
||||||
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
|
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
|
||||||
import { SwitchComponent } from '../../common/input/switch/switch.component'
|
import { SwitchComponent } from '../../common/input/switch/switch.component'
|
||||||
|
import { ConfirmButtonComponent } from '../../common/confirm-button/confirm-button.component'
|
||||||
|
import { By } from '@angular/platform-browser'
|
||||||
|
|
||||||
const mailAccounts = [
|
const mailAccounts = [
|
||||||
{ id: 1, name: 'account1' },
|
{ id: 1, name: 'account1' },
|
||||||
@ -84,6 +86,7 @@ describe('MailComponent', () => {
|
|||||||
PermissionsDialogComponent,
|
PermissionsDialogComponent,
|
||||||
PermissionsFormComponent,
|
PermissionsFormComponent,
|
||||||
SwitchComponent,
|
SwitchComponent,
|
||||||
|
ConfirmButtonComponent,
|
||||||
],
|
],
|
||||||
providers: [CustomDatePipe, DatePipe, PermissionsGuard],
|
providers: [CustomDatePipe, DatePipe, PermissionsGuard],
|
||||||
imports: [
|
imports: [
|
||||||
@ -183,10 +186,9 @@ describe('MailComponent', () => {
|
|||||||
|
|
||||||
it('should support delete mail account, show error if needed', () => {
|
it('should support delete mail account, show error if needed', () => {
|
||||||
completeSetup()
|
completeSetup()
|
||||||
let modal: NgbModalRef
|
const deleteButton = fixture.debugElement.query(
|
||||||
modalService.activeInstances.subscribe((refs) => (modal = refs[0]))
|
By.directive(ConfirmButtonComponent)
|
||||||
component.deleteMailAccount(mailAccounts[0] as MailAccount)
|
)
|
||||||
const deleteDialog = modal.componentInstance as ConfirmDialogComponent
|
|
||||||
const deleteSpy = jest.spyOn(mailAccountService, 'delete')
|
const deleteSpy = jest.spyOn(mailAccountService, 'delete')
|
||||||
const toastErrorSpy = jest.spyOn(toastService, 'showError')
|
const toastErrorSpy = jest.spyOn(toastService, 'showError')
|
||||||
const toastInfoSpy = jest.spyOn(toastService, 'showInfo')
|
const toastInfoSpy = jest.spyOn(toastService, 'showInfo')
|
||||||
@ -194,10 +196,10 @@ describe('MailComponent', () => {
|
|||||||
deleteSpy.mockReturnValueOnce(
|
deleteSpy.mockReturnValueOnce(
|
||||||
throwError(() => new Error('error deleting mail account'))
|
throwError(() => new Error('error deleting mail account'))
|
||||||
)
|
)
|
||||||
deleteDialog.confirm()
|
deleteButton.nativeElement.dispatchEvent(new Event('confirm'))
|
||||||
expect(toastErrorSpy).toBeCalled()
|
expect(toastErrorSpy).toBeCalled()
|
||||||
deleteSpy.mockReturnValueOnce(of(true))
|
deleteSpy.mockReturnValueOnce(of(true))
|
||||||
deleteDialog.confirm()
|
deleteButton.nativeElement.dispatchEvent(new Event('confirm'))
|
||||||
expect(listAllSpy).toHaveBeenCalled()
|
expect(listAllSpy).toHaveBeenCalled()
|
||||||
expect(toastInfoSpy).toHaveBeenCalledWith('Deleted mail account')
|
expect(toastInfoSpy).toHaveBeenCalledWith('Deleted mail account')
|
||||||
})
|
})
|
||||||
@ -222,10 +224,9 @@ describe('MailComponent', () => {
|
|||||||
|
|
||||||
it('should support delete mail rule, show error if needed', () => {
|
it('should support delete mail rule, show error if needed', () => {
|
||||||
completeSetup()
|
completeSetup()
|
||||||
let modal: NgbModalRef
|
const deleteButton = fixture.debugElement.queryAll(
|
||||||
modalService.activeInstances.subscribe((refs) => (modal = refs[0]))
|
By.directive(ConfirmButtonComponent)
|
||||||
component.deleteMailRule(mailRules[0] as MailRule)
|
)[2]
|
||||||
const deleteDialog = modal.componentInstance as ConfirmDialogComponent
|
|
||||||
const deleteSpy = jest.spyOn(mailRuleService, 'delete')
|
const deleteSpy = jest.spyOn(mailRuleService, 'delete')
|
||||||
const toastErrorSpy = jest.spyOn(toastService, 'showError')
|
const toastErrorSpy = jest.spyOn(toastService, 'showError')
|
||||||
const toastInfoSpy = jest.spyOn(toastService, 'showInfo')
|
const toastInfoSpy = jest.spyOn(toastService, 'showInfo')
|
||||||
@ -233,10 +234,10 @@ describe('MailComponent', () => {
|
|||||||
deleteSpy.mockReturnValueOnce(
|
deleteSpy.mockReturnValueOnce(
|
||||||
throwError(() => new Error('error deleting mail rule'))
|
throwError(() => new Error('error deleting mail rule'))
|
||||||
)
|
)
|
||||||
deleteDialog.confirm()
|
deleteButton.nativeElement.dispatchEvent(new Event('confirm'))
|
||||||
expect(toastErrorSpy).toBeCalled()
|
expect(toastErrorSpy).toBeCalled()
|
||||||
deleteSpy.mockReturnValueOnce(of(true))
|
deleteSpy.mockReturnValueOnce(of(true))
|
||||||
deleteDialog.confirm()
|
deleteButton.nativeElement.dispatchEvent(new Event('confirm'))
|
||||||
expect(listAllSpy).toHaveBeenCalled()
|
expect(listAllSpy).toHaveBeenCalled()
|
||||||
expect(toastInfoSpy).toHaveBeenCalledWith('Deleted mail rule')
|
expect(toastInfoSpy).toHaveBeenCalledWith('Deleted mail rule')
|
||||||
})
|
})
|
||||||
|
@ -106,34 +106,19 @@ export class MailComponent
|
|||||||
}
|
}
|
||||||
|
|
||||||
deleteMailAccount(account: MailAccount) {
|
deleteMailAccount(account: MailAccount) {
|
||||||
const modal = this.modalService.open(ConfirmDialogComponent, {
|
this.mailAccountService.delete(account).subscribe({
|
||||||
backdrop: 'static',
|
next: () => {
|
||||||
})
|
this.toastService.showInfo($localize`Deleted mail account`)
|
||||||
modal.componentInstance.title = $localize`Confirm delete mail account`
|
this.mailAccountService.clearCache()
|
||||||
modal.componentInstance.messageBold = $localize`This operation will permanently delete this mail account.`
|
this.mailAccountService
|
||||||
modal.componentInstance.message = $localize`This operation cannot be undone.`
|
.listAll(null, null, { full_perms: true })
|
||||||
modal.componentInstance.btnClass = 'btn-danger'
|
.subscribe((r) => {
|
||||||
modal.componentInstance.btnCaption = $localize`Proceed`
|
this.mailAccounts = r.results
|
||||||
modal.componentInstance.confirmClicked.subscribe(() => {
|
})
|
||||||
modal.componentInstance.buttonsEnabled = false
|
},
|
||||||
this.mailAccountService.delete(account).subscribe({
|
error: (e) => {
|
||||||
next: () => {
|
this.toastService.showError($localize`Error deleting mail account.`, e)
|
||||||
modal.close()
|
},
|
||||||
this.toastService.showInfo($localize`Deleted mail account`)
|
|
||||||
this.mailAccountService.clearCache()
|
|
||||||
this.mailAccountService
|
|
||||||
.listAll(null, null, { full_perms: true })
|
|
||||||
.subscribe((r) => {
|
|
||||||
this.mailAccounts = r.results
|
|
||||||
})
|
|
||||||
},
|
|
||||||
error: (e) => {
|
|
||||||
this.toastService.showError(
|
|
||||||
$localize`Error deleting mail account.`,
|
|
||||||
e
|
|
||||||
)
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,31 +150,19 @@ export class MailComponent
|
|||||||
}
|
}
|
||||||
|
|
||||||
deleteMailRule(rule: MailRule) {
|
deleteMailRule(rule: MailRule) {
|
||||||
const modal = this.modalService.open(ConfirmDialogComponent, {
|
this.mailRuleService.delete(rule).subscribe({
|
||||||
backdrop: 'static',
|
next: () => {
|
||||||
})
|
this.toastService.showInfo($localize`Deleted mail rule`)
|
||||||
modal.componentInstance.title = $localize`Confirm delete mail rule`
|
this.mailRuleService.clearCache()
|
||||||
modal.componentInstance.messageBold = $localize`This operation will permanently delete this mail rule.`
|
this.mailRuleService
|
||||||
modal.componentInstance.message = $localize`This operation cannot be undone.`
|
.listAll(null, null, { full_perms: true })
|
||||||
modal.componentInstance.btnClass = 'btn-danger'
|
.subscribe((r) => {
|
||||||
modal.componentInstance.btnCaption = $localize`Proceed`
|
this.mailRules = r.results
|
||||||
modal.componentInstance.confirmClicked.subscribe(() => {
|
})
|
||||||
modal.componentInstance.buttonsEnabled = false
|
},
|
||||||
this.mailRuleService.delete(rule).subscribe({
|
error: (e) => {
|
||||||
next: () => {
|
this.toastService.showError($localize`Error deleting mail rule.`, e)
|
||||||
modal.close()
|
},
|
||||||
this.toastService.showInfo($localize`Deleted mail rule`)
|
|
||||||
this.mailRuleService.clearCache()
|
|
||||||
this.mailRuleService
|
|
||||||
.listAll(null, null, { full_perms: true })
|
|
||||||
.subscribe((r) => {
|
|
||||||
this.mailRules = r.results
|
|
||||||
})
|
|
||||||
},
|
|
||||||
error: (e) => {
|
|
||||||
this.toastService.showError($localize`Error deleting mail rule.`, e)
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user