This commit is contained in:
2026-02-01 21:06:19 +01:00
parent 143706d856
commit 08365d9997
2 changed files with 192 additions and 218 deletions
+10 -1
View File
@@ -24,9 +24,19 @@ data:
import requests
from bs4 import BeautifulSoup
from fastapi import FastAPI, Response
from fastapi.middleware.cors import CORSMiddleware
from prometheus_client import Counter, Histogram, Gauge, generate_latest, CONTENT_TYPE_LATEST
APP = FastAPI()
# Add CORS middleware to allow cross-origin requests from Glance dashboards
APP.add_middleware(
CORSMiddleware,
allow_origins=["https://kisfenyo.dooplex.hu", "https://orsi.dooplex.hu", "https://glance-helper.dooplex.hu"],
allow_credentials=True,
allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"],
allow_headers=["*"],
)
# ================================
# Időkép configuration
@@ -1246,7 +1256,6 @@ data:
}, ensure_ascii=False),
media_type="application/json; charset=utf-8"
)
---
apiVersion: apps/v1
kind: Deployment
+182 -217
View File
@@ -777,14 +777,13 @@ data:
{{ $user := .Options.StringOr "user" "kisfenyo" }}
{{ $apiKey := .Options.StringOr "api_key" "" }}
{{ $todos := .JSON.Array "todos" }}
{{ $widgetId := "todo-kisfenyo" }}
<style>
.todo-widget { display: flex; flex-direction: column; gap: 8px; }
.todo-add { display: flex; gap: 8px; align-items: center; }
.todo-add-btn {
background: none; border: none; color: inherit; opacity: 0.6;
cursor: pointer; font-size: 16px; padding: 4px 8px;
cursor: pointer; font-size: 18px; padding: 4px 8px;
transition: opacity 0.15s;
}
.todo-add-btn:hover { opacity: 1; }
@@ -825,29 +824,22 @@ data:
.todo-item:hover .todo-delete { opacity: 0.5; }
.todo-delete:hover { opacity: 1 !important; color: #ef4444; }
.todo-empty { opacity: 0.5; font-size: 13px; padding: 8px 0; text-align: center; }
.todo-loading { opacity: 0.5; font-size: 12px; }
</style>
<div class="todo-widget" id="{{ $widgetId }}">
<div class="todo-widget" data-api="{{ $apiBase }}" data-user="{{ $user }}" data-key="{{ $apiKey }}">
<div class="todo-add">
<span class="todo-add-btn" onclick="todoAddFocus_{{ $widgetId }}()">+</span>
<input type="text" class="todo-add-input" id="{{ $widgetId }}-input"
placeholder="Add a task"
onkeydown="if(event.key==='Enter')todoAdd_{{ $widgetId }}(this.value)">
<button class="todo-add-btn" type="button">+</button>
<input type="text" class="todo-add-input" placeholder="Add a task">
</div>
<div class="todo-list" id="{{ $widgetId }}-list">
<div class="todo-list">
{{ if eq (len $todos) 0 }}
<div class="todo-empty">No tasks yet</div>
{{ else }}
{{ range $todos }}
{{ $id := .String "id" }}
{{ $text := .String "text" }}
{{ $done := .Bool "done" }}
<div class="todo-item" data-id="{{ $id }}" data-text="{{ $text }}" data-done="{{ $done }}">
<div class="todo-checkbox {{ if $done }}done{{ end }}"
onclick="todoToggle_{{ $widgetId }}(this.parentElement)"></div>
<span class="todo-text {{ if $done }}done{{ end }}">{{ $text }}</span>
<button class="todo-delete" onclick="todoDelete_{{ $widgetId }}('{{ $id }}')" title="Delete">🗑</button>
<div class="todo-item" data-id="{{ .String "id" }}" data-text="{{ .String "text" }}" data-done="{{ .Bool "done" }}">
<div class="todo-checkbox {{ if .Bool "done" }}done{{ end }}"></div>
<span class="todo-text {{ if .Bool "done" }}done{{ end }}">{{ .String "text" }}</span>
<button class="todo-delete" type="button" title="Delete">🗑</button>
</div>
{{ end }}
{{ end }}
@@ -856,76 +848,69 @@ data:
<script>
(function() {
const API_BASE = '{{ $apiBase }}';
const USER = '{{ $user }}';
const API_KEY = '{{ $apiKey }}';
const WIDGET_ID = '{{ $widgetId }}';
function getUrl(path) {
return API_BASE + path + (API_KEY ? '?key=' + API_KEY : '');
const widget = document.currentScript.previousElementSibling;
if (!widget || !widget.classList.contains('todo-widget')) return;
const API = widget.dataset.api;
const USER = widget.dataset.user;
const KEY = widget.dataset.key;
function apiUrl(path) {
return API + path + (KEY ? '?key=' + KEY : '');
}
window['todoAddFocus_' + WIDGET_ID] = function() {
document.getElementById(WIDGET_ID + '-input').focus();
};
window['todoAdd_' + WIDGET_ID] = async function(text) {
text = text.trim();
const input = widget.querySelector('.todo-add-input');
const addBtn = widget.querySelector('.todo-add-btn');
async function addTodo() {
const text = input.value.trim();
if (!text) return;
const input = document.getElementById(WIDGET_ID + '-input');
input.disabled = true;
try {
const resp = await fetch(getUrl('/userdata/' + USER + '/todos'), {
const r = await fetch(apiUrl('/userdata/' + USER + '/todos'), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text: text, done: false })
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({text: text, done: false})
});
if (resp.ok) {
input.value = '';
location.reload();
} else {
console.error('Failed to add todo:', await resp.text());
}
} catch (e) {
console.error('Error adding todo:', e);
} finally {
input.disabled = false;
input.focus();
if (r.ok) location.reload();
else console.error('Add failed:', await r.text());
} catch(e) { console.error('Add error:', e); }
input.disabled = false;
}
input.addEventListener('keydown', function(e) {
if (e.key === 'Enter') addTodo();
});
addBtn.addEventListener('click', function() { input.focus(); });
widget.addEventListener('click', async function(e) {
const item = e.target.closest('.todo-item');
if (!item) return;
if (e.target.closest('.todo-checkbox')) {
const id = item.dataset.id;
const text = item.dataset.text;
const newDone = item.dataset.done !== 'true';
try {
const r = await fetch(apiUrl('/userdata/' + USER + '/todos/' + id), {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({text: text, done: newDone})
});
if (r.ok) location.reload();
} catch(e) { console.error('Toggle error:', e); }
}
};
window['todoToggle_' + WIDGET_ID] = async function(itemEl) {
const id = itemEl.dataset.id;
const text = itemEl.dataset.text;
const newDone = itemEl.dataset.done !== 'true';
try {
const resp = await fetch(getUrl('/userdata/' + USER + '/todos/' + id), {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text: text, done: newDone })
});
if (resp.ok) {
location.reload();
}
} catch (e) {
console.error('Error toggling todo:', e);
if (e.target.closest('.todo-delete')) {
const id = item.dataset.id;
try {
const r = await fetch(apiUrl('/userdata/' + USER + '/todos/' + id), {
method: 'DELETE'
});
if (r.ok) location.reload();
} catch(e) { console.error('Delete error:', e); }
}
};
window['todoDelete_' + WIDGET_ID] = async function(id) {
try {
const resp = await fetch(getUrl('/userdata/' + USER + '/todos/' + id), {
method: 'DELETE'
});
if (resp.ok) {
location.reload();
}
} catch (e) {
console.error('Error deleting todo:', e);
}
};
});
})();
</script>
# Outline Notes iframe
@@ -1026,7 +1011,6 @@ data:
{{ $apiKey := .Options.StringOr "api_key" "" }}
{{ $quote := .JSON.String "quote" }}
{{ $total := .JSON.Int "total" }}
{{ $widgetId := "motiv-kisfenyo" }}
<style>
.motiv-widget { position: relative; }
@@ -1042,11 +1026,11 @@ data:
}
.motiv-gear {
cursor: pointer; padding: 2px 6px; border-radius: 4px;
transition: opacity 0.15s, background 0.15s;
transition: opacity 0.15s, background 0.15s; border: none; background: none;
color: inherit; font-size: 11px;
}
.motiv-gear:hover { opacity: 1; background: rgba(255,255,255,0.1); }
/* Management Modal */
.motiv-modal-overlay {
display: none; position: fixed; inset: 0;
background: rgba(0,0,0,0.6); z-index: 99999;
@@ -1068,87 +1052,58 @@ data:
.motiv-modal-close {
background: none; border: none; color: inherit; cursor: pointer;
font-size: 18px; opacity: 0.6; padding: 4px 8px;
transition: opacity 0.15s;
}
.motiv-modal-close:hover { opacity: 1; }
.motiv-modal-body {
flex: 1; overflow-y: auto; padding: 12px 16px;
display: flex; flex-direction: column; gap: 8px;
}
.motiv-modal-add {
display: flex; gap: 8px; padding-bottom: 12px;
border-bottom: 1px solid rgba(255,255,255,0.08);
}
.motiv-modal-add { display: flex; gap: 8px; padding-bottom: 12px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.motiv-modal-input {
flex: 1; background: rgba(255,255,255,0.08);
border: 1px solid rgba(255,255,255,0.1);
border-radius: 6px; padding: 10px 12px;
color: inherit; font-size: 13px; outline: none;
}
.motiv-modal-input:focus {
background: rgba(255,255,255,0.12);
border-color: rgba(255,255,255,0.25);
flex: 1; background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.1);
border-radius: 6px; padding: 10px 12px; color: inherit; font-size: 13px; outline: none;
}
.motiv-modal-input:focus { background: rgba(255,255,255,0.12); border-color: rgba(255,255,255,0.25); }
.motiv-modal-btn {
background: rgba(96, 165, 250, 0.3); border: none;
color: inherit; padding: 10px 16px; border-radius: 6px;
cursor: pointer; font-size: 13px; font-weight: 500;
transition: background 0.15s;
background: rgba(96, 165, 250, 0.3); border: none; color: inherit; padding: 10px 16px;
border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 500;
}
.motiv-modal-btn:hover { background: rgba(96, 165, 250, 0.5); }
.motiv-modal-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.motiv-list { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.motiv-list-title {
font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
opacity: 0.5; margin-bottom: 4px;
}
.motiv-list-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; opacity: 0.5; margin-bottom: 4px; }
.motiv-item {
display: flex; align-items: flex-start; gap: 10px;
padding: 10px 12px; background: rgba(255,255,255,0.04);
border-radius: 8px; transition: background 0.15s;
display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px;
background: rgba(255,255,255,0.04); border-radius: 8px;
}
.motiv-item:hover { background: rgba(255,255,255,0.08); }
.motiv-item-text {
flex: 1; font-size: 13px; line-height: 1.4; opacity: 0.9;
}
.motiv-item-text { flex: 1; font-size: 13px; line-height: 1.4; opacity: 0.9; }
.motiv-item-delete {
background: none; border: none; color: inherit;
cursor: pointer; opacity: 0.4; padding: 2px 6px;
font-size: 13px; transition: opacity 0.15s, color 0.15s;
background: none; border: none; color: inherit; cursor: pointer;
opacity: 0.4; padding: 2px 6px; font-size: 13px;
}
.motiv-item-delete:hover { opacity: 1; color: #ef4444; }
.motiv-empty {
text-align: center; opacity: 0.5; padding: 20px;
font-size: 13px;
}
.motiv-loading { text-align: center; padding: 20px; opacity: 0.6; }
.motiv-empty { text-align: center; opacity: 0.5; padding: 20px; font-size: 13px; }
</style>
<div class="motiv-widget" id="{{ $widgetId }}">
<div class="motiv-widget" data-api="{{ $apiBase }}" data-user="{{ $user }}" data-key="{{ $apiKey }}">
<div class="motiv-quote">{{ $quote }}</div>
<div class="motiv-meta">
<span>{{ $total }} quotes</span>
<span class="motiv-gear" onclick="motivOpenModal_{{ $widgetId }}()" title="Manage quotes">⚙️ Manage</span>
<button class="motiv-gear" type="button" title="Manage quotes">⚙️ Manage</button>
</div>
</div>
<!-- Management Modal (appended to body) -->
<div class="motiv-modal-overlay" id="{{ $widgetId }}-modal">
<div class="motiv-modal">
<div class="motiv-modal-header">
<span class="motiv-modal-title">Manage Motivation Quotes</span>
<button class="motiv-modal-close" onclick="motivCloseModal_{{ $widgetId }}()">×</button>
</div>
<div class="motiv-modal-body">
<div class="motiv-modal-add">
<input type="text" class="motiv-modal-input" id="{{ $widgetId }}-new"
placeholder="Add a new motivational quote..."
onkeydown="if(event.key==='Enter')motivAdd_{{ $widgetId }}()">
<button class="motiv-modal-btn" onclick="motivAdd_{{ $widgetId }}()">Add</button>
<div class="motiv-modal-overlay">
<div class="motiv-modal">
<div class="motiv-modal-header">
<span class="motiv-modal-title">Manage Motivation Quotes</span>
<button class="motiv-modal-close" type="button">×</button>
</div>
<div class="motiv-list-title">Your Quotes</div>
<div class="motiv-list" id="{{ $widgetId }}-list">
<div class="motiv-loading">Loading quotes...</div>
<div class="motiv-modal-body">
<div class="motiv-modal-add">
<input type="text" class="motiv-modal-input" placeholder="Add a new motivational quote...">
<button class="motiv-modal-btn" type="button">Add</button>
</div>
<div class="motiv-list-title">Your Quotes</div>
<div class="motiv-list"><div class="motiv-empty">Click Manage to load quotes</div></div>
</div>
</div>
</div>
@@ -1156,111 +1111,121 @@ data:
<script>
(function() {
const API_BASE = '{{ $apiBase }}';
const USER = '{{ $user }}';
const API_KEY = '{{ $apiKey }}';
const WIDGET_ID = '{{ $widgetId }}';
const widget = document.currentScript.previousElementSibling;
if (!widget || !widget.classList.contains('motiv-widget')) return;
let quotesCache = [];
function getUrl(path) {
return API_BASE + path + (API_KEY ? '?key=' + API_KEY : '');
const API = widget.dataset.api;
const USER = widget.dataset.user;
const KEY = widget.dataset.key;
const modal = widget.querySelector('.motiv-modal-overlay');
const listEl = widget.querySelector('.motiv-list');
const input = widget.querySelector('.motiv-modal-input');
const addBtn = widget.querySelector('.motiv-modal-btn');
const closeBtn = widget.querySelector('.motiv-modal-close');
const gearBtn = widget.querySelector('.motiv-gear');
let quotes = [];
function apiUrl(path) {
return API + path + (KEY ? '?key=' + KEY : '');
}
function escapeHtml(str) {
const div = document.createElement('div');
div.textContent = str;
return div.innerHTML;
function esc(s) {
const d = document.createElement('div');
d.textContent = s;
return d.innerHTML;
}
async function loadQuotes() {
const listEl = document.getElementById(WIDGET_ID + '-list');
listEl.innerHTML = '<div class="motiv-empty">Loading...</div>';
try {
const resp = await fetch(getUrl('/userdata/' + USER + '/motivation').replace('?key=', ''));
const data = await resp.json();
quotesCache = data.quotes || [];
renderQuotes();
} catch (e) {
listEl.innerHTML = '<div class="motiv-empty">Error loading quotes</div>';
console.error('Error loading quotes:', e);
const r = await fetch(API + '/userdata/' + USER + '/motivation');
const d = await r.json();
quotes = d.quotes || [];
render();
} catch(e) {
listEl.innerHTML = '<div class="motiv-empty">Error loading</div>';
console.error(e);
}
}
function renderQuotes() {
const listEl = document.getElementById(WIDGET_ID + '-list');
if (quotesCache.length === 0) {
listEl.innerHTML = '<div class="motiv-empty">No quotes yet. Add some above!</div>';
function render() {
if (!quotes.length) {
listEl.innerHTML = '<div class="motiv-empty">No quotes yet</div>';
return;
}
listEl.innerHTML = quotesCache.map((q, i) =>
'<div class="motiv-item">' +
'<span class="motiv-item-text">' + escapeHtml(q) + '</span>' +
'<button class="motiv-item-delete" onclick="motivDelete_' + WIDGET_ID + '(' + i + ')" title="Delete">🗑</button>' +
listEl.innerHTML = quotes.map((q, i) =>
'<div class="motiv-item" data-index="' + i + '">' +
'<span class="motiv-item-text">' + esc(q) + '</span>' +
'<button class="motiv-item-delete" type="button">🗑</button>' +
'</div>'
).join('');
}
window['motivOpenModal_' + WIDGET_ID] = function() {
const modal = document.getElementById(WIDGET_ID + '-modal');
gearBtn.addEventListener('click', function() {
modal.classList.add('active');
loadQuotes();
// Close on overlay click
modal.onclick = function(e) {
if (e.target === modal) window['motivCloseModal_' + WIDGET_ID]();
};
// Close on Escape
document.addEventListener('keydown', function handler(e) {
if (e.key === 'Escape') {
window['motivCloseModal_' + WIDGET_ID]();
document.removeEventListener('keydown', handler);
}
});
};
window['motivCloseModal_' + WIDGET_ID] = function() {
document.getElementById(WIDGET_ID + '-modal').classList.remove('active');
};
window['motivAdd_' + WIDGET_ID] = async function() {
const input = document.getElementById(WIDGET_ID + '-new');
});
closeBtn.addEventListener('click', function() {
modal.classList.remove('active');
});
modal.addEventListener('click', function(e) {
if (e.target === modal) modal.classList.remove('active');
});
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape' && modal.classList.contains('active')) {
modal.classList.remove('active');
}
});
async function addQuote() {
const text = input.value.trim();
if (!text) return;
input.disabled = true;
addBtn.disabled = true;
try {
const resp = await fetch(getUrl('/userdata/' + USER + '/motivation'), {
const r = await fetch(apiUrl('/userdata/' + USER + '/motivation'), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text: text })
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({text: text})
});
if (resp.ok) {
if (r.ok) {
input.value = '';
const data = await resp.json();
quotesCache = data.quotes || [];
renderQuotes();
const d = await r.json();
quotes = d.quotes || [];
render();
}
} catch (e) {
console.error('Error adding quote:', e);
} finally {
input.disabled = false;
input.focus();
}
};
window['motivDelete_' + WIDGET_ID] = async function(index) {
} catch(e) { console.error(e); }
input.disabled = false;
addBtn.disabled = false;
input.focus();
}
addBtn.addEventListener('click', addQuote);
input.addEventListener('keydown', function(e) {
if (e.key === 'Enter') addQuote();
});
listEl.addEventListener('click', async function(e) {
const del = e.target.closest('.motiv-item-delete');
if (!del) return;
const item = del.closest('.motiv-item');
const idx = item.dataset.index;
try {
const resp = await fetch(getUrl('/userdata/' + USER + '/motivation/' + index), {
const r = await fetch(apiUrl('/userdata/' + USER + '/motivation/' + idx), {
method: 'DELETE'
});
if (resp.ok) {
const data = await resp.json();
quotesCache = data.quotes || [];
renderQuotes();
if (r.ok) {
const d = await r.json();
quotes = d.quotes || [];
render();
}
} catch (e) {
console.error('Error deleting quote:', e);
}
};
} catch(e) { console.error(e); }
});
})();
</script>