Skip to content

Commit

Permalink
feat: tasks in projects (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss committed Nov 17, 2020
1 parent b10e28e commit c90ee8b
Show file tree
Hide file tree
Showing 64 changed files with 4,581 additions and 35 deletions.
2 changes: 1 addition & 1 deletion app/Console/Commands/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function handle(): void
$this->artisan('✓ Clear config cache', 'config:clear');
$this->artisan('✓ Resetting route cache', 'route:cache');
$this->artisan('✓ Resetting view cache', 'view:clear');
// @codeCoverageIgnoreEnd
// @codeCoverageIgnoreEnd
} else {
$this->artisan('✓ Clear config cache', 'config:clear');
$this->artisan('✓ Clear route cache', 'route:clear');
Expand Down
113 changes: 113 additions & 0 deletions app/Console/Commands/Tests/SetupDummyAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
use App\Services\Company\Adminland\Team\CreateTeam;
use App\Services\Company\Employee\Morale\LogMorale;
use App\Services\Company\Project\CreateProjectLink;
use App\Services\Company\Project\CreateProjectTask;
use App\Services\Company\Employee\Worklog\LogWorklog;
use App\Services\Company\Project\CreateProjectStatus;
use App\Services\Company\Employee\Answer\CreateAnswer;
use App\Services\Company\Project\AddEmployeeToProject;
use App\Services\Company\Project\CreateProjectMessage;
use App\Services\Company\Project\CreateProjectDecision;
use App\Services\Company\Project\CreateProjectTaskList;
use App\Services\Company\Employee\Expense\CreateExpense;
use App\Services\Company\Employee\Manager\AssignManager;
use App\Services\Company\Adminland\Company\CreateCompany;
Expand All @@ -44,6 +46,7 @@
use App\Services\Company\Adminland\Position\CreatePosition;
use App\Services\Company\Adminland\Question\CreateQuestion;
use App\Services\Company\Employee\HiringDate\SetHiringDate;
use App\Services\Company\Project\AssignProjecTaskToEmployee;
use App\Services\Company\Team\Description\SetTeamDescription;
use App\Services\Company\Employee\OneOnOne\CreateOneOnOneNote;
use App\Services\Company\Employee\Skill\AttachEmployeeToSkill;
Expand Down Expand Up @@ -1719,6 +1722,116 @@ private function addProjects(): void
]);
}
}

// add tasks
(new CreateProjectTask)->execute([
'company_id' => $this->company->id,
'author_id' => $this->michael->id,
'project_id' => $infinity->id,
'project_task_list_id' => null,
'title' => 'Organize a meetup with HR',
'description' => 'We need to make sure that HR is on par with what we want to achieve with this project.',
]);
$task = (new CreateProjectTask)->execute([
'company_id' => $this->company->id,
'author_id' => $this->meredith->id,
'project_id' => $infinity->id,
'project_task_list_id' => null,
'title' => 'Migrate domain names when the new site launches',
'description' => null,
]);
(new AssignProjecTaskToEmployee)->execute([
'company_id' => $this->company->id,
'author_id' => $this->meredith->id,
'project_id' => $infinity->id,
'project_task_id' => $task->id,
'assignee_id' => $this->oscar->id,
]);

$launchTaskList = (new CreateProjectTaskList)->execute([
'company_id' => $this->company->id,
'author_id' => $this->meredith->id,
'project_id' => $infinity->id,
'title' => 'Todos for the launch',
'description' => 'Everything we need to make sure before the new site launches',
]);
$task = (new CreateProjectTask)->execute([
'company_id' => $this->company->id,
'author_id' => $this->meredith->id,
'project_id' => $infinity->id,
'project_task_list_id' => $launchTaskList->id,
'title' => 'Make sure the SEO is implemented',
'description' => null,
]);
(new AssignProjecTaskToEmployee)->execute([
'company_id' => $this->company->id,
'author_id' => $this->jim->id,
'project_id' => $infinity->id,
'project_task_id' => $task->id,
'assignee_id' => $this->angela->id,
]);
(new CreateProjectTask)->execute([
'company_id' => $this->company->id,
'author_id' => $this->oscar->id,
'project_id' => $infinity->id,
'project_task_list_id' => $launchTaskList->id,
'title' => 'Check the Fathom Analytics code',
'description' => null,
]);
$task = (new CreateProjectTask)->execute([
'company_id' => $this->company->id,
'author_id' => $this->jim->id,
'project_id' => $infinity->id,
'project_task_list_id' => $launchTaskList->id,
'title' => 'Migrate the ACLs',
'description' => null,
]);
(new AssignProjecTaskToEmployee)->execute([
'company_id' => $this->company->id,
'author_id' => $this->meredith->id,
'project_id' => $infinity->id,
'project_task_id' => $task->id,
'assignee_id' => $this->erin->id,
]);

$marketingTaskList = (new CreateProjectTaskList)->execute([
'company_id' => $this->company->id,
'author_id' => $this->meredith->id,
'project_id' => $infinity->id,
'title' => 'Marketing assets to provide',
'description' => null,
]);
$task = (new CreateProjectTask)->execute([
'company_id' => $this->company->id,
'author_id' => $this->meredith->id,
'project_id' => $infinity->id,
'project_task_list_id' => $marketingTaskList->id,
'title' => 'Take appointment with the photographer',
'description' => 'We need to make sure all photos look great if possible',
]);
(new AssignProjecTaskToEmployee)->execute([
'company_id' => $this->company->id,
'author_id' => $this->michael->id,
'project_id' => $infinity->id,
'project_task_id' => $task->id,
'assignee_id' => $this->oscar->id,
]);
(new CreateProjectTask)->execute([
'company_id' => $this->company->id,
'author_id' => $this->oscar->id,
'project_id' => $infinity->id,
'project_task_list_id' => $marketingTaskList->id,
'title' => 'Update all business cards with the new URL',
'description' => null,
]);
(new CreateProjectTask)->execute([
'company_id' => $this->company->id,
'author_id' => $this->jim->id,
'project_id' => $infinity->id,
'project_task_list_id' => $marketingTaskList->id,
'title' => 'Migrate the ACLs',
'description' => null,
]);
}

private function addSecondaryBlankAccount(): void
Expand Down
83 changes: 83 additions & 0 deletions app/Helpers/LogHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,89 @@ public static function processAuditLog(AuditLog $log): string
]);
break;

case 'project_task_created':
$sentence = trans('account.log_project_task_created', [
'project_id' => $log->object->{'project_id'},
'project_name' => $log->object->{'project_name'},
'project_task_id' => $log->object->{'project_task_id'},
'project_task_title' => $log->object->{'project_task_title'},
]);
break;

case 'project_task_toggled':
$sentence = trans('account.log_project_task_toggled', [
'project_id' => $log->object->{'project_id'},
'project_name' => $log->object->{'project_name'},
'project_task_id' => $log->object->{'project_task_id'},
'project_task_title' => $log->object->{'project_task_title'},
]);
break;

case 'project_task_assigned_to_task_list':
$sentence = trans('account.log_project_task_assigned_to_task_list', [
'project_id' => $log->object->{'project_id'},
'project_name' => $log->object->{'project_name'},
'project_task_id' => $log->object->{'project_task_id'},
'project_task_title' => $log->object->{'project_task_title'},
'project_task_list_id' => $log->object->{'project_task_list_id'},
'project_task_list_title' => $log->object->{'project_task_list_title'},
]);
break;

case 'project_task_list_created':
$sentence = trans('account.log_project_task_list_created', [
'project_id' => $log->object->{'project_id'},
'project_name' => $log->object->{'project_name'},
'project_task_list_id' => $log->object->{'project_task_list_id'},
'project_task_list_title' => $log->object->{'project_task_list_title'},
]);
break;

case 'project_task_destroyed':
$sentence = trans('account.log_project_task_destroyed', [
'project_id' => $log->object->{'project_id'},
'project_name' => $log->object->{'project_name'},
'title' => $log->object->{'title'},
]);
break;

case 'project_task_list_destroyed':
$sentence = trans('account.log_project_task_list_destroyed', [
'project_id' => $log->object->{'project_id'},
'project_name' => $log->object->{'project_name'},
'title' => $log->object->{'title'},
]);
break;

case 'project_task_assigned_to_assignee':
$sentence = trans('account.log_project_task_assigned_to_assignee', [
'project_id' => $log->object->{'project_id'},
'project_name' => $log->object->{'project_name'},
'project_task_id' => $log->object->{'project_task_id'},
'project_task_title' => $log->object->{'project_task_title'},
'assignee_id' => $log->object->{'assignee_id'},
'assignee_name' => $log->object->{'assignee_name'},
]);
break;

case 'project_task_updated':
$sentence = trans('account.log_project_task_updated', [
'project_id' => $log->object->{'project_id'},
'project_name' => $log->object->{'project_name'},
'project_task_id' => $log->object->{'project_task_id'},
'project_task_title' => $log->object->{'project_task_title'},
]);
break;

case 'project_task_list_updated':
$sentence = trans('account.log_project_task_list_updated', [
'project_id' => $log->object->{'project_id'},
'project_name' => $log->object->{'project_name'},
'project_task_list_id' => $log->object->{'project_task_list_id'},
'project_task_list_title' => $log->object->{'project_task_list_title'},
]);
break;

default:
$sentence = '';
break;
Expand Down
134 changes: 134 additions & 0 deletions app/Http/Controllers/Company/Project/ProjectTaskListsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

namespace App\Http\Controllers\Company\Project;

use Inertia\Inertia;
use Inertia\Response;
use Illuminate\Http\Request;
use App\Helpers\InstanceHelper;
use App\Models\Company\Project;
use Illuminate\Http\JsonResponse;
use App\Helpers\NotificationHelper;
use App\Http\Controllers\Controller;
use App\Http\ViewHelpers\Project\ProjectViewHelper;
use App\Services\Company\Project\CreateProjectTaskList;
use App\Services\Company\Project\UpdateProjectTaskList;
use App\Http\ViewHelpers\Project\ProjectTasksViewHelper;
use App\Services\Company\Project\DestroyProjectTaskList;
use Illuminate\Database\Eloquent\ModelNotFoundException;

class ProjectTaskListsController extends Controller
{
/**
* Display the Create task list view.
*
* @param Request $request
* @param int $companyId
* @param int $projectId
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|Response
*/
public function create(Request $request, int $companyId, int $projectId)
{
$company = InstanceHelper::getLoggedCompany();

try {
$project = Project::where('company_id', $company->id)
->with('employees')
->findOrFail($projectId);
} catch (ModelNotFoundException $e) {
return redirect('home');
}

return Inertia::render('Project/Messages/Create', [
'project' => ProjectViewHelper::info($project),
'notifications' => NotificationHelper::getNotifications(InstanceHelper::getLoggedEmployee()),
]);
}

/**
* Create the task list.
*
* @param Request $request
* @param int $companyId
* @param int $projectId
* @return JsonResponse
*/
public function store(Request $request, int $companyId, int $projectId): JsonResponse
{
$loggedEmployee = InstanceHelper::getLoggedEmployee();
$company = InstanceHelper::getLoggedCompany();

$data = [
'company_id' => $company->id,
'author_id' => $loggedEmployee->id,
'project_id' => $projectId,
'title' => $request->input('title'),
'description' => $request->input('description'),
];

$taskList = (new CreateProjectTaskList)->execute($data);

return response()->json([
'data' => ProjectTasksViewHelper::getTaskListInfo($taskList),
], 201);
}

/**
* Update the task list.
*
* @param Request $request
* @param int $companyId
* @param int $projectId
* @param int $projectTaskListId
* @return JsonResponse
*/
public function update(Request $request, int $companyId, int $projectId, int $projectTaskListId): JsonResponse
{
$loggedEmployee = InstanceHelper::getLoggedEmployee();
$company = InstanceHelper::getLoggedCompany();

$data = [
'company_id' => $company->id,
'author_id' => $loggedEmployee->id,
'project_id' => $projectId,
'project_task_list_id' => $projectTaskListId,
'title' => $request->input('title'),
'description' => $request->input('description'),
];

$taskList = (new UpdateProjectTaskList)->execute($data);

return response()->json([
'data' => ProjectTasksViewHelper::getTaskListInfo($taskList),
], 200);
}

/**
* Delete the task list.
*
* @param Request $request
* @param int $companyId
* @param int $projectId
* @param int $projectTaskListId
* @return JsonResponse
*/
public function destroy(Request $request, int $companyId, int $projectId, int $projectTaskListId): JsonResponse
{
$loggedEmployee = InstanceHelper::getLoggedEmployee();
$company = InstanceHelper::getLoggedCompany();

$data = [
'company_id' => $company->id,
'author_id' => $loggedEmployee->id,
'project_id' => $projectId,
'project_task_list_id' => $projectTaskListId,
];

(new DestroyProjectTaskList)->execute($data);

return response()->json([
'data' => true,
], 200);
}
}

0 comments on commit c90ee8b

Please sign in to comment.