Tekniikka sub-tab pysyy refreshin yli (hash-navigointi)

URL-hash tallentaa nyt sub-tabin: #tekniikka/ipam, #tekniikka/sites
jne. Refreshatessa palataan samalle sub-tabille.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-11 09:25:57 +02:00
parent 03c9a7605a
commit 9830ed6b82

View File

@@ -194,9 +194,10 @@ async function showDashboard() {
populateCompanySelector();
// Avaa oikea tabi URL-hashin perusteella (tai customers oletuks)
const hash = window.location.hash.replace('#', '');
const [mainHash, subHash] = hash.split('/');
const validTabs = ['customers', 'leads', 'tekniikka', 'archive', 'changelog', 'support', 'users', 'settings', 'companies'];
const startTab = validTabs.includes(hash) ? hash : 'customers';
switchToTab(startTab);
const startTab = validTabs.includes(mainHash) ? mainHash : 'customers';
switchToTab(startTab, subHash);
}
function populateCompanySelector() {
@@ -223,13 +224,14 @@ async function switchCompany(companyId) {
} catch (e2) {}
// Lataa uudelleen aktiivinen tab
const hash = window.location.hash.replace('#', '') || 'customers';
switchToTab(hash);
const [mainTab, subTab] = hash.split('/');
switchToTab(mainTab, subTab);
} catch (e) { alert(e.message); }
}
// ==================== TABS ====================
function switchToTab(target) {
function switchToTab(target, subTab) {
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
const tabBtn = document.querySelector(`.tab[data-tab="${target}"]`);
@@ -237,11 +239,20 @@ function switchToTab(target) {
const content = document.getElementById('tab-content-' + target);
if (content) content.classList.add('active');
// Tallenna aktiivinen tabi URL-hashiin
window.location.hash = target;
if (target === 'tekniikka' && subTab) {
window.location.hash = target + '/' + subTab;
} else {
window.location.hash = target;
}
// Lataa sisältö tarvittaessa
if (target === 'customers') loadCustomers();
if (target === 'leads') loadLeads();
if (target === 'tekniikka') { loadDevices(); loadSitesTab(); loadIpam(); }
if (target === 'tekniikka') {
loadDevices(); loadSitesTab(); loadIpam();
// Palauta sub-tab
const validSubTabs = ['devices', 'sites', 'ipam'];
if (subTab && validSubTabs.includes(subTab)) switchSubTab(subTab);
}
if (target === 'archive') loadArchive();
if (target === 'changelog') loadChangelog();
if (target === 'support') { loadTickets(); showTicketListView(); if (document.getElementById('ticket-auto-refresh').checked) startTicketAutoRefresh(); }
@@ -2799,6 +2810,8 @@ function switchSubTab(target) {
if (btn) btn.classList.add('active');
const content = document.getElementById('subtab-' + target);
if (content) content.classList.add('active');
// Tallenna sub-tab hashiin (esim. #tekniikka/ipam)
window.location.hash = 'tekniikka/' + target;
}
document.querySelectorAll('#tab-content-tekniikka .sub-tab').forEach(btn => {