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

View File

@ -8,6 +8,7 @@ function initFilters() {
$('#clear_form_filters').on('click', () => { $('#clear_form_filters').on('click', () => {
$('#filters input').val(''); $('#filters input').val('');
$('#filters :checked').removeAttr('checked'); $('#filters :checked').removeAttr('checked');
return false; 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 * @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 * @return \Symfony\Component\HttpFoundation\RedirectResponse
*/ */

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -37,6 +37,7 @@ menu:
add_new_entry: 'Yeni bir makale ekle' add_new_entry: 'Yeni bir makale ekle'
search: 'Ara' search: 'Ara'
filter_entries: 'Filtrele' filter_entries: 'Filtrele'
# random_entry: Jump to a random entry from that list
export: 'Dışa Aktar' export: 'Dışa Aktar'
search_form: search_form:
input_label: 'Aramak istediğiniz herhangi bir şey yazın' 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="nb-results">{{ 'entry.list.number_on_the_page'|transchoice(entries.count) }}</div>
<div class="pagination"> <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('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 %} {% if app.user.config.rssToken %}
{% include "@WallabagCore/themes/common/Entry/_rss_link.html.twig" %} {% include "@WallabagCore/themes/common/Entry/_rss_link.html.twig" %}
{% endif %} {% 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 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> <i class="btn-clickable filter-btn material-icons md-24 js-filters-action">filter_list</i>
{% if entries.getNbPages > 1 %} {% if entries.getNbPages > 1 %}

View File

@ -28,7 +28,6 @@
<div class="nb-results"> <div class="nb-results">
{{ 'entry.list.number_on_the_page'|transchoice(entries.count) }} {{ '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('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 %} {% if app.user.config.rssToken %}
{% include "@WallabagCore/themes/common/Entry/_rss_link.html.twig" %} {% include "@WallabagCore/themes/common/Entry/_rss_link.html.twig" %}
{% endif %} {% endif %}

View File

@ -46,6 +46,8 @@
{% set activeRoute = 'starred' %} {% set activeRoute = 'starred' %}
{% elseif currentRoute == 'unread' or currentRoute == 'homepage' or currentRouteFromQueryParams == 'unread' %} {% elseif currentRoute == 'unread' or currentRoute == 'homepage' or currentRouteFromQueryParams == 'unread' %}
{% set activeRoute = 'unread' %} {% set activeRoute = 'unread' %}
{% elseif currentRoute == 'untagged' %}
{% set activeRoute = 'untagged' %}
{% endif %} {% endif %}
<li class="bold {% if activeRoute == 'unread' %}active{% endif %}"> <li class="bold {% if activeRoute == 'unread' %}active{% endif %}">
@ -113,6 +115,13 @@
<i class="material-icons">search</i> <i class="material-icons">search</i>
</a> </a>
</li> </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"> <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"> <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> <i class="material-icons">filter_list</i>
@ -125,7 +134,7 @@
</li> </li>
</ul> </ul>
</div> </div>
{{ render(controller("WallabagCoreBundle:Entry:searchForm", {'currentRoute': app.request.attributes.get('_route')})) }} {{ render(controller("WallabagCoreBundle:Entry:searchForm", {'currentRoute': currentRoute})) }}
{{ render(controller("WallabagCoreBundle:Entry:addEntryForm")) }} {{ render(controller("WallabagCoreBundle:Entry:addEntryForm")) }}
</div> </div>
</nav> </nav>

File diff suppressed because one or more lines are too long