Skip to content

Commit

Permalink
Add button and endpoints to delete objects (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchop authored Mar 21, 2024
1 parent 5ee722e commit 2a33a9a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
33 changes: 32 additions & 1 deletion src/components/EditObject.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<v-card-actions>
<v-btn text="Toggle full screen" color="primary" @click="toggleFullScreen"></v-btn>
<v-spacer></v-spacer>
<v-btn text="Delete object" color="cancel" variant="tonal" @click="dialogDelete = true"></v-btn>
<v-btn text="Cancel" color="cancel" @click="isActive.value = false"></v-btn>
<v-btn text="Save" color="primary" @click="saveObject" variant="tonal"></v-btn>
</v-card-actions>
Expand All @@ -21,6 +22,17 @@
</li>
</ul>
</v-alert>
<v-dialog v-model="dialogDelete" max-width="420px">
<v-card>
<v-card-title class="text-h6">Are you sure you want to delete this item?</v-card-title>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="light" variant="text" @click="dialogDelete = false">Cancel</v-btn>
<v-btn color="error" variant="flat" @click="deleteObject">Delete</v-btn>
<v-spacer></v-spacer>
</v-card-actions>
</v-card>
</v-dialog>
</v-card>
</template>

Expand Down Expand Up @@ -57,7 +69,8 @@ export default {
observable: "observables",
indicator: "indicators",
dfiq: "dfiq"
}
},
dialogDelete: false
};
},
mounted() {},
Expand Down Expand Up @@ -94,6 +107,24 @@ export default {
})
.finally();
},
deleteObject() {
axios
.delete(`/api/v2/${this.typeToEndpointMapping[this.object.root_type]}/${this.object.id}`)
.then(response => {
this.$eventBus.emit("displayMessage", {
message: `${this.object.name || "Observable"} succesfully deleted`,
status: "success"
});
this.$emit("success", response.data);
this.isActive.value = false;
this.$router.replace({ path: `/${this.typeToEndpointMapping[this.object.root_type]}` });
})
.catch(error => {
this.errors = [{ field: "details", message: error.response.data.detail }];
return;
})
.finally();
},
toggleFullScreen() {
this.fullScreen = !this.fullScreen;
this.$emit("toggle-fullscreen", this.fullScreen);
Expand Down
5 changes: 0 additions & 5 deletions src/views/ExportTemplates.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@
<template v-slot:item.name="{ item }">
<v-btn variant="plain" density="compact" @click="editTemplate(item)">{{ item.name }}</v-btn>
</template>

<template v-slot:item.actions="{ item }">
<v-icon size="small" class="me-2" @click="editTemplate(item)"> mdi-pencil </v-icon>
<v-icon size="small" @click="deleteTemplate(item)"> mdi-delete </v-icon>
</template>
</v-data-table>
<v-btn-group rounded="1" density="compact">
<v-btn color="primary" @click="newTemplate">New template</v-btn>
Expand Down

0 comments on commit 2a33a9a

Please sign in to comment.