-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ffc698
commit 3851cac
Showing
13 changed files
with
780 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Task; | ||
use App\Models\Contact; | ||
use App\Models\Lead; | ||
use App\Models\User; | ||
use App\Services\ReminderService; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class TaskController extends Controller | ||
{ | ||
protected $reminderService; | ||
|
||
public function __construct(ReminderService $reminderService) | ||
{ | ||
$this->reminderService = $reminderService; | ||
} | ||
|
||
public function index() | ||
{ | ||
$tasks = Task::where('assigned_to', Auth::id())->orderBy('due_date')->get(); | ||
return view('tasks.index', compact('tasks')); | ||
} | ||
|
||
public function create() | ||
{ | ||
$contacts = Contact::all(); | ||
$leads = Lead::all(); | ||
$users = User::all(); | ||
return view('tasks.create', compact('contacts', 'leads', 'users')); | ||
} | ||
|
||
public function store(Request $request) | ||
{ | ||
$validatedData = $request->validate([ | ||
'name' => 'required|string|max:255', | ||
'description' => 'nullable|string', | ||
'due_date' => 'required|date', | ||
'contact_id' => 'nullable|exists:contacts,id', | ||
'lead_id' => 'nullable|exists:leads,id', | ||
'assigned_to' => 'required|exists:users,id', | ||
'reminder_date' => 'nullable|date|before_or_equal:due_date', | ||
]); | ||
|
||
$task = Task::create($validatedData); | ||
|
||
if ($request->has('reminder_date')) { | ||
$this->reminderService->scheduleReminder($task, $request->reminder_date); | ||
} | ||
|
||
return redirect()->route('tasks.index')->with('success', 'Task created successfully.'); | ||
} | ||
|
||
public function edit(Task $task) | ||
{ | ||
$contacts = Contact::all(); | ||
$leads = Lead::all(); | ||
$users = User::all(); | ||
return view('tasks.edit', compact('task', 'contacts', 'leads', 'users')); | ||
} | ||
|
||
public function update(Request $request, Task $task) | ||
{ | ||
$validatedData = $request->validate([ | ||
'name' => 'required|string|max:255', | ||
'description' => 'nullable|string', | ||
'due_date' => 'required|date', | ||
'contact_id' => 'nullable|exists:contacts,id', | ||
'lead_id' => 'nullable|exists:leads,id', | ||
'assigned_to' => 'required|exists:users,id', | ||
'reminder_date' => 'nullable|date|before_or_equal:due_date', | ||
]); | ||
|
||
$task->update($validatedData); | ||
|
||
if ($request->has('reminder_date')) { | ||
$this->reminderService->scheduleReminder($task, $request->reminder_date); | ||
} | ||
|
||
return redirect()->route('tasks.index')->with('success', 'Task updated successfully.'); | ||
} | ||
|
||
public function destroy(Task $task) | ||
{ | ||
$task->delete(); | ||
return redirect()->route('tasks.index')->with('success', 'Task deleted successfully.'); | ||
} | ||
|
||
public function complete(Task $task) | ||
{ | ||
$task->markAsComplete(); | ||
return redirect()->back()->with('success', 'Task marked as complete.'); | ||
} | ||
|
||
public function incomplete(Task $task) | ||
{ | ||
$task->markAsIncomplete(); | ||
return redirect()->back()->with('success', 'Task marked as incomplete.'); | ||
} | ||
|
||
public function assign(Request $request, Task $task) | ||
{ | ||
$validatedData = $request->validate([ | ||
'user_id' => 'required|exists:users,id', | ||
]); | ||
|
||
$user = User::findOrFail($validatedData['user_id']); | ||
$task->assign($user); | ||
|
||
return redirect()->back()->with('success', 'Task assigned successfully.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire; | ||
|
||
use App\Models\Task; | ||
use App\Models\Contact; | ||
use App\Models\Lead; | ||
use App\Models\User; | ||
use Livewire\Component; | ||
|
||
class TaskForm extends Component | ||
{ | ||
public $task; | ||
public $taskId; | ||
public $name; | ||
public $description; | ||
public $due_date; | ||
public $contact_id; | ||
public $lead_id; | ||
public $assigned_to; | ||
public $reminder_date; | ||
|
||
protected $rules = [ | ||
'name' => 'required|string|max:255', | ||
'description' => 'nullable|string', | ||
'due_date' => 'required|date', | ||
'contact_id' => 'nullable|exists:contacts,id', | ||
'lead_id' => 'nullable|exists:leads,id', | ||
'assigned_to' => 'required|exists:users,id', | ||
'reminder_date' => 'nullable|date|before_or_equal:due_date', | ||
]; | ||
|
||
public function mount($taskId = null) | ||
{ | ||
if ($taskId) { | ||
$this->task = Task::findOrFail($taskId); | ||
$this->taskId = $this->task->id; | ||
$this->name = $this->task->name; | ||
$this->description = $this->task->description; | ||
$this->due_date = $this->task->due_date->format('Y-m-d\TH:i'); | ||
$this->contact_id = $this->task->contact_id; | ||
$this->lead_id = $this->task->lead_id; | ||
$this->assigned_to = $this->task->assigned_to; | ||
$this->reminder_date = $this->task->reminder_date ? $this->task->reminder_date->format('Y-m-d\TH:i') : null; | ||
} | ||
} | ||
|
||
public function save() | ||
{ | ||
$this->validate(); | ||
|
||
$taskData = [ | ||
'name' => $this->name, | ||
'description' => $this->description, | ||
'due_date' => $this->due_date, | ||
'contact_id' => $this->contact_id, | ||
'lead_id' => $this->lead_id, | ||
'assigned_to' => $this->assigned_to, | ||
'reminder_date' => $this->reminder_date, | ||
]; | ||
|
||
if ($this->taskId) { | ||
$this->task->update($taskData); | ||
session()->flash('message', 'Task updated successfully.'); | ||
} else { | ||
Task::create($taskData); | ||
session()->flash('message', 'Task created successfully.'); | ||
} | ||
|
||
return redirect()->route('tasks.index'); | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.task-form', [ | ||
'contacts' => Contact::all(), | ||
'leads' => Lead::all(), | ||
'users' => User::all(), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire; | ||
|
||
use App\Models\Task; | ||
use Livewire\Component; | ||
use Livewire\WithPagination; | ||
|
||
class TaskList extends Component | ||
{ | ||
use WithPagination; | ||
|
||
public $search = ''; | ||
public $status = ''; | ||
public $sortField = 'due_date'; | ||
public $sortDirection = 'asc'; | ||
|
||
protected $queryString = ['search', 'status', 'sortField', 'sortDirection']; | ||
|
||
public function updatingSearch() | ||
{ | ||
$this->resetPage(); | ||
} | ||
|
||
public function sortBy($field) | ||
{ | ||
if ($this->sortField === $field) { | ||
$this->sortDirection = $this->sortDirection === 'asc' ? 'desc' : 'asc'; | ||
} else { | ||
$this->sortDirection = 'asc'; | ||
} | ||
|
||
$this->sortField = $field; | ||
} | ||
|
||
public function render() | ||
{ | ||
$tasks = Task::query() | ||
->when($this->search, function ($query) { | ||
$query->where('name', 'like', '%' . $this->search . '%'); | ||
}) | ||
->when($this->status, function ($query) { | ||
$query->where('status', $this->status); | ||
}) | ||
->orderBy($this->sortField, $this->sortDirection) | ||
->paginate(10); | ||
|
||
return view('livewire.task-list', [ | ||
'tasks' => $tasks, | ||
]); | ||
} | ||
} |
Oops, something went wrong.