-
Notifications
You must be signed in to change notification settings - Fork 0
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
Mayank Infyom
committed
Oct 20, 2023
1 parent
b676d40
commit 5b595b0
Showing
11 changed files
with
465 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Task; | ||
use Illuminate\Http\Request; | ||
use Inertia\Inertia; | ||
|
||
class TaskController extends Controller | ||
{ | ||
|
||
public function index(){ | ||
|
||
|
||
$tasks = Task::select(['id', 'title', 'description', 'order', 'completed', 'section']); | ||
$allTasks = $tasks->get(); | ||
$currentTasks = $allTasks->where('completed',false)->groupBy('section')->toArray(); | ||
$completedTasks = $tasks->where('completed',1)->get()->toArray(); | ||
|
||
return Inertia::render('Todo/Todo', [ | ||
'tasks' => $currentTasks, | ||
'completedTasks' => $completedTasks | ||
]); | ||
} | ||
|
||
public function store(Request $request) | ||
{ | ||
$request->validate([ | ||
'title' => 'required', | ||
]); | ||
|
||
Task::create($request->all()); | ||
|
||
return to_route('todo.index'); | ||
} | ||
|
||
public function update(Request $request, $id) | ||
{ | ||
|
||
Task::find($id)->update($request->all()); | ||
|
||
return to_route('todo.index'); | ||
} | ||
|
||
public function destroy($id) | ||
{ | ||
Task::find($id)->delete(); | ||
|
||
return to_route('todo.index'); | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Task extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $fillable=[ | ||
'title', | ||
'description', | ||
'order', | ||
'completed', | ||
'section', | ||
]; | ||
} |
32 changes: 32 additions & 0 deletions
32
database/migrations/2023_10_19_092147_create_tasks_table.php
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,32 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('tasks', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('title'); | ||
$table->text('description')->nullable(); | ||
$table->integer('order')->nullable(); | ||
$table->boolean('completed')->default(false); | ||
$table->integer('section')->default(0); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('tasks'); | ||
} | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,5 @@ | ||
export const AllSection = { | ||
"backlog" : 0, | ||
'inProgress' : 1, | ||
'done' : 2 | ||
}; |
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,27 @@ | ||
import { router } from "@inertiajs/react"; | ||
import React, { useState } from "react"; | ||
import {AllSection} from "../Keys.jsx" | ||
|
||
export default function AddTask(props) { | ||
const { section,hideNewTaskCard } = props; | ||
const [ task , setTask ] = useState(''); | ||
const addNewTask = () => { | ||
hideNewTaskCard(); | ||
router.post('/todo', { | ||
title:task, | ||
section : AllSection[section] | ||
}); | ||
} | ||
|
||
return ( | ||
<div className="card my-2"> | ||
<div className="d-flex justify-content-between align-items-center bg-light "> | ||
<input className="mb-0 form-control" value={task} onChange={(e) => setTask(e.target.value)}/> | ||
<div className="d-flex align-items-center"> | ||
<button className="btn text-danger" onClick={addNewTask}>Add</button> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
|
||
} |
Oops, something went wrong.