Refactor: Restringimento drag & drop, legenda impostazioni, modalità offline e rimozione sezione liturgia
This commit is contained in:
+136
-12
@@ -13,6 +13,7 @@ import { ModalController, AlertController, ToastController } from '@ionic/angula
|
||||
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
|
||||
import { MyCantiService } from '../services/my-canti.service';
|
||||
import { QrScannerComponent } from '../components/qr-scanner/qr-scanner.component';
|
||||
import { CantiLettureService } from '../services/canti-letture.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-home',
|
||||
@@ -25,6 +26,9 @@ export class HomePage implements OnDestroy {
|
||||
public selectedLiturgico = signal<number | null>(null);
|
||||
public selectedTematico = signal<number | null>(null);
|
||||
public showOnlyMine = signal<boolean>(false);
|
||||
public showTopTen = signal<boolean>(false);
|
||||
public showSuggeriti = signal<boolean>(false);
|
||||
public isMassCardExpanded = signal<boolean>(false);
|
||||
public activeFilterType = signal<'liturgico' | 'tematico' | 'playlist' | null>(null);
|
||||
public loadedThumbs = new Set<string>();
|
||||
public version = VERSION;
|
||||
@@ -49,6 +53,7 @@ export class HomePage implements OnDestroy {
|
||||
public myCantiService = inject(MyCantiService);
|
||||
public playlistService = inject(PlaylistService);
|
||||
public settingsService = inject(SettingsService);
|
||||
public cantiLettureService = inject(CantiLettureService);
|
||||
private router = inject(Router);
|
||||
private route = inject(ActivatedRoute);
|
||||
private modalCtrl = inject(ModalController);
|
||||
@@ -93,6 +98,8 @@ export class HomePage implements OnDestroy {
|
||||
const litId = this.selectedLiturgico();
|
||||
const temId = this.selectedTematico();
|
||||
const onlyMine = this.showOnlyMine();
|
||||
const topTen = this.showTopTen();
|
||||
const suggeriti = this.showSuggeriti();
|
||||
|
||||
let list = [...this.cantiService.canti(), ...this.myCantiService.myCanti()];
|
||||
|
||||
@@ -107,12 +114,17 @@ export class HomePage implements OnDestroy {
|
||||
list = list.filter(c => c.id_momenti?.includes(temId));
|
||||
}
|
||||
|
||||
if (suggeriti) {
|
||||
const suggMap = this.cantiLettureService.suggestionsMap();
|
||||
list = list.filter(c => suggMap.has(c.id_canti));
|
||||
}
|
||||
|
||||
// Special List handling (from QR Code or Saved Playlists)
|
||||
const activeIds = this.playlistService.activeListIds();
|
||||
const selectionMode = this.playlistService.selectionMode();
|
||||
|
||||
// If we are in selection mode, only show restricted list if NOT adding songs AND we have a base list to reorder
|
||||
if (selectionMode && !this.isAddingSongs() && activeIds.length > 0) {
|
||||
// If we are in selection mode, only show restricted list if NOT adding songs
|
||||
if (selectionMode && !this.isAddingSongs()) {
|
||||
return this.reorderList();
|
||||
}
|
||||
|
||||
@@ -124,6 +136,25 @@ export class HomePage implements OnDestroy {
|
||||
.filter((c): c is any => !!c);
|
||||
}
|
||||
|
||||
if (suggeriti) {
|
||||
const suggMap = this.cantiLettureService.suggestionsMap();
|
||||
list = list.sort((a, b) => {
|
||||
const pesoA = suggMap.get(a.id_canti) || 0;
|
||||
const pesoB = suggMap.get(b.id_canti) || 0;
|
||||
return pesoB - pesoA;
|
||||
});
|
||||
} else if (topTen) {
|
||||
const eseguiti = this.cantiService.cantiEseguiti();
|
||||
const eseguitiMap = new Map<number, number>();
|
||||
eseguiti.forEach(x => eseguitiMap.set(x.id_canti, x.num));
|
||||
|
||||
list = list.sort((a, b) => {
|
||||
const numA = eseguitiMap.get(a.id_canti) || 0;
|
||||
const numB = eseguitiMap.get(b.id_canti) || 0;
|
||||
return numB - numA;
|
||||
});
|
||||
}
|
||||
|
||||
if (!query) return list;
|
||||
|
||||
// Converte "uno" in "1" per facilitare la ricerca vocale (es. "numero uno")
|
||||
@@ -170,15 +201,22 @@ export class HomePage implements OnDestroy {
|
||||
}
|
||||
});
|
||||
|
||||
let prevSelectionMode = false;
|
||||
|
||||
effect(() => {
|
||||
const selectionMode = this.playlistService.selectionMode();
|
||||
const selectedIds = this.playlistService.selectedIds();
|
||||
const activeIds = this.playlistService.activeListIds();
|
||||
|
||||
if (selectionMode) {
|
||||
if (activeIds.length === 0 && !this.isAddingSongs()) {
|
||||
this.isAddingSongs.set(true);
|
||||
if (!prevSelectionMode) {
|
||||
if (activeIds.length === 0) {
|
||||
this.isAddingSongs.set(true);
|
||||
} else {
|
||||
this.isAddingSongs.set(false);
|
||||
}
|
||||
}
|
||||
prevSelectionMode = true;
|
||||
|
||||
const currentIds = this.reorderList().map(c => c.id);
|
||||
const newIds = Array.from(selectedIds);
|
||||
@@ -208,6 +246,7 @@ export class HomePage implements OnDestroy {
|
||||
this.reorderList.set(updatedList);
|
||||
}
|
||||
} else {
|
||||
prevSelectionMode = false;
|
||||
this.isAddingSongs.set(false);
|
||||
}
|
||||
}, { allowSignalWrites: true });
|
||||
@@ -267,11 +306,6 @@ export class HomePage implements OnDestroy {
|
||||
}
|
||||
|
||||
goToCanto(id: string) {
|
||||
if (this.playlistService.selectionMode()) {
|
||||
this.playlistService.toggleSongSelection(id);
|
||||
return;
|
||||
}
|
||||
|
||||
const params: any = { id };
|
||||
const isPlaying = this.youtubePlayerService.isPlaying();
|
||||
|
||||
@@ -379,6 +413,8 @@ export class HomePage implements OnDestroy {
|
||||
return this.selectedLiturgico() !== null ||
|
||||
this.selectedTematico() !== null ||
|
||||
this.showOnlyMine() ||
|
||||
this.showTopTen() ||
|
||||
this.showSuggeriti() ||
|
||||
this.playlistService.activeListName() !== null ||
|
||||
this.searchQuery() !== '';
|
||||
}
|
||||
@@ -387,6 +423,8 @@ export class HomePage implements OnDestroy {
|
||||
this.selectedLiturgico.set(null);
|
||||
this.selectedTematico.set(null);
|
||||
this.showOnlyMine.set(false);
|
||||
this.showTopTen.set(false);
|
||||
this.showSuggeriti.set(false);
|
||||
this.playlistService.activeListIds.set([]);
|
||||
this.playlistService.activeListName.set(null);
|
||||
this.playlistService.activePlaylistId.set(null);
|
||||
@@ -415,6 +453,73 @@ export class HomePage implements OnDestroy {
|
||||
this.showOnlyMine.set(false);
|
||||
}
|
||||
|
||||
toggleTopTen() {
|
||||
this.showTopTen.update(v => !v);
|
||||
this.limit.set(30);
|
||||
}
|
||||
|
||||
clearTopTen(event?: Event) {
|
||||
if (event) event.stopPropagation();
|
||||
this.showTopTen.set(false);
|
||||
this.limit.set(30);
|
||||
}
|
||||
|
||||
toggleSuggeriti() {
|
||||
this.showSuggeriti.update(v => !v);
|
||||
this.limit.set(30);
|
||||
}
|
||||
|
||||
clearSuggeriti(event?: Event) {
|
||||
if (event) event.stopPropagation();
|
||||
this.showSuggeriti.set(false);
|
||||
this.limit.set(30);
|
||||
}
|
||||
|
||||
getMassSuggestionWeight(id_canti: number): number | null {
|
||||
const weight = this.cantiLettureService.suggestionsMap().get(id_canti);
|
||||
return weight !== undefined ? weight : null;
|
||||
}
|
||||
|
||||
getMassSuggestionMoment(id_canti: number): string | null {
|
||||
const moments = this.cantiLettureService.suggestionsMomentsMap().get(id_canti);
|
||||
return moments && moments.length > 0 ? moments.join(', ') : null;
|
||||
}
|
||||
|
||||
getSelectedMassFormattedDate(): string | null {
|
||||
const dateStr = this.cantiLettureService.selectedMassDate();
|
||||
if (!dateStr) return null;
|
||||
const parts = dateStr.split('-');
|
||||
if (parts.length === 3) {
|
||||
return `${parts[2]}/${parts[1]}/${parts[0]}`;
|
||||
}
|
||||
return dateStr;
|
||||
}
|
||||
|
||||
getSelectedMassTitle(): string | null {
|
||||
const dateStr = this.cantiLettureService.selectedMassDate();
|
||||
const data = this.cantiLettureService.data();
|
||||
if (dateStr && data && data.masses[dateStr]) {
|
||||
return data.masses[dateStr].title;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
getSelectedMassSummary(): string | null {
|
||||
const dateStr = this.cantiLettureService.selectedMassDate();
|
||||
const data = this.cantiLettureService.data();
|
||||
if (dateStr && data && data.masses[dateStr]) {
|
||||
return data.masses[dateStr].summary || null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
getEsecuzioniCount(id: string): number | null {
|
||||
const numId = parseInt(id, 10);
|
||||
if (isNaN(numId)) return null;
|
||||
const es = this.cantiService.cantiEseguiti().find(x => x.id_canti === numId);
|
||||
return es ? es.num : null;
|
||||
}
|
||||
|
||||
onImgLoad(id: string) {
|
||||
this.loadedThumbs.add(id);
|
||||
}
|
||||
@@ -429,6 +534,9 @@ export class HomePage implements OnDestroy {
|
||||
|
||||
playVideo(event: Event, id: string) {
|
||||
event.stopPropagation();
|
||||
if (!this.youtubePlayerService.isPlayerSupported()) {
|
||||
return;
|
||||
}
|
||||
this.youtubePlayerService.setMediaSessionCallbacks(
|
||||
() => this.playNextPreview(),
|
||||
() => this.playPrevPreview()
|
||||
@@ -577,14 +685,30 @@ export class HomePage implements OnDestroy {
|
||||
handleScannedData(data: string) {
|
||||
if (!data) return;
|
||||
|
||||
if (data.includes('?import=')) {
|
||||
if (data.includes('import=')) {
|
||||
try {
|
||||
const base64 = data.split('?import=')[1];
|
||||
let base64 = '';
|
||||
if (data.includes('?import=')) {
|
||||
base64 = data.split('?import=')[1];
|
||||
} else if (data.includes('&import=')) {
|
||||
base64 = data.split('&import=')[1];
|
||||
}
|
||||
|
||||
if (base64.includes('&')) {
|
||||
base64 = base64.split('&')[0];
|
||||
}
|
||||
if (base64.includes('#')) {
|
||||
base64 = base64.split('#')[0];
|
||||
}
|
||||
|
||||
this.handleImport(base64);
|
||||
return;
|
||||
} catch (e) {
|
||||
console.error('Failed to parse scanned link', e);
|
||||
}
|
||||
} else if (data.startsWith('canti:')) {
|
||||
}
|
||||
|
||||
if (data.startsWith('canti:')) {
|
||||
const parts = data.replace('canti:', '').split(':');
|
||||
let idsStr = '';
|
||||
if (parts.length > 1) {
|
||||
|
||||
Reference in New Issue
Block a user