Added order by consecutive selecting generators, order saved in local storage. #14

Merged
mastah merged 1 commits from feature/reorder into develop 2026-01-31 00:46:22 +01:00
2 changed files with 74 additions and 47 deletions

View File

@@ -5,12 +5,9 @@
@if (showControls) { @if (showControls) {
<div class="controls"> <div class="controls">
<mat-button-toggle-group vertical multiple class="generator-toggles"> <mat-button-toggle-group vertical multiple class="generator-toggles">
<mat-button-toggle [checked]="showRegon" (change)="showRegon = $event.source.checked; saveGeneratorSettings()">REGON</mat-button-toggle> @for (gen of generators; track gen.id) {
<mat-button-toggle [checked]="showNip" (change)="showNip = $event.source.checked; saveGeneratorSettings()">NIP</mat-button-toggle> <mat-button-toggle [checked]="gen.show" (change)="toggleGenerator(gen.id, $event.source.checked)">{{gen.label}}</mat-button-toggle>
<mat-button-toggle [checked]="showPesel" (change)="showPesel = $event.source.checked; saveGeneratorSettings()">PESEL</mat-button-toggle> }
<mat-button-toggle [checked]="showIdentityCard" (change)="showIdentityCard = $event.source.checked; saveGeneratorSettings()">DOWÓD</mat-button-toggle>
<mat-button-toggle [checked]="showMobile" (change)="showMobile = $event.source.checked; saveGeneratorSettings()">KOMÓRA</mat-button-toggle>
<mat-button-toggle [checked]="showIban" (change)="showIban = $event.source.checked; saveGeneratorSettings()">IBAN</mat-button-toggle>
</mat-button-toggle-group> </mat-button-toggle-group>
<mat-button-toggle-group vertical class="theme-toggles"> <mat-button-toggle-group vertical class="theme-toggles">
@@ -23,22 +20,16 @@
</div> </div>
} }
<div class="generators"> <div class="generators">
@if (showRegon) { @for (id of activeGenerators; track id) {
<app-regon></app-regon> @if (isGeneratorVisible(id)) {
} @switch (id) {
@if (showNip) { @case ('regon') { <app-regon></app-regon> }
<app-nip></app-nip> @case ('nip') { <app-nip></app-nip> }
} @case ('pesel') { <app-pesel></app-pesel> }
@if (showPesel) { @case ('identityCard') { <app-identity-card></app-identity-card> }
<app-pesel></app-pesel> @case ('mobile') { <app-mobile></app-mobile> }
} @case ('iban') { <app-iban></app-iban> }
@if (showIdentityCard) { }
<app-identity-card></app-identity-card> }
}
@if (showMobile) {
<app-mobile></app-mobile>
}
@if (showIban) {
<app-iban></app-iban>
} }
</div> </div>

View File

@@ -8,12 +8,16 @@ import { ChangeDetectorRef, Component, ElementRef, HostListener, OnInit } from '
}) })
export class AppComponent implements OnInit { export class AppComponent implements OnInit {
showRegon = true; generators = [
showNip = true; { id: 'regon', label: 'REGON', show: true },
showPesel = true; { id: 'nip', label: 'NIP', show: true },
showIdentityCard = true; { id: 'pesel', label: 'PESEL', show: true },
showIban = true; { id: 'identityCard', label: 'DOWÓD', show: true },
showMobile = true; { id: 'mobile', label: 'KOMÓRA', show: true },
{ id: 'iban', label: 'IBAN', show: true }
];
activeGenerators: string[] = ['regon', 'nip', 'pesel', 'identityCard', 'mobile', 'iban'];
showControls = false; showControls = false;
isInitialVisible = true; isInitialVisible = true;
@@ -40,12 +44,20 @@ export class AppComponent implements OnInit {
const savedGenerators = localStorage.getItem('generatorSettings'); const savedGenerators = localStorage.getItem('generatorSettings');
if (savedGenerators) { if (savedGenerators) {
const settings = JSON.parse(savedGenerators); const settings = JSON.parse(savedGenerators);
this.showRegon = settings.showRegon ?? true; this.generators.forEach(g => {
this.showNip = settings.showNip ?? true; g.show = settings[g.id] ?? true;
this.showPesel = settings.showPesel ?? true; });
this.showIdentityCard = settings.showIdentityCard ?? true; }
this.showIban = settings.showIban ?? true;
this.showMobile = settings.showMobile ?? true; const savedOrder = localStorage.getItem('generatorOrder');
if (savedOrder) {
this.activeGenerators = JSON.parse(savedOrder);
// Ensure all current generators are present in the order (for migration/updates)
this.generators.forEach(g => {
if (!this.activeGenerators.includes(g.id)) {
this.activeGenerators.push(g.id);
}
});
} }
setTimeout(() => { setTimeout(() => {
@@ -54,24 +66,48 @@ export class AppComponent implements OnInit {
}, 3000); }, 3000);
} }
toggleGenerator(id: string, checked: boolean) {
const generator = this.generators.find(g => g.id === id);
if (generator) {
generator.show = checked;
if (checked) {
// Add to end if not already in activeGenerators (it should be, but just in case)
if (!this.activeGenerators.includes(id)) {
this.activeGenerators.push(id);
} else {
// If it was already there but we want it at the end when RE-ENABLING:
const index = this.activeGenerators.indexOf(id);
this.activeGenerators.splice(index, 1);
this.activeGenerators.push(id);
}
}
this.saveGeneratorSettings();
}
}
saveGeneratorSettings() {
const settings: { [key: string]: boolean } = {};
this.generators.forEach(g => {
settings[g.id] = g.show;
});
localStorage.setItem('generatorSettings', JSON.stringify(settings));
localStorage.setItem('generatorOrder', JSON.stringify(this.activeGenerators));
}
getGenerator(id: string) {
return this.generators.find(g => g.id === id);
}
isGeneratorVisible(id: string): boolean {
return this.getGenerator(id)?.show ?? false;
}
setTheme(theme: string) { setTheme(theme: string) {
this.selectedTheme = theme; this.selectedTheme = theme;
localStorage.setItem('selectedTheme', theme); localStorage.setItem('selectedTheme', theme);
this.applyTheme(theme); this.applyTheme(theme);
} }
saveGeneratorSettings() {
const settings = {
showRegon: this.showRegon,
showNip: this.showNip,
showPesel: this.showPesel,
showIdentityCard: this.showIdentityCard,
showIban: this.showIban,
showMobile: this.showMobile
};
localStorage.setItem('generatorSettings', JSON.stringify(settings));
}
private applyTheme(theme: string) { private applyTheme(theme: string) {
const body = document.body; const body = document.body;
this.themes.forEach(t => { this.themes.forEach(t => {