diff options
Diffstat (limited to 'src')
4 files changed, 138 insertions, 1 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 8bbe4ca0..24b86344 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php | |||
@@ -7,9 +7,11 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |||
7 | use Symfony\Component\HttpFoundation\Request; | 7 | use Symfony\Component\HttpFoundation\Request; |
8 | use Symfony\Component\HttpFoundation\JsonResponse; | 8 | use Symfony\Component\HttpFoundation\JsonResponse; |
9 | use Wallabag\CoreBundle\Entity\Config; | 9 | use Wallabag\CoreBundle\Entity\Config; |
10 | use Wallabag\CoreBundle\Entity\TaggingRule; | ||
10 | use Wallabag\UserBundle\Entity\User; | 11 | use Wallabag\UserBundle\Entity\User; |
11 | use Wallabag\CoreBundle\Form\Type\ChangePasswordType; | 12 | use Wallabag\CoreBundle\Form\Type\ChangePasswordType; |
12 | use Wallabag\CoreBundle\Form\Type\UserInformationType; | 13 | use Wallabag\CoreBundle\Form\Type\UserInformationType; |
14 | use Wallabag\CoreBundle\Form\Type\TaggingRuleType; | ||
13 | use Wallabag\CoreBundle\Form\Type\NewUserType; | 15 | use Wallabag\CoreBundle\Form\Type\NewUserType; |
14 | use Wallabag\CoreBundle\Form\Type\RssType; | 16 | use Wallabag\CoreBundle\Form\Type\RssType; |
15 | use Wallabag\CoreBundle\Tools\Utils; | 17 | use Wallabag\CoreBundle\Tools\Utils; |
@@ -98,6 +100,24 @@ class ConfigController extends Controller | |||
98 | return $this->redirect($this->generateUrl('config')); | 100 | return $this->redirect($this->generateUrl('config')); |
99 | } | 101 | } |
100 | 102 | ||
103 | // handle tagging rule | ||
104 | $taggingRule = new TaggingRule(); | ||
105 | $newTaggingRule = $this->createForm(new TaggingRuleType(), $taggingRule); | ||
106 | $newTaggingRule->handleRequest($request); | ||
107 | |||
108 | if ($newTaggingRule->isValid()) { | ||
109 | $taggingRule->setConfig($config); | ||
110 | $em->persist($taggingRule); | ||
111 | $em->flush(); | ||
112 | |||
113 | $this->get('session')->getFlashBag()->add( | ||
114 | 'notice', | ||
115 | 'Tagging rules updated' | ||
116 | ); | ||
117 | |||
118 | return $this->redirect($this->generateUrl('config')); | ||
119 | } | ||
120 | |||
101 | // handle adding new user | 121 | // handle adding new user |
102 | $newUser = $userManager->createUser(); | 122 | $newUser = $userManager->createUser(); |
103 | // enable created user by default | 123 | // enable created user by default |
@@ -136,6 +156,7 @@ class ConfigController extends Controller | |||
136 | 'pwd' => $pwdForm->createView(), | 156 | 'pwd' => $pwdForm->createView(), |
137 | 'user' => $userForm->createView(), | 157 | 'user' => $userForm->createView(), |
138 | 'new_user' => $newUserForm->createView(), | 158 | 'new_user' => $newUserForm->createView(), |
159 | 'new_tagging_rule' => $newTaggingRule->createView(), | ||
139 | ), | 160 | ), |
140 | 'rss' => array( | 161 | 'rss' => array( |
141 | 'username' => $user->getUsername(), | 162 | 'username' => $user->getUsername(), |
diff --git a/src/Wallabag/CoreBundle/Form/DataTransformer/StringToListTransformer.php b/src/Wallabag/CoreBundle/Form/DataTransformer/StringToListTransformer.php new file mode 100644 index 00000000..332a91b8 --- /dev/null +++ b/src/Wallabag/CoreBundle/Form/DataTransformer/StringToListTransformer.php | |||
@@ -0,0 +1,49 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Form\DataTransformer; | ||
4 | |||
5 | use Doctrine\Common\Persistence\ObjectManager; | ||
6 | use Symfony\Component\Form\DataTransformerInterface; | ||
7 | use Symfony\Component\Form\Exception\TransformationFailedException; | ||
8 | |||
9 | class StringToListTransformer implements DataTransformerInterface | ||
10 | { | ||
11 | private $separator; | ||
12 | |||
13 | public function __construct($separator = ',') | ||
14 | { | ||
15 | $this->separator = $separator; | ||
16 | } | ||
17 | |||
18 | /** | ||
19 | * Transforms a list to a string. | ||
20 | * | ||
21 | * @param array|null $list | ||
22 | * | ||
23 | * @return string | ||
24 | */ | ||
25 | public function transform($list) | ||
26 | { | ||
27 | if (null === $list) { | ||
28 | return ''; | ||
29 | } | ||
30 | |||
31 | return implode($this->separator, $list); | ||
32 | } | ||
33 | |||
34 | /** | ||
35 | * Transforms a string to a list. | ||
36 | * | ||
37 | * @param string $string | ||
38 | * | ||
39 | * @return array|null | ||
40 | */ | ||
41 | public function reverseTransform($string) | ||
42 | { | ||
43 | if (!$string) { | ||
44 | return null; | ||
45 | } | ||
46 | |||
47 | return array_filter(array_map('trim', explode($this->separator, $string))); | ||
48 | } | ||
49 | } | ||
diff --git a/src/Wallabag/CoreBundle/Form/Type/TaggingRuleType.php b/src/Wallabag/CoreBundle/Form/Type/TaggingRuleType.php new file mode 100644 index 00000000..7fbba38a --- /dev/null +++ b/src/Wallabag/CoreBundle/Form/Type/TaggingRuleType.php | |||
@@ -0,0 +1,38 @@ | |||
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 | use Wallabag\CoreBundle\Form\DataTransformer\StringToListTransformer; | ||
10 | |||
11 | class TaggingRuleType extends AbstractType | ||
12 | { | ||
13 | public function buildForm(FormBuilderInterface $builder, array $options) | ||
14 | { | ||
15 | $builder | ||
16 | ->add('rule', 'text', array('required' => true)) | ||
17 | ->add('save', 'submit') | ||
18 | ; | ||
19 | |||
20 | $tagsField = $builder | ||
21 | ->create('tags', 'text') | ||
22 | ->addModelTransformer(new StringToListTransformer(',')); | ||
23 | |||
24 | $builder->add($tagsField); | ||
25 | } | ||
26 | |||
27 | public function configureOptions(OptionsResolver $resolver) | ||
28 | { | ||
29 | $resolver->setDefaults(array( | ||
30 | 'data_class' => 'Wallabag\CoreBundle\Entity\TaggingRule', | ||
31 | )); | ||
32 | } | ||
33 | |||
34 | public function getName() | ||
35 | { | ||
36 | return 'tagging_rule'; | ||
37 | } | ||
38 | } | ||
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig index 8f121a2b..d27a8ca6 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig | |||
@@ -15,8 +15,9 @@ | |||
15 | <li class="tab col s3"><a href="#set2">{% trans %}RSS{% endtrans %}</a></li> | 15 | <li class="tab col s3"><a href="#set2">{% trans %}RSS{% endtrans %}</a></li> |
16 | <li class="tab col s3"><a href="#set3">{% trans %}User information{% endtrans %}</a></li> | 16 | <li class="tab col s3"><a href="#set3">{% trans %}User information{% endtrans %}</a></li> |
17 | <li class="tab col s3"><a href="#set4">{% trans %}Password{% endtrans %}</a></li> | 17 | <li class="tab col s3"><a href="#set4">{% trans %}Password{% endtrans %}</a></li> |
18 | <li class="tab col s3"><a href="#set5">{% trans %}Tags{% endtrans %}</a></li> | ||
18 | {% if is_granted('ROLE_SUPER_ADMIN') %} | 19 | {% if is_granted('ROLE_SUPER_ADMIN') %} |
19 | <li class="tab col s3"><a href="#set5">{% trans %}Add a user{% endtrans %}</a></li> | 20 | <li class="tab col s3"><a href="#set6">{% trans %}Add a user{% endtrans %}</a></li> |
20 | {% endif %} | 21 | {% endif %} |
21 | </ul> | 22 | </ul> |
22 | </div> | 23 | </div> |
@@ -183,6 +184,34 @@ | |||
183 | </form> | 184 | </form> |
184 | </div> | 185 | </div> |
185 | 186 | ||
187 | <div id="set5" class="col s12"> | ||
188 | <form action="{{ path('config') }}#set5" method="post" {{ form_enctype(form.pwd) }}> | ||
189 | {{ form_errors(form.pwd) }} | ||
190 | |||
191 | <div class="row"> | ||
192 | <div class="input-field col s12"> | ||
193 | {{ form_label(form.new_tagging_rule.rule) }} | ||
194 | {{ form_errors(form.new_tagging_rule.rule) }} | ||
195 | {{ form_widget(form.new_tagging_rule.rule) }} | ||
196 | </div> | ||
197 | </div> | ||
198 | |||
199 | <div class="row"> | ||
200 | <div class="input-field col s12"> | ||
201 | {{ form_label(form.new_tagging_rule.tags) }} | ||
202 | {{ form_errors(form.new_tagging_rule.tags) }} | ||
203 | {{ form_widget(form.new_tagging_rule.tags) }} | ||
204 | </div> | ||
205 | </div> | ||
206 | |||
207 | <div class="hidden">{{ form_rest(form.new_tagging_rule) }}</div> | ||
208 | <button class="btn waves-effect waves-light" type="submit" name="action"> | ||
209 | {% trans %}Save{% endtrans %} | ||
210 | </button> | ||
211 | |||
212 | </form> | ||
213 | </div> | ||
214 | |||
186 | {% if is_granted('ROLE_SUPER_ADMIN') %} | 215 | {% if is_granted('ROLE_SUPER_ADMIN') %} |
187 | <div id="set5" class="col s12"> | 216 | <div id="set5" class="col s12"> |
188 | {{ form_start(form.new_user) }} | 217 | {{ form_start(form.new_user) }} |