Skip to content

Commit

Permalink
implement profile page #17
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost committed Oct 3, 2023
1 parent 737b79b commit ae8ec48
Show file tree
Hide file tree
Showing 21 changed files with 736 additions and 360 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ APP_VERSION='2.0.0'
APP_NAME=YGGtracker

APP_LOCALE=en
APP_LOCALES=en|uk
APP_LOCALES=en|uk
2 changes: 1 addition & 1 deletion public/asset/default/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ textarea {
color: #ccc;
border: 0;
border-radius: 3px;
padding: 6px 8px;
padding: 8px;
font-size: 13px;
}

Expand Down
22 changes: 21 additions & 1 deletion public/asset/default/css/framework.css
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ a.label-green:hover {
position: fixed;
}

.position-absolute {
position: absolute;
}

.vertical-align-middle {
vertical-align: middle;
}
Expand Down Expand Up @@ -170,7 +174,7 @@ a.label-green:hover {
border-top: 1px #5d627d solid;
}

.border-width-2 {
.border-width-2-px {
border-width: 2px;
}

Expand Down Expand Up @@ -299,6 +303,10 @@ a:visited.background-color-hover-night-light:hover {
padding: 16px;
}

.padding-24-px {
padding: 24px;
}

.margin-l-4-px {
margin-left: 4px;
}
Expand Down Expand Up @@ -328,6 +336,10 @@ a:visited.background-color-hover-night-light:hover {
margin-left: 12px;
}

.margin-l-96-px {
margin-left: 96px;
}

.margin-l--196-px {
margin-left: -196px;
}
Expand Down Expand Up @@ -366,6 +378,10 @@ a:visited.background-color-hover-night-light:hover {
display: block;
}

.display-flex {
display: flex;
}

.opacity-0 {
opacity: 0;
}
Expand Down Expand Up @@ -410,6 +426,10 @@ a:visited.background-color-hover-night-light:hover {
width: 80%;
}

.width-80-px {
width: 80px;
}

.width-180-px {
width: 180px;
}
Expand Down
33 changes: 33 additions & 0 deletions src/Controller/DashboardController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;

class DashboardController extends AbstractController
{
#[Route('/')]
public function indexNoLocale(): Response
{
return $this->redirectToRoute(
'dashboard_index',
[
'_locale' => 'en'
]
);
}

#[Route(
'/{_locale}',
name: 'dashboard_index'
)]
public function index(Request $request): Response
{
return $this->render(
'default/dashboard/index.html.twig'
);
}
}
20 changes: 0 additions & 20 deletions src/Controller/HomeController.php

This file was deleted.

5 changes: 5 additions & 0 deletions src/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class PageController extends AbstractController
)]
public function submit(): Response
{
/*
return $this->redirectToRoute('page', [
'id' => $page->getId()
]);
*/
return $this->render('default/page/submit.html.twig', [
// @TODO
]);
Expand Down
76 changes: 0 additions & 76 deletions src/Controller/ProfileController.php

This file was deleted.

161 changes: 161 additions & 0 deletions src/Controller/UserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;

use App\Service\UserService;
use App\Service\TimeService;

class UserController extends AbstractController
{
#[Route(
'/{_locale}/profile',
name: 'user_profile',
defaults: [
'_locale' => '%app.locale%'
],
requirements: [
'_locale' => '%app.locales%',
],
)]
public function profile(
Request $request,
UserService $userService,
TimeService $timeService): Response
{
// Init user
$user = $userService->init(
$request->getClientIp()
);

// Process post request
if ($request->isMethod('post'))
{
// Update locale
if (in_array($request->get('locale'), explode('|', $this->getParameter('app.locales'))))
{
$user->setLocale(
$request->get('locale')
);
}

// Update locales
if ($request->get('locales'))
{
$user->setLocales(
$request->get('locales')
);
}

// Save changes to DB
$userService->save($user);
}

// Generate identicon
$identicon = new \Jdenticon\Identicon();

$identicon->setValue($user->getAddress());
$identicon->setSize(48);
$identicon->setStyle(
[
'backgroundColor' => 'rgba(255, 255, 255, 0)',
'padding' => 0
]
);

// Render template
return $this->render(
'default/user/profile.html.twig',
[
'user' => [
'id' => $user->getId(),
'address' => $request->getClientIp() == $user->getAddress() ? $user->getAddress() : false,
'moderator' => $user->isModerator(),
'approved' => $user->isApproved(),
'status' => $user->isStatus(),
'locale' => $user->getLocale(),
'locales' => $user->getLocales(),
'added' => $timeService->ago(
$user->getAdded()
),
'identicon' => $identicon->getImageDataUri('webp'),
],
'locales' => explode('|', $this->getParameter('app.locales'))
]
);
}

#[Route(
'/{_locale}/user/{id}',
name: 'user_info',
defaults: [
'_locale' => '%app.locale%'
],
requirements: [
'_locale' => '%app.locales%',
],
)]
public function info(
int $id,
Request $request,
UserService $userService,
TimeService $timeService): Response
{
// Init user
if (!$user = $userService->get($id))
{
throw $this->createNotFoundException();
}

// Generate identicon
$identicon = new \Jdenticon\Identicon();

$identicon->setValue($user->getAddress());
$identicon->setSize(48);
$identicon->setStyle(
[
'backgroundColor' => 'rgba(255, 255, 255, 0)',
'padding' => 0
]
);

// Render template
return $this->render(
'default/user/info.html.twig',
[
'user' => [
'id' => $user->getId(),
'address' => $request->getClientIp() == $user->getAddress() ? $user->getAddress() : false,
'moderator' => $user->isModerator(),
'approved' => $user->isApproved(),
'status' => $user->isStatus(),
'locale' => $user->getLocale(),
'locales' => $user->getLocales(),
'added' => $timeService->ago(
$user->getAdded()
),
'identicon' => $identicon->getImageDataUri('webp'),
]
]
);
}

public function module(string $route = ''): Response
{
return $this->render(
'default/user/module.html.twig',
[
'route' => $route,
'stars' => 0,
'views' => 0,
'comments' => 0,
'downloads' => 0,
'editions' => 0,
]
);
}
}
Loading

0 comments on commit ae8ec48

Please sign in to comment.