Add reverse sort for open notes and a couple cleanups

This commit is contained in:
Ryan Prather 2024-05-22 19:42:50 -04:00
parent 6c6bbf8990
commit b307d616f6
5 changed files with 41 additions and 20 deletions

View File

@ -26,9 +26,11 @@ class DefaultController extends AbstractController
{ {
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY'); $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$last4Notes = $emi->getRepository(Note::class)->getLast4Notes($user); $last4Notes = $emi->getRepository(Note::class)->getLast4Notes($user);
$openNotes = $emi->getRepository(Note::class)->reverseNoteSort($user);
return $this->render('default/home.html.twig', [ return $this->render('default/home.html.twig', [
'last4Notes' => $last4Notes, 'last4Notes' => $last4Notes,
'reverseNoteSort' => $openNotes,
'isAdmin' => $this->isGranted('ROLE_ADMIN'), 'isAdmin' => $this->isGranted('ROLE_ADMIN'),
]); ]);
} }

View File

@ -17,6 +17,22 @@ class NoteRepository extends ServiceEntityRepository
parent::__construct($registry, Note::class); parent::__construct($registry, Note::class);
} }
public function reverseNoteSort(?User $user): array
{
if (!$user) {
return [];
}
$ret = $this->createQueryBuilder('n')
->where('n.user = :user')
->setParameter('user', $user->getId()->toBinary())
->orderBy('n.date', 'DESC')
->getQuery()
->getResult();
return $ret;
}
public function getLast4Notes(?User $user): array public function getLast4Notes(?User $user): array
{ {
if (!$user) { if (!$user) {
@ -36,13 +52,13 @@ class NoteRepository extends ServiceEntityRepository
public function findNote(string $query, string $userId): array public function findNote(string $query, string $userId): array
{ {
$ret = $this->createQueryBuilder('n') $ret = $this->createQueryBuilder('n')
->orderBy('n.date', 'DESC')
->where('n.title LIKE :query') ->where('n.title LIKE :query')
->orWhere('n.passage LIKE :query') ->orWhere('n.passage LIKE :query')
->orWhere('n.text LIKE :query') ->orWhere('n.text LIKE :query')
->andWhere('n.user = :user') ->andWhere('n.user = :user')
->setParameter('query', "%{$query}%") ->setParameter('query', "%{$query}%")
->setParameter('user', $userId) ->setParameter('user', $userId)
->orderBy('n.date', 'DESC')
->setMaxResults(3) ->setMaxResults(3)
->getQuery() ->getQuery()
->getResult(); ->getResult();

View File

@ -10,13 +10,10 @@
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" /> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<title>{% block title %}Welcome!{% endblock %}</title> <title>{% block title %}Welcome!{% endblock %}</title>
{% block stylesheets %} {% block stylesheets %}{% endblock %}
{% endblock %}
</head> </head>
<body class='is-preload' onload='setHeight()' onresize='setHeight()'> <body class='is-preload' onload='setHeight()' onresize='setHeight()'>
{% block body %}{% endblock %} {% block body %}{% endblock %}
{% block javascripts %} {% block javascripts %}{% endblock %}
{% block importmap %}{{ importmap('app') }}{% endblock %}
{% endblock %}
</body> </body>
</html> </html>

View File

@ -10,7 +10,6 @@
{% endblock %} {% endblock %}
{% block javascripts %} {% block javascripts %}
<script src='/js/data.js'></script>
<script src='/js/script.js'></script> <script src='/js/script.js'></script>
<script src="/theme/assets/js/jquery.min.js"></script> <script src="/theme/assets/js/jquery.min.js"></script>
<script src='/theme/assets/js/jquery-ui.js'></script> <script src='/theme/assets/js/jquery-ui.js'></script>
@ -24,19 +23,19 @@
{% block body %} {% block body %}
<div id='wrapper'> <div id='wrapper'>
<div id='main'> <div id='main'>
<div class='inner' style='padding-left:0;'> <div class='inner'>
<section class='ref-tab'> <section class='ref-tab'>
<ul id='ref-list'> <ul id='ref-list'>
</ul> </ul>
</section> </section>
<section class='ref'> <section class='ref'>
<h2 style='display:inline-block'>Reference</h2> <h2>Reference</h2>
<div style='display:inline-block'> <div style='display:inline-block'>
<button onclick='increaseFont()'><i class='fa fa-plus'></i></button>&nbsp; <button onclick='increaseFont()'><i class='fa fa-plus'></i></button>&nbsp;
<button onclick='decreaseFont()'><i class='fa fa-minus'></i></button> <button onclick='decreaseFont()'><i class='fa fa-minus'></i></button>
</div> </div>
<div id="ref"></div> <div id="ref" style='font-size:12pt;'></div>
<div id='note-list'> <div id='note-list'>
<table> <table>
<thead> <thead>
@ -48,9 +47,9 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for n in app.user.notes|reverse %} {% for n in reverseNoteSort %}
{{ n.toTableRow()|raw }}<br /> {{ n.toTableRow()|raw }}
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
</div> </div>
@ -59,7 +58,7 @@
<section class="notes"> <section class="notes">
<div id='note-header-left'> <div id='note-header-left'>
<h2>Notes</h2> <h2>Notes</h2>
<i id='save-check' class='fa fa-check' style='opacity:0;'></i> <i id='save-check' class='fa fa-check'></i>
</div> </div>
<div id='note-header-right'> <div id='note-header-right'>
<select id='template' onchange="retrieveTemplate('template','notes')"> <select id='template' onchange="retrieveTemplate('template','notes')">
@ -68,8 +67,13 @@
<option value="{{ t.id }}">{{ t.name }}</option> <option value="{{ t.id }}">{{ t.name }}</option>
{% endfor %} {% endfor %}
</select>&nbsp; </select>&nbsp;
<input type="button" id="previewBtn" class='button' value="Preview" onclick='previewNote()' />&nbsp; <button id="previewBtn" class='button' onclick='previewNote()'>
<input type='button' id='show-hide-btn' class='button' value='Show' onclick='toggleFields()' /> <i class='fa fa-eye'></i>
</button>
&nbsp;
<button id='show-hide-btn' class='button' onclick='toggleFields()'>
<i class='fa fa-table'></i>
</button>
</div> </div>
<div id='fields-container'> <div id='fields-container'>
@ -117,9 +121,12 @@
<option value='wsc'>Shorter Catechism</option> <option value='wsc'>Shorter Catechism</option>
<option value='wlc'>Larger Catechism</option> <option value='wlc'>Larger Catechism</option>
</select> </select>
<select id='referenceBook' style='display:none;'> <select id='referenceBook' onchange='filterBooks()'>
</select><br/> </select>
<input type="text" id="search" placeholder="Search"><br /> <span id='chapter-range' style='color:white;'></span>
<input type="text" id="referenceSearch" placeholder="Search" onkeyup='filterVerse()'>
<span id='verse-range' style='color:white;'></span>
<br />
<button id="searchBtn" onclick="queryRef()">Search</button> <button id="searchBtn" onclick="queryRef()">Search</button>
</div> </div>

View File

@ -12,7 +12,6 @@
<!-- Menu --> <!-- Menu -->
<nav id="menu"> <nav id="menu">
<header class="major"> <header class="major">
<h2>Menu</h2>
{% if app.user %} {% if app.user %}
<h3>Welcome {{ app.user.name }}</h3> <h3>Welcome {{ app.user.name }}</h3>
<a href='/index.php/logout'>Logout</a> <a href='/index.php/logout'>Logout</a>