Skip to content

Commit 5b7bd0f

Browse files
dashboard gitlab tile
1 parent c2974a1 commit 5b7bd0f

6 files changed

+106
-50
lines changed

composer.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": ":vendor/:package_name",
3-
"description": ":package_description",
2+
"name": "creacoon/laravel-dashboard-gitlab-tile",
3+
"description": "GitLab Tile",
44
"keywords": [
55
":vendor",
66
":package_name"
@@ -9,8 +9,8 @@
99
"license": "MIT",
1010
"authors": [
1111
{
12-
"name": ":author_name",
13-
"email": ":author_email",
12+
"name": ":juliana",
13+
"email": ":[email protected]",
1414
"homepage": "https://:vendor.be",
1515
"role": "Developer"
1616
}
@@ -25,12 +25,12 @@
2525
},
2626
"autoload": {
2727
"psr-4": {
28-
"Spatie\\MyTile\\": "src"
28+
"Creacoon\\GitLabTile\\": "src"
2929
}
3030
},
3131
"autoload-dev": {
3232
"psr-4": {
33-
"Spatie\\MyTile\\Tests\\": "tests"
33+
"Creacoon\\GitLabTile\\Tests\\": "tests"
3434
}
3535
},
3636
"scripts": {
@@ -44,7 +44,7 @@
4444
"extra": {
4545
"laravel": {
4646
"providers": [
47-
"Spatie\\MyTile\\MyTileServiceProvider"
47+
"Creacoon\\GitLabTile\\GitLabTileServiceProvider"
4848
]
4949
}
5050
},

resources/views/tile.blade.php

+36-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,41 @@
1-
<x-dashboard-tile :position="$position">
2-
<div class="grid grid-rows-auto-1 gap-2 h-full">
3-
<div
4-
class="flex items-center justify-center w-10 h-10 rounded-full"
5-
style="background-color: rgba(255, 255, 255, .9)"
6-
>
7-
<div class="text-3xl leading-none -mt-1">
8-
Tile title
1+
<x-dashboard-tile :position="$position" :refresh-interval="$refreshIntervalInSeconds">
2+
<div class="p-4 h-full">
3+
<div class="flex items-center justify-center mb-4">
4+
<div class="font-medium text-dimmed text-sm uppercase tracking-wide tabular-nums">
5+
GitLab User Counts
96
</div>
107
</div>
11-
<div wire:poll.{{ $refreshIntervalInSeconds }}s class="self-center | divide-y-2">
12-
{{-- tile content --}}
8+
<div wire:poll.{{ $refreshIntervalInSeconds }}s class="h-full overflow-y-auto">
9+
<table class="min-w-full divide-y divide-white">
10+
<thead>
11+
<tr>
12+
@foreach(['', 'To-dos', 'Merge Requests', 'Review Requested'] as $header)
13+
<th scope="col" class="px-3 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">{{ $header }}</th>
14+
@endforeach
15+
</tr>
16+
</thead>
17+
<tbody class="divide-y divide-white">
18+
@foreach($userCounts as $user => $counts)
19+
<tr class="bg-transparent">
20+
<td class="px-6 py-4 whitespace-nowrap">
21+
<div class="flex items-center">
22+
<div class="w-6 h-6 rounded-full bg-gray-200 flex items-center justify-center mr-2 overflow-hidden">
23+
@if(isset($counts['avatar_url']))
24+
<img src="{{ $counts['avatar_url'] }}" alt="{{ $user }}" class="w-full h-full object-cover">
25+
@else
26+
<span class="text-gray-500 text-xs">{{ strtoupper(substr($user, 0, 1)) }}</span>
27+
@endif
28+
</div>
29+
<div class="font-medium text-gray-200">{{ $user }}</div>
30+
</div>
31+
</td>
32+
<td class="text-gray-200 px-6 py-4 whitespace-nowrap">{{ $counts['todos'] }}</td>
33+
<td class="text-gray-200 px-6 py-4 whitespace-nowrap">{{ $counts['assigned_merge_requests'] }}</td>
34+
<td class="text-gray-200 px-6 py-4 whitespace-nowrap">{{ $counts['review_requested_merge_requests'] }}</td>
35+
</tr>
36+
@endforeach
37+
</tbody>
38+
</table>
1339
</div>
1440
</div>
1541
</x-dashboard-tile>

src/FetchDataFromApiCommand.php

+46-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,57 @@
11
<?php
22

3-
namespace Vendor\MyTile;
3+
namespace Creacoon\GitLabTile;
44

55
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\Http;
67

78
class FetchDataFromApiCommand extends Command
89
{
9-
protected $signature = 'dashboard:fetch-data-from-xxx-api';
10+
protected $signature = 'dashboard:fetch-data-from-gitlab-api';
11+
protected $description = 'Fetch data for GitLab tile';
1012

11-
protected $description = 'Fetch data for tile';
12-
13-
public function handle(VeloApi $velo)
13+
public function handle()
1414
{
15-
$this->info('Fetching Velo stations...');
16-
17-
$myData = Http::get($endpoint)->json();
18-
19-
MyStore::make()->setData($myData);
20-
21-
$this->info('All done!');
15+
$usersResponse = Http::withHeaders([
16+
'PRIVATE-TOKEN' => env('GITLAB_API_TOKEN'),
17+
])->get('https://gl.creacoon.nl/api/v4/users?active=true');
18+
19+
if ($usersResponse->successful()) {
20+
$usersData = $usersResponse->json();
21+
dump('Users Data:', $usersData);
22+
23+
$userProfiles = [];
24+
foreach ($usersData as $user) {
25+
$username = $user['username'];
26+
$userId = $user['id'];
27+
$userProfiles[$username] = [
28+
'avatar_url' => $user['avatar_url'] ?? null,
29+
'name' => $user['name'] ?? $username,
30+
'assigned_merge_requests' => 0,
31+
'review_requested_merge_requests' => 0,
32+
'todos' => 0,
33+
];
34+
35+
$userCountResponse = Http::withHeaders([
36+
'PRIVATE-TOKEN' => env('GITLAB_API_TOKEN'),
37+
])->get("https://gl.creacoon.nl/api/v4/user_counts");
38+
39+
if ($userCountResponse->successful()) {
40+
$userCountData = $userCountResponse->json();
41+
dump('User Count Data for '.$username.':', $userCountData);
42+
43+
$userProfiles[$username]['assigned_merge_requests'] = $userCountData['assigned_merge_requests'] ?? 0;
44+
$userProfiles[$username]['review_requested_merge_requests'] = $userCountData['review_requested_merge_requests'] ?? 0;
45+
$userProfiles[$username]['todos'] = $userCountData['todos'] ?? 0;
46+
} else {
47+
$this->error('Failed to fetch user count for: ' . $username . '. Status: ' . $userCountResponse->status() . ', Body: ' . $userCountResponse->body());
48+
}
49+
}
50+
51+
GitLabStore::make()->setData($userProfiles);
52+
$this->info('Data fetched successfully!');
53+
} else {
54+
$this->error('Failed to fetch user data: ' . $usersResponse->status());
55+
}
2256
}
2357
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
namespace Vendor\MyTile;
3+
namespace Creacoon\GitLabTile;
44

55
use Spatie\Dashboard\Models\Tile;
66

7-
class MyStore
7+
class GitLabStore
88
{
99
private Tile $tile;
1010

@@ -15,18 +15,17 @@ public static function make()
1515

1616
public function __construct()
1717
{
18-
$this->tile = Tile::firstOrCreateForName("myTileName");
18+
$this->tile = Tile::firstOrCreateForName("GitLabTile");
1919
}
2020

2121
public function setData(array $data): self
2222
{
23-
$this->tile->putData('key', $data);
24-
23+
$this->tile->putData('GitLabUserCounts', $data);
2524
return $this;
2625
}
2726

2827
public function getData(): array
2928
{
30-
return$this->tile->getData('key') ?? [];
29+
return $this->tile->getData('GitLabUserCounts') ?? [];
3130
}
3231
}
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
<?php
22

3-
namespace Vendor\MyTile;
3+
namespace Creacoon\GitLabTile;
44

55
use Livewire\Component;
66

7-
class MyTileComponent extends Component
7+
class GitLabTileComponent extends Component
88
{
99
public $position;
1010

11-
1211
public function mount(string $position)
1312
{
1413
$this->position = $position;
1514
}
16-
17-
15+
1816
public function render()
1917
{
20-
return view('dashboard-skeleton-tile::tile', [
21-
'myData' => MyStore::make()->getData(),
22-
'refreshIntervalInSeconds' => config('dashboard.tiles.skeleton.refresh_interval_in_seconds') ?? 60,
23-
18+
return view('dashboard-gitlab-tile::tile', [
19+
'refreshIntervalInSeconds' => config('dashboard.tiles.gitlab.refresh_interval_in_seconds') ?? 60,
20+
'userCounts' => GitLabStore::make()->getData(),
2421
]);
2522
}
2623
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace Vendor\MyTile;
3+
namespace Creacoon\GitLabTile;
44

55
use Illuminate\Support\ServiceProvider;
66
use Livewire\Livewire;
77

8-
class MyTileServiceProvider extends ServiceProvider
8+
class GitLabTileServiceProvider extends ServiceProvider
99
{
1010
public function boot()
1111
{
@@ -16,11 +16,11 @@ public function boot()
1616
}
1717

1818
$this->publishes([
19-
__DIR__ . '/../resources/views' => resource_path('views/vendor/dashboard-my-tile'),
20-
], 'dashboard-my-tile-views');
19+
__DIR__ . '/../resources/views' => resource_path('views/vendor/dashboard-gitlab-tile'),
20+
], 'dashboard-gitlab-tile-views');
2121

22-
$this->loadViewsFrom(__DIR__ . '/../resources/views', 'dashboard-my-tile');
22+
$this->loadViewsFrom(__DIR__ . '/../resources/views', 'dashboard-gitlab-tile');
2323

24-
Livewire::component('my-tile', MyTileComponent::class);
24+
Livewire::component('git-lab-tile', GitLabTileComponent::class);
2525
}
2626
}

0 commit comments

Comments
 (0)