mirror of
https://github.com/sigmasternchen/MyTube
synced 2025-03-15 21:08:55 +00:00
adding links now works
This commit is contained in:
parent
28da454eae
commit
f4748ee3d2
8 changed files with 130 additions and 7 deletions
|
@ -54,7 +54,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.info {
|
.info {
|
||||||
padding: 1vw;
|
padding: 2% 4% 4%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.disable {
|
.disable {
|
||||||
|
@ -81,4 +81,18 @@
|
||||||
width: 100%;
|
width: 100%;
|
||||||
top: 55%;
|
top: 55%;
|
||||||
color: lightgray;
|
color: lightgray;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link {
|
||||||
|
position: absolute;
|
||||||
|
top: calc(9 / 16 * 100% + 12%);
|
||||||
|
right: 3%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link a {
|
||||||
|
color: #9f44b4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link:hover a {
|
||||||
|
color: grey;
|
||||||
}
|
}
|
|
@ -5,11 +5,14 @@ namespace App\Controller;
|
||||||
|
|
||||||
|
|
||||||
use App\Entity\Video;
|
use App\Entity\Video;
|
||||||
|
use App\Entity\VideoLink;
|
||||||
use App\Form\VideoLinkType;
|
use App\Form\VideoLinkType;
|
||||||
|
use App\Form\VideoType;
|
||||||
use App\Mapper\CustomUuidMapper;
|
use App\Mapper\CustomUuidMapper;
|
||||||
use App\Service\UserService;
|
use App\Service\UserService;
|
||||||
use App\Service\VideoLinkService;
|
use App\Service\VideoLinkService;
|
||||||
use App\Service\VideoService;
|
use App\Service\VideoService;
|
||||||
|
use Doctrine\DBAL\Types\ConversionException;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\Form\FormError;
|
use Symfony\Component\Form\FormError;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
@ -70,7 +73,7 @@ class DashboardController extends AbstractController
|
||||||
}
|
}
|
||||||
|
|
||||||
$video = new Video();
|
$video = new Video();
|
||||||
$form = $this->createForm(VideoLinkType::class, $video);
|
$form = $this->createForm(VideoType::class, $video);
|
||||||
|
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
|
@ -81,6 +84,8 @@ class DashboardController extends AbstractController
|
||||||
$form->addError(new FormError(""));
|
$form->addError(new FormError(""));
|
||||||
} else {
|
} else {
|
||||||
$this->videoService->addVideo($video, $file);
|
$this->videoService->addVideo($video, $file);
|
||||||
|
|
||||||
|
return $this->redirectToRoute("app_dashboard");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +97,7 @@ class DashboardController extends AbstractController
|
||||||
/**
|
/**
|
||||||
* @Route("/links", name="app_links")
|
* @Route("/links", name="app_links")
|
||||||
*/
|
*/
|
||||||
public function links(): Response
|
public function showLinks(): Response
|
||||||
{
|
{
|
||||||
if (!$this->isGranted("ROLE_USER")) {
|
if (!$this->isGranted("ROLE_USER")) {
|
||||||
// not logged in
|
// not logged in
|
||||||
|
@ -106,4 +111,56 @@ class DashboardController extends AbstractController
|
||||||
"links" => $links
|
"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()
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -83,9 +83,9 @@ class VideoLink
|
||||||
return $this->created;
|
return $this->created;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCreated(DateTimeImmutable $created): self
|
public function setCreated(): self
|
||||||
{
|
{
|
||||||
$this->created = $created;
|
$this->created = new DateTimeImmutable();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ class VideoLink
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getViewableUntil(): DateTime
|
public function getViewableUntil(): ?DateTime
|
||||||
{
|
{
|
||||||
return $this->viewableUntil;
|
return $this->viewableUntil;
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ class VideoLink
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getViewableFor(): int
|
public function getViewableFor(): ?int
|
||||||
{
|
{
|
||||||
return $this->viewableFor;
|
return $this->viewableFor;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,10 @@ namespace App\Form;
|
||||||
|
|
||||||
use App\Entity\VideoLink;
|
use App\Entity\VideoLink;
|
||||||
use Symfony\Component\Form\AbstractType;
|
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\SubmitType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
|
@ -15,6 +18,18 @@ class VideoLinkType extends AbstractType
|
||||||
public function buildForm(FormBuilderInterface $builder, $options): void
|
public function buildForm(FormBuilderInterface $builder, $options): void
|
||||||
{
|
{
|
||||||
$builder
|
$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);
|
->add("submit", SubmitType::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,4 +26,9 @@ class VideoLinkService
|
||||||
{
|
{
|
||||||
return $this->videoLinkRepository->findByCreator($user);
|
return $this->videoLinkRepository->findByCreator($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function add($videoLink): void
|
||||||
|
{
|
||||||
|
$this->videoLinkRepository->save($videoLink);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -27,6 +27,11 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="info">
|
<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>
|
<h5>{{ video.name }}</h5>
|
||||||
<p>
|
<p>
|
||||||
{{ video.description }}
|
{{ video.description }}
|
||||||
|
|
16
templates/dashboard/newlink.html.twig
Normal file
16
templates/dashboard/newlink.html.twig
Normal 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 %}
|
Loading…
Reference in a new issue