File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55use App \Filament \Widgets \Timesheet \ActivitiesReport ;
66use App \Filament \Widgets \Timesheet \MonthlyReport ;
77use App \Filament \Widgets \Timesheet \WeeklyReport ;
8- use Filament \Pages \Page ;
8+ use Filament \Pages \Dashboard ;
99
10- class TimesheetDashboard extends Page
10+ class TimesheetDashboard extends Dashboard
1111{
1212 protected static ?string $ slug = 'timesheet-dashboard ' ;
1313
1414 protected static ?int $ navigationSort = 2 ;
1515
16- protected string $ view = 'filament::pages.dashboard ' ;
17-
1816 public function getColumns (): int | array
1917 {
2018 return 6 ;
Original file line number Diff line number Diff line change @@ -19,7 +19,13 @@ class ActivitiesReport extends ChartWidget
1919 'lg ' => 3
2020 ];
2121
22- public ?string $ filter = '2023 ' ;
22+ public ?string $ filter = null ;
23+
24+ public function mount (): void
25+ {
26+ $ this ->filter = (string ) Carbon::now ()->year ;
27+ parent ::mount ();
28+ }
2329
2430 public function getHeading (): string
2531 {
@@ -33,16 +39,23 @@ public function getType(): string
3339
3440 public function getFilters (): ?array
3541 {
36- return [
37- 2022 => 2022 ,
38- 2023 => 2023
39- ];
42+ $ currentYear = (int ) Carbon::now ()->year ;
43+ $ firstYear = (int ) (TicketHour::min ('created_at ' )
44+ ? Carbon::parse (TicketHour::min ('created_at ' ))->year
45+ : $ currentYear );
46+
47+ $ years = [];
48+ for ($ year = $ firstYear ; $ year <= $ currentYear ; $ year ++) {
49+ $ years [(string ) $ year ] = (string ) $ year ;
50+ }
51+
52+ return $ years ;
4053 }
4154
4255 public function getData (): array
4356 {
4457 $ collection = $ this ->filter (auth ()->user (), [
45- 'year ' => $ this ->filter
58+ 'year ' => $ this ->filter ?: Carbon:: now ()-> year
4659 ]);
4760
4861 $ datasets = $ this ->getDatasets ($ collection );
Original file line number Diff line number Diff line change @@ -18,7 +18,13 @@ public function getHeading(): string
1818 return __ ('Logged time monthly ' );
1919 }
2020
21- public ?string $ filter = '2023 ' ;
21+ public ?string $ filter = null ;
22+
23+ public function mount (): void
24+ {
25+ $ this ->filter = (string ) Carbon::now ()->year ;
26+ parent ::mount ();
27+ }
2228
2329 public function getType (): string
2430 {
@@ -52,10 +58,17 @@ public function getData(): array
5258
5359 public function getFilters (): ?array
5460 {
55- return [
56- 2022 => 2022 ,
57- 2023 => 2023
58- ];
61+ $ currentYear = (int ) Carbon::now ()->year ;
62+ $ firstYear = (int ) (TicketHour::min ('created_at ' )
63+ ? Carbon::parse (TicketHour::min ('created_at ' ))->year
64+ : $ currentYear );
65+
66+ $ years = [];
67+ for ($ year = $ firstYear ; $ year <= $ currentYear ; $ year ++) {
68+ $ years [(string ) $ year ] = (string ) $ year ;
69+ }
70+
71+ return $ years ;
5972 }
6073
6174 protected ?array $ options = [
Original file line number Diff line number Diff line change @@ -20,13 +20,12 @@ class WeeklyReport extends ChartWidget
2020 'lg ' => 3
2121 ];
2222
23- public function __construct ( $ id = null )
23+ public function mount (): void
2424 {
25- $ weekDaysData = $ this -> getWeekStartAndFinishDays ();
25+ parent :: mount ();
2626
27+ $ weekDaysData = $ this ->getWeekStartAndFinishDays ();
2728 $ this ->filter = $ weekDaysData ['weekStartDate ' ] . ' - ' . $ weekDaysData ['weekEndDate ' ];
28-
29- parent ::__construct ($ id );
3029 }
3130
3231 public function getHeading (): string
@@ -41,6 +40,11 @@ public function getType(): string
4140
4241 public function getData (): array
4342 {
43+ if (empty ($ this ->filter ) || !str_contains ($ this ->filter , ' - ' )) {
44+ $ weekDefaults = $ this ->getWeekStartAndFinishDays ();
45+ $ this ->filter = $ weekDefaults ['weekStartDate ' ] . ' - ' . $ weekDefaults ['weekEndDate ' ];
46+ }
47+
4448 $ weekDaysData = explode (' - ' , $ this ->filter );
4549
4650 $ collection = $ this ->filter (auth ()->user (), [
You can’t perform that action at this time.
0 commit comments