v0.14.15
This commit is contained in:
+28
-3
@@ -311,6 +311,17 @@ function drawCurrentChartIfVisible() {
|
||||
if (app.currentView === 'history') renderHistoryPage();
|
||||
}
|
||||
|
||||
function publicCustomChartUrl(path) {
|
||||
if (!APP_BASE.startsWith('/api/hassio_ingress/')) return `${location.origin}${APP_BASE}${path}`;
|
||||
const bind = String(app.system?.bind || '');
|
||||
const port = bind.match(/:(\d+)$/)?.[1] || '8787';
|
||||
const rawHost = location.hostname || 'localhost';
|
||||
const host = rawHost.includes(':') && !rawHost.startsWith('[') ? `[${rawHost}]` : rawHost;
|
||||
const configuredBase = String(app.system?.base_path || '').trim();
|
||||
const directBase = configuredBase === '/' ? '' : configuredBase.replace(/\/$/, '');
|
||||
return `http://${host}:${port}${directBase}${path}`;
|
||||
}
|
||||
|
||||
async function handleHistoryAction(button) {
|
||||
const action = button.dataset.historyAction;
|
||||
if (action === 'add-series') {
|
||||
@@ -338,9 +349,23 @@ async function handleHistoryAction(button) {
|
||||
}
|
||||
if (action === 'copy-chart-link') {
|
||||
if (!app.customChartSeries.length) return toast(tr('history.noCustomSeries'), true);
|
||||
const path = currentHistoryPath(); updateBrowserUrl(path, true); const link = `${location.origin}${APP_BASE}${path}`;
|
||||
try { await navigator.clipboard.writeText(link); } catch (_) { const area = document.createElement('textarea'); area.value = link; document.body.appendChild(area); area.select(); document.execCommand('copy'); area.remove(); }
|
||||
toast(tr('history.linkCopied')); return;
|
||||
try {
|
||||
const share = await api('/api/charts/custom/share', {
|
||||
method: 'POST',
|
||||
body: {
|
||||
title: $('#customChartName')?.value.trim() || tr('history.customChart'),
|
||||
series: [...app.customChartSeries],
|
||||
hours: Number($('#historyHours')?.value || 24),
|
||||
lang: app.language === 'pl' ? 'pl' : 'en',
|
||||
},
|
||||
});
|
||||
const link = publicCustomChartUrl(share.path);
|
||||
try { await navigator.clipboard.writeText(link); } catch (_) { const area = document.createElement('textarea'); area.value = link; document.body.appendChild(area); area.select(); document.execCommand('copy'); area.remove(); }
|
||||
toast(tr('history.linkCopied'));
|
||||
} catch (error) {
|
||||
toast(error.message, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user