Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions app/Http/Controllers/NotificationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Http\Controllers;

<<<<<<< Updated upstream
use App\Models\ProjectNotification;
=======
use Illuminate\Http\Request;
>>>>>>> Stashed changes

class NotificationController extends Controller
{
public function markAsRead($id)
{
$notification = ProjectNotification::findOrFail($id);
<<<<<<< Updated upstream
$notification->markAsRead();

=======
$notification->update(['read' => true]);
>>>>>>> Stashed changes
return response()->json(['success' => true]);
}
}
65 changes: 65 additions & 0 deletions app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use App\Notifications\ProjectInvitationNotification;
use Illuminate\Support\Facades\Notification;

use App\Models\ProjectNotification;
use PHPUnit\Event\Application\FinishedSubscriber;


Expand Down Expand Up @@ -223,10 +224,12 @@ public function add_member(string $idProject)
$users_relation = $project->users()->get();
$user = Auth::user();

<<<<<<< Updated upstream
if (!$project->userHasLevel($user, '1')) {
return redirect()->back()->with('error', 'You do not have permission to add a member to the project.');
}

<<<<<<< Updated upstream
return view('projects.add_member', compact('project', 'users_relation'));
}

Expand All @@ -248,11 +251,43 @@ public function add_member_project(ProjectAddMemberRequest $request, string $idP
$level_member = $request->get('level_member', 1); // Default to level 1 if not specified

$user = Auth::user();
=======
/**
* Add a member to a project based on the submitted form data.
*
* @param \App\Http\Requests\ProjectAddMemberRequest $request The validated request object.
* @param string $idProject The ID of the project.
* @return \Illuminate\Http\RedirectResponse
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
*/
=======
return view('projects.add_member', compact('project', 'users_relation'));
}
>>>>>>> Stashed changes
public function add_member_project(ProjectAddMemberRequest $request, string $idProject)
{
$request->validated();

// Carrega o projeto usando o id_project
$project = Project::findOrFail($idProject);

$email_member = $request->get('email_member');
$member_id = $this->findIdByEmail($email_member);
$name_member = User::findOrFail($member_id);
$user = Auth::user();
$level_member = $request->get('level_member', 1);

// Validações
if ($project->users()->wherePivot('id_user', $member_id)->exists()) {
return redirect()->back()->with('error', 'The user is already associated with the project.');
}
>>>>>>> Stashed changes

if ($project->users()->wherePivot('id_user', $member_id)->exists()) {
return redirect()->back()->with('error', 'The user is already associated with the project.');
}

<<<<<<< Updated upstream
if (!$project->userHasLevel($user, '1')) {
return redirect()->back()->with('error', 'You do not have permission to add a member to the project.');
}
Expand All @@ -265,6 +300,36 @@ public function add_member_project(ProjectAddMemberRequest $request, string $idP
]);

Notification::send($name_member, new ProjectInvitationNotification($project, $token));
=======
$token = Str::random(40);
$project->users()->attach($member_id, [
'level' => $level_member,
'invitation_token' => $token,
'status' => 'pending'
]);

<<<<<<< Updated upstream
// Criação da notificação usando id_project
ProjectNotification::create([
'user_id' => $member_id,
'project_id' => $project->id_project, // Usando o nome correto do campo
'type' => 'invitation',
'message' => "Você foi convidado para o projeto: {$project->title}",
=======
ProjectNotification::create([
'user_id' => $member_id, // ID do usuário convidado
'project_id' => $project->id,
'type' => 'invitation',
'message' => "Você foi adicionado ao projeto: {$project->title}",
>>>>>>> Stashed changes
'read' => false
]);

Notification::send($name_member, new ProjectInvitationNotification($project, $token));

$activity = "Sent invitation to " . $name_member->username . " to join the project " . $project->title;
ActivityLogHelper::insertActivityLog($activity, 1, $project->id_project, $user->id);
>>>>>>> Stashed changes

$activity = "Sent invitation to " . $name_member->username . " to join the project " . $project->title;
ActivityLogHelper::insertActivityLog($activity, 1, $project->id, $user->id);
Expand Down
1 change: 1 addition & 0 deletions app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Project extends Model
use HasFactory;

protected $fillable = [
'id_project',
'id_user',
'title',
'description',
Expand Down
60 changes: 60 additions & 0 deletions app/Models/ProjectNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace App\Models;

<<<<<<< Updated upstream
=======
use Illuminate\Database\Eloquent\Factories\HasFactory;
>>>>>>> Stashed changes
use Illuminate\Database\Eloquent\Model;

class ProjectNotification extends Model
{
<<<<<<< Updated upstream
protected $table = 'project_notifications'; // Tabela existente

protected $fillable = [
'user_id',
'project_id',
'type', // Ex: 'invitation', 'update'
'message',
'read' // 0 = não lida, 1 = lida
];

// Relação com o usuário
=======
protected $fillable = [
'user_id',
'project_id',
'type',
'message',
'read'
];

>>>>>>> Stashed changes
public function user()
{
return $this->belongsTo(User::class);
}

<<<<<<< Updated upstream
// Relação com o projeto
// app/Models/ProjectNotification.php

// Especifique a relação com Project usando a chave correta
public function project()
{
return $this->belongsTo(Project::class, 'project_id', 'id_project');
}

// Marcar como lida
public function markAsRead()
{
$this->update(['read' => true]);
=======
public function project()
{
return $this->belongsTo(Project::class);
>>>>>>> Stashed changes
}
}
5 changes: 5 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public function projects()
return $this->belongsToMany(Project::class, 'members', 'id_user', 'id_project');
}

public function notifications()
{
return $this->hasMany(ProjectNotification::class)->latest();
}

// Relacionamento com projetos com nível de acesso específico (usando o campo `level`)
public function projectsWithLevels()
{
Expand Down
157 changes: 86 additions & 71 deletions resources/views/layouts/navbars/auth/topnav.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,86 +46,101 @@ class="nav-link text-white font-weight-bold px-0">
<i class="fa fa-cog fixed-plugin-button-nav cursor-pointer"></i>
</a>
</li>
<!-- Ícone do Sino com Contador -->
<li class="nav-item dropdown pe-2 d-flex align-items-center">
<<<<<<< Updated upstream
<a href="javascript:;" class="nav-link text-white p-0" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-expanded="false">
<i class="fa fa-bell cursor-pointer position-relative">
@if(auth()->user()->notifications->where('read', false)->count() > 0)
<span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger" style="font-size: 0.6rem;">
{{ auth()->user()->notifications->where('read', false)->count() }}
</span>
@endif
</i>
</a>

<!-- Dropdown de Notificações -->
<ul class="dropdown-menu dropdown-menu-end px-2 py-3 me-sm-n4" aria-labelledby="dropdownMenuButton">
@forelse(auth()->user()->notifications->where('read', false)->take(5) as $notification)
=======
<a href="javascript:;" class="nav-link text-white p-0" id="dropdownMenuButton"
data-bs-toggle="dropdown" aria-expanded="false">
<i class="fa fa-bell cursor-pointer"></i>
<i class="fa fa-bell cursor-pointer position-relative">
@auth
@if(auth()->user()->notifications()->where('read', false)->count() > 0)
<span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger" style="font-size: 0.6rem;">
{{ auth()->user()->notifications()->where('read', false)->count() }}
</span>
@endif
@endauth
</i>
</a>
<ul class="dropdown-menu dropdown-menu-end px-2 py-3 me-sm-n4"
aria-labelledby="dropdownMenuButton">
<li class="mb-2">
<a class="dropdown-item border-radius-md" href="javascript:;">
<div class="d-flex py-1">

<div class="d-flex flex-column justify-content-center">
<h6 class="text-sm font-weight-normal mb-1">
<span class="font-weight-bold">{{ __('notification.new_message') }}</span> Laur
</h6>
<p class="text-xs text-secondary mb-0">
<i class="fa fa-clock me-1"></i>
13 minutes ago
</p>
</div>
</div>
</a>
</li>
<li class="mb-2">
<a class="dropdown-item border-radius-md" href="javascript:;">
<div class="d-flex py-1">

<div class="d-flex flex-column justify-content-center">
<h6 class="text-sm font-weight-normal mb-1">
<span class="font-weight-bold">{{ __('notification.new_album') }}</span> Travis Scott
</h6>
<p class="text-xs text-secondary mb-0">
<i class="fa fa-clock me-1"></i>
1 day
</p>
<!-- Dropdown de notificações -->
<ul class="dropdown-menu dropdown-menu-end px-2 py-3 me-sm-n4">
@auth
@forelse(auth()->user()->notifications()->where('read', false)->latest()->take(5)->get() as $notification)
>>>>>>> Stashed changes
<li class="mb-2">
<a href="{{ route('projects.show', $notification->project_id) }}"
class="dropdown-item border-radius-md {{ $notification->read ? '' : 'fw-bold' }}"
onclick="markAsRead({{ $notification->id }})">
<div class="d-flex py-1">
<div class="d-flex flex-column justify-content-center">
<h6 class="text-sm mb-1">
{{ $notification->message }}
</h6>
<p class="text-xs text-secondary mb-0">
<i class="fa fa-clock me-1"></i>
{{ $notification->created_at->diffForHumans() }}
</p>
</div>
</div>
</a>
</li>
@empty
<li class="mb-2">
<div class="dropdown-item border-radius-md">
<p class="text-sm text-muted mb-0">Nenhuma notificação nova</p>
</div>
</a>
</li>
<li>
<a class="dropdown-item border-radius-md" href="javascript:;">
<div class="d-flex py-1">
<div class="avatar avatar-sm bg-gradient-secondary me-3 my-auto">
<svg width="12px" height="12px" viewBox="0 0 43 36" version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<title>credit-card</title>
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g transform="translate(-2169.000000, -745.000000)" fill="#FFFFFF"
fill-rule="nonzero">
<g transform="translate(1716.000000, 291.000000)">
<g transform="translate(453.000000, 454.000000)">
<path class="color-background"
d="M43,10.7482083 L43,3.58333333 C43,1.60354167 41.3964583,0 39.4166667,0 L3.58333333,0 C1.60354167,0 0,1.60354167 0,3.58333333 L0,10.7482083 L43,10.7482083 Z"
opacity="0.593633743"></path>
<path class="color-background"
d="M0,16.125 L0,32.25 C0,34.2297917 1.60354167,35.8333333 3.58333333,35.8333333 L39.4166667,35.8333333 C41.3964583,35.8333333 43,34.2297917 43,32.25 L43,16.125 L0,16.125 Z M19.7083333,26.875 L7.16666667,26.875 L7.16666667,23.2916667 L19.7083333,23.2916667 L19.7083333,26.875 Z M35.8333333,26.875 L28.6666667,26.875 L28.6666667,23.2916667 L35.8333333,23.2916667 L35.8333333,26.875 Z">
</path>
</g>
</g>
</g>
</g>
</svg>
</div>
<div class="d-flex flex-column justify-content-center">
<h6 class="text-sm font-weight-normal mb-1">
{{ __('notification.pyment_success') }}
</h6>
<p class="text-xs text-secondary mb-0">
<i class="fa fa-clock me-1"></i>
2 days
</p>
</div>
</div>
</a>
</li>
</li>
@endforelse
<<<<<<< Updated upstream
=======
@endauth
>>>>>>> Stashed changes
</ul>

@push('scripts')
<script>
function markAsRead(id) {
fetch(`/notifications/${id}/read`, {
method: 'POST',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}',
'Accept': 'application/json'
}
});
}
</script>
@endpush
</li>

<!-- Script para marcar como lida -->
@push('scripts')
<script>
function markAsRead(id) {
fetch(`/notifications/${id}/read`, {
method: 'POST',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}',
'Accept': 'application/json'
}
});
}
</script>
@endpush
</li>
</ul>
</div>
</div>
</nav>
<!-- End Navbar -->
6 changes: 6 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@
// End of the Projects Routes
Route::get('/project/{idProject}/accept-invitation', [ProjectController::class, 'acceptInvitation'])->name('projects.accept_invitation');

Route::post('/notifications/{id}/read', [NotificationController::class, 'markAsRead'])
->name('notifications.read');

Route::post('/notifications/{id}/read', [NotificationController::class, 'markAsRead'])
->name('notifications.read');


// Project Routes
Route::prefix('project/{projectId}')->middleware(['auth', Localization::class])->group(function () {
Expand Down
Loading