parsley/app/javascript/components/TheLogList.vue

71 lines
1.6 KiB
Vue
Raw Normal View History

2018-04-13 10:25:18 -05:00
<template>
<div>
<h1 class="title">
Log Entries
</h1>
<table class="table">
<thead>
2018-04-13 10:25:18 -05:00
<tr>
<th>Recipe</th>
<th>Date</th>
<th>Rating</th>
<th>Notes</th>
</tr>
</thead>
2018-04-13 10:25:18 -05:00
<tbody>
2018-04-13 10:25:18 -05:00
<tr v-for="l in logs" :key="l.id">
2018-04-14 15:04:08 -05:00
<td> <router-link :to="{name: 'log', params: {id: l.id}}">{{l.recipe.name}}</router-link></td>
2018-04-13 23:32:34 -05:00
<td><app-date-time :date-time="l.date" :show-time="false"></app-date-time> </td>
2024-10-02 14:34:50 -05:00
<td><app-rating :model-value="l.rating" readonly></app-rating></td>
2018-04-13 23:32:34 -05:00
<td>{{l.notes}}</td>
2018-04-13 10:25:18 -05:00
</tr>
</tbody>
2018-04-13 10:25:18 -05:00
</table>
</div>
</template>
2024-10-02 14:34:50 -05:00
<script setup>
2018-04-13 10:25:18 -05:00
2024-10-02 14:34:50 -05:00
import { computed, reactive, ref, watch } from "vue";
2018-04-13 10:25:18 -05:00
import api from "../lib/Api";
import debounce from "lodash/debounce";
2024-10-02 14:34:50 -05:00
import { useLoadResource } from "../lib/useLoadResource";
2018-04-13 10:25:18 -05:00
2024-10-02 14:34:50 -05:00
const { loadResource } = useLoadResource();
2018-04-13 10:25:18 -05:00
2024-10-02 14:34:50 -05:00
const logData = ref(null);
const search = reactive({
page: 1,
per: 25
});
2018-04-13 10:25:18 -05:00
2024-10-02 14:34:50 -05:00
const logs = computed(() => logData.value?.logs || []);
const totalPages = computed(() => logData.value?.total_pages || 0);
const currentPage = computed(() => logData.value?.current_page || 0);
2018-04-13 10:25:18 -05:00
2024-10-02 14:34:50 -05:00
const getList = debounce(function() {
loadResource(
api.getLogList(search.page, search.per)
.then(data => logData.value = data)
);
}, 500, {leading: true, trailing: true});
2018-04-13 10:25:18 -05:00
2024-10-02 14:34:50 -05:00
watch(search,
() => getList(),
{
deep: true,
immediate: true
}
);
2018-04-13 10:25:18 -05:00
2024-10-02 14:34:50 -05:00
function changePage(idx) {
search.page = idx;
2018-04-13 10:25:18 -05:00
}
</script>
<style lang="scss" scoped>
</style>