|
| 1 | +<template> |
| 2 | + <v-card> |
| 3 | + <v-card-title>{{ object.name || object.value }}</v-card-title> |
| 4 | + <v-card-subtitle>Editing DFIQ {{ object.type }}</v-card-subtitle> |
| 5 | + <v-card-text> |
| 6 | + <v-textarea class="yeti-code" label="DFIQ Yaml" auto-grow v-model="object.dfiq_yaml"></v-textarea> |
| 7 | + </v-card-text> |
| 8 | + |
| 9 | + <v-card-actions> |
| 10 | + <v-btn text="Toggle full screen" color="primary" @click="toggleFullScreen"></v-btn> |
| 11 | + <v-spacer></v-spacer> |
| 12 | + <v-btn text="Cancel" color="cancel" @click="isActive.value = false"></v-btn> |
| 13 | + <v-btn text="Save" color="primary" @click="saveDFIQObject" variant="tonal"></v-btn> |
| 14 | + </v-card-actions> |
| 15 | + <v-alert v-if="errors.length > 0" type="error"> |
| 16 | + Error saving DFIQ {{ object.type }}: |
| 17 | + <ul> |
| 18 | + <li v-for="error in errors"> |
| 19 | + <strong>{{ error.field }}</strong |
| 20 | + >: {{ error.message }} |
| 21 | + </li> |
| 22 | + </ul> |
| 23 | + </v-alert> |
| 24 | + </v-card> |
| 25 | +</template> |
| 26 | + |
| 27 | +<script lang="ts" setup> |
| 28 | +import axios from "axios"; |
| 29 | +
|
| 30 | +import ObjectFields from "@/components/ObjectFields.vue"; |
| 31 | +</script> |
| 32 | + |
| 33 | +<script lang="ts"> |
| 34 | +export default { |
| 35 | + components: { ObjectFields }, |
| 36 | + props: { |
| 37 | + object: { |
| 38 | + type: Object, |
| 39 | + default: () => {} |
| 40 | + }, |
| 41 | + isActive: { |
| 42 | + type: Object, |
| 43 | + default: () => {} |
| 44 | + } |
| 45 | + }, |
| 46 | + data() { |
| 47 | + return { |
| 48 | + localObject: { ...this.object }, |
| 49 | + errors: [], |
| 50 | + fullScreen: false, |
| 51 | + typeToEndpointMapping: { |
| 52 | + entity: "entities", |
| 53 | + observable: "observables", |
| 54 | + indicator: "indicators", |
| 55 | + dfiq: "dfiq" |
| 56 | + } |
| 57 | + }; |
| 58 | + }, |
| 59 | + mounted() {}, |
| 60 | + methods: { |
| 61 | + saveDFIQObject() { |
| 62 | + let patchRequest = { |
| 63 | + dfiq_type: this.object.type, |
| 64 | + dfiq_yaml: this.object.dfiq_yaml |
| 65 | + }; |
| 66 | +
|
| 67 | + axios |
| 68 | + .patch(`/api/v2/dfiq/${this.object.id}`, patchRequest) |
| 69 | + .then(response => { |
| 70 | + this.$eventBus.emit("displayMessage", { |
| 71 | + message: "DFIQ object succesfully updated", |
| 72 | + status: "success" |
| 73 | + }); |
| 74 | + this.$emit("success", response.data); |
| 75 | + this.isActive.value = false; |
| 76 | + }) |
| 77 | + .catch(error => { |
| 78 | + console.log(error); |
| 79 | + this.errors = error.response.data.detail |
| 80 | + .filter(detail => detail.loc[1] !== "type") |
| 81 | + .map(detail => { |
| 82 | + return { field: detail.loc[1], message: detail.msg }; |
| 83 | + }); |
| 84 | + }) |
| 85 | + .finally(); |
| 86 | + }, |
| 87 | + toggleFullScreen() { |
| 88 | + this.fullScreen = !this.fullScreen; |
| 89 | + this.$emit("toggle-fullscreen", this.fullScreen); |
| 90 | + } |
| 91 | + } |
| 92 | +}; |
| 93 | +</script> |
| 94 | + |
| 95 | +<style> |
| 96 | +.yeti-code textarea { |
| 97 | + font-family: monospace; |
| 98 | +} |
| 99 | +</style> |
0 commit comments