diff --git a/src/Controller/AjaxController.php b/src/Controller/AjaxController.php index 4499464..a573f5c 100644 --- a/src/Controller/AjaxController.php +++ b/src/Controller/AjaxController.php @@ -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; + } } diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index adf7fd3..5ea6f91 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -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 { diff --git a/src/Entity/User.php b/src/Entity/User.php index e6157a8..3a60ac7 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -68,12 +68,22 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, JsonSer #[ORM\OneToMany(targetEntity: Note::class, mappedBy: 'user')] private Collection $notes; + /** + * @var Collection + */ + #[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 + */ + 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; + } } diff --git a/templates/default/home.html.twig b/templates/default/home.html.twig index 6acf1fa..2aeba82 100644 --- a/templates/default/home.html.twig +++ b/templates/default/home.html.twig @@ -8,6 +8,12 @@ + {% endblock %} {% block javascripts %} @@ -20,6 +26,12 @@ + {% endblock %} @@ -50,11 +62,6 @@ Date - {# - {% for n in reverseNoteSort %} - {{ n.toTableRow()|raw }} - {% endfor %} - #} @@ -62,10 +69,10 @@

Notes

- +
- {% for t in app.user.templates %} diff --git a/templates/default/profile.html.twig b/templates/default/profile.html.twig new file mode 100644 index 0000000..5eea527 --- /dev/null +++ b/templates/default/profile.html.twig @@ -0,0 +1,156 @@ +{% extends 'base.html.twig' %} + +{% block title %}Profile | Sermon Notes{% endblock %} + +{% block stylesheets %} + + + + + + +{% endblock %} + +{% block javascripts %} + + + + + + + + + +{% endblock %} + +{% block body %} +
+
+ +
+ + +
+ + +
+ + +
+ + +
+
+
+ +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + + +
+
+ + +
+
+
+{% endblock %} \ No newline at end of file diff --git a/templates/default/sidebar.html.twig b/templates/default/sidebar.html.twig index e5b08b0..44fa7fe 100644 --- a/templates/default/sidebar.html.twig +++ b/templates/default/sidebar.html.twig @@ -13,7 +13,7 @@