Editing videos now works

This commit is contained in:
overflowerror 2021-01-17 22:30:30 +01:00
parent fa306ca450
commit e69df013b3
4 changed files with 79 additions and 11 deletions

View file

@ -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"})
*/

View file

@ -20,8 +20,10 @@ class VideoType extends AbstractType
{
$builder
->add("name", TextType::class)
->add("description", TextareaType::class)
->add("file", FileType::class, [
->add("description", TextareaType::class);
if ($options["file"]) {
$builder->add("file", FileType::class, [
"label" => "Video File",
"mapped" => false,
"required" => true,
@ -40,14 +42,17 @@ class VideoType extends AbstractType
"mimeTypesMessage" => "Video type not supported."
])
]
])
->add("submit", SubmitType::class);
]);
}
$builder->add("submit", SubmitType::class);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Video::class,
"data_class" => Video::class,
"file" => true,
]);
}

View file

@ -66,14 +66,13 @@
</div>
<div class="info">
<div class="buttons btn-group btn-group-sm">
<button class="btn btn-primary"
onclick="location.href='{{ path("app_new_link") }}?video={{ video.customId }}'">
<a class="btn btn-primary" href="{{ path("app_new_link") }}?video={{ video.customId }}">
<i class="fas fa-link"></i>
</button>
<button class="btn btn-primary"
onclick="alert('not yet implemented')">
</a>
<a class="btn btn-primary"
href="{{ path("app_video_edit") }}?video={{ video.customId }}">
<i class="fas fa-cog"></i>
</button>
</a>
<form action="{{ path("app_video_delete") }}" method="POST">
<input type="hidden" name="videoId" value="{{ video.customId }}">
<input type="hidden" name="csrfToken" value="{{ deleteCsrfToken }}">

View 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 %}