adding links now works

This commit is contained in:
overflowerror 2021-01-06 23:36:15 +01:00
parent 28da454eae
commit f4748ee3d2
8 changed files with 130 additions and 7 deletions

View file

@ -54,7 +54,7 @@
}
.info {
padding: 1vw;
padding: 2% 4% 4%;
}
.disable {
@ -81,4 +81,18 @@
width: 100%;
top: 55%;
color: lightgray;
}
.link {
position: absolute;
top: calc(9 / 16 * 100% + 12%);
right: 3%;
}
.link a {
color: #9f44b4;
}
.link:hover a {
color: grey;
}

View file

@ -5,11 +5,14 @@ namespace App\Controller;
use App\Entity\Video;
use App\Entity\VideoLink;
use App\Form\VideoLinkType;
use App\Form\VideoType;
use App\Mapper\CustomUuidMapper;
use App\Service\UserService;
use App\Service\VideoLinkService;
use App\Service\VideoService;
use Doctrine\DBAL\Types\ConversionException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormError;
use Symfony\Component\HttpFoundation\Request;
@ -70,7 +73,7 @@ class DashboardController extends AbstractController
}
$video = new Video();
$form = $this->createForm(VideoLinkType::class, $video);
$form = $this->createForm(VideoType::class, $video);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
@ -81,6 +84,8 @@ class DashboardController extends AbstractController
$form->addError(new FormError(""));
} else {
$this->videoService->addVideo($video, $file);
return $this->redirectToRoute("app_dashboard");
}
}
@ -92,7 +97,7 @@ class DashboardController extends AbstractController
/**
* @Route("/links", name="app_links")
*/
public function links(): Response
public function showLinks(): Response
{
if (!$this->isGranted("ROLE_USER")) {
// not logged in
@ -106,4 +111,56 @@ class DashboardController extends AbstractController
"links" => $links
]);
}
/**
* @Route("/links/new", name="app_new_link")
*/
public function newLink(Request $request): Response
{
if (!$this->isGranted("ROLE_USER")) {
// not logged in
return $this->redirectToRoute("app_login");
}
$videoId = $request->query->get("video");
if (!$videoId) {
return $this->redirectToRoute("app_links");
}
try {
$videoId = $this->uuidMapper->fromString($videoId);
} catch (ConversionException $e) {
return $this->redirectToRoute("app_links");
}
$video = $this->videoService->get($videoId);
if (!$video) {
return $this->redirectToRoute("app_dashboard");
}
$videoLink = new VideoLink();
$videoLink->setVideo($video);
$form = $this->createForm(VideoLinkType::class, $videoLink);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$videoLink = $form->getData();
$user = $this->userService->getLoggedInUser();
$videoLink->setCreator($user);
$videoLink->setCreated();
$this->videoLinkService->add($videoLink);
return $this->redirectToRoute("app_links");
}
$video->setCustomId($this->uuidMapper->toString($video->getId()));
return $this->render("dashboard/newlink.html.twig", [
"video" => $video,
"form" => $form->createView()
]);
}
}

View file

@ -83,9 +83,9 @@ class VideoLink
return $this->created;
}
public function setCreated(DateTimeImmutable $created): self
public function setCreated(): self
{
$this->created = $created;
$this->created = new DateTimeImmutable();
return $this;
}
@ -102,7 +102,7 @@ class VideoLink
return $this;
}
public function getViewableUntil(): DateTime
public function getViewableUntil(): ?DateTime
{
return $this->viewableUntil;
}
@ -113,7 +113,7 @@ class VideoLink
return $this;
}
public function getViewableFor(): int
public function getViewableFor(): ?int
{
return $this->viewableFor;
}

View file

@ -6,7 +6,10 @@ namespace App\Form;
use App\Entity\VideoLink;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
@ -15,6 +18,18 @@ class VideoLinkType extends AbstractType
public function buildForm(FormBuilderInterface $builder, $options): void
{
$builder
->add("maxViews", NumberType::class, [
"required" => false
])
->add("viewableFor", NumberType::class, [
"required" => false
])
->add("viewableUntil", DateType::class, [
"required" => false
])
->add("comment", TextType::class, [
"required" => false
])
->add("submit", SubmitType::class);
}

View file

@ -47,4 +47,15 @@ class VideoLinkRepository extends ServiceEntityRepository
;
}
*/
public function save(VideoLink $videoLink)
{
$this->_em->persist($videoLink);
$this->_em->flush();
}
public function update()
{
$this->_em->flush();
}
}

View file

@ -26,4 +26,9 @@ class VideoLinkService
{
return $this->videoLinkRepository->findByCreator($user);
}
public function add($videoLink): void
{
$this->videoLinkRepository->save($videoLink);
}
}

View file

@ -27,6 +27,11 @@
{% endif %}
</div>
<div class="info">
<div class="link">
<a href="{{ path("app_new_link") }}?video={{ video.customId }}">
<i class="fas fa-link"></i>
</a>
</div>
<h5>{{ video.name }}</h5>
<p>
{{ video.description }}

View file

@ -0,0 +1,16 @@
{% extends 'base.html.twig' %}
{% block title %}Links{% endblock %}
{% block stylesheets %}
<link rel="stylesheet" href="{{ asset("css/links.css") }}">
{% endblock %}
{% block body %}
<img alt="Thumbnail" src="{{ path("app_watch_thumbnail", {
linkId: constant("App\\Controller\\WatchController::OWNER_LINK_ID"),
videoId: video.customId
}) }}"/>
{{ video.name }}
{{ form(form) }}
{% endblock %}