Skip to content
Snippets Groups Projects
Commit 1e308260 authored by Camille Simiand's avatar Camille Simiand
Browse files

Refacto

parent 62af2963
No related tags found
1 merge request!49tuleap-139-fix-capsule-time-loading-regression
Pipeline #782 passed
......@@ -10,7 +10,6 @@ use App\Helper\StringHelper;
use App\Repository\CapsuleRepository;
use App\Builder\CapsuleBuilder;
use App\Form\CreateCapsuleFormType;
use App\Retriever\ProjectRetriever;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Filesystem\Filesystem;
......@@ -110,31 +109,6 @@ class CapsuleController extends AbstractController
);
}
/**
* @Route("capsule/{capsule_id}/video_preview", name="video_preview")
*/
public function videoPreview(int $capsule_id): Response
{
chdir('../legacy/');
$file_system = new Filesystem();
$capsule = $this->capsule_repository->findOneBy(['id' => $capsule_id]);
if (! $capsule instanceof Capsule) {
throw new \Exception('The retrieved capsule is not an instance of Capsule.');
}
if (! $file_system->exists($capsule->getLinkPath())) {
return $this->render('project/project_not_found.html.twig');
}
$video_preview_image_link = $this->getVideoPreviewImageLink($capsule);
return $this->render(
'project/project_preview.html.twig',
['video_preview_url' => $video_preview_image_link]
);
}
/**
* @Route("capsule/edit/{path}", name="edit_capsule")
*/
......@@ -148,12 +122,12 @@ class CapsuleController extends AbstractController
$capsule = $this->capsule_repository->findOneBy(['link_path' => $path]);
if (null === $capsule) {
$this->addFlash('warning', $translator->trans('capsule.edit.not_found'));
$this->addFlash('warning', $this->translator->trans('capsule.edit.not_found'));
return $this->redirectToRoute('capsule_list');
}
if (! $capsule->getEditors()->contains($current_user)) {
$this->addFlash('warning', $translator->trans('capsule.edit.not_allowed'));
$this->addFlash('warning', $this->translator->trans('capsule.edit.not_allowed'));
return $this->redirectToRoute('capsule_list');
}
......@@ -327,17 +301,4 @@ class CapsuleController extends AbstractController
return $capsule;
}
private function getVideoPreviewImageLink(Capsule $capsule): string
{
$project_retriever = new ProjectRetriever($capsule);
$video_url = $project_retriever->getVideoUrl();
$video_id = $project_retriever->getVideoId($video_url);
if (strpos($video_url, 'yout') !== false) {
return 'https://img.youtube.com/vi/' . $video_id . '/maxresdefault.jpg';
}
return 'https://vumbnail.com/' . $video_id . '.jpg';
}
}
......@@ -211,4 +211,24 @@ class Capsule
{
return $this->editors;
}
public function getVideoPreviewImageLink(): ?string
{
$file_system = new Filesystem();
if (! $file_system->exists('../legacy/' . $this->getLinkPath())) {
return null;
}
$project_retriever = new ProjectRetriever($this);
$video_url = $project_retriever->getVideoUrl();
$video_id = $project_retriever->getVideoId($video_url);
if (strpos($video_url, 'yout') !== false) {
return 'https://img.youtube.com/vi/' . $video_id . '/maxresdefault.jpg';
}
return 'https://vumbnail.com/' . $video_id . '.jpg';
}
}
......@@ -56,21 +56,12 @@
<div class="d-flex flex-column flex-md-row justify-content-center align-items-center">
<div class="m-4 ratio ratio-16x9">
{# <img src="{{ capsule.getVideoPreviewImageLink() }}" alt="video preview">#}
{# <img src="/capsule/{{ capsule.getId() }}/video_preview" alt="video preview">#}
</div>
{# {% if 'yout' in video_url %}#}
{# <img src="https://img.youtube.com/vi/{{ capsule.getVideoId() }}maxresdefault.jpg">#}
{# {% else %}#}
{# <img src="https://vumbnail.com/{{ capsule.getVideoId() }}.jpg">#}
{# <div class="m-4 ratio ratio-16x9">#}
{# <iframe#}
{# src="/capsule/preview/{{ capsule.getLinkPath() }}"#}
{# allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"#}
{# allowfullscreen>#}
{# </iframe>#}
{# </div>#}
{% if capsule.getVideoPreviewImageLink() is null %}
<img src="{{ asset('build/images/project_not_found.jpg') }}" alt="video preview">
{% else %}
<img src="{{ capsule.getVideoPreviewImageLink() }}" alt="video preview">
{% endif %}
</div>
<div class="d-flex flex-column justify-content-center m-2 pe-2">
<i class="fa-thin fa-gears"></i>
......
{% extends 'layout.html.twig' %}
{% block title %}
{{ 'project.not_found'|trans }}
{{ 'project.not_exist'|trans }}
-
{{ parent() }}
{% endblock %}
{% block body %}
<div class="col-10 col-md-8 col-lg-6 col-xl-5 col-xxl-6 m-auto d-flex flex-row align-items-center justify-content-center mb-5 alert alert-warning" role="status">
<span class="p-5">{{ 'project.not_found' | trans }}</span>
<span class="p-5">{{ 'project.not_exist' | trans }}</span>
</div>
{% endblock %}
\ No newline at end of file
......@@ -86,7 +86,7 @@ class ProjectControllerTest extends WebTestCase
$submit_button = $crawler->selectButton('Create a capsule');
$this->form = $submit_button->form();
$video_url = "https://TestUrl";
$video_url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ&ab_channel=RickAstley";
$this->form['create_capsule_form[name]'] = self::CAPSULE_NAME;
$this->form['create_capsule_form[video_url]'] = $video_url;
......@@ -123,7 +123,7 @@ class ProjectControllerTest extends WebTestCase
$video_url_in_xml_file = $video_node->getAttribute('url');
$this->assertEquals($video_url, $video_url_in_xml_file);
$this->assertEquals($video_url, htmlspecialchars_decode($video_url_in_xml_file));
$this->assertSame(self::CAPSULE_NAME, $capsule_name_in_db);
}
......@@ -293,7 +293,7 @@ class ProjectControllerTest extends WebTestCase
$submit_button = $crawler->selectButton('Create a capsule');
$this->form = $submit_button->form();
$video_url = "https://TestUrl";
$video_url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ&ab_channel=RickAstley";
$this->form['create_capsule_form[name]'] = self::CAPSULE_NAME;
$this->form['create_capsule_form[video_url]'] = $video_url;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment