diff --git a/src/components/table-2.vue b/src/components/table-2.vue new file mode 100644 index 0000000000000000000000000000000000000000..11a2c6beac37c23063120162de56cb6f53d3f0b3 --- /dev/null +++ b/src/components/table-2.vue @@ -0,0 +1,198 @@ +<template> + <div class="table-responsive"> + <table class="table table-bordered"> + <thead> + <tr> + <template v-for="c in columns" :key="c"> + <th + v-if="!c.hidden" + @click="sort(c.data)" + class="text-blue clickable" + > + {{ c.name}} + </th> + </template> + <th class="text-blue">Aksi</th> + </tr> + </thead> + <tbody> + + <tr + v-for="e in this.entries.slice( + (this.page - 1) * this.entry_per_page, + this.page * this.entry_per_page + )" + :key="e.id" + > + <template v-for="c in columns" :key="c"> + <template v-if="!c.hidden"> + <td v-if="c.clickable" @click="this.$emit('detail-entry', e[columns.Id.data])" class="clickable"> + {{ e[c.data] }} + </td> + <td v-else > + {{ e[c.data]}} + </td> + </template> + </template> + + <td style="text-align: center"> + <button @click="this.$emit('edit-entry', e[columns.Id.data])" class="btn btn-blue"> <i class="icon ion-android-create" style="font-size: 20px"></i> Edit </button> + <button @click="this.$emit('delete-entry', e[columns.Id.data])" class="btn-red"> <i class="icon ion-ios-trash-outline" style="font-size: 23px"></i> </button> + </td> + </tr> + </tbody> + </table> + <nav aria-label="Page navigation"> + <ul class="pagination justify-content-end"> + <li v-if="this.page > 1" class="page-item"> + <div class="page-link" @click="prevPage()">Previous</div> + </li> + <li v-else class="page-item disabled"> + <div class="page-link">Previous</div> + </li> + <template v-for="p in this.pagination" :key="p"> + <li v-if="this.page == p" class="page-item disabled"> + <div class="page-link">{{ p }}</div> + </li> + <li v-else class="page-item"> + <div class="page-link" @click="goPage(p)">{{ p }}</div> + </li> + </template> + <li v-if="this.page < this.page_num" class="page-item"> + <div class="page-link" @click="nextPage()">Next</div> + </li> + <li v-else class="page-item disabled"> + <div class="page-link">Next</div> + </li> + </ul> + </nav> + </div> +</template> + +<script> + +import { HTTP } from '../http-common' +// import axios from 'axios'; + +export default { + name: "Table2", + props: { + //map nama kolom ke data + columns: Object, + endpoint: String, + filter: String, + filter_column: String, + + }, + data() { + return { + pagination: [], + sorted: { + column: this.columns.Id.data, + asc: true, + }, + entries: [], + entry_per_page: 10, + page: 1, + page_num: 0, + }; + }, + mounted() { + this.getData() + }, + watch: { + filter() { + console.log(this.filter) + this.page = 1 + this.getData() + } + }, + methods: { + getData(){ + let sortCol = this.sorted.column + if (!this.sorted.asc){ + sortCol = `-${sortCol}` + } + HTTP.get(`${this.endpoint}?page=${this.page}?sort=${sortCol}?filter[${this.filter_column}]=${this.filter}`).then((res)=>{ + if (res.status == 200){ + console.log(res.data) + this.entries = res.data.data.data + this.page = res.data.data.current_page + this.entry_per_page = res.data.data.per_page + this.page_num = res.data.data.last_page + this.updatePagination(); + } + }) + }, + sort(column) { + console.log("sort "+ column) + if (column === this.sorted.column) { + this.sorted.asc = !this.sorted.asc; + } else { + this.sorted.column = column; + this.sorted.asc = true + } + this.page = 1 + this.getData() + }, + nextPage() { + if (this.page < this.page_num) { + this.page += 1; + this.getData() + } + }, + prevPage() { + if (this.page > 1) { + this.page -= 1; + this.getData() + } + }, + goPage(i) { + this.page = i; + this.getData() + }, + updatePagination() { + this.pagination = []; + for (let i = this.page - 2; i <= this.page + 2; i++) { + if (i <= this.page_num && i > 0) { + this.pagination.push(i); + } + } + }, + }, +}; +</script> + +<style scoped> +li { + padding: 0; +} + +.table-bordered td, +.table-bordered th, +.table-bordered thead { + border: 1px solid #6992b4 !important; +} + +.btn-blue { + background-color: #6992b4; + color: #f1f7fc; + border-radius: 15px; + padding: 5px; + margin-right: 5px; + vertical-align:middle +} + +.btn-red { + background-color: #f4476b; + color: #f1f7fc; + border-radius: 8px; + padding-left: 5px; + padding-right: 5px; + vertical-align:middle +} + +th{ + text-align: center; +} +</style> diff --git a/src/components/table.vue b/src/components/table.vue index f418a5fbc1b7054ff271ddb3cd2dace80d803b16..1a07429ef84d5bfc02507cd815a7973900dd2a56 100644 --- a/src/components/table.vue +++ b/src/components/table.vue @@ -43,7 +43,7 @@ </tbody> </table> <nav aria-label="Page navigation"> - <ul class="pagination justify-content-end"> + <ul class="pagination justify-content-end clickable"> <li v-if="this.page > 1" class="page-item"> <div class="page-link" @click="prevPage()">Previous</div> </li> @@ -80,7 +80,6 @@ export default { }, data() { return { - // entries: [], pagination: [], sorted: { column: "", @@ -104,7 +103,6 @@ export default { return entries; }, - }, methods: { changes(entries) { diff --git a/src/http-common.js b/src/http-common.js index 79a652db6c05881d51273c7944758e302983e845..44da233e4de33f0432230b95f20d831af1822761 100644 --- a/src/http-common.js +++ b/src/http-common.js @@ -1,8 +1,12 @@ import axios from 'axios'; +const token = localStorage.getItem('token') + export const HTTP = axios.create({ baseURL: `https://simkpi-backend.herokuapp.com/api`, -// headers: { -// Authorization: 'Bearer {token}' -// } + // baseURL: 'localhost:8000/api/', + headers: { + Accept: 'application/json', + Authorization: `Bearer ${token}` + } }) diff --git a/src/router/index.js b/src/router/index.js index 02fd825abeddd9fcf37ebf05615b442dd439650f..aac63d1d1d09c434c7829723f5125610f7d7d6a0 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -11,6 +11,7 @@ import KaryawanEdit from "../views/KaryawanEdit.vue"; import AdminInsert from "../views/AdminInsert.vue"; import AdminEdit from "../views/AdminEdit.vue"; import KpiIndex from "../views/KpiIndex.vue"; +import Test from "../views/Test.vue"; const routes = [ { @@ -73,6 +74,11 @@ const routes = [ name: "kpiIndex", component: KpiIndex, }, + { + path: "/test", + name: "test", + component: Test, + }, ]; const router = createRouter({ diff --git a/src/views/Login.vue b/src/views/Login.vue index d5e03ed71ed0484f38fa7bf5a1889b7fb6cd17b5..bb757d84bf6825fb606c283e205ece7267781696 100644 --- a/src/views/Login.vue +++ b/src/views/Login.vue @@ -109,6 +109,7 @@ export default { }) .then((response) => { if (response.data.success) { + localStorage.setItem("token", response.data.token) this.$router.push({ name: "Home" }); } }) diff --git a/src/views/Test.vue b/src/views/Test.vue new file mode 100644 index 0000000000000000000000000000000000000000..0c051c15e566227d5a3d0f81c2c9002f42a8ac4d --- /dev/null +++ b/src/views/Test.vue @@ -0,0 +1,68 @@ +<template> + <div class="container-fluid"> + <div class="row flex-nowrap"> + <Sidebar current_page = "About"></Sidebar> + <div class="col ps-md-2 pt-2"> + <Header></Header> + <input v-model="filter" type="text"> + <Table2 :endpoint="'kpis'" :columns="columns" :filter="filter" :filter_column="'name'" @edit-entry="print" @delete-entry="print" @detail-entry="print" ></Table2> + </div> + </div> + </div> +</template> + +<script> + +import Header from "../components/header" +import Sidebar from "../components/sidebar" +import Table2 from "../components/table-2"; + + +export default { + name: "Template", + components: { + Header, + Sidebar, + Table2 + }, + data(){ + return{ + filter: "", + columns: { + Id: { + name : "Id", + data : "id", + hidden : true, + clickable : false + }, + Nama: { + name : "Nama", + data : "name", + hidden : false, + clickable : true + }, + }, + } + }, + methods: { + print(id){ + console.log(id) + } + } +} +</script> + +<style scoped> +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +body { + min-height: 100vh; + background-color: #fff; +} + + +</style> \ No newline at end of file