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

feat: add messages in project #355

Merged
merged 14 commits into from
Nov 1, 2020
35 changes: 35 additions & 0 deletions app/Console/Commands/Tests/SetupDummyAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
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\Employee\Expense\CreateExpense;
use App\Services\Company\Employee\Manager\AssignManager;
use App\Services\Company\Adminland\Company\CreateCompany;
use App\Services\Company\Adminland\Hardware\LendHardware;
use App\Services\Company\Employee\Birthdate\SetBirthdate;
use App\Services\Company\Employee\Team\AddEmployeeToTeam;
use App\Services\Company\Project\MarkProjectMessageasRead;
use App\Services\Company\Adminland\Hardware\CreateHardware;
use App\Services\Company\Adminland\Position\CreatePosition;
use App\Services\Company\Adminland\Question\CreateQuestion;
Expand Down Expand Up @@ -1684,6 +1686,39 @@ private function addProjects(): void
'decided_at' => '2019-06-29',
'deciders' => [$this->dwight->id, $this->oscar->id],
]);

// add messages
$messages = collect([
'Let’s change how we do business',
'Ryan promoted as the principal project manager',
'Changing the name of the project - my thoughts',
'Need more resources? Contact Corporate if you need help',
]);
$content = 'Kelly tries to restart her relationship with Ryan, an effort he ignores until she (untruly) tells him she’s pregnant. He agrees to discuss the situation over dinner that night. Jim informs Pam that Dwight and Angela are secretly dating, only to discover that she has known this for quite some time. Meanwhile, Dwight attempts to make amends for the death of Angela’s cat Sprinkles by giving her a stray cat he found in his barn. Dwight’s cousin Mose named the cat Garbage because that’s what it eats. Angela rejects the gift, and Dwight attempts to dump the cat into the office of Vance Refrigeration.

Creed dyes his hair jet-black (using ink cartridges) in an attempt to convince everyone that he’s much younger. After a conversation with Jan, Michael decides to formally challenge Dunder Mifflin Infinity by claiming that Ryan is being ageist. Michael brings the octogenarian co-founder of Dunder Mifflin into a meeting to make his point about old things still being useful, but shoves Dunder out after tiring of his rambling stories. Angela asks Dwight out to dinner, where she breaks up with him, saying that she can’t look into Dwight’s eyes without seeing Sprinkles’ corpse.

* Alternate talking heads of different people reacting to Jim and Pam dating
* Michael drives a rental car to the office using a GPS. Jan calls him and yells at him for allegedly eating her Grape-Nuts';

foreach ($messages as $message) {
$message = (new CreateProjectMessage)->execute([
'company_id' => $this->company->id,
'author_id' => $this->jim->id,
'project_id' => $infinity->id,
'title' => $message,
'content' => $content,
]);

if (rand(1, 2) == 1) {
(new MarkProjectMessageasRead)->execute([
'company_id' => $this->company->id,
'author_id' => $this->michael->id,
'project_id' => $infinity->id,
'project_message_id' => $message->id,
]);
}
}
}

private function addSecondaryBlankAccount(): void
Expand Down
26 changes: 25 additions & 1 deletion app/Helpers/LogHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,32 @@ public static function processAuditLog(AuditLog $log): string
'project_name' => $log->object->{'project_name'},
'title' => $log->object->{'title'},
]);
break;

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

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

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

// no break
default:
$sentence = '';
break;
Expand Down
35 changes: 0 additions & 35 deletions app/Http/Controllers/Company/Project/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,41 +372,6 @@ public function clear(Request $request, int $companyId, int $projectId): JsonRes
], 200);
}

/**
* Display the project messages.
*
* @param Request $request
* @param int $companyId
* @param int $projectId
* @return Response
*/
public function messages(Request $request, int $companyId, int $projectId): Response
{
$company = InstanceHelper::getLoggedCompany();

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

/**
* Display the project messages.
*
* @param Request $request
* @param int $companyId
* @param int $projectId
* @param int $messageId
* @return Response
*/
public function message(Request $request, int $companyId, int $projectId, int $messageId): Response
{
$company = InstanceHelper::getLoggedCompany();

return Inertia::render('Project/Message', [
'notifications' => NotificationHelper::getNotifications(InstanceHelper::getLoggedEmployee()),
]);
}

/**
* Display the create new project form.
*
Expand Down
250 changes: 250 additions & 0 deletions app/Http/Controllers/Company/Project/ProjectMessagesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
<?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\Models\Company\ProjectMessage;
use App\Http\ViewHelpers\Project\ProjectViewHelper;
use App\Services\Company\Project\CreateProjectMessage;
use App\Services\Company\Project\UpdateProjectMessage;
use App\Services\Company\Project\DestroyProjectMessage;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use App\Services\Company\Project\MarkProjectMessageasRead;
use App\Http\ViewHelpers\Project\ProjectMessagesViewHelper;

class ProjectMessagesController extends Controller
{
/**
* Display the list of messages in the project.
*
* @param Request $request
* @param int $companyId
* @param int $projectId
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|Response
*/
public function index(Request $request, int $companyId, int $projectId)
{
$company = InstanceHelper::getLoggedCompany();
$employee = InstanceHelper::getLoggedEmployee();

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

return Inertia::render('Project/Messages/Index', [
'tab' => 'messages',
'project' => ProjectViewHelper::info($project),
'messages' => ProjectMessagesViewHelper::index($project, $employee),
'notifications' => NotificationHelper::getNotifications(InstanceHelper::getLoggedEmployee()),
]);
}

/**
* Display the Create message 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 message.
*
* @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'),
'content' => $request->input('content'),
];

$message = (new CreateProjectMessage)->execute($data);

return response()->json([
'data' => $message->id,
], 201);
}

/**
* Display the detail of a given message.
*
* @param Request $request
* @param int $companyId
* @param int $projectId
* @param int $messageId
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|Response
*/
public function show(Request $request, int $companyId, int $projectId, int $messageId)
{
$loggedCompany = InstanceHelper::getLoggedCompany();
$loggedEmployee = InstanceHelper::getLoggedEmployee();

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

try {
$message = ProjectMessage::where('project_id', $project->id)
->with('project')
->findOrFail($messageId);
} catch (ModelNotFoundException $e) {
return redirect('home');
}

(new MarkProjectMessageasRead)->execute([
'company_id' => $loggedCompany->id,
'author_id' => $loggedEmployee->id,
'project_id' => $project->id,
'project_message_id' => $message->id,
]);

return Inertia::render('Project/Messages/Show', [
'tab' => 'messages',
'project' => ProjectViewHelper::info($project),
'message' => ProjectMessagesViewHelper::show($message),
'notifications' => NotificationHelper::getNotifications(InstanceHelper::getLoggedEmployee()),
]);
}

/**
* Display the edit message page.
*
* @param Request $request
* @param int $companyId
* @param int $projectId
* @param int $messageId
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|Response
*/
public function edit(Request $request, int $companyId, int $projectId, int $messageId)
{
$company = InstanceHelper::getLoggedCompany();

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

try {
$message = ProjectMessage::where('project_id', $project->id)
->with('project')
->findOrFail($messageId);
} catch (ModelNotFoundException $e) {
return redirect('home');
}

return Inertia::render('Project/Messages/Update', [
'tab' => 'messages',
'project' => ProjectViewHelper::info($project),
'message' => ProjectMessagesViewHelper::edit($message),
'notifications' => NotificationHelper::getNotifications(InstanceHelper::getLoggedEmployee()),
]);
}

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

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

$message = (new UpdateProjectMessage)->execute($data);

return response()->json([
'data' => $message->id,
], 201);
}

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

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

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

return response()->json([
'data' => true,
], 201);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static function decisions(Project $project): Collection

$decisionsCollection = collect([]);
foreach ($decisions as $decision) {
$deciders = $decision->deciders()->get();
$deciders = $decision->deciders;
$decidersCollection = collect([]);
foreach ($deciders as $decider) {
$decidersCollection->push([
Expand Down
Loading