2018-03-30 14:31:09 -05:00
|
|
|
<template>
|
2018-04-07 10:54:56 -05:00
|
|
|
<div>
|
|
|
|
<div class="buttons">
|
|
|
|
<button type="button" class="button is-primary" @click="addNote">Add Note</button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<app-modal title="Add Note" :open="editNote !== null" @dismiss="cancelNote">
|
|
|
|
<note-edit v-if="editNote !== null" :note="editNote" @save="saveNote" @cancel="cancelNote"></note-edit>
|
|
|
|
</app-modal>
|
|
|
|
|
|
|
|
<table class="table">
|
2024-09-28 20:58:25 -05:00
|
|
|
<thead>
|
2018-04-07 10:54:56 -05:00
|
|
|
<tr>
|
|
|
|
<th>Note</th>
|
|
|
|
<th>Date</th>
|
|
|
|
<th></th>
|
|
|
|
</tr>
|
2024-09-28 20:58:25 -05:00
|
|
|
</thead>
|
2018-04-07 10:54:56 -05:00
|
|
|
|
2024-09-28 20:58:25 -05:00
|
|
|
<tbody>
|
2018-04-07 10:54:56 -05:00
|
|
|
<tr v-for="n in notes" :key="n.id">
|
|
|
|
<td>
|
|
|
|
{{ n.content }}
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<app-date-time :date-time="n.created_at"></app-date-time>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<button type="button" class="button is-danger" @click="deleteNote(n)">
|
|
|
|
<app-icon icon="x"></app-icon>
|
|
|
|
</button>
|
|
|
|
</td>
|
|
|
|
</tr>
|
2024-09-28 20:58:25 -05:00
|
|
|
</tbody>
|
2018-04-07 10:54:56 -05:00
|
|
|
|
|
|
|
</table>
|
|
|
|
</div>
|
2018-03-30 14:31:09 -05:00
|
|
|
|
|
|
|
</template>
|
|
|
|
|
2024-10-02 14:34:50 -05:00
|
|
|
<script setup>
|
2018-03-30 14:31:09 -05:00
|
|
|
|
2024-10-02 14:34:50 -05:00
|
|
|
import { onBeforeMount, ref } from "vue";
|
2018-04-07 10:54:56 -05:00
|
|
|
import api from "../lib/Api";
|
|
|
|
import NoteEdit from "./NoteEdit";
|
2024-10-02 14:34:50 -05:00
|
|
|
import { useLoadResource } from "../lib/useLoadResource";
|
2018-04-07 10:54:56 -05:00
|
|
|
|
2024-10-02 14:34:50 -05:00
|
|
|
const { loadResource } = useLoadResource();
|
|
|
|
const notes = ref([]);
|
|
|
|
const editNote = ref(null);
|
|
|
|
|
|
|
|
onBeforeMount(() => {
|
|
|
|
refreshList();
|
|
|
|
});
|
|
|
|
|
|
|
|
function refreshList() {
|
|
|
|
loadResource(
|
|
|
|
api.getNoteList()
|
|
|
|
.then(data => notes.value = data)
|
|
|
|
);
|
|
|
|
}
|
2018-04-07 10:54:56 -05:00
|
|
|
|
2024-10-02 14:34:50 -05:00
|
|
|
function addNote() {
|
|
|
|
editNote.value = { id: null, content: "" };
|
|
|
|
}
|
2018-04-07 10:54:56 -05:00
|
|
|
|
2024-10-02 14:34:50 -05:00
|
|
|
function saveNote() {
|
|
|
|
loadResource(
|
|
|
|
api.postNote(editNote.value)
|
2018-04-07 10:54:56 -05:00
|
|
|
.then(() => {
|
2024-10-02 14:34:50 -05:00
|
|
|
editNote.value = null;
|
|
|
|
return refreshList();
|
2018-04-07 10:54:56 -05:00
|
|
|
})
|
2024-10-02 14:34:50 -05:00
|
|
|
);
|
|
|
|
}
|
2018-04-07 10:54:56 -05:00
|
|
|
|
2024-10-02 14:34:50 -05:00
|
|
|
function cancelNote() {
|
|
|
|
editNote.value = null;
|
|
|
|
}
|
2018-03-30 14:31:09 -05:00
|
|
|
|
2024-10-02 14:34:50 -05:00
|
|
|
function deleteNote(n) {
|
|
|
|
loadResource(
|
|
|
|
api.deleteNote(n)
|
|
|
|
.then(() => {
|
|
|
|
return refreshList();
|
|
|
|
})
|
|
|
|
);
|
2018-03-30 14:31:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
</style>
|