mirror of
https://github.com/sigmasternchen/MyTube
synced 2025-03-15 21:08:55 +00:00
Editing videos now works
This commit is contained in:
parent
fa306ca450
commit
e69df013b3
4 changed files with 79 additions and 11 deletions
|
@ -105,6 +105,52 @@ class DashboardController extends AbstractController
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route("/video/edit", name="app_video_edit")
|
||||||
|
*/
|
||||||
|
public function editVideo(Request $request): Response
|
||||||
|
{
|
||||||
|
if (!$this->isGranted("ROLE_USER")) {
|
||||||
|
// not logged in
|
||||||
|
return $this->redirectToRoute("app_login");
|
||||||
|
}
|
||||||
|
|
||||||
|
$videoId = $request->query->get("video");
|
||||||
|
|
||||||
|
if (!$videoId) {
|
||||||
|
throw new BadRequestHttpException();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$videoId = $this->uuidMapper->fromString($videoId);
|
||||||
|
} catch (ConversionException $e) {
|
||||||
|
throw new BadRequestHttpException();
|
||||||
|
}
|
||||||
|
|
||||||
|
$video = $this->videoService->get($videoId);
|
||||||
|
if ($video == null || $video->getUploader() != $this->userService->getLoggedInUser()) {
|
||||||
|
throw new AccessDeniedHttpException();
|
||||||
|
}
|
||||||
|
|
||||||
|
$form = $this->createForm(VideoType::class, $video, ["file" => false]);
|
||||||
|
|
||||||
|
$saveOk = false;
|
||||||
|
|
||||||
|
$form->handleRequest($request);
|
||||||
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
|
$video = $form->getData();
|
||||||
|
|
||||||
|
$saveOk = true;
|
||||||
|
|
||||||
|
$this->videoService->update($video);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render("dashboard/video-edit.html.twig", [
|
||||||
|
"form" => $form->createView(),
|
||||||
|
"ok" => $saveOk
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/video/delete", name="app_video_delete", methods={"POST"})
|
* @Route("/video/delete", name="app_video_delete", methods={"POST"})
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -20,8 +20,10 @@ class VideoType extends AbstractType
|
||||||
{
|
{
|
||||||
$builder
|
$builder
|
||||||
->add("name", TextType::class)
|
->add("name", TextType::class)
|
||||||
->add("description", TextareaType::class)
|
->add("description", TextareaType::class);
|
||||||
->add("file", FileType::class, [
|
|
||||||
|
if ($options["file"]) {
|
||||||
|
$builder->add("file", FileType::class, [
|
||||||
"label" => "Video File",
|
"label" => "Video File",
|
||||||
"mapped" => false,
|
"mapped" => false,
|
||||||
"required" => true,
|
"required" => true,
|
||||||
|
@ -40,14 +42,17 @@ class VideoType extends AbstractType
|
||||||
"mimeTypesMessage" => "Video type not supported."
|
"mimeTypesMessage" => "Video type not supported."
|
||||||
])
|
])
|
||||||
]
|
]
|
||||||
])
|
]);
|
||||||
->add("submit", SubmitType::class);
|
}
|
||||||
|
|
||||||
|
$builder->add("submit", SubmitType::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configureOptions(OptionsResolver $resolver): void
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
{
|
{
|
||||||
$resolver->setDefaults([
|
$resolver->setDefaults([
|
||||||
'data_class' => Video::class,
|
"data_class" => Video::class,
|
||||||
|
"file" => true,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,14 +66,13 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="info">
|
<div class="info">
|
||||||
<div class="buttons btn-group btn-group-sm">
|
<div class="buttons btn-group btn-group-sm">
|
||||||
<button class="btn btn-primary"
|
<a class="btn btn-primary" href="{{ path("app_new_link") }}?video={{ video.customId }}">
|
||||||
onclick="location.href='{{ path("app_new_link") }}?video={{ video.customId }}'">
|
|
||||||
<i class="fas fa-link"></i>
|
<i class="fas fa-link"></i>
|
||||||
</button>
|
</a>
|
||||||
<button class="btn btn-primary"
|
<a class="btn btn-primary"
|
||||||
onclick="alert('not yet implemented')">
|
href="{{ path("app_video_edit") }}?video={{ video.customId }}">
|
||||||
<i class="fas fa-cog"></i>
|
<i class="fas fa-cog"></i>
|
||||||
</button>
|
</a>
|
||||||
<form action="{{ path("app_video_delete") }}" method="POST">
|
<form action="{{ path("app_video_delete") }}" method="POST">
|
||||||
<input type="hidden" name="videoId" value="{{ video.customId }}">
|
<input type="hidden" name="videoId" value="{{ video.customId }}">
|
||||||
<input type="hidden" name="csrfToken" value="{{ deleteCsrfToken }}">
|
<input type="hidden" name="csrfToken" value="{{ deleteCsrfToken }}">
|
||||||
|
|
18
templates/dashboard/video-edit.html.twig
Normal file
18
templates/dashboard/video-edit.html.twig
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Home{% endblock %}
|
||||||
|
|
||||||
|
{% block javascripts %}
|
||||||
|
{% if ok %}
|
||||||
|
<script>
|
||||||
|
window.setTimeout(function () {
|
||||||
|
toast("Saved");
|
||||||
|
}, 0);
|
||||||
|
</script>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<h1>Edit Video</h1>
|
||||||
|
{{ form(form) }}
|
||||||
|
{% endblock %}
|
Loading…
Reference in a new issue