Merge pull request #2410 from wallabag/tag-optim

Optimize tag list display
This commit is contained in:
Nicolas Lœuillet 2016-10-09 21:27:47 +02:00 committed by GitHub
commit 47508f004f
15 changed files with 104 additions and 47 deletions

View file

@ -414,9 +414,10 @@ main ul.row {
max-width: 50%;
}
.card .card-entry-labels li {
.card .card-entry-labels li,
.card-tag-labels li {
margin: 10px 10px 10px auto;
padding: 5px 12px 5px 16px;
padding: 5px 12px 5px 16px !important;
background-color: rgba(0, 151, 167, 0.85);
border-radius: 0 3px 3px 0;
color: #fff;
@ -447,6 +448,7 @@ main ul.row {
.card-entry-tags a,
.card-entry-labels a,
.card-tag-labels a,
.card-entry-labels-hidden a,
#list .chip a {
text-decoration: none;

View file

@ -387,7 +387,7 @@ class WallabagRestController extends FOSRestController
$tags = $this->getDoctrine()
->getRepository('WallabagCoreBundle:Tag')
->findAllTagsWithEntries($this->getUser()->getId());
->findAllTags($this->getUser()->getId());
$json = $this->get('serializer')->serialize($tags, 'json');

View file

@ -34,10 +34,13 @@ class TagAllCommand extends ContainerAwareCommand
}
$tagger = $this->getContainer()->get('wallabag_core.rule_based_tagger');
$output->write(sprintf('Tagging entries for user « <info>%s</info> »... ', $user->getUserName()));
$output->write(sprintf('Tagging entries for user « <comment>%s</comment> »... ', $user->getUserName()));
$entries = $tagger->tagAllForUser($user);
$output->writeln('<info>Done.</info>');
$output->write(sprintf('Persist entries ... ', $user->getUserName()));
$em = $this->getDoctrine()->getManager();
foreach ($entries as $entry) {
$em->persist($entry);

View file

@ -86,10 +86,25 @@ class TagController extends Controller
{
$tags = $this->getDoctrine()
->getRepository('WallabagCoreBundle:Tag')
->findAllTagsWithEntries($this->getUser()->getId());
->findAllTags($this->getUser()->getId());
$flatTags = [];
foreach ($tags as $key => $tag) {
$nbEntries = $this->getDoctrine()
->getRepository('WallabagCoreBundle:Entry')
->countAllEntriesByUserIdAndTagId($this->getUser()->getId(), $tag['id']);
$flatTags[] = [
'id' => $tag['id'],
'label' => $tag['label'],
'slug' => $tag['slug'],
'nbEntries' => $nbEntries,
];
}
return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [
'tags' => $tags,
'tags' => $flatTags,
]);
}

View file

@ -55,6 +55,7 @@ class RuleBasedTagger
{
$rules = $this->getRulesForUser($user);
$entries = [];
$tagsCache = [];
foreach ($rules as $rule) {
$qb = $this->entryRepository->getBuilderForAllByUser($user->getId());
@ -62,7 +63,12 @@ class RuleBasedTagger
foreach ($entries as $entry) {
foreach ($rule->getTags() as $label) {
$tag = $this->getTag($label);
// avoid new tag duplicate by manually caching them
if (!isset($tagsCache[$label])) {
$tagsCache[$label] = $this->getTag($label);
}
$tag = $tagsCache[$label];
$entry->addTag($tag);
}

View file

@ -309,4 +309,24 @@ class EntryRepository extends EntityRepository
return $qb->getQuery()->getSingleScalarResult();
}
/**
* Count all entries for a tag and a user.
*
* @param int $userId
* @param int $tagId
*
* @return int
*/
public function countAllEntriesByUserIdAndTagId($userId, $tagId)
{
$qb = $this->createQueryBuilder('e')
->select('count(e.id)')
->leftJoin('e.tags', 't')
->where('e.user=:userId')->setParameter('userId', $userId)
->andWhere('t.id=:tagId')->setParameter('tagId', $tagId)
;
return $qb->getQuery()->getSingleScalarResult();
}
}

View file

@ -33,19 +33,23 @@ class TagRepository extends EntityRepository
}
/**
* Find all tags with associated entries per user.
* Find all tags per user.
*
* @param int $userId
*
* @return array
*/
public function findAllTagsWithEntries($userId)
public function findAllTags($userId)
{
return $this->createQueryBuilder('t')
->select('t.slug', 't.label', 't.id')
->leftJoin('t.entries', 'e')
->where('e.user = :userId')->setParameter('userId', $userId)
->groupBy('t.slug')
->addGroupBy('t.label')
->addGroupBy('t.id')
->getQuery()
->getResult();
->getArrayResult();
}
/**

View file

@ -9,7 +9,7 @@
<ul>
{% for tag in tags %}
<li id="tag-{{ tag.id|e }}"><a href="{{ path('tag_entries', {'slug': tag.slug}) }}">{{tag.label}} ({{ tag.entries.getValues | length }})</a></li>
<li id="tag-{{ tag.id|e }}"><a href="{{ path('tag_entries', {'slug': tag.slug}) }}">{{tag.label}} ({{ tag.nbEntries | length }})</a></li>
{% endfor %}
</ul>

View file

@ -6,12 +6,19 @@
<div class="results clearfix">
<div class="nb-results left">{{ 'tag.list.number_on_the_page'|transchoice(tags|length) }}</div>
</div>
<br />
<ul class="row data">
{% for tag in tags %}
<li id="tag-{{ tag.id|e }}" class="col l4 m6 s12"><a href="{{ path('tag_entries', {'slug': tag.slug}) }}">{{tag.label}} ({{ tag.entries.getValues | length }})</a></li>
{% endfor %}
</ul>
<div class="row">
<ul class="card-tag-labels">
{% for tag in tags %}
<li title="{{tag.label}} ({{ tag.nbEntries }})" id="tag-{{ tag.id }}" class="col l2 m2 s2">
<a href="{{ path('tag_entries', {'slug': tag.slug}) }}">{{tag.label}} ({{ tag.nbEntries }})</a>
</li>
{% endfor %}
</ul>
</div>
<div>
<a href="{{ path('untagged') }}">{{ 'tag.list.see_untagged_entries'|trans }}</a>
</div>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long