|
| 1 | +<template> |
| 2 | + <v-card |
| 3 | + v-if="all_required_params_are_available" |
| 4 | + elevation="2" |
| 5 | + class="mb-4 mt-4 pa-4 d-flex flex-row flex-grow-0 justify-left failsafe-card" |
| 6 | + > |
| 7 | + <div class="ma-4"> |
| 8 | + <!-- this is theoretically not safe, but we have a command that gives users root access, so... --> |
| 9 | + <!-- eslint-disable vue/no-v-html --> |
| 10 | + <i :class="`${svg_outside_style} svg-icon`" v-html="image" /> |
| 11 | + </div> |
| 12 | + <div class="d-flex flex-column justify-center"> |
| 13 | + <v-card-title> {{ failsafeDefinition.name }}</v-card-title> |
| 14 | + <v-card-text> |
| 15 | + {{ failsafeDefinition.generalDescription }} |
| 16 | + </v-card-text> |
| 17 | + <div> |
| 18 | + <div v-for="param in available_params" :key="param.name"> |
| 19 | + <v-row class="justify-right"> |
| 20 | + <v-col :key="param.name" class="action-col" cols="7"> |
| 21 | + <v-icon v-if="param.icon"> |
| 22 | + {{ param.icon }} |
| 23 | + </v-icon> |
| 24 | + {{ param.replacementTitle ?? param.name }} |
| 25 | + </v-col> |
| 26 | + <v-col :key="`${param.name}-editor`" cols="5" class="pt-1 pb-1"> |
| 27 | + <inline-parameter-editor :key="failsafeDefinition.name" :auto-set="true" :param="params[param.name]" /> |
| 28 | + </v-col> |
| 29 | + </v-row> |
| 30 | + </div> |
| 31 | + </div> |
| 32 | + </div> |
| 33 | + </v-card> |
| 34 | +</template> |
| 35 | + |
| 36 | +<script lang="ts"> |
| 37 | +import axios from 'axios' |
| 38 | +import Vue, { PropType } from 'vue' |
| 39 | +import { Dictionary } from 'vue-router/types/router.js' |
| 40 | +
|
| 41 | +import { FailsafeDefinition, ParamDefinitions } from '@/components/vehiclesetup/configuration/failsafes/types' |
| 42 | +import autopilot_data from '@/store/autopilot' |
| 43 | +import settings from '@/store/settings' |
| 44 | +import Parameter from '@/types/autopilot/parameter' |
| 45 | +
|
| 46 | +export default Vue.extend({ |
| 47 | + name: 'FailsafeCard', |
| 48 | + components: { |
| 49 | + 'inline-parameter-editor': () => import('@/components/parameter-editor/InlineParameterEditor.vue'), |
| 50 | + }, |
| 51 | + props: { |
| 52 | + failsafeDefinition: { |
| 53 | + type: Object as PropType<FailsafeDefinition>, |
| 54 | + required: true, |
| 55 | + }, |
| 56 | +
|
| 57 | + }, |
| 58 | + data() { |
| 59 | + return { |
| 60 | + image: undefined as string | undefined, |
| 61 | + } |
| 62 | + }, |
| 63 | + computed: { |
| 64 | + svg_outside_style(): string { |
| 65 | + return `mr-0 ${settings.is_dark_theme ? 'svg-outline-dark' : 'svg-outline-light'}` |
| 66 | + }, |
| 67 | + params(): Dictionary<Parameter> { |
| 68 | + return autopilot_data.parameters |
| 69 | + .filter((param) => this.failsafeDefinition.params.map((parameter) => parameter.name) |
| 70 | + .includes(param.name)) |
| 71 | + .reduce((dict: Dictionary<Parameter>, param: Parameter) => { |
| 72 | + dict[param.name] = param |
| 73 | + return dict |
| 74 | + }, {}) |
| 75 | + }, |
| 76 | + all_required_params_are_available(): boolean { |
| 77 | + return this.failsafeDefinition.params.every((param) => param.name in this.params || param.optional) |
| 78 | + }, |
| 79 | + available_params(): ParamDefinitions[] { |
| 80 | + return this.failsafeDefinition.params.filter((param) => param.name in this.params) |
| 81 | + }, |
| 82 | + }, |
| 83 | + mounted() { |
| 84 | + this.loadImage() |
| 85 | + }, |
| 86 | + methods: { |
| 87 | + loadImage() { |
| 88 | + axios.get(this.failsafeDefinition.image).then((response) => { |
| 89 | + this.image = response.data |
| 90 | + }) |
| 91 | + }, |
| 92 | + }, |
| 93 | +
|
| 94 | +}) |
| 95 | +</script> |
| 96 | + |
| 97 | +<style> |
| 98 | +
|
| 99 | +i.svg-icon svg { |
| 100 | + height: 100% !important; |
| 101 | + min-width: 180px; |
| 102 | +} |
| 103 | +
|
| 104 | +i.svg-outline-dark path { |
| 105 | + fill: #d1eaf1; |
| 106 | +} |
| 107 | +
|
| 108 | +i.svg-outline-light path { |
| 109 | + fill: #002f45; |
| 110 | +} |
| 111 | +
|
| 112 | +.failsafe-card { |
| 113 | + margin-left: auto; |
| 114 | + margin-right: auto; |
| 115 | + width: 700px; |
| 116 | +} |
| 117 | +
|
| 118 | +.action-col { |
| 119 | + text-align: end; |
| 120 | + margin: auto; |
| 121 | +} |
| 122 | +</style> |
0 commit comments