From 2325d12395e0a7e7f944165e7de4d9e88915b4d6 Mon Sep 17 00:00:00 2001
From: Santo Cariotti <santo@dcariotti.me>
Date: Thu, 13 Oct 2022 22:35:20 +0200
Subject: Add pagination on admin cp

---
 pages/admin/reports.vue | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

(limited to 'pages/admin/reports.vue')

diff --git a/pages/admin/reports.vue b/pages/admin/reports.vue
index 7d49a40..074360a 100644
--- a/pages/admin/reports.vue
+++ b/pages/admin/reports.vue
@@ -9,12 +9,14 @@
           :keys="['id', 'model_id', 'created', 'updated', 'user', 'resolved', 'note', 'admin_note']"
           :fields="warnings"
         )
+        pagination(:page="page" :pages="pages" v-if="count" path="/admin/reports")
 </template>
 
 <script>
 import { mapGetters } from "vuex";
 
 import AdminSidebar from "@/components/AdminSidebar.vue";
+import Pagination from "@/components/Pagination.vue";
 import VTable from "@/components/VTable.vue";
 
 export default {
@@ -22,9 +24,19 @@ export default {
   head: { title: "Models · Verden" },
   computed: {
     ...mapGetters("auth", ["isLogged", "me"]),
-    ...mapGetters("warnings", ["warnings"]),
+    ...mapGetters("warnings", ["warnings", "count"]),
+  },
+  data() {
+    return {
+      page: 0,
+      pages: 0,
+    };
+  },
+  components: {
+    AdminSidebar,
+    pagination: Pagination,
+    "v-table": VTable,
   },
-  components: { AdminSidebar, "v-table": VTable },
   async mounted() {
     await this.$store.dispatch("auth/findMe");
 
@@ -32,7 +44,10 @@ export default {
       window.location.href = "/";
     }
 
-    this.$store.dispatch("warnings/getWarnings", 0);
+    this.page = this.$route.query.page ?? 0;
+    this.$store.dispatch("warnings/getWarnings", this.page).then(() => {
+      this.pages = Math.ceil(this.count / 20);
+    });
   },
 };
 </script>
-- 
cgit v1.2.3-18-g5258

