diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php new file mode 100644 index 0000000..f9f26d4 --- /dev/null +++ b/app/Http/Controllers/DashboardController.php @@ -0,0 +1,26 @@ +user()->load('portfolios'); + + $dashboard = new stdClass; + $dashboard->marketGainLoss = rand(-200, 3999); + $dashboard->totalCostBasis = rand(-200, 3999); + $dashboard->totalMarketValue = rand(-200, 3999); + $dashboard->realizedGainLoss = rand(-200, 3999); + $dashboard->dividendsEarned = rand(-200, 3999); + + return view('dashboard', compact('user', 'dashboard')); + } +} diff --git a/app/Http/Controllers/PortfolioController.php b/app/Http/Controllers/PortfolioController.php index 16483a2..90e3777 100644 --- a/app/Http/Controllers/PortfolioController.php +++ b/app/Http/Controllers/PortfolioController.php @@ -20,6 +20,13 @@ class PortfolioController extends Controller */ public function show(Portfolio $portfolio) { + + $portfolio->marketGainLoss = rand(-200, 3999); + $portfolio->totalCostBasis = rand(-200, 3999); + $portfolio->totalMarketValue = rand(-200, 3999); + $portfolio->realizedGainLoss = rand(-200, 3999); + $portfolio->dividendsEarned = rand(-200, 3999); + return view('portfolio.show', compact('portfolio')); } } diff --git a/resources/views/components/ib-apex-chart.blade.php b/resources/views/components/ib-apex-chart.blade.php index 61e37d2..cf31202 100644 --- a/resources/views/components/ib-apex-chart.blade.php +++ b/resources/views/components/ib-apex-chart.blade.php @@ -73,92 +73,79 @@ $seriesData = json_encode($seriesData) @endphp -
-
-
- + + var chart = new ApexCharts(document.querySelector('#chart-{{ $name }}'), this.data); + + chart.render(); + + function renderCustomLegend(chartContext) { + var legendContainer = document.querySelector('#chart-legend-{{ $name }}'); + + if (!legendContainer) return; + + legendContainer.innerHTML = ''; // Clear any existing legend items + + chartContext.w.globals.seriesNames.forEach(function (seriesName, i) { + + var seriesColor = chartContext.w.config.colors[i]; + var legendItem = document.createElement('div'); + legendItem.classList.add('flex', 'items-center', 'm-2', 'cursor-pointer'); + legendItem.setAttribute('data-series-index', i); + + var colorBox = document.createElement('span'); + colorBox.id = seriesName + colorBox.classList.add('w-4', 'h-4', 'inline-block', 'mr-2'); + colorBox.style.backgroundColor = seriesColor; + + var labelText = document.createElement('span'); + labelText.textContent = seriesName; + + legendItem.appendChild(colorBox); + legendItem.appendChild(labelText); + legendContainer.appendChild(legendItem); + + // Initial visibility state + var isCollapsed = chartContext.w.globals.collapsedSeriesIndices.includes(i); + if (isCollapsed) { + legendItem.classList.add('opacity-50'); + } + + legendItem.addEventListener('click', function () { + + var seriesIndex = parseInt(this.getAttribute('data-series-index'), 10); + var isCurrentlyCollapsed = chartContext.w.globals.collapsedSeriesIndices.includes(seriesIndex); + + chart.toggleSeries(chartContext.w.globals.seriesNames[seriesIndex]); + + if (isCurrentlyCollapsed) { + this.classList.remove('opacity-50'); + } else { + this.classList.add('opacity-50'); + } + }); + }); + } + + } + }" +> +
+ + diff --git a/resources/views/components/partials/side-bar.blade.php b/resources/views/components/partials/side-bar.blade.php index 429087c..cb55a9e 100644 --- a/resources/views/components/partials/side-bar.blade.php +++ b/resources/views/components/partials/side-bar.blade.php @@ -3,7 +3,15 @@ @foreach (auth()->user()->portfolios as $portfolio) - + + + {{ $portfolio->title }} + @if($portfolio->wishlist) + + @endif + + + @endforeach diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 0820ae9..ada1d93 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -1,62 +1,59 @@ - + @livewire('portfolio-performance-cards', [ + 'name' => 'dashboard' + ]) - @livewire('portfolio-performance-chart', [ - 'name' => 'dashboard' - ]) - - +
+ @php + $formatter = new NumberFormatter('en_US', NumberFormatter::CURRENCY); + @endphp -
- - - - - + +
{{ __('Market Gain/Loss') }}
+
{{ $formatter->formatCurrency($dashboard->marketGainLoss, 'USD') }}
+
+ +
{{ __('Total Cost Basis') }}
+
{{ $formatter->formatCurrency($dashboard->totalCostBasis, 'USD') }}
+
+ + +
{{ __('Total Market Value') }}
+
{{ $formatter->formatCurrency($dashboard->totalMarketValue, 'USD') }}
+
+ + +
{{ __('Realized Gain/Loss') }}
+
{{ $formatter->formatCurrency($dashboard->realizedGainLoss, 'USD') }}
+
+ + +
{{ __('Dividends Earned') }}
+
{{ $formatter->formatCurrency($dashboard->dividendsEarned, 'USD') }}
+
+
- - - @php - $users = App\Models\User::take(3)->get(); - @endphp + - @foreach($users as $user) - + @foreach($user->portfolios as $portfolio) + + + {{ $portfolio->title }} + @if($portfolio->wishlist) + + @endif + + @endforeach - + @php $users = App\Models\User::take(3)->get(); @@ -68,7 +65,7 @@ - + @php $users = App\Models\User::take(3)->get(); @@ -80,7 +77,7 @@ - + @php $users = App\Models\User::take(3)->get(); diff --git a/resources/views/livewire/manage-portfolio-form.blade.php b/resources/views/livewire/manage-portfolio-form.blade.php index 716399d..74e2850 100644 --- a/resources/views/livewire/manage-portfolio-form.blade.php +++ b/resources/views/livewire/manage-portfolio-form.blade.php @@ -42,7 +42,7 @@ new class extends Component { // $this->portfolio->owner_id = auth()->user()->id; $this->portfolio->save(); - $this->success('Portfolio updated', redirectTo: "/portfolio/{$this->portfolio->id}"); + $this->success(__('Portfolio updated'), redirectTo: "/portfolio/{$this->portfolio->id}"); } public function save() @@ -65,7 +65,7 @@ new class extends Component { // $portfolio->owner_id = auth()->user()->id; $portfolio->save(); - $this->success('Portfolio created', redirectTo: "/portfolio/{$portfolio->id}"); + $this->success(__('Portfolio created'), redirectTo: "/portfolio/{$portfolio->id}"); } public function delete() @@ -73,17 +73,17 @@ new class extends Component { $this->portfolio->delete(); - $this->success('Portfolio deleted', redirectTo: "/dashboard"); + $this->success(__('Portfolio deleted'), redirectTo: "/dashboard"); } }; ?>
- + - + - + @if ($portfolio) @@ -96,7 +96,7 @@ new class extends Component { @endif @if (!$hideCancel) - + @endif diff --git a/resources/views/livewire/portfolio-performance-card.blade.php b/resources/views/livewire/portfolio-performance-card.blade.php deleted file mode 100644 index 5013d0a..0000000 --- a/resources/views/livewire/portfolio-performance-card.blade.php +++ /dev/null @@ -1,44 +0,0 @@ - '1M', 'name' => '1 month'], - ['id' => '3M', 'name' => '3 months'], - ['id' => 'YTD', 'name' => 'Year to date'], - ['id' => '1Y', 'name' => '1 year'], - ['id' => '3Y', 'name' => '3 years'], - ['id' => 'ALL', 'name' => 'All time'] - ]; - - protected $listeners = ['data-scope-updated' => 'test']; - - public function test() - { - $this->value = 148; - } - - // methods - public function mount() - { - // - - } - -}; ?> - - diff --git a/resources/views/livewire/portfolio-performance-chart.blade.php b/resources/views/livewire/portfolio-performance-cards.blade.php similarity index 95% rename from resources/views/livewire/portfolio-performance-chart.blade.php rename to resources/views/livewire/portfolio-performance-cards.blade.php index 59f271b..2c9b336 100644 --- a/resources/views/livewire/portfolio-performance-chart.blade.php +++ b/resources/views/livewire/portfolio-performance-cards.blade.php @@ -38,6 +38,8 @@ new class extends Component { ], ]; + + // $this->marketGainLoss = rand(-200, 3999); } public function changeScope($scope) @@ -77,7 +79,7 @@ new class extends Component { }; ?> -
+
@@ -109,4 +111,4 @@ new class extends Component {
-
+
\ No newline at end of file diff --git a/resources/views/portfolio/show.blade.php b/resources/views/portfolio/show.blade.php index 56e018c..fd4a613 100644 --- a/resources/views/portfolio/show.blade.php +++ b/resources/views/portfolio/show.blade.php @@ -27,50 +27,44 @@ /> - + @livewire('portfolio-performance-cards', [ + 'name' => 'portfolio-'.$portfolio->id, + 'portfolio' => $portfolio + ]) - @livewire('portfolio-performance-chart', [ - 'name' => 'portfolio-'.$portfolio->id, - 'portfolio' => $portfolio - ]) +
+ @php + $formatter = new NumberFormatter('en_US', NumberFormatter::CURRENCY); + @endphp - - -
- @livewire('portfolio-performance-card') - {{-- --}} - - - - + +
{{ __('Market Gain/Loss') }}
+
{{ $formatter->formatCurrency($portfolio->marketGainLoss, 'USD') }}
+
+ +
{{ __('Total Cost Basis') }}
+
{{ $formatter->formatCurrency($portfolio->totalCostBasis, 'USD') }}
+
+ + +
{{ __('Total Market Value') }}
+
{{ $formatter->formatCurrency($portfolio->totalMarketValue, 'USD') }}
+
+ + +
{{ __('Realized Gain/Loss') }}
+
{{ $formatter->formatCurrency($portfolio->realizedGainLoss, 'USD') }}
+
+ + +
{{ __('Dividends Earned') }}
+
{{ $formatter->formatCurrency($portfolio->dividendsEarned, 'USD') }}
+
+
+
diff --git a/routes/web.php b/routes/web.php index d7d92a4..0d252c1 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,6 +1,7 @@ group(function () { - Route::view('/dashboard', 'dashboard')->name('dashboard'); + Route::get('/dashboard', [DashboardController::class, 'show'])->name('dashboard'); Route::get('/portfolio/create', [PortfolioController::class, 'create'])->name('portfolio.create'); Route::get('/portfolio/{portfolio}', [PortfolioController::class, 'show'])->name('portfolio.show');