|
1 | 1 | <script setup lang="ts"> |
2 | 2 | import type { CRU, Field, FieldOptionUpdate, FieldUpdate, Type } from "facilmap-types"; |
3 | | - import { canControl, formatCheckboxValue, mergeObject } from "facilmap-utils"; |
| 3 | + import { canControl, formatCheckboxValue, getDefaultFieldShowInLegend, mergeObject } from "facilmap-utils"; |
4 | 4 | import { getUniqueId } from "../../utils/utils"; |
5 | 5 | import { cloneDeep, isEqual } from "lodash-es"; |
6 | 6 | import ColourPicker from "../ui/colour-picker.vue"; |
|
124 | 124 |
|
125 | 125 | const columns = computed(() => controlNumber.value + (fieldValue.value.type === "checkbox" ? 2 : 3)); |
126 | 126 |
|
| 127 | + const defaultShowInLegend = computed(() => getDefaultFieldShowInLegend(props.type, fieldValue.value)); |
| 128 | +
|
| 129 | + const showInLegend = computed({ |
| 130 | + get: () => fieldValue.value.showInLegend ?? defaultShowInLegend.value, |
| 131 | + set: (v) => { |
| 132 | + if (v === defaultShowInLegend.value) { |
| 133 | + delete fieldValue.value.showInLegend; |
| 134 | + } else { |
| 135 | + fieldValue.value.showInLegend = v; |
| 136 | + } |
| 137 | + } |
| 138 | + }); |
| 139 | +
|
| 140 | + watch(defaultShowInLegend, () => { |
| 141 | + delete fieldValue.value.showInLegend; |
| 142 | + }); |
| 143 | +
|
127 | 144 | function validateOptionValue(value: string): string | undefined { |
128 | 145 | if (fieldValue.value.type !== "checkbox" && fieldValue.value.options!.filter((op) => op.value === value).length > 1) { |
129 | 146 | return i18n.t("edit-type-dropdown-dialog.unique-value-error"); |
|
257 | 274 | {{i18n.t("edit-type-dropdown-dialog.control-stroke", { type: typeInterpolation })}} |
258 | 275 | </label> |
259 | 276 | </div> |
| 277 | + |
| 278 | + <div v-if="type.showInLegend" class="form-check"> |
| 279 | + <input |
| 280 | + :id="`${id}-showInLegend`" |
| 281 | + class="form-check-input" |
| 282 | + type="checkbox" |
| 283 | + v-model="showInLegend" |
| 284 | + /> |
| 285 | + <label |
| 286 | + class="form-check-label" |
| 287 | + :for="`${id}-showInLegend`" |
| 288 | + > |
| 289 | + {{i18n.t("edit-type-dropdown-dialog.show-in-legend")}} |
| 290 | + </label> |
| 291 | + </div> |
260 | 292 | </div> |
261 | 293 | </div> |
262 | | - <table v-if="fieldValue.type != 'checkbox' || controlNumber > 0" class="table table-striped table-hover"> |
| 294 | + <table v-if="fieldValue.type != 'checkbox' || controlNumber > 0 || showInLegend" class="table table-striped table-hover"> |
263 | 295 | <thead> |
264 | 296 | <tr> |
265 | 297 | <th>{{i18n.t("edit-type-dropdown-dialog.option")}}</th> |
266 | | - <th v-if="fieldValue.type == 'checkbox'">{{i18n.t("edit-type-dropdown-dialog.label")}}</th> |
| 298 | + <th v-if="fieldValue.type == 'checkbox' && showInLegend">{{i18n.t("edit-type-dropdown-dialog.label")}}</th> |
267 | 299 | <th v-if="fieldValue.controlColour">{{i18n.t("edit-type-dropdown-dialog.colour")}}</th> |
268 | 300 | <th v-if="fieldValue.controlSize">{{i18n.t("edit-type-dropdown-dialog.size")}}</th> |
269 | 301 | <th v-if="fieldValue.controlIcon">{{i18n.t("edit-type-dropdown-dialog.icon")}}</th> |
|
286 | 318 | <strong>{{formatCheckboxValue(idx === 0 ? "0" : "1")}}</strong> |
287 | 319 | </td> |
288 | 320 | <ValidatedField |
| 321 | + v-if="fieldValue.type !== 'checkbox' || showInLegend" |
289 | 322 | tag="td" |
290 | 323 | class="field position-relative" |
291 | 324 | :value="option.value" |
|
0 commit comments