Fix: Admin SPA Ana Sayfa dönüş problemi çözüldü
- Ana Sayfa butonu çalışmıyordu, sayfa yenileniyordu
- Engelleleyici genel condition kaldırıldı: if (page === '') → goto('/dashboard')
- Admin-specific Ana Sayfa case'i eklendi
- resetAdminStates() fonksiyonu ile tüm state'ler sıfırlanıyor
- Svelte reactivity için tick() eklendi
- Active buton durumları düzgün çalışıyor
- Single Page Application navigation artık sorunsuz
🚀 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,12 @@
|
|||||||
<script>
|
<script>
|
||||||
import { onMount, onDestroy } from 'svelte';
|
import { onMount, onDestroy, tick } from 'svelte';
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
import { io } from 'socket.io-client';
|
import { io } from 'socket.io-client';
|
||||||
|
import VehiclesContent from '$lib/components/VehiclesContent.svelte';
|
||||||
|
import UnitsContent from '$lib/components/UnitsContent.svelte';
|
||||||
|
import PersonnelContent from '$lib/components/PersonnelContent.svelte';
|
||||||
|
import GoodsManagersContent from '$lib/components/GoodsManagersContent.svelte';
|
||||||
|
import GoodsManagerContent from '$lib/components/GoodsManagerContent.svelte';
|
||||||
|
|
||||||
let user = null;
|
let user = null;
|
||||||
let loading = true;
|
let loading = true;
|
||||||
@@ -9,8 +14,23 @@
|
|||||||
let showMobileMenu = false;
|
let showMobileMenu = false;
|
||||||
let showFuelForm = false;
|
let showFuelForm = false;
|
||||||
let showGoodsManager = false;
|
let showGoodsManager = false;
|
||||||
|
let showVehicles = false;
|
||||||
|
let showUnits = false;
|
||||||
|
let showPersonnel = false;
|
||||||
|
let showGoodsManagers = false;
|
||||||
let socket = null;
|
let socket = null;
|
||||||
|
|
||||||
|
// Admin state reset function
|
||||||
|
function resetAdminStates() {
|
||||||
|
showVehicles = false;
|
||||||
|
showUnits = false;
|
||||||
|
showPersonnel = false;
|
||||||
|
showGoodsManagers = false;
|
||||||
|
showFuelForm = false;
|
||||||
|
showGoodsManager = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Fuel Manager için veriler
|
// Fuel Manager için veriler
|
||||||
let fuelSummary = { benzin: 0, motorin: 0 };
|
let fuelSummary = { benzin: 0, motorin: 0 };
|
||||||
let pendingSlips = [];
|
let pendingSlips = [];
|
||||||
@@ -331,7 +351,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function navigateTo(page) {
|
function navigateTo(page) {
|
||||||
console.log('🔄 navigateTo called with:', page, 'user role:', user?.role);
|
|
||||||
|
|
||||||
if (page === 'fuel-slips' && user?.role === 'fuel_manager') {
|
if (page === 'fuel-slips' && user?.role === 'fuel_manager') {
|
||||||
showFuelForm = true;
|
showFuelForm = true;
|
||||||
@@ -367,11 +386,6 @@
|
|||||||
|
|
||||||
showMobileMenu = false;
|
showMobileMenu = false;
|
||||||
|
|
||||||
if (page === '') {
|
|
||||||
goto('/dashboard');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (page === 'goods-manager') {
|
if (page === 'goods-manager') {
|
||||||
if (user?.role === 'goods_manager') {
|
if (user?.role === 'goods_manager') {
|
||||||
console.log('🎯 Setting showGoodsManager to true');
|
console.log('🎯 Setting showGoodsManager to true');
|
||||||
@@ -385,6 +399,49 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Admin page navigation for SPA
|
||||||
|
if (user?.role === 'admin') {
|
||||||
|
// Hide all content first
|
||||||
|
showFuelForm = false;
|
||||||
|
showGoodsManager = false;
|
||||||
|
|
||||||
|
// 🎯 Ana Sayfa Case'i - Admin SPA içinde ana sayfaya dönüş
|
||||||
|
if (page === '') {
|
||||||
|
resetAdminStates(); // Tüm admin state'lerini false yap
|
||||||
|
showMobileMenu = false;
|
||||||
|
tick(); // Svelte reactivity'yi zorla
|
||||||
|
return; // goto çağrısı yapma, SPA içinde kal
|
||||||
|
}
|
||||||
|
|
||||||
|
if (page === 'vehicles') {
|
||||||
|
resetAdminStates();
|
||||||
|
showVehicles = true;
|
||||||
|
showMobileMenu = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (page === 'units') {
|
||||||
|
resetAdminStates();
|
||||||
|
showUnits = true;
|
||||||
|
showMobileMenu = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (page === 'personnel') {
|
||||||
|
resetAdminStates();
|
||||||
|
showPersonnel = true;
|
||||||
|
showMobileMenu = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (page === 'goods-managers') {
|
||||||
|
resetAdminStates();
|
||||||
|
showGoodsManagers = true;
|
||||||
|
showMobileMenu = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
goto(`/dashboard/${page}`);
|
goto(`/dashboard/${page}`);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -414,7 +471,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<ul class="nav-menu">
|
<ul class="nav-menu">
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<button class="nav-btn" on:click={() => navigateTo('')} class:active={user.role === 'goods_manager' ? !showGoodsManager : (user.role !== 'fuel_manager' ? !showFuelForm : true)}>
|
<button class="nav-btn" on:click={() => navigateTo('')} class:active={user.role === 'admin' ? !showVehicles && !showUnits && !showPersonnel && !showGoodsManagers : (user.role === 'goods_manager' ? !showGoodsManager : (user.role !== 'fuel_manager' ? !showFuelForm : true))}>
|
||||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
<path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/>
|
<path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/>
|
||||||
<polyline points="9 22 9 12 15 12 15 22"/>
|
<polyline points="9 22 9 12 15 12 15 22"/>
|
||||||
@@ -425,7 +482,7 @@
|
|||||||
|
|
||||||
{#if user.role === 'admin'}
|
{#if user.role === 'admin'}
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<button class="nav-btn" on:click={() => navigateTo('vehicles')}>
|
<button class="nav-btn" on:click={() => navigateTo('vehicles')} class:active={showVehicles}>
|
||||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
<path d="M19 9l-7 7-7-7"/>
|
<path d="M19 9l-7 7-7-7"/>
|
||||||
<rect x="11" y="5" width="2" height="14"/>
|
<rect x="11" y="5" width="2" height="14"/>
|
||||||
@@ -435,7 +492,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<button class="nav-btn" on:click={() => navigateTo('units')}>
|
<button class="nav-btn" on:click={() => navigateTo('units')} class:active={showUnits}>
|
||||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
<path d="M3 21h18"/>
|
<path d="M3 21h18"/>
|
||||||
<path d="M5 21V7l8-4v18"/>
|
<path d="M5 21V7l8-4v18"/>
|
||||||
@@ -445,7 +502,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<button class="nav-btn" on:click={() => navigateTo('personnel')}>
|
<button class="nav-btn" on:click={() => navigateTo('personnel')} class:active={showPersonnel}>
|
||||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/>
|
<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/>
|
||||||
<circle cx="9" cy="7" r="4"/>
|
<circle cx="9" cy="7" r="4"/>
|
||||||
@@ -456,7 +513,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<button class="nav-btn" on:click={() => navigateTo('goods-managers')}>
|
<button class="nav-btn" on:click={() => navigateTo('goods-managers')} class:active={showGoodsManagers}>
|
||||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/>
|
<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/>
|
||||||
<circle cx="9" cy="7" r="4"/>
|
<circle cx="9" cy="7" r="4"/>
|
||||||
@@ -544,7 +601,7 @@
|
|||||||
<div class="divider"></div>
|
<div class="divider"></div>
|
||||||
|
|
||||||
<!-- Sadece admin ve goods_manager için bilgilendirme -->
|
<!-- Sadece admin ve goods_manager için bilgilendirme -->
|
||||||
{#if user.role === 'admin' || (user.role === 'goods_manager' && !showGoodsManager)}
|
{#if user.role === 'admin' && !showVehicles && !showUnits && !showPersonnel && !showGoodsManagers}
|
||||||
<!-- Karşılama mesajı -->
|
<!-- Karşılama mesajı -->
|
||||||
<div class="welcome-content">
|
<div class="welcome-content">
|
||||||
<div class="welcome-icon">
|
<div class="welcome-icon">
|
||||||
@@ -664,6 +721,30 @@
|
|||||||
<p style="margin-top: 1rem; color: var(--primary-color); font-weight: 600;">✅ SPA navigasyonu başarıyla çalışıyor!</p>
|
<p style="margin-top: 1rem; color: var(--primary-color); font-weight: 600;">✅ SPA navigasyonu başarıyla çalışıyor!</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{:else if user.role === 'admin'}
|
||||||
|
<!-- Admin Dynamic Content -->
|
||||||
|
|
||||||
|
{#if showVehicles}
|
||||||
|
<VehiclesContent {user} />
|
||||||
|
{:else if showUnits}
|
||||||
|
<UnitsContent {user} />
|
||||||
|
{:else if showPersonnel}
|
||||||
|
<PersonnelContent {user} />
|
||||||
|
{:else if showGoodsManagers}
|
||||||
|
<GoodsManagersContent {user} />
|
||||||
|
{:else}
|
||||||
|
<!-- Admin Welcome Message (Default) -->
|
||||||
|
<div class="welcome-card card">
|
||||||
|
<div class="card-header">
|
||||||
|
<div class="card-icon">🚗</div>
|
||||||
|
<h3>Araç Yönetimi</h3>
|
||||||
|
</div>
|
||||||
|
<div class="card-content">
|
||||||
|
<p>Yukarıdaki menüden Araç Yönetimi'ni seçerek araçları yönetebilirsiniz.</p>
|
||||||
|
<p style="margin-top: 1rem; color: var(--primary-color); font-weight: 600;">✅ Admin SPA yüklendi!</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
{:else}
|
{:else}
|
||||||
<!-- Fuel Manager ana görünümü -->
|
<!-- Fuel Manager ana görünümü -->
|
||||||
{#if formSuccess}
|
{#if formSuccess}
|
||||||
|
|||||||
Reference in New Issue
Block a user