Updates
This commit is contained in:
@ -387,4 +387,52 @@ class AjaxController extends AbstractController
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
#[Route('/save-settings', name: 'app_save_settings', methods: ['POST'])]
|
||||
public function saveSettings(Request $req, EntityManagerInterface $emi): Response
|
||||
{
|
||||
$data = json_decode($req->getContent());
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
|
||||
if (!$user) {
|
||||
return new Response(json_encode([
|
||||
'msg' => 'No User'
|
||||
]));
|
||||
}
|
||||
|
||||
if (!$data->saveInterval) {
|
||||
$data->saveInterval = 15;
|
||||
}
|
||||
|
||||
if (!$data->saveReferences) {
|
||||
$data->saveReferences = true;
|
||||
}
|
||||
|
||||
if (!$data->noteTextSize) {
|
||||
$data->noteTextSize = 12;
|
||||
}
|
||||
|
||||
if (!$data->trackSaveSize) {
|
||||
$data->trackSaveSize = false;
|
||||
}
|
||||
|
||||
$meta = $user->getMetaData();
|
||||
$meta['saveInterval'] = $data->saveInterval;
|
||||
$meta['saveReferences'] = $data->saveReferences;
|
||||
$meta['noteTextSize'] = $data->noteTextSize;
|
||||
$meta['trackSaveSize'] = $data->trackSaveSize;
|
||||
$meta['saveTimeout'] = $data->saveTimeout;
|
||||
$meta['save-failure-count'] = $data->saveFailureCount;
|
||||
$user->setMetaData($meta);
|
||||
$emi->persist($user);
|
||||
$emi->flush();
|
||||
|
||||
$res = new Response();
|
||||
$res->setContent(json_encode([
|
||||
'msg' => 'Settings Saved'
|
||||
]));
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Note;
|
||||
use App\Entity\Reference;
|
||||
use App\Entity\User;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
@ -11,7 +10,6 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\CurrentUser;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
|
||||
class DefaultController extends AbstractController
|
||||
{
|
||||
@ -30,11 +28,13 @@ class DefaultController extends AbstractController
|
||||
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
|
||||
$last4Notes = $emi->getRepository(Note::class)->getLast4Notes($user);
|
||||
$openNotes = $emi->getRepository(Note::class)->reverseNoteSort($user);
|
||||
$meta = $user->getMetaData();
|
||||
|
||||
return $this->render('default/home.html.twig', [
|
||||
'last4Notes' => $last4Notes,
|
||||
'reverseNoteSort' => $openNotes,
|
||||
'isAdmin' => $this->isGranted('ROLE_ADMIN'),
|
||||
'meta' => $meta,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -44,6 +44,31 @@ class DefaultController extends AbstractController
|
||||
return $this->render('default/cheat-sheet.html.twig');
|
||||
}
|
||||
|
||||
#[Route('/profile', name: 'app_profile')]
|
||||
public function profile(): Response
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$meta = $user->getMetaData();
|
||||
if (!$meta) {
|
||||
$meta = [
|
||||
'saveInterval' => 15,
|
||||
'saveReferences' => 'checked',
|
||||
'noteTextSize' => 12,
|
||||
'trackSaveSize' => null,
|
||||
'saveFailureCount' => 3,
|
||||
'saveTimeout' => 5,
|
||||
];
|
||||
} else {
|
||||
$meta['saveReferences'] = $meta['saveReferences'] ? 'checked' : null;
|
||||
$meta['trackSaveSize'] = $meta['trackSaveSize'] ? 'checked' : null;
|
||||
}
|
||||
|
||||
return $this->render('default/profile.html.twig', [
|
||||
'meta' => $meta,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/reference-editor', name: 'app_reference_editor')]
|
||||
public function referenceEditor(EntityManagerInterface $emi): Response
|
||||
{
|
||||
|
@ -68,12 +68,22 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, JsonSer
|
||||
#[ORM\OneToMany(targetEntity: Note::class, mappedBy: 'user')]
|
||||
private Collection $notes;
|
||||
|
||||
/**
|
||||
* @var Collection<int, NoteShares>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: NoteShares::class, mappedBy: 'ownerId', orphanRemoval: true)]
|
||||
private Collection $noteShares;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?array $metaData = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->series = new ArrayCollection();
|
||||
$this->speakers = new ArrayCollection();
|
||||
$this->templates = new ArrayCollection();
|
||||
$this->notes = new ArrayCollection();
|
||||
$this->noteShares = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?Uuid
|
||||
@ -81,6 +91,11 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, JsonSer
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getHexId(): string
|
||||
{
|
||||
return $this->id->toHex();
|
||||
}
|
||||
|
||||
public function setId(?Uuid $id): static
|
||||
{
|
||||
$this->id = $id;
|
||||
@ -303,4 +318,46 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, JsonSer
|
||||
'name' => $this->name,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, NoteShares>
|
||||
*/
|
||||
public function getNoteShares(): Collection
|
||||
{
|
||||
return $this->noteShares;
|
||||
}
|
||||
|
||||
public function addNoteShare(NoteShares $noteShare): static
|
||||
{
|
||||
if (!$this->noteShares->contains($noteShare)) {
|
||||
$this->noteShares->add($noteShare);
|
||||
$noteShare->setOwner($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeNoteShare(NoteShares $noteShare): static
|
||||
{
|
||||
if ($this->noteShares->removeElement($noteShare)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($noteShare->getOwner() === $this) {
|
||||
$noteShare->setOwner(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMetaData(): ?array
|
||||
{
|
||||
return $this->metaData;
|
||||
}
|
||||
|
||||
public function setMetaData(?array $metaData): static
|
||||
{
|
||||
$this->metaData = $metaData;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user