Add dashboard widget to show the latest notes. Issue #51

p.s: I would like to be able to select a particular tag to show, but
none of the dashboard widgets are configurable.

I hate increasing the app size from 300k to almost 3 mb for something
so simple, but we must adapt to the majority and use vue here.
This commit is contained in:
Matias De lellis
2022-05-25 10:29:20 -03:00
parent e6d52bfa5a
commit b6db15d8d2
14 changed files with 21727 additions and 308 deletions

View File

@@ -67,6 +67,41 @@ class NoteController extends Controller {
return $response;
}
/**
* @NoAdminRequired
*/
public function dashboard(): JSONResponse {
$notes = $this->noteService->getAll($this->userId);
if (count($notes) === 0) {
return new JSONResponse([
'notes' => []
]);
}
$items = array_map(function ($note) {
return [
'id' => $note->getId(),
'title' => strip_tags($note->getTitle()),
'content' => strip_tags($note->getContent()),
'pinned' => $note->getIsPinned(),
'timestamp' => $note->getTimestamp(),
];
}, $notes);
usort($items, function ($a, $b) {
if ($a['pinned'] == $b['pinned'])
return $b['timestamp'] - $a['timestamp'];
if ($a['pinned'] && !$b['pinned'])
return -1;
if (!$a['pinned'] && $b['pinned'])
return 1;
});
return new JSONResponse([
'notes' => array_slice($items, 0, 7)
]);
}
/**
* @NoAdminRequired
*