diff options
author | salixor <kevin.cocchi@gmail.com> | 2022-08-02 10:37:35 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-02 10:37:35 +0300 |
commit | dccf0b36bc658aa6e1fdea57efd0be7397957e97 (patch) | |
tree | 3beceda5f6236db66e1421404b629f3863a8f07a | |
parent | 04e8db21727e08d1a15a4dd7a4011060f6421f4f (diff) |
Add a button to create a new note to the dashboard
-rw-r--r-- | appinfo/routes.php | 1 | ||||
-rw-r--r-- | lib/AppInfo/SearchProvider.php | 2 | ||||
-rw-r--r-- | lib/Controller/NotesController.php | 4 | ||||
-rw-r--r-- | lib/Controller/PageController.php | 4 | ||||
-rw-r--r-- | lib/Service/NotesService.php | 4 | ||||
-rw-r--r-- | src/App.vue | 11 | ||||
-rw-r--r-- | src/NotesService.js | 2 | ||||
-rw-r--r-- | src/components/Dashboard.vue | 83 |
8 files changed, 63 insertions, 48 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php index a954653b..bc16fec3 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -17,7 +17,6 @@ return ['routes' => [ 'name' => 'page#create', 'url' => '/new', 'verb' => 'GET', - 'postfix' => 'new', ], [ 'name' => 'page#index', diff --git a/lib/AppInfo/SearchProvider.php b/lib/AppInfo/SearchProvider.php index b56094e5..b24349b4 100644 --- a/lib/AppInfo/SearchProvider.php +++ b/lib/AppInfo/SearchProvider.php @@ -66,7 +66,7 @@ class SearchProvider implements IProvider { '', $note->getTitle(), $excerpt, - $this->url->linkToRouteAbsolute('notes.page.index') . 'note/'.$note->getId(), + $this->url->linkToRouteAbsolute('notes.page.indexnote', [ 'id' => $note->getId() ]), 'icon-notes-trans' ); }, diff --git a/lib/Controller/NotesController.php b/lib/Controller/NotesController.php index ee5ddcba..4d8858ce 100644 --- a/lib/Controller/NotesController.php +++ b/lib/Controller/NotesController.php @@ -95,9 +95,9 @@ class NotesController extends Controller { */ public function dashboard() : JSONResponse { return $this->helper->handleErrorResponse(function () { - $maxItems = 7; + $maxItems = 6; $userId = $this->helper->getUID(); - $notes = $this->notesService->getTopNotes($userId, $maxItems + 1); + $notes = $this->notesService->getTopNotes($userId); $hasMoreNotes = count($notes) > $maxItems; $notes = array_slice($notes, 0, $maxItems); $items = array_map(function ($note) { diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 68735135..b9baf3e0 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -59,7 +59,7 @@ class PageController extends Controller { public function create() : RedirectResponse { $note = $this->notesService->create($this->userSession->getUser()->getUID(), '', ''); $note->setContent(''); - $url = $this->urlGenerator->linkToRoute('notes.page.index', [ 'id' => $note->getId() ]); - return new RedirectResponse($url); + $url = $this->urlGenerator->linkToRoute('notes.page.indexnote', [ 'id' => $note->getId() ]); + return new RedirectResponse($url . '?new'); } } diff --git a/lib/Service/NotesService.php b/lib/Service/NotesService.php index 1c2b5922..2474f2bf 100644 --- a/lib/Service/NotesService.php +++ b/lib/Service/NotesService.php @@ -37,7 +37,7 @@ class NotesService { return [ 'notes' => $notes, 'categories' => $data['categories'] ]; } - public function getTopNotes(string $userId, int $count) : array { + public function getTopNotes(string $userId) : array { $notes = $this->getAll($userId)['notes']; usort($notes, function (Note $a, Note $b) { $favA = $a->getFavorite(); @@ -48,7 +48,7 @@ class NotesService { return $favA > $favB ? -1 : 1; } }); - return array_slice($notes, 0, $count); + return $notes; } public function get(string $userId, int $id) : Note { diff --git a/src/App.vue b/src/App.vue index 96f020ec..50e499d8 100644 --- a/src/App.vue +++ b/src/App.vue @@ -213,11 +213,12 @@ export default { } }, - routeToNote(noteId, query) { - if (this.$route.name !== 'note' || this.$route.params.noteId !== noteId.toString()) { + routeToNote(id, query) { + const noteId = id.toString() + if (this.$route.name !== 'note' || this.$route.params.noteId !== noteId) { this.$router.push({ name: 'note', - params: { noteId: noteId.toString() }, + params: { noteId }, query, }) } @@ -228,13 +229,13 @@ export default { return } this.loading.create = true - createNote(this.filter.category || '') + createNote(this.filter.category) .then(note => { this.routeToNote(note.id, { new: null }) }) .catch(() => { }) - .then(() => { + .finally(() => { this.loading.create = false }) }, diff --git a/src/NotesService.js b/src/NotesService.js index 26a458a9..245a1ee8 100644 --- a/src/NotesService.js +++ b/src/NotesService.js @@ -179,7 +179,7 @@ export const setTitle = (noteId, title) => { export const createNote = category => { return axios - .post(url('/notes'), { category }) + .post(url('/notes'), { category: category || '' }) .then(response => { _updateLocalNote(response.data) return response.data diff --git a/src/components/Dashboard.vue b/src/components/Dashboard.vue index 9de25be1..14df7a6f 100644 --- a/src/components/Dashboard.vue +++ b/src/components/Dashboard.vue @@ -1,38 +1,40 @@ <template> - <DashboardWidget :items="items" - :loading="loading" - > - <template #default="{ item }"> - <DashboardWidgetItem - :target-url="getItemTargetUrl(item)" - :main-text="item.title" - :sub-text="subtext(item)" - > - <template #avatar> - <div - class="note-item" - :class="{ 'note-item-favorite': item.favorite, 'note-item-no-favorites': !hasFavorites }" - /> - </template> - </DashboardWidgetItem> - </template> - <template #empty-content> - <EmptyContent icon="icon-notes"> - <template #desc> - <p class="notes-empty-content-label"> - {{ t('notes', 'No notes yet') }} - </p> - <p> - <a :href="createNoteUrl" class="button">{{ t('notes', 'New note') }}</a> - </p> - </template> - </EmptyContent> - </template> - </DashboardWidget> + <div class="dashboard-box"> + <DashboardWidget :items="items" :loading="loading"> + <template #default="{ item }"> + <DashboardWidgetItem + :target-url="getItemTargetUrl(item)" + :main-text="item.title" + :sub-text="subtext(item)" + > + <template #avatar> + <div + class="note-item" + :class="{ 'note-item-favorite': item.favorite, 'note-item-no-favorites': !hasFavorites }" + /> + </template> + </DashboardWidgetItem> + </template> + <template #empty-content> + <EmptyContent icon="icon-notes"> + <template #desc> + <p class="notes-empty-content-label"> + {{ t('notes', 'No notes yet') }} + </p> + </template> + </EmptyContent> + </template> + </DashboardWidget> + <div v-if="!loading" class="buttons-footer"> + <a :href="createNoteUrl" class="button"> + {{ t('notes', 'New note') }} + </a> + </div> + </div> </template> <script> -import { DashboardWidget, DashboardWidgetItem } from '@nextcloud/vue-dashboard' +import { DashboardWidget, DashboardWidgetItem } from '@nextcloud/vue-dashboard' // TODO: should be refactored with next release of @nextcloud/vue : https://github.com/nextcloud/nextcloud-vue-dashboard/issues/407 import { EmptyContent } from '@nextcloud/vue' import { generateUrl } from '@nextcloud/router' @@ -51,6 +53,7 @@ export default { data() { return { loading: true, + creating: false, items: [], hasMoreItems: false, } @@ -71,7 +74,7 @@ export default { getItemTargetUrl() { return (note) => { - return generateUrl('/apps/notes/note/' + note.id) + return generateUrl(`/apps/notes/note/${note.id}`) } }, }, @@ -90,13 +93,18 @@ export default { }, subtext(item) { - return item.excerpt ? item.excerpt : categoryLabel(item.category) + return item.excerpt || categoryLabel(item.category) }, }, - } </script> + <style scoped> +.dashboard-box { + position: relative; + height: 100%; +} + .note-item-favorite { background: var(--icon-star-dark-FC0, var(--icon-star-dark-fc0)); } @@ -118,4 +126,11 @@ export default { .notes-empty-content-label { margin-bottom: 20px; } + +.buttons-footer { + position: absolute; + bottom: 1em; + width: 100%; + text-align: center; +} </style> |