|
@@ -7,7 +7,7 @@
|
|
|
add-item
|
|
add-item
|
|
|
:show-search-field="false"
|
|
:show-search-field="false"
|
|
|
hide-no-data-label
|
|
hide-no-data-label
|
|
|
- @on-add-item="addMedia"
|
|
|
|
|
|
|
+ @on-add-item="openAddDialog"
|
|
|
>
|
|
>
|
|
|
<template #body-cell-item="{ rowIndex }">
|
|
<template #body-cell-item="{ rowIndex }">
|
|
|
<q-td>{{ rowIndex + 1 }}</q-td>
|
|
<q-td>{{ rowIndex + 1 }}</q-td>
|
|
@@ -20,14 +20,15 @@
|
|
|
dense
|
|
dense
|
|
|
icon="mdi-eye-outline"
|
|
icon="mdi-eye-outline"
|
|
|
class="q-mr-xs"
|
|
class="q-mr-xs"
|
|
|
- @click.stop="viewMedia(row)"
|
|
|
|
|
|
|
+ :disable="!row.file_url"
|
|
|
|
|
+ @click.stop="openFile(row.file_url)"
|
|
|
/>
|
|
/>
|
|
|
<q-btn
|
|
<q-btn
|
|
|
flat
|
|
flat
|
|
|
round
|
|
round
|
|
|
dense
|
|
dense
|
|
|
icon="mdi-trash-can-outline"
|
|
icon="mdi-trash-can-outline"
|
|
|
- @click.stop="deleteMedia(row)"
|
|
|
|
|
|
|
+ @click.stop="confirmDelete(row)"
|
|
|
/>
|
|
/>
|
|
|
</template>
|
|
</template>
|
|
|
</DefaultTable>
|
|
</DefaultTable>
|
|
@@ -35,36 +36,62 @@
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
|
<script setup>
|
|
|
-import { ref } from "vue";
|
|
|
|
|
|
|
+import { ref, onMounted } from "vue";
|
|
|
|
|
+import { useQuasar } from "quasar";
|
|
|
import DefaultTable from "src/components/defaults/DefaultTable.vue";
|
|
import DefaultTable from "src/components/defaults/DefaultTable.vue";
|
|
|
|
|
+import AddStudentMediaDialog from "src/pages/students/components/AddStudentMediaDialog.vue";
|
|
|
|
|
+import { getStudentMedias, deleteStudentMedia } from "src/api/student_media";
|
|
|
|
|
|
|
|
-const rows = ref([
|
|
|
|
|
- { id: 1, date: "23/08/2024", name: "Comprovante de pagamento" },
|
|
|
|
|
- { id: 2, date: "23/08/2024", name: "Certidão de nascimento" },
|
|
|
|
|
- { id: 3, date: "23/08/2024", name: "Comprovante de residência" },
|
|
|
|
|
-]);
|
|
|
|
|
|
|
+const props = defineProps({
|
|
|
|
|
+ studentId: { type: Number, required: true },
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+const $q = useQuasar();
|
|
|
|
|
+const rows = ref([]);
|
|
|
|
|
|
|
|
const columns = [
|
|
const columns = [
|
|
|
{ name: "item", label: "Item", field: "id", align: "left" },
|
|
{ name: "item", label: "Item", field: "id", align: "left" },
|
|
|
- { name: "date", label: "Data", field: "date", align: "left" },
|
|
|
|
|
- {
|
|
|
|
|
- name: "name",
|
|
|
|
|
- label: "Comprovante de pagamento",
|
|
|
|
|
- field: "name",
|
|
|
|
|
- align: "left",
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ { name: "date", label: "Data", field: "created_at", align: "left" },
|
|
|
|
|
+ { name: "name", label: "Nome", field: "name", align: "left" },
|
|
|
{ name: "actions", label: "Ações", field: null, align: "right" },
|
|
{ name: "actions", label: "Ações", field: null, align: "right" },
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
-function addMedia() {
|
|
|
|
|
- // TODO: open upload dialog
|
|
|
|
|
|
|
+async function fetchMedias() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ rows.value = await getStudentMedias(props.studentId);
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ console.error(e);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function openAddDialog() {
|
|
|
|
|
+ $q.dialog({
|
|
|
|
|
+ component: AddStudentMediaDialog,
|
|
|
|
|
+ componentProps: { studentId: props.studentId },
|
|
|
|
|
+ }).onOk((result) => {
|
|
|
|
|
+ rows.value.unshift(result);
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function viewMedia(row) {
|
|
|
|
|
- console.log(row);
|
|
|
|
|
|
|
+function openFile(url) {
|
|
|
|
|
+ window.open(url, "_blank");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function deleteMedia(row) {
|
|
|
|
|
- rows.value = rows.value.filter((r) => r.id !== row.id);
|
|
|
|
|
|
|
+function confirmDelete(row) {
|
|
|
|
|
+ $q.dialog({
|
|
|
|
|
+ title: "Remover mídia",
|
|
|
|
|
+ message: `Deseja remover "${row.name}"?`,
|
|
|
|
|
+ ok: { color: "negative", label: "Remover" },
|
|
|
|
|
+ cancel: { color: "primary", outline: true, label: "Cancelar" },
|
|
|
|
|
+ }).onOk(async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await deleteStudentMedia(row.id);
|
|
|
|
|
+ rows.value = rows.value.filter((r) => r.id !== row.id);
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ console.error(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+onMounted(fetchMedias);
|
|
|
</script>
|
|
</script>
|