mirror of
https://github.com/JanGross/quicknotes.git
synced 2025-11-30 23:37:16 +01:00
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:
@@ -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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user