import '../_global/index';
/* Tools */
-import { initExport, initFilters, initRandom } from './js/tools';
+import { initExport, initFilters, initRandom, initSort } from './js/tools';
/* Import shortcuts */
import './js/shortcuts/main';
initRandom();
stickyNav();
articleScroll();
+ initSort();
const toggleNav = (toShow, toFocus) => {
$('.nav-panel-actions').hide(100);
// defined as null by default because each repository method have the right field as default value too
// like `getBuilderForStarredByUser` will have `starredAt` sort by default
$sortBy = null;
- if (in_array($request->get('sort', 'createdAt'), ['id', 'title', 'createdAt', 'updatedAt', 'starredAt', 'archivedAt'], true)) {
+ if (\in_array($request->get('sort', 'createdAt'), ['id', 'title', 'createdAt', 'updatedAt', 'starredAt', 'archivedAt'], true)) {
$sortBy = $request->get('sort', null);
}
*/
public function getBuilderForAllByUser($userId, $sortBy = 'id', $direction = 'DESC')
{
+ $sortBy = $sortBy ?: 'id';
+
return $this
->getSortedQueryBuilderByUser($userId, $sortBy, $direction)
;
*/
public function getBuilderForUnreadByUser($userId, $sortBy = 'id', $direction = 'DESC')
{
+ $sortBy = $sortBy ?: 'id';
+
return $this
->getSortedQueryBuilderByUser($userId, $sortBy, $direction)
->andWhere('e.isArchived = false')
*/
public function getBuilderForArchiveByUser($userId, $sortBy = 'archivedAt', $direction = 'DESC')
{
+ $sortBy = $sortBy ?: 'archivedAt';
+
return $this
->getSortedQueryBuilderByUser($userId, $sortBy, $direction)
->andWhere('e.isArchived = true')
*/
public function getBuilderForStarredByUser($userId, $sortBy = 'starredAt', $direction = 'DESC')
{
+ $sortBy = $sortBy ?: 'starredAt';
+
return $this
->getSortedQueryBuilderByUser($userId, $sortBy, $direction)
->andWhere('e.isStarred = true')
*/
private function sortQueryBuilder(QueryBuilder $qb, $sortBy = 'createdAt', $direction = 'desc')
{
- return $qb->orderBy(sprintf('e.%s', $sortBy), $direction);
+ // in case one of these isn't defined, don't apply the orderBy
+ if (!$sortBy || !$direction) {
+ return $qb;
+ }
+
+ return $qb->orderBy(sprintf('e.%s', $sortBy), strtoupper($direction));
}
}