canti primo tag
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { IonicModule } from '@ionic/angular';
|
||||
import { DragDropModule } from '@angular/cdk/drag-drop';
|
||||
import { PlaylistPage } from './playlist.page';
|
||||
import { RouterModule, Routes } from '@angular/router';
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: PlaylistPage
|
||||
}
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
IonicModule,
|
||||
DragDropModule,
|
||||
RouterModule.forChild(routes)
|
||||
],
|
||||
declarations: [PlaylistPage]
|
||||
})
|
||||
export class PlaylistPageModule {}
|
||||
@@ -0,0 +1,43 @@
|
||||
<ion-header class="ion-no-border">
|
||||
<ion-toolbar class="bg-gradient">
|
||||
<ion-buttons slot="start">
|
||||
<ion-back-button defaultHref="/home" color="secondary"></ion-back-button>
|
||||
</ion-buttons>
|
||||
<ion-title class="outfit-font">Gestione Playlist</ion-title>
|
||||
<ion-buttons slot="end">
|
||||
<ion-button (click)="savePlaylist()" [disabled]="localSongs.length === 0">
|
||||
<ion-icon slot="icon-only" name="save-outline"></ion-icon>
|
||||
</ion-button>
|
||||
</ion-buttons>
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
|
||||
<ion-content class="bg-gradient">
|
||||
<div class="ion-padding">
|
||||
<div class="header-info glass ion-margin-bottom" *ngIf="localSongs.length > 0">
|
||||
<p>Trascina i canti per riordinarli. Una volta finito puoi salvare la playlist.</p>
|
||||
</div>
|
||||
|
||||
<div cdkDropList class="song-list" (cdkDropListDropped)="drop($event)">
|
||||
<div class="song-item glass ion-margin-bottom" *ngFor="let song of localSongs" cdkDrag>
|
||||
<div class="drag-handle" cdkDragHandle>
|
||||
<ion-icon name="reorder-two-outline"></ion-icon>
|
||||
</div>
|
||||
<div class="song-info">
|
||||
<span class="canto-number">{{ song.id_canti }}</span>
|
||||
<span class="song-title">{{ song.titolo }}</span>
|
||||
</div>
|
||||
<div class="example-custom-placeholder" *cdkDragPlaceholder></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div *ngIf="localSongs.length === 0" class="empty-state ion-text-center">
|
||||
<ion-icon name="musical-notes-outline" class="large-icon"></ion-icon>
|
||||
<p>Nessun canto selezionato.</p>
|
||||
<ion-button routerLink="/home" fill="outline" color="secondary" class="ion-margin-top">
|
||||
Torna alla Home
|
||||
</ion-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</ion-content>
|
||||
@@ -0,0 +1,179 @@
|
||||
.song-list {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.song-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 12px;
|
||||
border-radius: 12px;
|
||||
cursor: move;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
|
||||
.drag-handle {
|
||||
margin-right: 12px;
|
||||
color: rgba(255, 255, 255, 0.3);
|
||||
font-size: 1.5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.song-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
|
||||
.canto-number {
|
||||
background: rgba(var(--ion-color-secondary-rgb), 0.1);
|
||||
color: var(--ion-color-secondary);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.song-title {
|
||||
font-weight: 500;
|
||||
color: white;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.cdk-drag-preview {
|
||||
box-sizing: border-box;
|
||||
border-radius: 4px;
|
||||
box-shadow: 0 5px 5px -3px rgba(0, 0, 0, 0.2),
|
||||
0 8px 10px 1px rgba(0, 0, 0, 0.14),
|
||||
0 3px 14px 2px rgba(0, 0, 0, 0.12);
|
||||
background: #1e1e1e;
|
||||
padding: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.cdk-drag-placeholder {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.cdk-drag-animating {
|
||||
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.song-list.cdk-drop-list-dragging .song-item:not(.cdk-drag-placeholder) {
|
||||
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.header-info {
|
||||
padding: 12px;
|
||||
border-radius: 12px;
|
||||
p {
|
||||
margin: 0;
|
||||
font-size: 0.9rem;
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
margin-top: 100px;
|
||||
.large-icon {
|
||||
font-size: 5rem;
|
||||
color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
p {
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
margin-top: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
.qr-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 1000;
|
||||
backdrop-filter: blur(5px);
|
||||
|
||||
.qr-card {
|
||||
background: #ffffff;
|
||||
padding: 24px;
|
||||
border-radius: 20px;
|
||||
width: 90%;
|
||||
max-width: 350px;
|
||||
text-align: center;
|
||||
color: #000;
|
||||
|
||||
.qr-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 16px;
|
||||
h3 { margin: 0; text-align: left; }
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 0.9rem;
|
||||
color: #666;
|
||||
margin-bottom: 24px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.qr-img-container {
|
||||
background: #f8f8f8;
|
||||
padding: 16px;
|
||||
border-radius: 16px;
|
||||
margin-bottom: 24px;
|
||||
img {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.qr-actions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.save-export-fab {
|
||||
--border-radius: 30px;
|
||||
width: auto;
|
||||
min-width: 160px;
|
||||
|
||||
.fab-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0 16px;
|
||||
gap: 8px;
|
||||
|
||||
ion-icon {
|
||||
font-size: 1.4rem;
|
||||
}
|
||||
|
||||
.fab-label {
|
||||
font-size: 0.9rem;
|
||||
font-weight: 600;
|
||||
text-transform: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:host-context(body.high-contrast) {
|
||||
.song-item {
|
||||
background: #ffffff !important;
|
||||
border-color: #000000 !important;
|
||||
.song-title { color: #000000 !important; }
|
||||
.drag-handle { color: #000000 !important; }
|
||||
}
|
||||
.header-info p { color: #000000 !important; }
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
import { Component, inject, computed } from '@angular/core';
|
||||
import { PlaylistService } from '../../services/playlist.service';
|
||||
import { CantiService } from '../../services/canti.service';
|
||||
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
|
||||
import { AlertController, ToastController, ModalController } from '@ionic/angular';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-playlist',
|
||||
templateUrl: './playlist.page.html',
|
||||
styleUrls: ['./playlist.page.scss'],
|
||||
standalone: false
|
||||
})
|
||||
export class PlaylistPage {
|
||||
public playlistService = inject(PlaylistService);
|
||||
public cantiService = inject(CantiService);
|
||||
private alertCtrl = inject(AlertController);
|
||||
private toastCtrl = inject(ToastController);
|
||||
private router = inject(Router);
|
||||
|
||||
public selectedSongs = computed(() => {
|
||||
const ids = Array.from(this.playlistService.selectedIds());
|
||||
return ids.map(id => this.cantiService.canti().find(c => c.id === id)).filter(c => !!c);
|
||||
});
|
||||
|
||||
public localSongs: any[] = [];
|
||||
public qrCodeImage: string | null = null;
|
||||
public savedPlaylistName: string | null = null;
|
||||
|
||||
constructor() {
|
||||
// Initial copy to allow local reordering
|
||||
this.localSongs = [...this.selectedSongs()];
|
||||
}
|
||||
|
||||
drop(event: CdkDragDrop<string[]>) {
|
||||
moveItemInArray(this.localSongs, event.previousIndex, event.currentIndex);
|
||||
}
|
||||
|
||||
async savePlaylist() {
|
||||
const alert = await this.alertCtrl.create({
|
||||
header: 'Salva Playlist',
|
||||
inputs: [
|
||||
{
|
||||
name: 'name',
|
||||
type: 'text',
|
||||
placeholder: 'Nome della playlist',
|
||||
value: this.savedPlaylistName || ''
|
||||
}
|
||||
],
|
||||
buttons: [
|
||||
{
|
||||
text: 'Annulla',
|
||||
role: 'cancel'
|
||||
},
|
||||
{
|
||||
text: 'Salva',
|
||||
handler: (data) => {
|
||||
if (data.name) {
|
||||
this.savedPlaylistName = data.name;
|
||||
this.playlistService.savePlaylist(data.name, this.localSongs.map(s => s.id));
|
||||
this.showToast('Playlist salvata!');
|
||||
this.router.navigate(['/settings']);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
await alert.present();
|
||||
}
|
||||
|
||||
async saveAndExport() {
|
||||
const alert = await this.alertCtrl.create({
|
||||
header: 'Salva ed Esporta QR',
|
||||
message: 'Inserisci un nome per la playlist. Verrà salvata e generato il QR Code.',
|
||||
inputs: [
|
||||
{
|
||||
name: 'name',
|
||||
type: 'text',
|
||||
placeholder: 'Nome della playlist',
|
||||
value: this.savedPlaylistName || ''
|
||||
}
|
||||
],
|
||||
buttons: [
|
||||
{
|
||||
text: 'Annulla',
|
||||
role: 'cancel'
|
||||
},
|
||||
{
|
||||
text: 'Salva ed Esporta',
|
||||
handler: async (data) => {
|
||||
if (data.name) {
|
||||
this.savedPlaylistName = data.name;
|
||||
const ids = this.localSongs.map(s => s.id);
|
||||
await this.playlistService.savePlaylist(data.name, ids);
|
||||
this.qrCodeImage = await this.playlistService.generateQR(ids, data.name);
|
||||
this.showToast('Playlist salvata!');
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
await alert.present();
|
||||
}
|
||||
|
||||
async sharePlaylist() {
|
||||
if (this.localSongs.length === 0) return;
|
||||
|
||||
const ids = this.localSongs.map(s => s.id);
|
||||
const name = this.savedPlaylistName || 'Playlist Condivisa';
|
||||
this.qrCodeImage = await this.playlistService.generateQR(ids, name);
|
||||
}
|
||||
|
||||
downloadQR() {
|
||||
if (!this.qrCodeImage) return;
|
||||
|
||||
const name = this.savedPlaylistName || 'playlist';
|
||||
const fileName = `${name.toLowerCase().replace(/\s+/g, '_')}_qr.png`;
|
||||
|
||||
const link = document.createElement('a');
|
||||
link.href = this.qrCodeImage;
|
||||
link.download = fileName;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
|
||||
this.showToast('Immagine scaricata!');
|
||||
}
|
||||
|
||||
async shareQR() {
|
||||
if (!this.qrCodeImage) return;
|
||||
const name = this.savedPlaylistName || 'playlist';
|
||||
const shareLink = this.playlistService.getShareLink(this.localSongs.map(s => s.id), name);
|
||||
const fileName = `${name.toLowerCase().replace(/\s+/g, '_')}_qr.png`;
|
||||
|
||||
try {
|
||||
// Convert base64 to blob/file for sharing
|
||||
const res = await fetch(this.qrCodeImage);
|
||||
const blob = await res.blob();
|
||||
const file = new File([blob], fileName, { type: 'image/png' });
|
||||
|
||||
if (navigator.share && navigator.canShare && navigator.canShare({ files: [file] })) {
|
||||
await navigator.share({
|
||||
files: [file],
|
||||
title: 'Playlist CantiCristiani',
|
||||
text: `Ecco la playlist: ${name}\n\nClicca qui per aprirla subito: ${shareLink}`
|
||||
});
|
||||
} else {
|
||||
// Fallback to simple share text or download
|
||||
if (navigator.share) {
|
||||
await navigator.share({
|
||||
title: 'Playlist CantiCristiani',
|
||||
text: `Ecco la playlist: ${name}\n\nClicca qui per aprirla: ${shareLink}`
|
||||
});
|
||||
} else {
|
||||
this.downloadQR();
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Share failed', err);
|
||||
this.downloadQR();
|
||||
}
|
||||
}
|
||||
|
||||
closeQR() {
|
||||
this.qrCodeImage = null;
|
||||
}
|
||||
|
||||
async showToast(message: string) {
|
||||
const toast = await this.toastCtrl.create({
|
||||
message,
|
||||
duration: 2000,
|
||||
color: 'success'
|
||||
});
|
||||
await toast.present();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user