Skip to content

Commit

Permalink
feat: ability to set a company logo (#635)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss committed Mar 17, 2021
1 parent 535e958 commit e737974
Show file tree
Hide file tree
Showing 101 changed files with 699 additions and 277 deletions.
22 changes: 18 additions & 4 deletions app/Helpers/AvatarHelper.php → app/Helpers/ImageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

namespace App\Helpers;

use App\Models\Company\File;
use App\Models\Company\Employee;

class AvatarHelper
class ImageHelper
{
/**
* Get the avatar of the user, at the requested size if it exists.
*
* @var Employee
* @var int
* @param Employee $employee
* @param int $width
* @return string|null
*/
public static function getImage(Employee $employee, int $width = null): ?string
public static function getAvatar(Employee $employee, int $width = null): ?string
{
if (! $employee->avatar_file_id) {
return 'https://ui-avatars.com/api/?name='.$employee->name;
Expand All @@ -27,4 +28,17 @@ public static function getImage(Employee $employee, int $width = null): ?string

return $url;
}

/**
* Get the URL of an image.
*
* @param File $file
* @param int $width
* @param int $height
* @return string|null
*/
public static function getImage(File $file, int $width = null, int $height = null): ?string
{
return $file->cdn_url.'-/preview/'.$width.'x'.$height.'/';
}
}
2 changes: 1 addition & 1 deletion app/Helpers/InstanceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class InstanceHelper
{
/**
* Return the employee as set in the cache.
* Return the company as set in the cache.
*
* @return mixed
*/
Expand Down
4 changes: 4 additions & 0 deletions app/Helpers/LogHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,10 @@ public static function processAuditLog(AuditLog $log): string
$sentence = trans('account.log_toggle_e_coffee_process');
break;

case 'company_logo_changed':
$sentence = trans('account.log_company_logo_changed');
break;

default:
$sentence = '';
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Inertia\Inertia;
use Inertia\Response;
use App\Helpers\ImageHelper;
use Illuminate\Http\Request;
use App\Helpers\AvatarHelper;
use App\Helpers\InstanceHelper;
use App\Models\Company\Employee;
use Illuminate\Http\JsonResponse;
Expand Down Expand Up @@ -145,7 +145,7 @@ public function search(Request $request, int $companyId): JsonResponse
$employees->push([
'id' => $employee->id,
'name' => $employee->name,
'avatar' => AvatarHelper::getImage($employee),
'avatar' => ImageHelper::getAvatar($employee),
]);
}

Expand Down Expand Up @@ -178,7 +178,7 @@ public function addEmployee(Request $request, int $companyId): JsonResponse
'data' => [
'id' => $employee->id,
'name' => $employee->name,
'avatar' => AvatarHelper::getImage($employee),
'avatar' => ImageHelper::getAvatar($employee),
'url' => route('employees.show', [
'company' => $loggedCompany,
'employee' => $employee,
Expand Down
38 changes: 38 additions & 0 deletions app/Http/Controllers/Company/Adminland/AdminGeneralController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

use Inertia\Inertia;
use Inertia\Response;
use App\Helpers\ImageHelper;
use Illuminate\Http\Request;
use App\Helpers\InstanceHelper;
use Illuminate\Http\JsonResponse;
use App\Helpers\NotificationHelper;
use App\Http\Controllers\Controller;
use App\Services\Company\Adminland\File\UploadFile;
use App\Services\Company\Adminland\Company\RenameCompany;
use App\Http\ViewHelpers\Adminland\AdminGeneralViewHelper;
use App\Services\Company\Adminland\Company\UpdateCompanyLogo;
use App\Services\Company\Adminland\Company\UpdateCompanyCurrency;

class AdminGeneralController extends Controller
Expand Down Expand Up @@ -82,4 +85,39 @@ public function currency(Request $request, int $companyId): JsonResponse
'data' => true,
], 200);
}

/**
* Update the company’s logo.
*
* @param Request $request
* @param int $companyId
* @return JsonResponse
*/
public function logo(Request $request, int $companyId): JsonResponse
{
$loggedEmployee = InstanceHelper::getLoggedEmployee();
$loggedCompany = InstanceHelper::getLoggedCompany();

$file = (new UploadFile)->execute([
'company_id' => $loggedCompany->id,
'author_id' => $loggedEmployee->id,
'uuid' => $request->input('uuid'),
'name' => $request->input('name'),
'original_url' => $request->input('original_url'),
'cdn_url' => $request->input('cdn_url'),
'mime_type' => $request->input('mime_type'),
'size' => $request->input('size'),
'type' => 'company_logo',
]);

(new UpdateCompanyLogo)->execute([
'company_id' => $loggedCompany->id,
'author_id' => $loggedEmployee->id,
'file_id' => $file->id,
]);

return response()->json([
'data' => ImageHelper::getImage($file, 300, 300),
], 200);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Inertia\Inertia;
use Inertia\Response;
use App\Helpers\ImageHelper;
use Illuminate\Http\Request;
use App\Helpers\AvatarHelper;
use App\Helpers\InstanceHelper;
use App\Models\Company\Hardware;
use Illuminate\Http\JsonResponse;
Expand Down Expand Up @@ -118,7 +118,7 @@ public function show(Request $request, int $companyId, int $hardwareId)
'employee' => $hardware->employee ? [
'id' => $hardware->employee->id,
'name' => $hardware->employee->name,
'avatar' => AvatarHelper::getImage($hardware->employee),
'avatar' => ImageHelper::getAvatar($hardware->employee),
] : null,
];

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Company/Company/CompanyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function index(): Response
$company = InstanceHelper::getLoggedCompany();
$employee = InstanceHelper::getLoggedEmployee();

$statistics = CompanyViewHelper::statistics($company);
$statistics = CompanyViewHelper::information($company);
$latestQuestions = CompanyViewHelper::latestQuestions($company);
$birthdaysThisWeek = CompanyViewHelper::birthdaysThisWeek($company);
$newHiresThisWeek = CompanyViewHelper::newHiresThisWeek($company);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function index(): Response
$employee = InstanceHelper::getLoggedEmployee();

$eCoffees = CompanyHRViewHelper::eCoffees($company);
$statistics = CompanyViewHelper::statistics($company);
$statistics = CompanyViewHelper::information($company);

return Inertia::render('Company/HR/Index', [
'tab' => 'hr',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Inertia\Inertia;
use Inertia\Response;
use App\Helpers\ImageHelper;
use Illuminate\Http\Request;
use App\Helpers\AvatarHelper;
use App\Helpers\StringHelper;
use App\Helpers\InstanceHelper;
use App\Models\Company\Project;
Expand Down Expand Up @@ -42,7 +42,7 @@ class ProjectController extends Controller
public function index(Request $request, int $companyId): Response
{
$company = InstanceHelper::getLoggedCompany();
$statistics = CompanyViewHelper::statistics($company);
$statistics = CompanyViewHelper::information($company);

return Inertia::render('Company/Project/Index', [
'statistics' => $statistics,
Expand Down Expand Up @@ -331,7 +331,7 @@ public function assign(Request $request, int $companyId, int $projectId): JsonRe
'data' => [
'id' => $lead->id,
'name' => $lead->name,
'avatar' => AvatarHelper::getImage($lead, 35),
'avatar' => ImageHelper::getAvatar($lead, 35),
'position' => (! $lead->position) ? null : [
'id' => $lead->position->id,
'title' => $lead->position->title,
Expand Down Expand Up @@ -411,7 +411,7 @@ public function search(Request $request, int $companyId): JsonResponse
$employees->push([
'id' => $employee->id,
'name' => $employee->name,
'avatar' => AvatarHelper::getImage($employee),
'avatar' => ImageHelper::getAvatar($employee),
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use Inertia\Inertia;
use Inertia\Response;
use App\Helpers\DateHelper;
use App\Helpers\ImageHelper;
use Illuminate\Http\Request;
use App\Helpers\AvatarHelper;
use App\Helpers\InstanceHelper;
use App\Models\Company\Project;
use App\Models\Company\Employee;
Expand Down Expand Up @@ -100,7 +100,7 @@ public function search(Request $request, int $companyId): JsonResponse
$employees->push([
'id' => $employee->id,
'name' => $employee->name,
'avatar' => AvatarHelper::getImage($employee),
'avatar' => ImageHelper::getAvatar($employee),
]);
}

Expand Down Expand Up @@ -148,7 +148,7 @@ public function store(Request $request, int $companyId, int $projectId): JsonRes
$decidersCollection->push([
'id' => $decider->id,
'name' => $decider->name,
'avatar' => AvatarHelper::getImage($decider),
'avatar' => ImageHelper::getAvatar($decider),
'url' => route('employees.show', [
'company' => $loggedCompany,
'employee' => $decider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use Inertia\Inertia;
use Inertia\Response;
use App\Helpers\DateHelper;
use App\Helpers\ImageHelper;
use Illuminate\Http\Request;
use App\Helpers\AvatarHelper;
use App\Helpers\InstanceHelper;
use App\Models\Company\Project;
use Illuminate\Http\JsonResponse;
Expand Down Expand Up @@ -104,7 +104,7 @@ public function store(Request $request, int $companyId, int $projectId): JsonRes
'data' => [
'id' => $employee->id,
'name' => $employee->name,
'avatar' => AvatarHelper::getImage($employee, 64),
'avatar' => ImageHelper::getAvatar($employee, 64),
'role' => $request->input('role'),
'added_at' => DateHelper::formatDate(Carbon::now()),
'position' => (! $employee->position) ? null : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use Inertia\Inertia;
use Inertia\Response;
use App\Helpers\TimeHelper;
use App\Helpers\ImageHelper;
use Illuminate\Http\Request;
use App\Helpers\AvatarHelper;
use App\Helpers\InstanceHelper;
use App\Models\Company\Project;
use Illuminate\Http\JsonResponse;
Expand Down Expand Up @@ -144,7 +144,7 @@ public function store(Request $request, int $companyId, int $projectId): JsonRes
'assignee' => $task->assignee ? [
'id' => $task->assignee->id,
'name' => $task->assignee->name,
'avatar' => AvatarHelper::getImage($task->assignee),
'avatar' => ImageHelper::getAvatar($task->assignee),
'url' => route('employees.show', [
'company' => $company,
'employee' => $task->assignee,
Expand Down Expand Up @@ -208,7 +208,7 @@ public function update(Request $request, int $companyId, int $projectId, int $ta
'assignee' => $task->assignee ? [
'id' => $task->assignee->id,
'name' => $task->assignee->name,
'avatar' => AvatarHelper::getImage($task->assignee),
'avatar' => ImageHelper::getAvatar($task->assignee),
'url' => route('employees.show', [
'company' => $company,
'employee' => $task->assignee,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Http\Controllers\Company\Dashboard;

use App\Helpers\ImageHelper;
use Illuminate\Http\Request;
use App\Helpers\AvatarHelper;
use Illuminate\Http\Response;
use App\Helpers\InstanceHelper;
use Illuminate\Http\JsonResponse;
Expand Down Expand Up @@ -45,7 +45,7 @@ public function store(Request $request): JsonResponse
'employee' => [
'id' => $answer->employee->id,
'name' => $answer->employee->name,
'avatar' => AvatarHelper::getImage($answer->employee),
'avatar' => ImageHelper::getAvatar($answer->employee),
],
]);
}
Expand Down Expand Up @@ -85,7 +85,7 @@ public function update(Request $request, int $companyId, int $answerId): JsonRes
'employee' => [
'id' => $answer->employee->id,
'name' => $answer->employee->name,
'avatar' => AvatarHelper::getImage($answer->employee),
'avatar' => ImageHelper::getAvatar($answer->employee),
],
],
], 200);
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/Company/Employee/EmployeeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Inertia\Inertia;
use Inertia\Response;
use App\Helpers\ImageHelper;
use Illuminate\Http\Request;
use App\Helpers\AvatarHelper;
use App\Helpers\InstanceHelper;
use App\Models\Company\Employee;
use Illuminate\Http\JsonResponse;
Expand Down Expand Up @@ -41,7 +41,7 @@ public function index(Request $request, int $companyId): Response
$employeesCollection->push([
'id' => $employee->id,
'name' => $employee->name,
'avatar' => AvatarHelper::getImage($employee, 64),
'avatar' => ImageHelper::getAvatar($employee, 64),
'teams' => $employee->teams,
'position' => (! $employee->position) ? null : [
'id' => $employee->position->id,
Expand Down Expand Up @@ -148,7 +148,7 @@ public function assignManager(Request $request, int $companyId, int $employeeId)
'data' => [
'id' => $manager->id,
'name' => $manager->name,
'avatar' => AvatarHelper::getImage($manager),
'avatar' => ImageHelper::getAvatar($manager),
'position' => (! $manager->position) ? null : [
'id' => $manager->position->id,
'title' => $manager->position->title,
Expand Down Expand Up @@ -188,7 +188,7 @@ public function assignDirectReport(Request $request, int $companyId, int $employ
'data' =>[
'id' => $directReport->id,
'name' => $directReport->name,
'avatar' => AvatarHelper::getImage($directReport),
'avatar' => ImageHelper::getAvatar($directReport),
'position' => (! $directReport->position) ? null : [
'id' => $directReport->position->id,
'title' => $directReport->position->title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace App\Http\Controllers\Company\Employee;

use Inertia\Response;
use App\Helpers\ImageHelper;
use Illuminate\Http\Request;
use App\Helpers\AvatarHelper;
use App\Helpers\InstanceHelper;
use App\Models\Company\Employee;
use Illuminate\Http\JsonResponse;
Expand Down Expand Up @@ -51,7 +51,7 @@ public function update(Request $request, int $companyId, int $employeeId): JsonR
$employee->refresh();

return response()->json([
'avatar' => AvatarHelper::getImage($employee),
'avatar' => ImageHelper::getAvatar($employee),
], 200);
}
}

0 comments on commit e737974

Please sign in to comment.