Skip to content

Commit 2bfa729

Browse files
committed
1 parent 9e8dc61 commit 2bfa729

File tree

9 files changed

+169
-11
lines changed

9 files changed

+169
-11
lines changed

app/Broadcasting/TaskActivity.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace App\Broadcasting;
4+
5+
use App\Models\User;
6+
7+
class TaskActivity
8+
{
9+
/**
10+
* Create a new channel instance.
11+
*/
12+
public function __construct()
13+
{
14+
//
15+
}
16+
17+
/**
18+
* Authenticate the user's access to the channel.
19+
*/
20+
public function join(User $user)
21+
{
22+
return true;
23+
}
24+
}

app/Events/TaskActivityTriggered.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace App\Events;
4+
5+
use Illuminate\Support\Facades\Log;
6+
use Illuminate\Broadcasting\Channel;
7+
use Illuminate\Queue\SerializesModels;
8+
use Illuminate\Foundation\Events\Dispatchable;
9+
use Illuminate\Broadcasting\InteractsWithSockets;
10+
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow ;
11+
12+
class TaskActivityTriggered implements ShouldBroadcastNow
13+
{
14+
use Dispatchable, InteractsWithSockets, SerializesModels;
15+
16+
public $message;
17+
/**
18+
* Create a new event instance.
19+
*/
20+
public function __construct($message)
21+
{
22+
$this->message = $message;
23+
}
24+
25+
/**
26+
* Get the channels the event should broadcast on.
27+
*
28+
* @return array<int, \Illuminate\Broadcasting\Channel>
29+
*/
30+
public function broadcastOn(): array
31+
{
32+
return [
33+
new Channel('TaskActivity'),
34+
];
35+
}
36+
37+
public function broadcastAs()
38+
{
39+
return 'task.activity.triggered';
40+
}
41+
}

app/Http/Controllers/Planning/AndonAlertController.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
namespace App\Http\Controllers\Planning;
44

5+
use Carbon\Carbon;
56
use Illuminate\Http\Request;
67
use App\Events\AndonAlertTriggered;
78
use App\Http\Controllers\Controller;
89
use App\Models\Planning\AndonAlerts;
910
use Illuminate\Support\Facades\Auth;
11+
use App\Models\Planning\TaskActivities;
1012

1113
class AndonAlertController extends Controller
1214
{
@@ -21,7 +23,7 @@ public function triggerAlert(Request $request)
2123
'user_id' => Auth::id(),
2224
'triggered_at' => now(),
2325
]);
24-
$alertData= ['message' => 'Une alerte Andon a été déclenchée'];
26+
2527
// Émettre l'événement
2628
broadcast(new AndonAlertTriggered($alert));
2729

@@ -50,9 +52,17 @@ public function inProgressAlert($id)
5052
return redirect()->back();
5153
}
5254

53-
public function dashboard()
55+
public function taskAlertsDashboard()
5456
{
5557
$andonAlerts = AndonAlerts::orderByRaw("FIELD(status, '1', '2', '3')")->orderByDesc('id')->get();
5658
return view('workshop/workshop-andon', compact('andonAlerts'));
5759
}
60+
61+
public function taskActivityDashboard()
62+
{
63+
$taskActivities = TaskActivities::where('timestamp', '>=', Carbon::now()->subDay())
64+
->orderByDesc('id')
65+
->get();
66+
return view('workshop/workshop-andon-task-activity', compact('taskActivities'));
67+
}
5868
}

app/Models/Planning/TaskActivities.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class TaskActivities extends Model
2020
'comment',];
2121

2222

23-
public function Taks()
23+
public function Tasks()
2424
{
2525
return $this->belongsTo(Task::class, 'task_id');
2626
}

app/Services/TaskService.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace App\Services;
44

5-
5+
use App\Events\TaskActivityTriggered;
66
use Carbon\Carbon;
77
use App\Models\Planning\Task;
88
use App\Events\TaskChangeStatu;
@@ -36,7 +36,7 @@ public function closeTasks($orderLineId)
3636

3737
public function recordTaskActivity($taskId, $type, $goodQty, $addBadQt)
3838
{
39-
TaskActivities::create([
39+
$taskActivity = TaskActivities::create([
4040
'task_id' => $taskId,
4141
'user_id'=> Auth::user()->id,
4242
'type' => $type,
@@ -45,5 +45,7 @@ public function recordTaskActivity($taskId, $type, $goodQty, $addBadQt)
4545
'bad_qt'=> $addBadQt,
4646
'comment' => '',
4747
]);
48+
49+
broadcast(new TaskActivityTriggered($taskActivity));
4850
}
4951
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
@extends('adminlte::page')
2+
3+
@section('title', __('general_content.logs_activity_trans_key'))
4+
5+
@section('content_header')
6+
<h1>{{ __('general_content.logs_activity_trans_key') }}</h1>
7+
@stop
8+
9+
@section('content')
10+
<div class="timeline">
11+
@foreach($taskActivities as $taskActivity)
12+
<div style=" display: flex; justify-content: space-between; padding: 10px; border-radius: 10px; background-color:
13+
@if($taskActivity->type == 1) #3490dc
14+
@elseif($taskActivity->type == 2) #ffed4a
15+
@elseif($taskActivity->type == 3) #38c172
16+
@elseif($taskActivity->type == 4) #4dc0b5
17+
@elseif($taskActivity->type == 5) #e3342f
18+
@else #6c757d @endif; margin-bottom: 10px;">
19+
20+
<!-- Première colonne : Type d'activité -->
21+
<div class="col-2">
22+
@if($taskActivity->type == 1)
23+
<h3><i class="fas fa-play-circle"></i> {{ __('general_content.set_to_start_trans_key') }}</h3>
24+
@elseif($taskActivity->type == 2)
25+
<h3><i class="fas fa-pause-circle"></i> {{ __('general_content.set_to_end_trans_key') }}</h3>
26+
@elseif($taskActivity->type == 3)
27+
<h3><i class="fas fa-check-circle"></i> {{ __('general_content.set_to_finish_trans_key') }}</h3>
28+
@elseif($taskActivity->type == 4)
29+
<h3><i class="fas fa-box"></i> {{ __('general_content.declare_finish_trans_key') }} : {{ $taskActivity->good_qt }} {{ __('general_content.part_trans_key') }}</h3>
30+
@elseif($taskActivity->type == 5)
31+
<h3><i class="fas fa-times-circle"></i> {{ __('general_content.declare_rejected_trans_key') }} : {{ $taskActivity->bad_qt }} {{ __('general_content.part_trans_key') }}</h3>
32+
@else
33+
<h3><i class="fas fa-question-circle"></i> {{ __('general_content.unknown_activity_trans_key') }}</h3>
34+
@endif
35+
</div>
36+
37+
<!-- Deuxième colonne : Date et Utilisateur -->
38+
<div class="col-3">
39+
<h3>{{ $taskActivity->GetPrettyCreatedAttribute() }} / {{ $taskActivity->user->name ?? 'System' }}</h3>
40+
</div>
41+
42+
<!-- Troisième colonne : Détails de la tâche -->
43+
<div class="col-3"><h3>
44+
<a href="{{ route('production.task.statu.id', ['id' => $taskActivity->task_id]) }}" class="btn btn-sm btn-success">{{__('general_content.view_trans_key') }} </a>
45+
46+
{{ __('general_content.task_trans_key') }} : #{{ $taskActivity->task_id }} - {{ $taskActivity->Tasks->label }}</h3>
47+
</div>
48+
49+
<!-- Quatrième colonne : Commentaire -->
50+
<div class="col-3">
51+
<x-OrderButton id="{{ $taskActivity->Tasks->OrderLines->orders_id }}" code="{{ $taskActivity->Tasks->OrderLines->order->code }} #{{ __('general_content.line_trans_key') }} {{ $taskActivity->Tasks->OrderLines->label }}" />
52+
</div>
53+
54+
</div>
55+
@endforeach
56+
</div>
57+
@stop
58+
59+
@section('css')
60+
61+
@stop
62+
63+
@section('js')
64+
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
65+
<script>
66+
$(document).ready(function(){
67+
// Cache la sidebar dès le chargement
68+
$("body").addClass("sidebar-hidden");
69+
});
70+
</script>
71+
72+
<script src="{{ mix('js/app.js') }}"></script>
73+
<script>
74+
Echo.channel('TaskActivity')
75+
.listen('.task.activity.triggered', function(data) {
76+
setTimeout(() => {
77+
location.reload();
78+
}, 200);
79+
});
80+
</script>
81+
@stop

resources/views/workshop/workshop-andon.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<!-- Première colonne : Type et Déclenchement -->
1414
<div class="col-3">
1515
<h3>{{ $alert->type }}</h3>
16-
<small>{{ $alert->GetPrettyCreatedAttribute() }} par {{ $alert->UserManagement['name'] }}</small>
16+
<small>{{ $alert->GetPrettyCreatedAttribute() }} / {{ $alert->UserManagement['name'] }}</small>
1717
</div>
1818

1919
<!-- Deuxième colonne : Description -->

routes/channels.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use App\Broadcasting\AndonAlert;
4+
use App\Broadcasting\TaskActivity;
45
use Illuminate\Support\Facades\Broadcast;
56

67
/*
@@ -19,8 +20,5 @@
1920
});
2021

2122
Broadcast::channel('AndonAlert', AndonAlert::class);
22-
23-
Broadcast::channel( 'my-channel', function ($user) {
24-
return true; // Autorise tous les utilisateurs à rejoindre ce canal
25-
});
23+
Broadcast::channel('TaskActivity', TaskActivity::class);
2624

routes/web.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@
3838
Route::get('/Stock/Detail', 'App\Http\Controllers\Workshop\WorkshopController@stockDetail')->name('workshop.stock.detail');
3939

4040

41-
Route::get('/andon', 'App\Http\Controllers\Planning\AndonAlertController@dashboard')->name('workshop.andon');
41+
Route::get('/andon', 'App\Http\Controllers\Planning\AndonAlertController@taskAlertsDashboard')->name('workshop.andon');
4242
Route::post('/andon/store', 'App\Http\Controllers\Planning\AndonAlertController@triggerAlert')->name('workshop.andon.store');
4343
Route::post('/andon/inProgress/{id}', 'App\Http\Controllers\Planning\AndonAlertController@inProgressAlert')->name('workshop.andon.inProgress');
4444
Route::post('/andon/resolve/{id}', 'App\Http\Controllers\Planning\AndonAlertController@resolveAlert')->name('workshop.andon.resolve');
45+
46+
Route::get('/andon/task-activity', 'App\Http\Controllers\Planning\AndonAlertController@taskActivityDashboard')->name('workshop.andon.task-activity');
4547
});
4648

4749

0 commit comments

Comments
 (0)