feat: Add view to see non-conforming notes
This commit is contained in:
parent
6b184ca014
commit
cbaac88644
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\Note;
|
||||||
use App\Service\AnkiService;
|
use App\Service\AnkiService;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
@ -14,24 +15,43 @@ class AnkiController extends AbstractController
|
||||||
private AnkiService $ankiService,
|
private AnkiService $ankiService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
public static function tmpl(string $path): string
|
||||||
|
{
|
||||||
|
return "anki/$path.html.twig";
|
||||||
|
}
|
||||||
|
|
||||||
#[Route('/', name: 'main')]
|
#[Route('/', name: 'main')]
|
||||||
public function index(): Response
|
public function index(): Response
|
||||||
{
|
{
|
||||||
$note = $this->ankiService->getLatestNote();
|
$allIds = $this->ankiService->getAllNoteIds();
|
||||||
|
|
||||||
$this->ankiService->updateNote($note);
|
$allNotes = $this->ankiService->getNotes($allIds);
|
||||||
|
|
||||||
dd($note);
|
dd($allNotes);
|
||||||
dd($note->toAnki());
|
}
|
||||||
|
|
||||||
return $this->render('anki/index.html.twig', [
|
#[Route('/nonconforming', name: 'nonconforming')]
|
||||||
'controller_name' => $latestId,
|
public function nonconforming(): Response
|
||||||
|
{
|
||||||
|
$allIds = $this->ankiService->getAllNoteIds();
|
||||||
|
|
||||||
|
$allNotes = $this->ankiService->getNotes($allIds);
|
||||||
|
|
||||||
|
$lacking = array_filter($allNotes, function ($note) {
|
||||||
|
assert($note instanceof Note);
|
||||||
|
return empty($note->getTerms());
|
||||||
|
});
|
||||||
|
|
||||||
|
return $this->render(self::tmpl('nonconforming'), [
|
||||||
|
'notes' => $lacking,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/note/{nid}/get', name: 'get_note')]
|
#[Route('/note/{nid}/get', name: 'get_note')]
|
||||||
public function get_note(int $nid)
|
public function get_note(int $nid)
|
||||||
{
|
{
|
||||||
dd($this->ankiService->getNote($nid));
|
$note = $this->ankiService->getNote($nid);
|
||||||
|
//$this->ankiService->updateNote($note);
|
||||||
|
dd($note);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,14 @@ class Note
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
public function getTerms(): array
|
||||||
|
{
|
||||||
|
return $this->terms;
|
||||||
|
}
|
||||||
|
public function getFields(): array
|
||||||
|
{
|
||||||
|
return $this->fields;
|
||||||
|
}
|
||||||
|
|
||||||
public function hasTerm(string $kanji): bool
|
public function hasTerm(string $kanji): bool
|
||||||
{
|
{
|
||||||
|
|
|
@ -41,7 +41,7 @@ class AnkiService
|
||||||
/** Give an array of IDs, the note Infos are returned. if info for a given
|
/** Give an array of IDs, the note Infos are returned. if info for a given
|
||||||
* doesn't exist, it is assigned to null instead of the default [].
|
* doesn't exist, it is assigned to null instead of the default [].
|
||||||
*/
|
*/
|
||||||
private function getNotesInfo(array $noteIds): array
|
public function getNotesInfo(array $noteIds): array
|
||||||
{
|
{
|
||||||
$noteInfos = $this->request('notesInfo', ['notes' => $noteIds]);
|
$noteInfos = $this->request('notesInfo', ['notes' => $noteIds]);
|
||||||
|
|
||||||
|
@ -53,11 +53,16 @@ class AnkiService
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns info form note given an ID, returns null if it doesn't exist */
|
/** Returns info form note given an ID, returns null if it doesn't exist */
|
||||||
private function getNoteInfo(int $noteId): ?array
|
public function getNoteInfo(int $noteId): ?array
|
||||||
{
|
{
|
||||||
return $this->getNotesInfo([$noteId])[0];
|
return $this->getNotesInfo([$noteId])[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getNotes(array $nids): array
|
||||||
|
{
|
||||||
|
return array_map(Note::fromAnki(...), $this->getNotesInfo($nids));
|
||||||
|
}
|
||||||
|
|
||||||
public function getNote(int $nid): ?Note
|
public function getNote(int $nid): ?Note
|
||||||
{
|
{
|
||||||
return Note::fromAnki($this->getNoteInfo($nid));
|
return Note::fromAnki($this->getNoteInfo($nid));
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Main{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<div class="example-wrapper">
|
||||||
|
<h1>hello</h1>
|
||||||
|
<span>total {{ notes|length }}</span>
|
||||||
|
{% for note in notes %}
|
||||||
|
<div style="
|
||||||
|
border: 1px solid black;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
padding: 5px;
|
||||||
|
border-radius: 5px;
|
||||||
|
">
|
||||||
|
{{ note.fields.SentKanji }}
|
||||||
|
<br>
|
||||||
|
<a href="{{ path('app_anki_get_note', {nid: note.id}) }}">view</a>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
Loading…
Reference in New Issue