Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
heloufir authored Jan 31, 2023
2 parents beb014e + c6334de commit 3945000
Show file tree
Hide file tree
Showing 12 changed files with 244 additions and 103 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ All this made with the best technologies.

Full documentation can be viewed online: [Docs](https://devaslanphp.github.io/project-management)

## Online Demo

You can see the application in action here: [https://project-helper.net](https://project-helper.net)

## Work in progress

We are always working to make Project Management a better application, all contributions are welcome.
Expand Down Expand Up @@ -135,8 +131,8 @@ The MIT License (MIT). Please see [License File](LICENSE.md) for more informatio
- Add jira integration #36
- New feature: Import jira projects / tickets
- **Release 1.2.2**
- Add jira integration #36
- New feature: Import jira projects / tickets
- Dockerize application #23
- PR #45
- **Release 1.2.3**
- Update german language #52
- SSO with OpenID (OIDC) #48
Expand Down
13 changes: 9 additions & 4 deletions app/Filament/Pages/TimesheetDashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@

use App\Filament\Widgets\Timesheet\ActivitiesReport;
use App\Filament\Widgets\Timesheet\MonthlyReport;
use App\Filament\Widgets\Timesheet\WeeklyReport;
use Filament\Pages\Page;

class TimesheetDashboard extends Page
{
protected static ?string $slug = 'timesheet-dashboard';

protected static ?int $navigationSort = 1;
protected static ?int $navigationSort = 2;

protected static string $view = 'filament::pages.dashboard';

protected static bool $shouldRegisterNavigation = false;

protected function getColumns(): int | array
{
return 6;
Expand All @@ -31,11 +30,17 @@ protected static function getNavigationGroup(): ?string
return __('Timesheet');
}

protected static function shouldRegisterNavigation(): bool
{
return auth()->user()->can('View timesheet dashboard');
}

protected function getWidgets(): array
{
return [
MonthlyReport::class,
ActivitiesReport::class
ActivitiesReport::class,
WeeklyReport::class
];
}
}
7 changes: 5 additions & 2 deletions app/Filament/Resources/TimesheetResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class TimesheetResource extends Resource

protected static ?int $navigationSort = 4;

protected static bool $shouldRegisterNavigation = false;

protected static function getNavigationLabel(): string
{
return __('Timesheet');
Expand All @@ -40,6 +38,11 @@ protected static function getNavigationGroup(): ?string
return __('Timesheet');
}

protected static function shouldRegisterNavigation(): bool
{
return auth()->user()->can('List timesheet data');
}

public static function form(Form $form): Form
{
return $form
Expand Down
4 changes: 2 additions & 2 deletions app/Filament/Widgets/Timesheet/ActivitiesReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ActivitiesReport extends BarChartWidget
];

public ?string $filter = '2023';

protected function getHeading(): string
{
return __('Logged time by activity');
Expand Down Expand Up @@ -68,7 +68,7 @@ protected function getDatasets(Collection $collection): array

foreach ($collection as $item) {
$datasets['sets'][] = $item->value;
$datasets['labels'][] = $item->activity->name;
$datasets['labels'][] = $item->activity?->name ?? __('No activity');
}

return $datasets;
Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Widgets/Timesheet/MonthlyReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function filter(User $user, array $params)
DB::raw("YEAR(created_at)=" . (is_null($params['year']) ? Carbon::now()->format('Y') : $params['year']))
)
->where('user_id', $user->id)
->groupBy(DB::raw("DATE_FORMAT (created_at, '%m')"))
->groupBy(DB::raw("DATE_FORMAT(created_at,'%m')"))
->get();
}

Expand Down
101 changes: 101 additions & 0 deletions app/Filament/Widgets/Timesheet/WeeklyReport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

declare(strict_types=1);

namespace App\Filament\Widgets\Timesheet;

use App\Models\TicketHour;
use App\Models\User;
use Carbon\Carbon;
use Carbon\CarbonPeriod;
use Filament\Widgets\BarChartWidget;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\DB;

class WeeklyReport extends BarChartWidget
{
protected int|string|array $columnSpan = [
'sm' => 1,
'md' => 6,
'lg' => 3
];

protected function getData(): array
{
$now = Carbon::now();

$weekStartDate = $now->startOfWeek()->format('Y-m-d');
$weekEndDate = $now->endOfWeek()->format('Y-m-d');

$collection = $this->filter(auth()->user(), [
'year' => null,
'weekStartDate' => $weekStartDate,
'weekEndDate' => $weekEndDate
]);

$dates = $this->buildDatesRange($weekStartDate, $weekEndDate);

$datasets = $this->buildRapport($collection, $dates);

return [
'datasets' => [
[
'label' => __('Weekly time logged'),
'data' => $datasets,
'backgroundColor' => [
'rgba(54, 162, 235, .6)'
],
'borderColor' => [
'rgba(54, 162, 235, .8)'
],
],
],
'labels' => $dates,
];
}

protected function buildRapport(Collection $collection, array $dates): array
{
$template = $this->createReportTemplate($dates);
foreach ($collection as $item) {
$template[$item->day]['value'] = $item->value;
}
return collect($template)->pluck('value')->toArray();
}

protected function filter(User $user, array $params)
{
return TicketHour::select([
DB::raw("DATE_FORMAT(created_at,'%Y-%m-%d') as day"),
DB::raw('SUM(value) as value'),
])
->whereBetween('created_at', [$params['weekStartDate'], $params['weekEndDate']])
->whereRaw(
DB::raw("YEAR(created_at)=" . (is_null($params['year']) ? Carbon::now()->format('Y') : $params['year']))
)
->where('user_id', $user->id)
->groupBy(DB::raw("DATE_FORMAT(created_at,'%Y-%m-%d')"))
->get();
}

protected function buildDatesRange($weekStartDate, $weekEndDate): array
{
$period = CarbonPeriod::create($weekStartDate, $weekEndDate);

$dates = [];
foreach ($period as $item) {
$dates[] = $item->format('Y-m-d');
}

return $dates;
}

protected function createReportTemplate(array $dates): array
{
$template = [];
foreach ($dates as $date) {
$template[$date]['value'] = 0;
}
return $template;
}
}
65 changes: 65 additions & 0 deletions app/Http/Livewire/Timesheet/TimeLogged.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);

namespace App\Http\Livewire\Timesheet;

use App\Models\Ticket;
use Filament\Tables;
use Filament\Tables\Concerns\InteractsWithTable;
use Filament\Tables\Contracts\HasTable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Livewire\Component;

class TimeLogged extends Component implements HasTable
{
use InteractsWithTable;

public Ticket $ticket;

protected function getFormModel(): Model|string|null
{
return $this->ticket;
}

protected function getTableQuery(): Builder
{
return $this->ticket->hours()->getQuery();
}

protected function getTableColumns(): array
{
return [
Tables\Columns\TextColumn::make('user.name')
->label(__('Owner'))
->sortable()
->formatStateUsing(fn($record) => view('components.user-avatar', ['user' => $record->user]))
->searchable(),

Tables\Columns\TextColumn::make('value')
->label(__('Hours'))
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('comment')
->label(__('Comment'))
->limit(50)
->sortable()
->searchable(),

Tables\Columns\TextColumn::make('activity.name')
->label(__('Activity'))
->sortable(),

Tables\Columns\TextColumn::make('ticket.name')
->label(__('Ticket'))
->sortable(),

Tables\Columns\TextColumn::make('created_at')
->label(__('Created at'))
->dateTime()
->sortable()
->searchable(),
];
}
}
3 changes: 2 additions & 1 deletion database/seeders/PermissionsSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class PermissionsSeeder extends Seeder
];

private array $extraPermissions = [
'Manage general settings', 'Import from Jira'
'Manage general settings', 'Import from Jira',
'List timesheet data', 'View timesheet dashboard'
];

private string $defaultRole = 'Default role';
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
timeout: 10s
retries: 3
helper:
image: devaslanphp/helper:latest
image: eloufirhatim/helper:latest
container_name: helper-server
environment:
- DB_CONNECTION=mysql
Expand Down
Loading

0 comments on commit 3945000

Please sign in to comment.