diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2015-06-02 18:54:34 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2015-06-02 18:56:07 +0200 |
commit | 82d6d9cb06a1486e2e3b05fa6ce857b3b8655180 (patch) | |
tree | 973017b934f12bed3a46cc23b30446a41c9ff7d8 | |
parent | 51d9699fa130a18a1c5cd09d1b03a382d73e91db (diff) | |
download | wallabag-82d6d9cb06a1486e2e3b05fa6ce857b3b8655180.tar.gz wallabag-82d6d9cb06a1486e2e3b05fa6ce857b3b8655180.tar.zst wallabag-82d6d9cb06a1486e2e3b05fa6ce857b3b8655180.zip |
Add basic title edition
Fix #218
I mean basic, because there is no javascript at all. It could be a nice edit-in-place. But for the moment, it is simple.
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/EntryController.php | 43 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Entity/Entry.php | 2 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Entity/Tag.php | 6 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Form/Type/EditEntryType.php | 36 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Form/Type/NewEntryType.php (renamed from src/Wallabag/CoreBundle/Form/Type/EntryType.php) | 2 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Resources/views/Entry/edit.html.twig | 7 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Resources/views/Entry/entry.html.twig | 16 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php | 48 |
8 files changed, 147 insertions, 13 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 7fd982c9..4a7a0644 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php | |||
@@ -7,7 +7,8 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |||
7 | use Symfony\Component\HttpFoundation\Request; | 7 | use Symfony\Component\HttpFoundation\Request; |
8 | use Wallabag\CoreBundle\Entity\Entry; | 8 | use Wallabag\CoreBundle\Entity\Entry; |
9 | use Wallabag\CoreBundle\Service\Extractor; | 9 | use Wallabag\CoreBundle\Service\Extractor; |
10 | use Wallabag\CoreBundle\Form\Type\EntryType; | 10 | use Wallabag\CoreBundle\Form\Type\NewEntryType; |
11 | use Wallabag\CoreBundle\Form\Type\EditEntryType; | ||
11 | 12 | ||
12 | class EntryController extends Controller | 13 | class EntryController extends Controller |
13 | { | 14 | { |
@@ -22,7 +23,7 @@ class EntryController extends Controller | |||
22 | { | 23 | { |
23 | $entry = new Entry($this->getUser()); | 24 | $entry = new Entry($this->getUser()); |
24 | 25 | ||
25 | $form = $this->createForm(new EntryType(), $entry); | 26 | $form = $this->createForm(new NewEntryType(), $entry); |
26 | 27 | ||
27 | $form->handleRequest($request); | 28 | $form->handleRequest($request); |
28 | 29 | ||
@@ -50,6 +51,42 @@ class EntryController extends Controller | |||
50 | } | 51 | } |
51 | 52 | ||
52 | /** | 53 | /** |
54 | * Edit an entry content. | ||
55 | * | ||
56 | * @param Request $request | ||
57 | * @param Entry $entry | ||
58 | * | ||
59 | * @Route("/edit/{id}", requirements={"id" = "\d+"}, name="edit") | ||
60 | * | ||
61 | * @return \Symfony\Component\HttpFoundation\Response | ||
62 | */ | ||
63 | public function editEntryAction(Request $request, Entry $entry) | ||
64 | { | ||
65 | $this->checkUserAction($entry); | ||
66 | |||
67 | $form = $this->createForm(new EditEntryType(), $entry); | ||
68 | |||
69 | $form->handleRequest($request); | ||
70 | |||
71 | if ($form->isValid()) { | ||
72 | $em = $this->getDoctrine()->getManager(); | ||
73 | $em->persist($entry); | ||
74 | $em->flush(); | ||
75 | |||
76 | $this->get('session')->getFlashBag()->add( | ||
77 | 'notice', | ||
78 | 'Entry updated' | ||
79 | ); | ||
80 | |||
81 | return $this->redirect($this->generateUrl('view', array('id' => $entry->getId()))); | ||
82 | } | ||
83 | |||
84 | return $this->render('WallabagCoreBundle:Entry:edit.html.twig', array( | ||
85 | 'form' => $form->createView(), | ||
86 | )); | ||
87 | } | ||
88 | |||
89 | /** | ||
53 | * Shows unread entries for current user. | 90 | * Shows unread entries for current user. |
54 | * | 91 | * |
55 | * @Route("/unread", name="unread") | 92 | * @Route("/unread", name="unread") |
@@ -212,7 +249,7 @@ class EntryController extends Controller | |||
212 | private function checkUserAction(Entry $entry) | 249 | private function checkUserAction(Entry $entry) |
213 | { | 250 | { |
214 | if ($this->getUser()->getId() != $entry->getUser()->getId()) { | 251 | if ($this->getUser()->getId() != $entry->getUser()->getId()) { |
215 | throw $this->createAccessDeniedException('You can not use this entry.'); | 252 | throw $this->createAccessDeniedException('You can not access this entry.'); |
216 | } | 253 | } |
217 | } | 254 | } |
218 | } | 255 | } |
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index b1998ab6..f139bbac 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php | |||
@@ -390,7 +390,7 @@ class Entry | |||
390 | /** | 390 | /** |
391 | * @param bool $isPublic | 391 | * @param bool $isPublic |
392 | */ | 392 | */ |
393 | public function setPublic($isPublic) | 393 | public function setIsPublic($isPublic) |
394 | { | 394 | { |
395 | $this->isPublic = $isPublic; | 395 | $this->isPublic = $isPublic; |
396 | } | 396 | } |
diff --git a/src/Wallabag/CoreBundle/Entity/Tag.php b/src/Wallabag/CoreBundle/Entity/Tag.php index afe9e1b9..92442df6 100644 --- a/src/Wallabag/CoreBundle/Entity/Tag.php +++ b/src/Wallabag/CoreBundle/Entity/Tag.php | |||
@@ -51,6 +51,12 @@ class Tag | |||
51 | $this->user = $user; | 51 | $this->user = $user; |
52 | $this->entries = new ArrayCollection(); | 52 | $this->entries = new ArrayCollection(); |
53 | } | 53 | } |
54 | |||
55 | public function __toString() | ||
56 | { | ||
57 | return $this->label; | ||
58 | } | ||
59 | |||
54 | /** | 60 | /** |
55 | * Get id. | 61 | * Get id. |
56 | * | 62 | * |
diff --git a/src/Wallabag/CoreBundle/Form/Type/EditEntryType.php b/src/Wallabag/CoreBundle/Form/Type/EditEntryType.php new file mode 100644 index 00000000..0fa4b71f --- /dev/null +++ b/src/Wallabag/CoreBundle/Form/Type/EditEntryType.php | |||
@@ -0,0 +1,36 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Form\Type; | ||
4 | |||
5 | use Symfony\Component\Form\AbstractType; | ||
6 | use Symfony\Component\Form\FormBuilderInterface; | ||
7 | use Symfony\Component\OptionsResolver\OptionsResolver; | ||
8 | |||
9 | class EditEntryType extends AbstractType | ||
10 | { | ||
11 | public function buildForm(FormBuilderInterface $builder, array $options) | ||
12 | { | ||
13 | $builder | ||
14 | ->add('title', 'text', array('required' => true)) | ||
15 | ->add('is_public', 'checkbox', array('required' => false)) | ||
16 | // @todo: add autocomplete | ||
17 | // ->add('tags', 'entity', array( | ||
18 | // 'class' => 'Wallabag\CoreBundle\Entity\Tag', | ||
19 | // 'choice_translation_domain' => true, | ||
20 | // )) | ||
21 | ->add('save', 'submit') | ||
22 | ; | ||
23 | } | ||
24 | |||
25 | public function configureOptions(OptionsResolver $resolver) | ||
26 | { | ||
27 | $resolver->setDefaults(array( | ||
28 | 'data_class' => 'Wallabag\CoreBundle\Entity\Entry', | ||
29 | )); | ||
30 | } | ||
31 | |||
32 | public function getName() | ||
33 | { | ||
34 | return 'entry'; | ||
35 | } | ||
36 | } | ||
diff --git a/src/Wallabag/CoreBundle/Form/Type/EntryType.php b/src/Wallabag/CoreBundle/Form/Type/NewEntryType.php index 0532bf10..a2d203ea 100644 --- a/src/Wallabag/CoreBundle/Form/Type/EntryType.php +++ b/src/Wallabag/CoreBundle/Form/Type/NewEntryType.php | |||
@@ -6,7 +6,7 @@ use Symfony\Component\Form\AbstractType; | |||
6 | use Symfony\Component\Form\FormBuilderInterface; | 6 | use Symfony\Component\Form\FormBuilderInterface; |
7 | use Symfony\Component\OptionsResolver\OptionsResolverInterface; | 7 | use Symfony\Component\OptionsResolver\OptionsResolverInterface; |
8 | 8 | ||
9 | class EntryType extends AbstractType | 9 | class NewEntryType extends AbstractType |
10 | { | 10 | { |
11 | public function buildForm(FormBuilderInterface $builder, array $options) | 11 | public function buildForm(FormBuilderInterface $builder, array $options) |
12 | { | 12 | { |
diff --git a/src/Wallabag/CoreBundle/Resources/views/Entry/edit.html.twig b/src/Wallabag/CoreBundle/Resources/views/Entry/edit.html.twig new file mode 100644 index 00000000..0d4d5ad2 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/Entry/edit.html.twig | |||
@@ -0,0 +1,7 @@ | |||
1 | {% extends "WallabagCoreBundle::layout.html.twig" %} | ||
2 | |||
3 | {% block title %}{% trans %}Edit an entry{% endtrans %}{% endblock %} | ||
4 | |||
5 | {% block content %} | ||
6 | {{ form(form) }} | ||
7 | {% endblock %} | ||
diff --git a/src/Wallabag/CoreBundle/Resources/views/Entry/entry.html.twig b/src/Wallabag/CoreBundle/Resources/views/Entry/entry.html.twig index f23ab968..f5c19ea3 100644 --- a/src/Wallabag/CoreBundle/Resources/views/Entry/entry.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/Entry/entry.html.twig | |||
@@ -17,18 +17,18 @@ | |||
17 | {# {% if flattr %}{% if flattr.status == flattrable %}<li><a href="http://flattr.com/submit/auto?url={{ entry.url }}" class="tool flattr icon icon-flattr" target="_blank" title="{% trans %}flattr{% endtrans %}"><span>{% trans %}flattr{% endtrans %}</span></a></li>{% elseif flattr.status == flattred %}<li><a href="{{ flattr.flattrItemURL }}" class="tool flattr icon icon-flattr" target="_blank" title="{% trans %}flattr{% endtrans %}><span>{% trans %}flattr{% endtrans %}</span> ({{ flattr.numFlattrs }})</a></li>{% endif %}{% endif %} #} | 17 | {# {% if flattr %}{% if flattr.status == flattrable %}<li><a href="http://flattr.com/submit/auto?url={{ entry.url }}" class="tool flattr icon icon-flattr" target="_blank" title="{% trans %}flattr{% endtrans %}"><span>{% trans %}flattr{% endtrans %}</span></a></li>{% elseif flattr.status == flattred %}<li><a href="{{ flattr.flattrItemURL }}" class="tool flattr icon icon-flattr" target="_blank" title="{% trans %}flattr{% endtrans %}><span>{% trans %}flattr{% endtrans %}</span> ({{ flattr.numFlattrs }})</a></li>{% endif %}{% endif %} #} |
18 | {% if carrot %}<li><a href="https://secure.carrot.org/GiveAndGetBack.do?url={{ entry.url|url_encode }}&title={{ entry.title|url_encode }}" class="tool carrot icon-image icon-image--carrot" target="_blank" title="{% trans %}carrot{% endtrans %}"><span>Carrot</span></a></li>{% endif %} | 18 | {% if carrot %}<li><a href="https://secure.carrot.org/GiveAndGetBack.do?url={{ entry.url|url_encode }}&title={{ entry.title|url_encode }}" class="tool carrot icon-image icon-image--carrot" target="_blank" title="{% trans %}carrot{% endtrans %}"><span>Carrot</span></a></li>{% endif %} |
19 | {% if show_printlink %}<li><a title="{% trans %}Print{% endtrans %}" class="tool icon icon-print" href="javascript: window.print();"><span>{% trans %}Print{% endtrans %}</span></a></li>{% endif %} | 19 | {% if show_printlink %}<li><a title="{% trans %}Print{% endtrans %}" class="tool icon icon-print" href="javascript: window.print();"><span>{% trans %}Print{% endtrans %}</span></a></li>{% endif %} |
20 | {% if export_epub %}<li><a href="?epub&method=id&value={{ entry.id|e }}" title="Generate ePub file">EPUB</a></li>{% endif %} | 20 | {% if export_epub %}<li><a href="?epub&method=id&value={{ entry.id }}" title="Generate ePub file">EPUB</a></li>{% endif %} |
21 | {% if export_mobi %}<li><a href="?mobi&method=id&value={{ entry.id|e }}" title="Generate Mobi file">MOBI</a></li>{% endif %} | 21 | {% if export_mobi %}<li><a href="?mobi&method=id&value={{ entry.id }}" title="Generate Mobi file">MOBI</a></li>{% endif %} |
22 | {% if export_pdf %}<li><a href="?pdf&method=id&value={{ entry.id|e }}" title="Generate PDF file">PDF</a></li>{% endif %} | 22 | {% if export_pdf %}<li><a href="?pdf&method=id&value={{ entry.id }}" title="Generate PDF file">PDF</a></li>{% endif %} |
23 | <li><a href="mailto:hello@wallabag.org?subject=Wrong%20display%20in%20wallabag&body={{ entry.url|url_encode }}" title="{% trans %}Does this article appear wrong?{% endtrans %}" class="tool bad-display icon icon-delete"><span>{% trans %}Does this article appear wrong?{% endtrans %}</span></a></li> | 23 | <li><a href="mailto:hello@wallabag.org?subject=Wrong%20display%20in%20wallabag&body={{ entry.url|url_encode }}" title="{% trans %}Does this article appear wrong?{% endtrans %}" class="tool bad-display icon icon-delete"><span>{% trans %}Does this article appear wrong?{% endtrans %}</span></a></li> |
24 | </ul> | 24 | </ul> |
25 | </div> | 25 | </div> |
26 | <div id="article"> | 26 | <div id="article"> |
27 | <header class="mbm"> | 27 | <header class="mbm"> |
28 | <h1>{{ entry.title|raw }}</h1> | 28 | <h1>{{ entry.title|raw }} <a href="{{ path('edit', { 'id': entry.id }) }}" title="{% trans %}Edit tags{% endtrans %}">✎</a></h1> |
29 | </header> | 29 | </header> |
30 | <aside class="tags"> | 30 | <aside class="tags"> |
31 | tags: {# {% for tag in tags %}<a href="./?view=tag&id={{ tag.id }}">{{ tag.value }}</a> {% endfor %}<a href="./?view=edit-tags&id={{ entry.id|e }}" title="{% trans %}Edit tags{% endtrans %}">✎</a> #} | 31 | tags: {% for tag in entry.tags %}<a href="./?view=tag&id={{ tag.id }}">{{ tag.label }}</a> {% endfor %}<a href="./?view=edit-tags&id={{ entry.id }}" title="{% trans %}Edit tags{% endtrans %}">✎</a> |
32 | </aside> | 32 | </aside> |
33 | <article> | 33 | <article> |
34 | {{ entry.content | raw }} | 34 | {{ entry.content | raw }} |
@@ -87,13 +87,13 @@ | |||
87 | var docHeight = $(document).height(); | 87 | var docHeight = $(document).height(); |
88 | var scrollPercent = (scrollTop) / (docHeight); | 88 | var scrollPercent = (scrollTop) / (docHeight); |
89 | var scrollPercentRounded = Math.round(scrollPercent*100)/100; | 89 | var scrollPercentRounded = Math.round(scrollPercent*100)/100; |
90 | savePercent({{ entry.id|e }}, scrollPercentRounded); | 90 | savePercent({{ entry.id }}, scrollPercentRounded); |
91 | }); | 91 | }); |
92 | 92 | ||
93 | retrievePercent({{ entry.id|e }}); | 93 | retrievePercent({{ entry.id }}); |
94 | 94 | ||
95 | $(window).resize(function(){ | 95 | $(window).resize(function(){ |
96 | retrievePercent({{ entry.id|e }}); | 96 | retrievePercent({{ entry.id }}); |
97 | }); | 97 | }); |
98 | }); | 98 | }); |
99 | </script> | 99 | </script> |
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index 8a7fdda2..904e2a5c 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php | |||
@@ -109,6 +109,54 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
109 | $this->assertContains($content->getTitle(), $client->getResponse()->getContent()); | 109 | $this->assertContains($content->getTitle(), $client->getResponse()->getContent()); |
110 | } | 110 | } |
111 | 111 | ||
112 | public function testEdit() | ||
113 | { | ||
114 | $this->logInAs('admin'); | ||
115 | $client = $this->getClient(); | ||
116 | |||
117 | $content = $client->getContainer() | ||
118 | ->get('doctrine.orm.entity_manager') | ||
119 | ->getRepository('WallabagCoreBundle:Entry') | ||
120 | ->findOneByIsArchived(false); | ||
121 | |||
122 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | ||
123 | |||
124 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
125 | |||
126 | $this->assertCount(1, $crawler->filter('input[id=entry_title]')); | ||
127 | $this->assertCount(1, $crawler->filter('button[id=entry_save]')); | ||
128 | } | ||
129 | |||
130 | public function testEditUpdate() | ||
131 | { | ||
132 | $this->logInAs('admin'); | ||
133 | $client = $this->getClient(); | ||
134 | |||
135 | $content = $client->getContainer() | ||
136 | ->get('doctrine.orm.entity_manager') | ||
137 | ->getRepository('WallabagCoreBundle:Entry') | ||
138 | ->findOneByIsArchived(false); | ||
139 | |||
140 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | ||
141 | |||
142 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
143 | |||
144 | $form = $crawler->filter('button[type=submit]')->form(); | ||
145 | |||
146 | $data = array( | ||
147 | 'entry[title]' => 'My updated title hehe :)', | ||
148 | ); | ||
149 | |||
150 | $client->submit($form, $data); | ||
151 | |||
152 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
153 | |||
154 | $crawler = $client->followRedirect(); | ||
155 | |||
156 | $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(array('_text'))); | ||
157 | $this->assertContains('My updated title hehe :)', $alert[0]); | ||
158 | } | ||
159 | |||
112 | public function testToggleArchive() | 160 | public function testToggleArchive() |
113 | { | 161 | { |
114 | $this->logInAs('admin'); | 162 | $this->logInAs('admin'); |