feat: ButtonVisibilityService in mehreren Schaltflächen-Komponenten implementiert
- `ButtonVisibilityService` zur Verwaltung der Sichtbarkeit in verschiedenen Schaltflächen-Komponenten integriert. - Schaltflächen-Komponenten aktualisiert, um den Dienst für dynamische Sichtbarkeitskontrolle zu verwenden. - Tests refaktoriert, um sicherzustellen, dass der Dienst korrekt in den Komponenten angewendet wird.
This commit is contained in:
parent
06197876e7
commit
c8bcc2820b
@ -30,7 +30,7 @@
|
||||
<!-- Right menu -->
|
||||
<div class="navbar-collapse justify-content-end me-5">
|
||||
<a class="navbar-brand" [routerLink]="['/']">User Manager Portal</a>
|
||||
<mat-slide-toggle *ngIf="isLogedIn()" [(ngModel)]="updateService.isEditable"></mat-slide-toggle>
|
||||
<mat-slide-toggle *ngIf="isLogedIn()" [(ngModel)]="updateService.isEditable" [ngStyle]="{ 'visibility': creationService.isVisible ? 'visible' : 'hidden' }"></mat-slide-toggle>
|
||||
<button *ngIf="isLogedIn()" class="btn" (click)="updateService.executeAll()" [ngStyle]="{ 'visibility': updateService.isVisible ? 'visible' : 'hidden' }">
|
||||
<mat-icon class="scale-pulse" [matBadge]="updateActCount === 0 ? '' : updateActCount">save</mat-icon>
|
||||
</button>
|
||||
|
||||
@ -3,6 +3,7 @@ import { RefreshService } from '../../services/button/refresh.service';
|
||||
import { CreationService } from '../../services/button/creation.service';
|
||||
import { UpdateService } from '../../services/button/update.service';
|
||||
import { TransferService } from '../../services/button/transfer.service';
|
||||
import { ButtonVisibilityService } from '../../services/button/button-visibility.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-base-page',
|
||||
@ -17,6 +18,7 @@ export class BasePageComponent {
|
||||
protected creationService: CreationService = inject(CreationService)
|
||||
protected updateService: UpdateService = inject(UpdateService)
|
||||
protected transferService: TransferService = inject(TransferService)
|
||||
protected buttonVisibilityService: ButtonVisibilityService = inject(ButtonVisibilityService)
|
||||
|
||||
constructor() {
|
||||
this.refreshService.removeAll()
|
||||
|
||||
@ -35,6 +35,7 @@ export class GroupComponent extends BasePageComponent implements AfterViewInit {
|
||||
private sGroupId = null;
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
this.buttonVisibilityService.setVisibleOnly(this.refreshService, this.creationService, this.updateService)
|
||||
this.refreshService.removeAll()
|
||||
this.refreshService.add(() => {
|
||||
this.groupTable.fetchData();
|
||||
|
||||
@ -18,6 +18,7 @@ export class ModuleComponent extends BasePageComponent implements AfterViewInit
|
||||
|
||||
initWithoutData = () => { }
|
||||
ngAfterViewInit(): void {
|
||||
this.buttonVisibilityService.setVisibleOnly()
|
||||
this.refreshService.removeAll()
|
||||
this.refreshService.add(() => {
|
||||
this.moduleTable.fetchData();
|
||||
|
||||
@ -50,6 +50,9 @@ export class UserAssignmentComponent extends BasePageComponent implements OnInit
|
||||
ngOnInit(): void { }
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
|
||||
this.buttonVisibilityService.setVisibleOnly(this.refreshService, this.transferService)
|
||||
|
||||
this.refreshService.removeAll()
|
||||
this.refreshService.add(() => {
|
||||
this.modules.fetchData();
|
||||
|
||||
@ -37,6 +37,7 @@ export class UserRepresentationComponent extends BasePageComponent implements Af
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
this.buttonVisibilityService.setVisibleOnly(this.refreshService, this.transferService)
|
||||
this.refreshService.removeAll();
|
||||
this.refreshService.add(() => {
|
||||
this.users.fetchData();
|
||||
|
||||
@ -36,6 +36,7 @@ export class UserComponent extends BasePageComponent implements AfterViewInit {
|
||||
private sUsername = null;
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
this.buttonVisibilityService.setVisibleOnly(this.refreshService, this.creationService, this.updateService)
|
||||
this.refreshService.removeAll()
|
||||
this.refreshService.add(() => {
|
||||
this.userTable.fetchData();
|
||||
|
||||
@ -1,4 +1,16 @@
|
||||
import { Injectable, inject } from "@angular/core";
|
||||
import { ButtonVisibilityService } from "./button-visibility.service";
|
||||
|
||||
export class BaseButtonService {
|
||||
|
||||
constructor() {
|
||||
const bvService = inject(ButtonVisibilityService);
|
||||
bvService.buttons[this.constructorName] = this;
|
||||
}
|
||||
|
||||
public isVisible: boolean = true;
|
||||
|
||||
public get constructorName() {
|
||||
return this.constructor.name;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ButtonVisibilityService } from './button-visibility.service';
|
||||
|
||||
describe('ButtonVisibilityService', () => {
|
||||
let service: ButtonVisibilityService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(ButtonVisibilityService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,37 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BaseButtonService } from './base-button.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ButtonVisibilityService {
|
||||
_buttons: { [key: string]: BaseButtonService } = {};
|
||||
public get buttons() {
|
||||
return this._buttons;
|
||||
}
|
||||
|
||||
setVisibility(key: string, show: boolean) {
|
||||
const bttn = this._buttons[key];
|
||||
|
||||
if (show && !bttn.isVisible) {
|
||||
bttn.isVisible = true
|
||||
return
|
||||
}
|
||||
|
||||
if (!show && bttn.isVisible) {
|
||||
bttn.isVisible = false
|
||||
}
|
||||
}
|
||||
|
||||
setVisibleOnly(...buttons: BaseButtonService[]) {
|
||||
const keys = buttons.map(b => b.constructorName)
|
||||
for (const key in this._buttons) {
|
||||
if (keys.includes(key)) {
|
||||
this.setVisibility(key, true)
|
||||
}
|
||||
else {
|
||||
this.setVisibility(key, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user