Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for checklists items and Comments #8

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
10 changes: 5 additions & 5 deletions database/migrations/2020_10_27_102330_create_tasks_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class extends Migration {
public function up()
{
Schema::create('tasks', function (Blueprint $table) {
Expand All @@ -15,10 +14,11 @@ public function up()
$table->text('description');

$table->tinyInteger('flag')->nullable()->index();

$table->boolean('completed')->index();

$table->dateTime('reminder')->nullable();
$table->smallInteger('status')->nullable();
$table->dateTime('from')->nullable();
$table->dateTime('to')->nullable();
$table->boolean('muted')->default(false);

$table->unsignedInteger('allocated_to')->nullable()->index();
$table->foreign('allocated_to')->references('id')->on('users');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

use LaravelEnso\Migrator\Database\Migration;

return new class extends Migration
{
return new class extends Migration {
protected array $permissions = [
['name' => 'tasks.index', 'description' => 'Show index for tasks', 'is_default' => false],
['name' => 'tasks.create', 'description' => 'Create task', 'is_default' => false],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
public function up()
{
Schema::create('task_checklist_items', function (Blueprint $table) {
$table->id();
$table->foreignId('task_id')->constrained('tasks');
MusahMusah marked this conversation as resolved.
Show resolved Hide resolved

$table->string('name');
$table->unsignedInteger('order_index')->nullable();
$table->boolean('is_completed');
$table->timestamps();
});
}

public function down()
{
Schema::dropIfExists('task_checklist_items');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

use LaravelEnso\Migrator\Database\Migration;

return new class extends Migration {
protected array $permissions = [
['name' => 'tasks.checklistItems.store', 'description' => 'Store a new check list', 'is_default' => false],
['name' => 'tasks.checklistItems.update', 'description' => 'Update check list', 'is_default' => false],
['name' => 'tasks.checklistItems.destroy', 'description' => 'Delete check list', 'is_default' => false],
];

protected ?string $parentMenu = '';
};

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
public function up()
{
Schema::create('task_comments', function (Blueprint $table) {
$table->increments('id');
$table->foreignId('task_id')->constrained();
$table->text('body');

$table->integer('created_by')->unsigned()->nullable()->index();
$table->foreign('created_by')->references('id')->on('users');

$table->integer('updated_by')->unsigned()->nullable();
$table->foreign('updated_by')->references('id')->on('users');

$table->timestamps();
});
}

public function down()
{
Schema::dropIfExists('task_comments');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

use LaravelEnso\Migrator\Database\Migration;

return new class extends Migration {
protected array $permissions = [
['name' => 'tasks.comments.index', 'description' => 'Show index for comments', 'is_default' => false],
['name' => 'tasks.comments.store', 'description' => 'Store a new comment', 'is_default' => false],
['name' => 'tasks.comments.update', 'description' => 'Update comment', 'is_default' => false],
['name' => 'tasks.comments.destroy', 'description' => 'Delete comment', 'is_default' => false],
];
};
3 changes: 3 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@
Route::get('', Index::class)->name('index');

Route::get('users', Users::class)->name('users');

require __DIR__.'/checklistsItems.php';
require __DIR__.'/comments.php';
});
14 changes: 14 additions & 0 deletions routes/checklistsItems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

use Illuminate\Support\Facades\Route;
use LaravelEnso\Tasks\Http\Controllers\Tasks\ChecklistItems\Destroy;
use LaravelEnso\Tasks\Http\Controllers\Tasks\ChecklistItems\Store;
use LaravelEnso\Tasks\Http\Controllers\Tasks\ChecklistItems\Update;

Route::prefix('checklistItems')
->as('checklistItems.')
->group(function () {
Route::post('', Store::class)->name('store');
Route::patch('{checklistItem}', Update::class)->name('update');
Route::delete('{checklistItem}', Destroy::class)->name('destroy');
});
16 changes: 16 additions & 0 deletions routes/comments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use App\Http\Controllers\Tasks\Comments\Destroy;
use App\Http\Controllers\Tasks\Comments\Index;
use App\Http\Controllers\Tasks\Comments\Store;
use App\Http\Controllers\Tasks\Comments\Update;
use Illuminate\Support\Facades\Route;

Route::prefix('comments')
->as('comments.')
->group(function () {
Route::get('', Index::class)->name('index');
Route::post('', Store::class)->name('store');
Route::patch('{comment}', Update::class)->name('update');
Route::delete('{comment}', Destroy::class)->name('destroy');
});
3 changes: 3 additions & 0 deletions src/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use LaravelEnso\DynamicMethods\Services\Methods;
use LaravelEnso\Tasks\Commands\SendTaskReminders;
use LaravelEnso\Tasks\DynamicRelations\Tasks;
use LaravelEnso\Tasks\Models\ChecklistItem;
use LaravelEnso\Tasks\Models\Task as Model;
use LaravelEnso\Tasks\Observers\ChecklistItem as ChecklistItemObserver;
use LaravelEnso\Tasks\Observers\Task as Observer;
use LaravelEnso\Users\Models\User;

Expand All @@ -20,6 +22,7 @@ public function boot()
->command()
->relations()
->observers();
ChecklistItem::observe(ChecklistItemObserver::class);
}

private function load(): self
Expand Down
5 changes: 4 additions & 1 deletion src/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
namespace LaravelEnso\Tasks;

use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use LaravelEnso\Tasks\Models\Comment;
use LaravelEnso\Tasks\Models\Task;
use LaravelEnso\Tasks\Policies\Comment as TaskCommentPolicy;
use LaravelEnso\Tasks\Policies\Task as Policy;

class AuthServiceProvider extends ServiceProvider
{
protected $policies = [
Task::class => Policy::class,
Task::class => Policy::class,
Comment::class => TaskCommentPolicy::class,
];

public function boot()
Expand Down
4 changes: 3 additions & 1 deletion src/EnumServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

use LaravelEnso\Enums\EnumServiceProvider as ServiceProvider;
use LaravelEnso\Tasks\Enums\Flags;
use LaravelEnso\Tasks\Enums\Statuses;

class EnumServiceProvider extends ServiceProvider
{
public $register = [
'flags' => Flags::class,
'flags' => Flags::class,
'Statuses' => Statuses::class,
];
}
18 changes: 18 additions & 0 deletions src/Enums/Statuses.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace LaravelEnso\Tasks\Enums;

use LaravelEnso\Enums\Services\Enum;

class Statuses extends Enum
{
public const New = 1;
public const InProgress = 2;
public const Finished = 3;

protected static array $data = [
self::New => 'New',
self::InProgress => 'In Progress',
self::Finished => 'Finished',
];
}
4 changes: 3 additions & 1 deletion src/Forms/Builders/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Facades\Auth;
use LaravelEnso\Forms\Services\Form;
use LaravelEnso\Tasks\Enums\Statuses;
use LaravelEnso\Tasks\Models\Task as Model;

class Task
Expand All @@ -21,8 +22,9 @@ public function __construct()

public function create()
{
return $this->form->hide('completed')
return $this->form->hide('status')
->value('allocated_to', Auth::id())
->value('status', Statuses::New)
->create();
}

Expand Down
51 changes: 47 additions & 4 deletions src/Forms/Templates/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,21 @@
"type": "input",
"content": "text"
}
},
{
"label": "Status",
"name": "status",
"value": null,
"meta": {
"type": "select",
"options": "LaravelEnso\\Tasks\\Enums\\Statuses",
"placeholder": "Choose Task Status"
}
}
]
},
{
"columns": 3,
"columns": 2,
"fields": [
{
"label": "Allocated To",
Expand All @@ -48,10 +58,43 @@
"format": "Y-m-d H:i:s",
"time": true
}
}
]
},
{
"columns": 2,
"fields": [
{
"label": "From",
"name": "from",
"value": "",
"meta": {
"type": "datepicker",
"altFormat": "m-d-Y H:i",
"format": "Y-m-d H:i:s",
"time": true
}
},
{
"label": "Completed",
"name": "completed",
"label": "To",
"name": "to",
"value": "",
"meta": {
"type": "datepicker",
"altFormat": "m-d-Y H:i",
"format": "Y-m-d H:i:s",
"time": true
}
}
]
},
{
"columns": "custom",
"fields": [
{
"column": 3,
"label": "Muted",
"name": "muted",
"value": false,
"meta": {
"type": "input",
Expand All @@ -74,4 +117,4 @@
]
}
]
}
}
18 changes: 18 additions & 0 deletions src/Http/Controllers/Tasks/ChecklistItems/Destroy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace LaravelEnso\Tasks\Http\Controllers\Tasks\ChecklistItems;

use Illuminate\Routing\Controller;
use LaravelEnso\Tasks\Models\ChecklistItem;

class Destroy extends Controller
{
public function __invoke(ChecklistItem $checklistItem)
{
$checklistItem->delete();

return [
'message' => __('The item was successfully deleted'),
];
}
}
21 changes: 21 additions & 0 deletions src/Http/Controllers/Tasks/ChecklistItems/Store.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace LaravelEnso\Tasks\Http\Controllers\Tasks\ChecklistItems;

use Illuminate\Routing\Controller;
use LaravelEnso\Tasks\Http\Requests\ValidateChecklistItem;
use LaravelEnso\Tasks\Models\ChecklistItem;

class Store extends Controller
{
public function __invoke(ValidateChecklistItem $request, ChecklistItem $checklistItem)
{
$checklistItem->fill($request->validated() + ['is_completed' => false])->save();

return [
'message' => __('The item was successfully created'),
'param' => ['checklist' => $checklistItem->id],
'data' => $checklistItem,
];
}
}
17 changes: 17 additions & 0 deletions src/Http/Controllers/Tasks/ChecklistItems/Update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace LaravelEnso\Tasks\Http\Controllers\Tasks\ChecklistItems;

use Illuminate\Routing\Controller;
use LaravelEnso\Tasks\Http\Requests\ValidateChecklistItem;
use LaravelEnso\Tasks\Models\ChecklistItem;

class Update extends Controller
{
public function __invoke(ValidateChecklistItem $request, ChecklistItem $checklistItem)
{
$checklistItem->update($request->validated());

return ['message' => __('The item was successfully updated')];
}
}
Loading