Skip to content

Commit 858e379

Browse files
committed
Replace a common interview form template with a component
InterviewInputsFactory is not using a generated factory/interface because I couldn't get it working with the name service that should be passed to InterviewInputs, was getting "Service '' is not defined." because of some mapping applied strangely when only one create() parameter was present probably.
1 parent 3721249 commit 858e379

File tree

11 files changed

+89
-43
lines changed

11 files changed

+89
-43
lines changed

site/app/Admin/Presenters/InterviewsPresenter.php

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33

44
namespace MichalSpacekCz\Admin\Presenters;
55

6-
use MichalSpacekCz\Form\InterviewFormFactory;
76
use MichalSpacekCz\Formatter\TexyFormatter;
87
use MichalSpacekCz\Interviews\Exceptions\InterviewDoesNotExistException;
98
use MichalSpacekCz\Interviews\Interview;
9+
use MichalSpacekCz\Interviews\InterviewInputs;
10+
use MichalSpacekCz\Interviews\InterviewInputsFactory;
1011
use MichalSpacekCz\Interviews\Interviews;
11-
use MichalSpacekCz\Media\VideoThumbnails;
1212
use Nette\Application\BadRequestException;
13-
use Nette\Forms\Form;
1413

1514
class InterviewsPresenter extends BasePresenter
1615
{
@@ -21,8 +20,7 @@ class InterviewsPresenter extends BasePresenter
2120
public function __construct(
2221
private readonly TexyFormatter $texyFormatter,
2322
private readonly Interviews $interviews,
24-
private readonly InterviewFormFactory $interviewFormFactory,
25-
private readonly VideoThumbnails $videoThumbnails,
23+
private readonly InterviewInputsFactory $interviewInputsFactory,
2624
) {
2725
parent::__construct();
2826
}
@@ -32,8 +30,6 @@ public function renderDefault(): void
3230
{
3331
$this->template->pageTitle = $this->translator->translate('messages.title.interviews');
3432
$this->template->interviews = $this->interviews->getAll();
35-
$this->template->videoThumbnailWidth = $this->videoThumbnails->getWidth();
36-
$this->template->videoThumbnailHeight = $this->videoThumbnails->getHeight();
3733
}
3834

3935

@@ -46,32 +42,18 @@ public function actionInterview(int $param): void
4642
}
4743

4844
$this->template->pageTitle = $this->texyFormatter->translate('messages.title.interview', [strip_tags($this->interview->getTitle())]);
49-
$this->template->interview = $this->interview;
50-
$this->template->videoThumbnailWidth = $this->videoThumbnails->getWidth();
51-
$this->template->videoThumbnailHeight = $this->videoThumbnails->getHeight();
5245
}
5346

5447

55-
protected function createComponentEditInterview(): Form
48+
protected function createComponentEditInterviewInputs(): InterviewInputs
5649
{
57-
return $this->interviewFormFactory->create(
58-
function (): never {
59-
$this->flashMessage('Rozhovor upraven');
60-
$this->redirect('Interviews:');
61-
},
62-
$this->interview,
63-
);
50+
return $this->interviewInputsFactory->createFor($this->interview);
6451
}
6552

6653

67-
protected function createComponentAddInterview(): Form
54+
protected function createComponentAddInterviewInputs(): InterviewInputs
6855
{
69-
return $this->interviewFormFactory->create(
70-
function (): never {
71-
$this->flashMessage('Rozhovor přidán');
72-
$this->redirect('Interviews:');
73-
},
74-
);
56+
return $this->interviewInputsFactory->create();
7557
}
7658

7759
}

site/app/Admin/Presenters/PresenterTemplates/Interviews/InterviewsInterview.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@
33

44
namespace MichalSpacekCz\Admin\Presenters\PresenterTemplates\Interviews;
55

6+
use MichalSpacekCz\Interviews\Interview;
67
use Nette\Bridges\ApplicationLatte\Template;
7-
use Nette\Database\Row;
88

99
class InterviewsInterview extends Template
1010
{
1111

1212
public string $pageTitle;
1313

14-
/** @var Row<mixed> */
15-
public Row $interview;
16-
17-
public int $videoThumbnailWidth;
18-
19-
public int $videoThumbnailHeight;
14+
public Interview $interview;
2015

2116
}

site/app/Admin/Presenters/templates/Interviews/default.latte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
{templateType MichalSpacekCz\Admin\Presenters\PresenterTemplates\Interviews\InterviewsDefault}
2-
{varType int $videoThumbnailWidth}
3-
{varType int $videoThumbnailHeight}
42
{define #content}
53
<div n:foreach="$flashes as $flash" class="flash {$flash->type}"><strong>{$flash->message}</strong></div>
64
<div id="pridat-rozhovor">
75
<p><a href="#pridat-rozhovor" class="open-container block">Přidat rozhovor</a></p>
86
<div id="pridat-rozhovor-container" class="hidden">
9-
{include "common/interviewForm.latte", form: addInterview, interview: null, videoThumbnailWidth: $videoThumbnailWidth, videoThumbnailHeight: $videoThumbnailHeight}
7+
{control addInterviewInputs}
108
</div>
119
</div>
1210
<hr>
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
{templateType MichalSpacekCz\Admin\Presenters\PresenterTemplates\Interviews\InterviewsInterview}
2-
{varType int $videoThumbnailWidth}
3-
{varType int $videoThumbnailHeight}
42
{define #menu}
53
&raquo; <a n:href=":Www:Homepage:">Michal Špaček</a>
64
&raquo; <a n:href="Homepage:">Administrace</a>
75
&raquo; <a n:href="Interviews:">{_messages.title.interviews}</a>
86
{/define}
97

108
{define #content}
11-
{include "common/interviewForm.latte", form: editInterview, videoThumbnailWidth: $videoThumbnailWidth, videoThumbnailHeight: $videoThumbnailHeight}
9+
{control editInterviewInputs}
1210
{/define}

site/app/Admin/Presenters/templates/Talks/common/talkForm.latte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<tr>
3737
<th>{label videoHref /}</th><td>{input videoHref}</td>
3838
</tr>
39-
{include "formVideoThumbnails.latte", video: $talk?->getVideo(), videoThumbnailWidth: $videoThumbnailWidth, videoThumbnailHeight: $videoThumbnailHeight}
39+
{include "../../../../../Media/Thumbnails/videoThumbnailsInputs.latte", video: $talk?->getVideo(), videoThumbnailWidth: $videoThumbnailWidth, videoThumbnailHeight: $videoThumbnailHeight}
4040
<tr class="lighter">
4141
<th class="align-top">{label videoEmbed /}</th><td>{input videoEmbed}<br><small><em>deprecated</em></small></td>
4242
</tr>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
declare(strict_types = 1);
3+
4+
namespace MichalSpacekCz\Interviews;
5+
6+
use MichalSpacekCz\Application\UiControl;
7+
use MichalSpacekCz\Form\InterviewFormFactory;
8+
use MichalSpacekCz\Media\VideoThumbnails;
9+
use Nette\Forms\Form;
10+
11+
class InterviewInputs extends UiControl
12+
{
13+
14+
public function __construct(
15+
private readonly VideoThumbnails $videoThumbnails,
16+
private readonly InterviewFormFactory $interviewFormFactory,
17+
private readonly ?Interview $interview,
18+
) {
19+
}
20+
21+
22+
public function render(): void
23+
{
24+
$this->template->interview = $this->interview;
25+
$this->template->videoThumbnailWidth = $this->videoThumbnails->getWidth();
26+
$this->template->videoThumbnailHeight = $this->videoThumbnails->getHeight();
27+
$this->template->render(__DIR__ . '/interviewInputs.latte');
28+
}
29+
30+
31+
protected function createComponentInterview(): Form
32+
{
33+
return $this->interviewFormFactory->create(
34+
function (): never {
35+
$this->flashMessage($this->interview ? 'Rozhovor upraven' : 'Rozhovor přidán');
36+
$this->redirect('Interviews:');
37+
},
38+
$this->interview,
39+
);
40+
}
41+
42+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
declare(strict_types = 1);
3+
4+
namespace MichalSpacekCz\Interviews;
5+
6+
use MichalSpacekCz\Form\InterviewFormFactory;
7+
use MichalSpacekCz\Media\VideoThumbnails;
8+
9+
class InterviewInputsFactory
10+
{
11+
12+
public function __construct(
13+
private readonly VideoThumbnails $videoThumbnails,
14+
private readonly InterviewFormFactory $interviewFormFactory,
15+
) {
16+
}
17+
18+
19+
public function create(): InterviewInputs
20+
{
21+
return new InterviewInputs($this->videoThumbnails, $this->interviewFormFactory, null);
22+
}
23+
24+
25+
public function createFor(Interview $interview): InterviewInputs
26+
{
27+
return new InterviewInputs($this->videoThumbnails, $this->interviewFormFactory, $interview);
28+
}
29+
30+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
{varType MichalSpacekCz\Interviews\Interview|null $interview}
33
{varType int $videoThumbnailWidth}
44
{varType int $videoThumbnailHeight}
5-
{form $form class => "aligned wide"}
5+
{form interview class => "aligned wide"}
66
<table>
77
<tr>
88
<th>{label action /}</th><td>{input action}<br></td>
99
</tr>
1010
<tr>
11-
<th>{label title /}</th><td>{input title}<br><small><a n:if="$interview?->getAction()" n:href=":Www:Interviews:interview $interview->getAction()">zobrazit rozhovor</a></small></td>
11+
<th>{label title /}</th><td>{input title}<br><small><a n:if="$interview?->getAction()" href="{plink :Www:Interviews:interview $interview->getAction()}">zobrazit rozhovor</a></small></td>
1212
</tr>
1313
<tr>
1414
<th class="align-top">{label description /}</th><td>{input description}</td>
@@ -28,7 +28,7 @@
2828
<tr>
2929
<th>{label videoHref /}</th><td>{input videoHref}</td>
3030
</tr>
31-
{include "../../Talks/common/formVideoThumbnails.latte", video: $interview?->getVideo(), videoThumbnailWidth: $videoThumbnailWidth, videoThumbnailHeight: $videoThumbnailHeight}
31+
{include "../Media/Thumbnails/videoThumbnailsInputs.latte", video: $interview?->getVideo(), videoThumbnailWidth: $videoThumbnailWidth, videoThumbnailHeight: $videoThumbnailHeight}
3232
<tr class="lighter">
3333
<th class="align-top">{label videoEmbed /}</th><td>{input videoEmbed}<br><small><em>deprecated</em></small></td>
3434
</tr>

site/config/presenters.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ services:
3232
- MichalSpacekCz\Admin\Presenters\HomepagePresenter
3333
- MichalSpacekCz\Admin\Presenters\HoneypotPresenter
3434
- MichalSpacekCz\Admin\Presenters\InfoPresenter
35-
- MichalSpacekCz\Admin\Presenters\InterviewsPresenter(videoThumbnails: @interviewVideoThumbnails)
35+
- MichalSpacekCz\Admin\Presenters\InterviewsPresenter
3636
- MichalSpacekCz\Admin\Presenters\InvoicesPresenter
3737
- MichalSpacekCz\Admin\Presenters\PulsePresenter
3838
- MichalSpacekCz\Admin\Presenters\ReviewsPresenter

0 commit comments

Comments
 (0)