Skip to content

Commit 9a8cd47

Browse files
committed
Adding MarkdownEditType, cancel action
1 parent 9fb1a7e commit 9a8cd47

File tree

7 files changed

+46
-37
lines changed

7 files changed

+46
-37
lines changed

Controller/FileController.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
43
namespace Dontdrinkandroot\GitkiBundle\Controller;
54

65
use Dontdrinkandroot\GitkiBundle\Exception\FileLockedException;
@@ -13,7 +12,6 @@
1312

1413
class FileController extends BaseController
1514
{
16-
1715
public function serveAction(Request $request, $path)
1816
{
1917
$this->assertWatcher();
@@ -146,6 +144,23 @@ public function moveAction(Request $request, $path)
146144
);
147145
}
148146

147+
/**
148+
* Cancels editing.
149+
*
150+
* @param string $path
151+
*
152+
* @return Response
153+
*/
154+
public function cancelAction($path)
155+
{
156+
$this->assertCommitter();
157+
$filePath = FilePath::parse($path);
158+
$user = $this->getGitUser();
159+
$this->getWikiService()->removeLock($user, $filePath);
160+
161+
return $this->redirect($this->generateUrl('ddr_gitki_file', ['path' => $filePath]));
162+
}
163+
149164
/**
150165
* @param File $file
151166
*

Controller/MarkdownController.php

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
namespace Dontdrinkandroot\GitkiBundle\Controller;
44

55
use Dontdrinkandroot\GitkiBundle\Exception\FileLockedException;
6+
use Dontdrinkandroot\GitkiBundle\Form\Type\MarkdownEditType;
67
use Dontdrinkandroot\GitkiBundle\Service\Markdown\MarkdownServiceInterface;
78
use Dontdrinkandroot\Path\FilePath;
89
use GitWrapper\GitException;
9-
use Symfony\Component\Form\SubmitButton;
1010
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
1111
use Symfony\Component\HttpFoundation\Request;
1212
use Symfony\Component\HttpFoundation\Response;
@@ -96,37 +96,10 @@ public function editAction(Request $request, $path)
9696
return new Response($renderedView, Response::HTTP_LOCKED);
9797
}
9898

99-
$form = $this->createFormBuilder()
100-
->add('content', 'textarea', ['attr' => ['rows' => 15], 'label' => false])
101-
->add('commitMessage', 'text', ['label' => 'Commit Message', 'required' => true])
102-
->add(
103-
'actions',
104-
'form_actions',
105-
[
106-
'buttons' => [
107-
'save' => [
108-
'type' => 'submit',
109-
'options' => ['label' => 'Save']
110-
],
111-
'cancel' => [
112-
'type' => 'submit',
113-
'options' => ['label' => 'Cancel', 'button_class' => 'default']
114-
],
115-
]
116-
]
117-
)
118-
->getForm();
99+
$form = $this->createForm(MarkdownEditType::class);
119100

120101
$form->handleRequest($request);
121102

122-
/** @var SubmitButton $cancelButton */
123-
$cancelButton = $form->get('actions')->get('cancel');
124-
if ($cancelButton->isClicked()) {
125-
$this->getWikiService()->removeLock($user, $filePath);
126-
127-
return $this->redirect($this->generateUrl('ddr_gitki_file', ['path' => $filePath]));
128-
}
129-
130103
if ($form->isValid()) {
131104
$content = $form->get('content')->getData();
132105
$commitMessage = $form->get('commitMessage')->getData();

Form/Type/MarkdownEditType.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
namespace Dontdrinkandroot\GitkiBundle\Form\Type;
3+
4+
use Symfony\Component\Form\AbstractType;
5+
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
6+
use Symfony\Component\Form\Extension\Core\Type\TextType;
7+
use Symfony\Component\Form\FormBuilderInterface;
8+
9+
class MarkdownEditType extends AbstractType
10+
{
11+
/**
12+
* {@inheritdoc}
13+
*/
14+
public function buildForm(FormBuilderInterface $builder, array $options)
15+
{
16+
$builder
17+
->add('content', TextareaType::class, ['attr' => ['rows' => 15], 'label' => false])
18+
->add('commitMessage', TextType::class, ['label' => 'Commit Message', 'required' => true]);
19+
}
20+
}

Resources/config/services.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ services:
3737
- [registerFileAction, ['DdrGitkiBundle:File:holdLock', 'holdlock']]
3838
- [registerFileAction, ['DdrGitkiBundle:File:history', 'history']]
3939
- [registerFileAction, ['DdrGitkiBundle:File:move', 'move']]
40+
- [registerFileAction, ['DdrGitkiBundle:File:cancel', 'cancel']]
4041
- [registerFileAction, ['DdrGitkiBundle:Markdown:preview','preview','md']]
4142
- [registerDirectoryAction, ['DdrGitkiBundle:Directory:index']]
4243
- [registerDirectoryAction, ['DdrGitkiBundle:Directory:list', 'list']]
4344
- [registerDirectoryAction, ['DdrGitkiBundle:Directory:index', 'index']]
44-
- [registerDirectoryAction, ['DdrGitkiBundle:Directory:createSubdirectory', 'subdirectory.create']]
45+
- [registerDirectoryAction, ['DdrGitkiBundle:Directory:createSubdirectory','subdirectory.create']]
4546
- [registerDirectoryAction, ['DdrGitkiBundle:Directory:createFile', 'file.create']]
4647
- [registerDirectoryAction, ['DdrGitkiBundle:Directory:remove', 'remove']]
4748
- [registerDirectoryAction, ['DdrGitkiBundle:Directory:uploadFile', 'file.upload']]

Resources/views/Markdown/edit.html.twig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@
4242
</button>
4343
</div>
4444
</div>
45-
{{ form(form, { 'attr': {'class' : 'edit' }}) }}
45+
{{ form_start(form, { 'attr': {'class' : 'edit' }}) }}
46+
{{ form_rest(form) }}
47+
<button type="submit" class="btn btn-primary">Save</button>
48+
<a href="{{ path('ddr_gitki_file', {'path': path, 'action': 'cancel'}) }}" class="btn btn-default">Cancel</a>
49+
{{ form_end(form) }}
4650
</div>
4751
<div class="col-md-6">
4852
<div id="preview" class="markdown-page">

Service/ExtensionRegistry/ExtensionRegistry.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<?php
22

3-
43
namespace Dontdrinkandroot\GitkiBundle\Service\ExtensionRegistry;
54

65
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
76

87
class ExtensionRegistry implements ExtensionRegistryInterface
98
{
10-
119
const ACTION_VIEW = '';
1210

1311
const ACTION_EDIT = 'edit';

Service/ExtensionRegistry/ExtensionRegistryInterface.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
<?php
22

3-
43
namespace Dontdrinkandroot\GitkiBundle\Service\ExtensionRegistry;
54

65
interface ExtensionRegistryInterface
76
{
8-
97
/**
108
* @param string $extension
119
*

0 commit comments

Comments
 (0)