diff --git a/.env.example b/.env.example index 283b404..9fbfe05 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,7 @@ # App level ENVIRONMENT=debug DEFAULT_LOCAL=en +PAGINATION_SIZE=50 TOKEN_DRIVER=local APP_SSL_KEY=randomVeryLongKey API_ENDPOINT=/v1/api diff --git a/apps/dashboard/src/components/data/Table.vue b/apps/dashboard/src/components/data/Table.vue new file mode 100644 index 0000000..d9b1c5d --- /dev/null +++ b/apps/dashboard/src/components/data/Table.vue @@ -0,0 +1,45 @@ + + + diff --git a/apps/dashboard/src/components/data/TablePagination.vue b/apps/dashboard/src/components/data/TablePagination.vue new file mode 100644 index 0000000..4b185d8 --- /dev/null +++ b/apps/dashboard/src/components/data/TablePagination.vue @@ -0,0 +1,22 @@ + + + diff --git a/apps/dashboard/src/components/view/Sidebar.vue b/apps/dashboard/src/components/view/Sidebar.vue index efefa75..46b1706 100644 --- a/apps/dashboard/src/components/view/Sidebar.vue +++ b/apps/dashboard/src/components/view/Sidebar.vue @@ -75,7 +75,7 @@ - + diff --git a/apps/dashboard/src/heplers/CursorPaginator.ts b/apps/dashboard/src/heplers/CursorPaginator.ts new file mode 100644 index 0000000..662eb54 --- /dev/null +++ b/apps/dashboard/src/heplers/CursorPaginator.ts @@ -0,0 +1,68 @@ +import type { Ref } from 'vue'; +import NetworkHelper from '@/heplers/NetworkHelper'; +import type { Router } from 'vue-router'; + +export default class CursorPaginator { + private items: Ref; + private readonly url: string; + private hasNext: Ref; + private hasPrev: Ref; + private tableLoading: Ref; + private router: Router; + + constructor(url: string, items: Ref, tableLoading: Ref, hasNext: Ref, hasPrev: Ref, router: Router) { + this.url = url; + this.items = items; + this.tableLoading = tableLoading; + this.hasPrev = hasPrev; + this.hasNext = hasNext; + this.router = router; + } + + public async next() { + this.tableLoading.value = true; + + await this.loadData(CursorPaginator.getURLParam('next')); + + this.tableLoading.value = false; + } + + public async prev() { + this.tableLoading.value = true; + const id = parseInt(CursorPaginator.getURLParam('prev')) + parseInt(CursorPaginator.getURLParam('size')); + + await this.loadData(id); + + this.tableLoading.value = false; + } + + public async loadData(lastId: any = 0) { + try { + const res = await NetworkHelper.get(`${this.url}${lastId}/`); + + if (res.success) { + const data = res.data; + + this.items.value = data.items; + this.hasPrev.value = data.hasPrev; + this.hasNext.value = data.hasNext; + const next = data.items[data.items.length - 1].id; + const size = data.size; + + await this.router.replace(`${this.router.currentRoute.value.path}?next=${next}&prev=${lastId}&size=${size}`); + } + } catch (e) { + // TODO: Toast for error + } + } + + private static getURLParam(param: string) { + const url = new URL(window.location.href.replace('#', '')); + + return url.searchParams.get(param) ?? '0'; + } + + async init() { + await this.loadData(CursorPaginator.getURLParam('prev')); + } +} diff --git a/apps/dashboard/src/heplers/NetworkHelper.ts b/apps/dashboard/src/heplers/NetworkHelper.ts index 8cd3e87..9dcdd92 100644 --- a/apps/dashboard/src/heplers/NetworkHelper.ts +++ b/apps/dashboard/src/heplers/NetworkHelper.ts @@ -3,6 +3,7 @@ export default class NetworkHelper { static readonly whoAmI = '/whoami'; static readonly server = '/server'; static readonly links = '/links/'; + static readonly linksAll = '/links/all/'; static readonly linkStats = '/links/stat/'; static readonly updateProfile = '/user/update'; @@ -51,4 +52,5 @@ export default class NetworkHelper { const base = import.meta.env.MODE === 'development' ? 'http://localhost:8081/v1/api' : `${window.location.origin}/v1/api`; return `${base}${appendUrl}`; } + } diff --git a/apps/dashboard/src/views/LinksView.vue b/apps/dashboard/src/views/LinksView.vue index a06fe19..ef9664c 100644 --- a/apps/dashboard/src/views/LinksView.vue +++ b/apps/dashboard/src/views/LinksView.vue @@ -6,75 +6,46 @@
- -
-
-
-
-
-
-
-
-

{{ $t('Just a moment') }}

-
-
- - - - - - - - - - - - - - - - - - - - - -
#{{ $t('Title') }}{{ $t('Short') }}{{ $t('Clicks') }}{{ $t('Destination') }}
{{ link.id }} - {{ link.title }} - -
- {{ link.short }} - - - - - - - - - -
-
{{ parseInt(link.clicks.toString()).toLocaleString() }} - {{ link.dest.substring(0, 50) }}{{ link.dest.length > 50 ? '...' : '' }} - -
- -
-
-
+ + + + + + + + + +
{{ link.id }} + {{ link.title }} + +
+ {{ link.short }} + + + + + + + + + +
+
{{ parseInt(link.clicks.toString()).toLocaleString() }} + {{ link.dest.substring(0, 50) }}{{ link.dest.length > 50 ? '...' : '' }} + +
+
+ + + + + + +
- - - +
+
@@ -83,29 +54,41 @@