mirror of
https://github.com/wallabag/wallabag.git
synced 2025-08-01 17:38:38 +00:00
Merge pull request #5838 from wallabag/feat/mass-action-tag
Add support of mass action to tag entries
This commit is contained in:
commit
2f1f6e9c51
6 changed files with 88 additions and 2 deletions
|
@ -11,6 +11,7 @@ use Symfony\Component\HttpFoundation\Request;
|
|||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Wallabag\CoreBundle\Entity\Entry;
|
||||
use Wallabag\CoreBundle\Entity\Tag;
|
||||
use Wallabag\CoreBundle\Event\EntryDeletedEvent;
|
||||
use Wallabag\CoreBundle\Event\EntrySavedEvent;
|
||||
use Wallabag\CoreBundle\Form\Type\EditEntryType;
|
||||
|
@ -30,11 +31,44 @@ class EntryController extends Controller
|
|||
$em = $this->getDoctrine()->getManager();
|
||||
$values = $request->request->all();
|
||||
|
||||
$tagsToAdd = [];
|
||||
$tagsToRemove = [];
|
||||
|
||||
$action = 'toggle-read';
|
||||
if (isset($values['toggle-star'])) {
|
||||
$action = 'toggle-star';
|
||||
} elseif (isset($values['delete'])) {
|
||||
$action = 'delete';
|
||||
} elseif (isset($values['tag'])) {
|
||||
$action = 'tag';
|
||||
|
||||
if (isset($values['tags'])) {
|
||||
$labels = array_filter(explode(',', $values['tags']),
|
||||
function ($v) {
|
||||
$v = trim($v);
|
||||
|
||||
return '' !== $v;
|
||||
});
|
||||
foreach ($labels as $label) {
|
||||
$remove = false;
|
||||
if (0 === strpos($label, '-')) {
|
||||
$label = substr($label, 1);
|
||||
$remove = true;
|
||||
}
|
||||
$tag = $this->get('wallabag_core.tag_repository')->findOneByLabel($label);
|
||||
if ($remove) {
|
||||
if (null !== $tag) {
|
||||
$tagsToRemove[] = $tag;
|
||||
}
|
||||
} else {
|
||||
if (null === $tag) {
|
||||
$tag = new Tag();
|
||||
$tag->setLabel($label);
|
||||
}
|
||||
$tagsToAdd[] = $tag;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($values['entry-checkbox'])) {
|
||||
|
@ -48,6 +82,13 @@ class EntryController extends Controller
|
|||
$entry->toggleArchive();
|
||||
} elseif ('toggle-star' === $action) {
|
||||
$entry->toggleStar();
|
||||
} elseif ('tag' === $action) {
|
||||
foreach ($tagsToAdd as $tag) {
|
||||
$entry->addTag($tag);
|
||||
}
|
||||
foreach ($tagsToRemove as $tag) {
|
||||
$entry->removeTag($tag);
|
||||
}
|
||||
} elseif ('delete' === $action) {
|
||||
$this->get('event_dispatcher')->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry));
|
||||
$em->remove($entry);
|
||||
|
|
|
@ -51,6 +51,11 @@
|
|||
<button class="btn cyan darken-1" type="submit" name="toggle-read" title="{{ 'entry.list.toogle_as_read'|trans }}"><i class="material-icons">done</i></button>
|
||||
<button class="btn cyan darken-1" type="submit" name="toggle-star" title="{{ 'entry.list.toogle_as_star'|trans }}" ><i class="material-icons">star</i></button>
|
||||
<button class="btn cyan darken-1" type="submit" name="delete" onclick="return confirm('{{ 'entry.confirm.delete_entries'|trans|escape('js') }}')" title="{{ 'entry.list.delete'|trans }}"><i class="material-icons">delete</i></button>
|
||||
<button class="btn cyan darken-1" type="submit" name="tag"><i class="material-icons">label</i></button>
|
||||
</span>
|
||||
|
||||
<span class="input-field inline">
|
||||
<input type="text" name="tags" />
|
||||
</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue