Move icon into the top menu bar

Change the way to select a random entry:
- select all ids from the given user (with filters)
- choose randomly one in php
- find that entry
This commit is contained in:
Jeremy Benoist 2019-01-19 22:08:29 +01:00
parent 9a57653aec
commit 50f35f0db2
No known key found for this signature in database
GPG Key ID: BCA73962457ACC3C
22 changed files with 57 additions and 28 deletions

View File

@ -8,7 +8,7 @@ import 'materialize-css/dist/js/materialize';
import '../_global/index';
/* Tools */
import { initExport, initFilters } from './js/tools';
import { initExport, initFilters, initRandom } from './js/tools';
/* Import shortcuts */
import './js/shortcuts/main';
@ -32,8 +32,10 @@ $(document).ready(() => {
format: 'dd/mm/yyyy',
container: 'body',
});
initFilters();
initExport();
initRandom();
const toggleNav = (toShow, toFocus) => {
$('.nav-panel-actions').hide(100);

View File

@ -8,6 +8,7 @@ function initFilters() {
$('#clear_form_filters').on('click', () => {
$('#filters input').val('');
$('#filters :checked').removeAttr('checked');
return false;
});
}
@ -21,4 +22,15 @@ function initExport() {
}
}
export { initExport, initFilters };
function initRandom() {
// no display if export (ie: entries) not available
if ($('div').is('#export')) {
$('#button_random').show();
}
}
export {
initExport,
initFilters,
initRandom,
};

View File

@ -253,7 +253,7 @@ class EntryController extends Controller
*
* @param string $type
*
* @Route("/{type}/random", name="random_entry", requirements={"_locale": "unread|starred|archive|untagged|all"})
* @Route("/{type}/random", name="random_entry", requirements={"type": "unread|starred|archive|untagged|all"})
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/

View File

@ -325,8 +325,8 @@ class EntryRepository extends EntityRepository
* Find an entry by its url and its owner.
* If it exists, return the entry otherwise return false.
*
* @param $url
* @param $userId
* @param string $url
* @param int $userId
*
* @return Entry|bool
*/
@ -417,8 +417,8 @@ class EntryRepository extends EntityRepository
/**
* Find all entries by url and owner.
*
* @param $url
* @param $userId
* @param string $url
* @param int $userId
*
* @return array
*/
@ -434,20 +434,17 @@ class EntryRepository extends EntityRepository
/**
* Returns a random entry, filtering by status.
*
* @param $userId
* @param string $type can be unread, archive, starred, etc
* @param int $userId
* @param string $type Can be unread, archive, starred, etc
*
* @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException
*
* @see https://github.com/doctrine/doctrine2/issues/5479#issuecomment-403862934
*
* @return Entry
*/
public function getRandomEntry($userId, $type = '')
{
$qb = $this->getQueryBuilderByUser($userId)
->select('MIN(e.id)', 'MAX(e.id)');
->select('e.id');
switch ($type) {
case 'unread':
@ -465,18 +462,12 @@ class EntryRepository extends EntityRepository
break;
}
$idLimits = $qb
->getQuery()
->getOneOrNullResult();
$randomPossibleIds = rand($idLimits[1], $idLimits[2]);
$ids = $qb->getQuery()->getArrayResult();
return $qb
->select('e')
->andWhere('e.id >= :random_id')
->setParameter('random_id', $randomPossibleIds)
->setMaxResults(1)
->getQuery()
->getSingleResult();
// random select one in the list
$randomId = $ids[mt_rand(0, \count($ids) - 1)]['id'];
return $this->find($randomId);
}
/**

View File

@ -37,6 +37,7 @@ menu:
add_new_entry: 'Tilføj ny artikel'
search: 'Søg'
filter_entries: 'Filtrer artikler'
# random_entry: Jump to a random entry from that list
# export: 'Export'
search_form:
input_label: 'Indtast søgning'

View File

@ -37,6 +37,7 @@ menu:
add_new_entry: 'Neuen Artikel hinzufügen'
search: 'Suche'
filter_entries: 'Artikel filtern'
# random_entry: Jump to a random entry from that list
export: 'Exportieren'
search_form:
input_label: 'Suchbegriff hier eingeben'

View File

@ -37,6 +37,7 @@ menu:
add_new_entry: 'Add a new entry'
search: 'Search'
filter_entries: 'Filter entries'
random_entry: Jump to a random entry from that list
export: 'Export'
search_form:
input_label: 'Enter your search here'

View File

@ -37,6 +37,7 @@ menu:
add_new_entry: 'Añadir un nuevo artículo'
search: 'Buscar'
filter_entries: 'Filtrar los artículos'
# random_entry: Jump to a random entry from that list
export: 'Exportar'
search_form:
input_label: 'Introduzca su búsqueda aquí'

View File

@ -37,6 +37,7 @@ menu:
add_new_entry: 'افزودن مقالهٔ تازه'
search: 'جستجو'
filter_entries: 'فیلترکردن مقاله‌ها'
# random_entry: Jump to a random entry from that list
export: 'برون‌بری'
search_form:
input_label: 'جستجوی خود را این‌جا بنویسید:'

View File

@ -37,6 +37,7 @@ menu:
add_new_entry: "Sauvegarder un nouvel article"
search: "Rechercher"
filter_entries: "Filtrer les articles"
random_entry: Aller à un article aléatoire de cette liste
export: "Exporter"
search_form:
input_label: "Saisissez votre terme de recherche"

View File

@ -37,6 +37,7 @@ menu:
add_new_entry: 'Aggiungi un nuovo contenuto'
search: 'Cerca'
filter_entries: 'Filtra contenuti'
# random_entry: Jump to a random entry from that list
export: 'Esporta'
search_form:
input_label: 'Inserisci qui la tua ricerca'

View File

@ -37,6 +37,7 @@ menu:
add_new_entry: 'Enregistrar un novèl article'
search: 'Cercar'
filter_entries: 'Filtrar los articles'
# random_entry: Jump to a random entry from that list
export: 'Exportar'
search_form:
input_label: 'Picatz vòstre mot-clau a cercar aquí'

View File

@ -37,6 +37,7 @@ menu:
add_new_entry: 'Dodaj nowy wpis'
search: 'Szukaj'
filter_entries: 'Filtruj wpisy'
# random_entry: Jump to a random entry from that list
export: 'Eksportuj'
search_form:
input_label: 'Wpisz swoje zapytanie tutaj'

View File

@ -37,6 +37,7 @@ menu:
add_new_entry: 'Adicionar uma nova entrada'
search: 'Pesquisa'
filter_entries: 'Filtrar entradas'
# random_entry: Jump to a random entry from that list
export: 'Exportar'
search_form:
input_label: 'Digite aqui sua pesquisa'

View File

@ -37,6 +37,7 @@ menu:
add_new_entry: 'Introdu un nou articol'
search: 'Căutare'
filter_entries: 'Filtrează articolele'
# random_entry: Jump to a random entry from that list
# export: 'Export'
search_form:
input_label: 'Introdu căutarea ta'

View File

@ -36,6 +36,7 @@ menu:
add_new_entry: 'Добавить новую запись'
search: 'Поиск'
filter_entries: 'Фильтр записей'
# random_entry: Jump to a random entry from that list
export: 'Экспорт'
search_form:
input_label: 'Введите текст для поиска'

View File

@ -37,6 +37,7 @@ menu:
add_new_entry: 'เพิ่มรายการใหม่'
search: 'ค้นหา'
filter_entries: 'ตัวกรองรายการ'
# random_entry: Jump to a random entry from that list
export: 'นำข้อมูลออก'
search_form:
input_label: 'ค้นหาที่นี้'

View File

@ -37,6 +37,7 @@ menu:
add_new_entry: 'Yeni bir makale ekle'
search: 'Ara'
filter_entries: 'Filtrele'
# random_entry: Jump to a random entry from that list
export: 'Dışa Aktar'
search_form:
input_label: 'Aramak istediğiniz herhangi bir şey yazın'

View File

@ -28,10 +28,12 @@
<div class="nb-results">{{ 'entry.list.number_on_the_page'|transchoice(entries.count) }}</div>
<div class="pagination">
<a href="{{ path('switch_view_mode') }}"><i class="listMode-btn material-icons md-24">{% if listMode == 0 %}list{% else %}view_module{% endif %}</i></a>
<a href="{{ path('random_entry', { 'type': currentRoute }) }}">random</a>
{% if app.user.config.rssToken %}
{% include "@WallabagCore/themes/common/Entry/_rss_link.html.twig" %}
{% endif %}
{% if currentRoute in ['unread', 'starred', 'archive', 'untagged', 'all'] %}
<a href="{{ path('random_entry', { 'type': currentRoute }) }}"><i class="btn-clickable material-icons md-24 js-random-action">shuffle</i></a>
{% endif %}
<i class="btn-clickable download-btn material-icons md-24 js-export-action">file_download</i>
<i class="btn-clickable filter-btn material-icons md-24 js-filters-action">filter_list</i>
{% if entries.getNbPages > 1 %}

View File

@ -28,7 +28,6 @@
<div class="nb-results">
{{ 'entry.list.number_on_the_page'|transchoice(entries.count) }}
<a href="{{ path('switch_view_mode') }}"><i class="material-icons">{% if listMode == 0 %}view_list{% else %}view_module{% endif %}</i></a>
<a href="{{ path('random_entry', { 'type': currentRoute }) }}" title="random"><i class="material-icons">shuffle</i></a>
{% if app.user.config.rssToken %}
{% include "@WallabagCore/themes/common/Entry/_rss_link.html.twig" %}
{% endif %}

View File

@ -46,6 +46,8 @@
{% set activeRoute = 'starred' %}
{% elseif currentRoute == 'unread' or currentRoute == 'homepage' or currentRouteFromQueryParams == 'unread' %}
{% set activeRoute = 'unread' %}
{% elseif currentRoute == 'untagged' %}
{% set activeRoute = 'untagged' %}
{% endif %}
<li class="bold {% if activeRoute == 'unread' %}active{% endif %}">
@ -113,6 +115,13 @@
<i class="material-icons">search</i>
</a>
</li>
{% if activeRoute %}
<li id="button_random">
<a class="waves-effect tooltipped js-random-action" data-position="bottom" data-delay="50" data-tooltip="{{ 'menu.top.random_entry'|trans }}" href="{{ path('random_entry', { 'type': activeRoute }) }}">
<i class="material-icons">shuffle</i>
</a>
</li>
{% endif %}
<li id="button_filters">
<a class="nav-panel-menu button-collapse-right tooltipped js-filters-action" data-position="bottom" data-delay="50" data-tooltip="{{ 'menu.top.filter_entries'|trans }}" href="#" data-activates="filters">
<i class="material-icons">filter_list</i>
@ -125,7 +134,7 @@
</li>
</ul>
</div>
{{ render(controller("WallabagCoreBundle:Entry:searchForm", {'currentRoute': app.request.attributes.get('_route')})) }}
{{ render(controller("WallabagCoreBundle:Entry:searchForm", {'currentRoute': currentRoute})) }}
{{ render(controller("WallabagCoreBundle:Entry:addEntryForm")) }}
</div>
</nav>

File diff suppressed because one or more lines are too long