Edit poljubne in ustvari novo. #11
This commit is contained in:
@@ -156,15 +156,25 @@ def search_songs():
|
|||||||
|
|
||||||
@app.route('/api/get_song_details', methods=['GET'])
|
@app.route('/api/get_song_details', methods=['GET'])
|
||||||
def get_song_details():
|
def get_song_details():
|
||||||
"""Vrne podrobnosti trenutno naložene pesmi"""
|
"""Vrne podrobnosti trenutno naložene pesmi ali pesmi po ID-ju"""
|
||||||
if _projector_app is None:
|
if _projector_app is None:
|
||||||
return jsonify({'status': 'error', 'message': 'Aplikacija ni inicijalizirana'})
|
return jsonify({'status': 'error', 'message': 'Aplikacija ni inicijalizirana'})
|
||||||
|
|
||||||
if not _projector_app.song_number_last:
|
song_id_param = request.args.get('id')
|
||||||
|
if song_id_param:
|
||||||
|
try:
|
||||||
|
song_id = int(song_id_param)
|
||||||
|
except ValueError:
|
||||||
|
return jsonify({'status': 'error', 'message': 'Neveljaven ID pesmi'})
|
||||||
|
elif _projector_app.song_number_last:
|
||||||
|
try:
|
||||||
|
song_id = int(_projector_app.song_number_last)
|
||||||
|
except ValueError:
|
||||||
|
return jsonify({'status': 'error', 'message': 'Neveljavna številka naložene pesmi'})
|
||||||
|
else:
|
||||||
return jsonify({'status': 'error', 'message': 'Nobena pesem ni naložena'})
|
return jsonify({'status': 'error', 'message': 'Nobena pesem ni naložena'})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
song_id = int(_projector_app.song_number_last)
|
|
||||||
_projector_app.cursor.execute("SELECT id, title, lyrics FROM songs WHERE id=?", (song_id,))
|
_projector_app.cursor.execute("SELECT id, title, lyrics FROM songs WHERE id=?", (song_id,))
|
||||||
result = _projector_app.cursor.fetchone()
|
result = _projector_app.cursor.fetchone()
|
||||||
if result:
|
if result:
|
||||||
@@ -177,14 +187,14 @@ def get_song_details():
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
return jsonify({'status': 'error', 'message': 'Pesem ni najdena v bazi'})
|
return jsonify({'status': 'error', 'message': f'Pesem s številko {song_id} ni najdena v bazi'})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({'status': 'error', 'message': str(e)})
|
return jsonify({'status': 'error', 'message': str(e)})
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/update_song', methods=['POST'])
|
@app.route('/api/update_song', methods=['POST'])
|
||||||
def update_song():
|
def update_song():
|
||||||
"""Posodobi naslov in besedilo pesmi"""
|
"""Posodobi naslov in besedilo pesmi ali ustvari novo"""
|
||||||
if _projector_app is None:
|
if _projector_app is None:
|
||||||
return jsonify({'status': 'error', 'message': 'Aplikacija ni inicijalizirana'})
|
return jsonify({'status': 'error', 'message': 'Aplikacija ni inicijalizirana'})
|
||||||
|
|
||||||
@@ -197,6 +207,25 @@ def update_song():
|
|||||||
return jsonify({'status': 'error', 'message': 'Manjkajoči podatki'})
|
return jsonify({'status': 'error', 'message': 'Manjkajoči podatki'})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if song_id == 'new':
|
||||||
|
# Pridobi prvo naslednjo prosto številko
|
||||||
|
_projector_app.cursor.execute("SELECT MAX(id) FROM songs")
|
||||||
|
max_id = _projector_app.cursor.fetchone()[0]
|
||||||
|
new_id = (max_id or 0) + 1
|
||||||
|
|
||||||
|
_projector_app.cursor.execute(
|
||||||
|
"INSERT INTO songs (id, title, lyrics) VALUES (?, ?, ?)",
|
||||||
|
(new_id, title, lyrics)
|
||||||
|
)
|
||||||
|
_projector_app.conn.commit()
|
||||||
|
|
||||||
|
# Naloži novo pesem
|
||||||
|
_projector_app.song_number = str(new_id)
|
||||||
|
_projector_app.load_song()
|
||||||
|
|
||||||
|
return jsonify({'status': 'ok', 'new_id': new_id})
|
||||||
|
|
||||||
|
# Obstoječa pesem
|
||||||
_projector_app.cursor.execute("UPDATE songs SET title=?, lyrics=? WHERE id=?", (title, lyrics, song_id))
|
_projector_app.cursor.execute("UPDATE songs SET title=?, lyrics=? WHERE id=?", (title, lyrics, song_id))
|
||||||
_projector_app.conn.commit()
|
_projector_app.conn.commit()
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,19 @@ const editTitleInput = document.getElementById('edit-title');
|
|||||||
const editLyricsInput = document.getElementById('edit-lyrics');
|
const editLyricsInput = document.getElementById('edit-lyrics');
|
||||||
const saveEditBtn = document.getElementById('save-edit-btn');
|
const saveEditBtn = document.getElementById('save-edit-btn');
|
||||||
const cancelEditBtn = document.getElementById('cancel-edit-btn');
|
const cancelEditBtn = document.getElementById('cancel-edit-btn');
|
||||||
|
const editSongNumberDisplay = document.getElementById('edit-song-number-display');
|
||||||
|
|
||||||
|
// Prompt Modal elementi
|
||||||
|
const promptModal = document.getElementById('prompt-modal');
|
||||||
|
const promptInput = document.getElementById('prompt-input');
|
||||||
|
const promptEditBtn = document.getElementById('prompt-edit-btn');
|
||||||
|
const promptCancelBtn = document.getElementById('prompt-cancel-btn');
|
||||||
|
const promptNewBtn = document.getElementById('prompt-new-btn');
|
||||||
|
|
||||||
|
// Info Modal elementi
|
||||||
|
const infoModal = document.getElementById('info-modal');
|
||||||
|
const infoMessage = document.getElementById('info-message');
|
||||||
|
const infoOkBtn = document.getElementById('info-ok-btn');
|
||||||
|
|
||||||
let capsMode = false;
|
let capsMode = false;
|
||||||
let wakeLock = null;
|
let wakeLock = null;
|
||||||
@@ -225,20 +238,38 @@ async function toggleCaps() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Odpri urejevalnik
|
// Odpri urejevalnik
|
||||||
async function openEditor() {
|
async function openEditor(songId = null) {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/get_song_details');
|
if (songId === 'new') {
|
||||||
|
editTitleInput.value = '';
|
||||||
|
editLyricsInput.value = '';
|
||||||
|
editModal.dataset.songId = 'new';
|
||||||
|
editSongNumberDisplay.textContent = '';
|
||||||
|
editModal.style.display = 'block';
|
||||||
|
menuDropdown.classList.remove('show');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = songId ? `/api/get_song_details?id=${songId}` : '/api/get_song_details';
|
||||||
|
const response = await fetch(url);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
if (data.status === 'ok') {
|
if (data.status === 'ok') {
|
||||||
editTitleInput.value = data.song.title;
|
editTitleInput.value = data.song.title;
|
||||||
editLyricsInput.value = data.song.lyrics;
|
editLyricsInput.value = data.song.lyrics;
|
||||||
editModal.dataset.songId = data.song.id;
|
editModal.dataset.songId = data.song.id;
|
||||||
|
editSongNumberDisplay.textContent = data.song.id;
|
||||||
editModal.style.display = 'block';
|
editModal.style.display = 'block';
|
||||||
menuDropdown.classList.remove('show');
|
menuDropdown.classList.remove('show');
|
||||||
} else {
|
} else {
|
||||||
alert(data.message || 'Za urejanje najprej naložite besedilo.');
|
if (!songId) {
|
||||||
|
// Če ni naložene pesmi, pokaži prompt
|
||||||
|
promptModal.style.display = 'block';
|
||||||
|
promptInput.value = '';
|
||||||
menuDropdown.classList.remove('show');
|
menuDropdown.classList.remove('show');
|
||||||
|
} else {
|
||||||
|
alert(data.message || 'Napaka pri pridobivanju podatkov.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Napaka pri pridobivanju podatkov:', error);
|
console.error('Napaka pri pridobivanju podatkov:', error);
|
||||||
@@ -246,6 +277,11 @@ async function openEditor() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showInfo(message) {
|
||||||
|
infoMessage.textContent = message;
|
||||||
|
infoModal.style.display = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
// Zapri urejevalnik
|
// Zapri urejevalnik
|
||||||
function closeEditor() {
|
function closeEditor() {
|
||||||
editModal.style.display = 'none';
|
editModal.style.display = 'none';
|
||||||
@@ -276,6 +312,9 @@ async function saveSongEdit() {
|
|||||||
|
|
||||||
if (data.status === 'ok') {
|
if (data.status === 'ok') {
|
||||||
closeEditor();
|
closeEditor();
|
||||||
|
if (data.new_id) {
|
||||||
|
showInfo(`Nova pesem je bila shranjena pod številko: ${data.new_id}`);
|
||||||
|
}
|
||||||
await updateState(true);
|
await updateState(true);
|
||||||
} else {
|
} else {
|
||||||
alert('Napaka pri shranjevanju: ' + data.message);
|
alert('Napaka pri shranjevanju: ' + data.message);
|
||||||
@@ -376,6 +415,39 @@ if (saveEditBtn) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prompt Modal dogodki
|
||||||
|
if (promptEditBtn) {
|
||||||
|
promptEditBtn.addEventListener('click', () => {
|
||||||
|
const id = promptInput.value.trim();
|
||||||
|
if (id) {
|
||||||
|
promptModal.style.display = 'none';
|
||||||
|
openEditor(id);
|
||||||
|
} else {
|
||||||
|
alert('Vnesite številko pesmi.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (promptCancelBtn) {
|
||||||
|
promptCancelBtn.addEventListener('click', () => {
|
||||||
|
promptModal.style.display = 'none';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (promptNewBtn) {
|
||||||
|
promptNewBtn.addEventListener('click', () => {
|
||||||
|
promptModal.style.display = 'none';
|
||||||
|
openEditor('new');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Info Modal dogodki
|
||||||
|
if (infoOkBtn) {
|
||||||
|
infoOkBtn.addEventListener('click', () => {
|
||||||
|
infoModal.style.display = 'none';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Hamburger menu toggle
|
// Hamburger menu toggle
|
||||||
if (menuToggle) {
|
if (menuToggle) {
|
||||||
menuToggle.addEventListener('click', (e) => {
|
menuToggle.addEventListener('click', (e) => {
|
||||||
@@ -430,6 +502,14 @@ document.addEventListener('keydown', (e) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Če smo v promptu za številko, ne procesiraj bližnjic za numerično tipkovnico
|
||||||
|
if (promptModal && promptModal.style.display === 'block') {
|
||||||
|
if (e.key === 'Escape') {
|
||||||
|
promptModal.style.display = 'none';
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// na telefonu ni potrebe; na velikih ekranih pa naj dela
|
// na telefonu ni potrebe; na velikih ekranih pa naj dela
|
||||||
if (window.innerWidth < 901) return;
|
if (window.innerWidth < 901) return;
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
<!-- Edit Modal -->
|
<!-- Edit Modal -->
|
||||||
<div id="edit-modal" class="modal">
|
<div id="edit-modal" class="modal">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<h2 id="edit-modal-title">Uredi besedilo</h2>
|
<h2 id="edit-modal-title">Uredi besedilo <span id="edit-song-number-display" style="float: right; color: var(--text-muted);"></span></h2>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="edit-title">Naslov:</label>
|
<label for="edit-title">Naslov:</label>
|
||||||
<input type="text" id="edit-title" class="form-control">
|
<input type="text" id="edit-title" class="form-control">
|
||||||
@@ -49,6 +49,35 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Prompt Modal -->
|
||||||
|
<div id="prompt-modal" class="modal">
|
||||||
|
<div class="modal-content">
|
||||||
|
<h2 id="prompt-title">Uredi besedilo</h2>
|
||||||
|
<p id="prompt-message">Nobena pesem ni naložena. Vnesite številko pesmi za urejanje ali ustvarite novo.</p>
|
||||||
|
<div class="form-group">
|
||||||
|
<input type="number" id="prompt-input" class="form-control" placeholder="Številka pesmi">
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer" style="justify-content: space-between;">
|
||||||
|
<button id="prompt-new-btn" class="btn-secondary" style="background-color: #c28b24; color: white; border: none;">Ustvari novo</button>
|
||||||
|
<div style="display: flex; gap: 10px;">
|
||||||
|
<button id="prompt-cancel-btn" class="btn-secondary">Prekliči</button>
|
||||||
|
<button id="prompt-edit-btn" class="btn-primary">Uredi</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Info Modal -->
|
||||||
|
<div id="info-modal" class="modal">
|
||||||
|
<div class="modal-content">
|
||||||
|
<h2 id="info-title">Informacija</h2>
|
||||||
|
<p id="info-message"></p>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button id="info-ok-btn" class="btn-primary">V redu</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div id="display-area" class="lyrics-display">
|
<div id="display-area" class="lyrics-display">
|
||||||
<span class="status-message">Pripravljeno. Vpiši številko pesmi ali drugega besedila.</span>
|
<span class="status-message">Pripravljeno. Vpiši številko pesmi ali drugega besedila.</span>
|
||||||
|
|||||||
Reference in New Issue
Block a user