|
| 1 | +<script lang="ts"> |
| 2 | +import { |
| 3 | + Ref, computed, defineComponent, onMounted, ref, watch, |
| 4 | +} from 'vue'; |
| 5 | +import { |
| 6 | + AbstractMapLayerListItem, DisplayConfiguration, |
| 7 | +} from '../../types'; |
| 8 | +import UVdatApi from '../../api/UVDATApi'; |
| 9 | +
|
| 10 | +export default defineComponent({ |
| 11 | + name: 'DisplayConfigurationEditor', |
| 12 | + setup() { |
| 13 | + const config: Ref<DisplayConfiguration | null> = ref(null); |
| 14 | + const enabledUiOptions = ['Scenarios', 'Collections', 'Datasets', 'Metadata']; |
| 15 | + const layerTypes = ['netcdf', 'vector', 'raster']; |
| 16 | + const snackbar = ref({ show: false, text: '', color: '' }); |
| 17 | + const layers: Ref<AbstractMapLayerListItem[]> = ref([]); |
| 18 | + const selectedLayers: Ref<string[]> = ref([]); |
| 19 | + onMounted(async () => { |
| 20 | + config.value = await UVdatApi.getDisplayConfiguration(); |
| 21 | + layers.value = await UVdatApi.getMapLayerAll(); |
| 22 | + selectedLayers.value = config.value.default_displayed_layers.map((item) => (`${item.type}_${item.id}`)); |
| 23 | + }); |
| 24 | +
|
| 25 | + watch(() => config.value?.enabled_ui, (newVal) => { |
| 26 | + if (config.value && newVal && !newVal?.includes(config.value.default_tab)) { |
| 27 | + config.value.default_tab = newVal[0] || ''; |
| 28 | + } |
| 29 | + }); |
| 30 | +
|
| 31 | + const availableLayers = computed(() => { |
| 32 | + if (layers.value) { |
| 33 | + return layers.value.map((item) => ({ |
| 34 | + id: item.id, name: item.name, type: item.type, index: `${item.type}_${item.id}`, |
| 35 | + })); |
| 36 | + } |
| 37 | + return []; |
| 38 | + }); |
| 39 | +
|
| 40 | + const saveConfig = async () => { |
| 41 | + try { |
| 42 | + if (config.value) { |
| 43 | + config.value.default_displayed_layers = []; |
| 44 | + selectedLayers.value.forEach((item) => { |
| 45 | + const data = availableLayers.value.find((layer) => layer.index === item); |
| 46 | + if (data) { |
| 47 | + config.value?.default_displayed_layers.push({ id: data.id, name: data.name, type: data.type }); |
| 48 | + } |
| 49 | + }); |
| 50 | + await UVdatApi.updateDisplayConfiguration(config.value); |
| 51 | + } |
| 52 | + snackbar.value = { show: true, text: 'Configuration updated successfully!', color: 'success' }; |
| 53 | + } catch (error) { |
| 54 | + snackbar.value = { show: true, text: 'Failed to update configuration', color: 'error' }; |
| 55 | + } |
| 56 | + }; |
| 57 | +
|
| 58 | + return { |
| 59 | + config, |
| 60 | + enabledUiOptions, |
| 61 | + layerTypes, |
| 62 | + saveConfig, |
| 63 | + snackbar, |
| 64 | + availableLayers, |
| 65 | + selectedLayers, |
| 66 | + }; |
| 67 | + }, |
| 68 | +}); |
| 69 | +</script> |
| 70 | +<template> |
| 71 | + <v-app-bar app> |
| 72 | + <v-btn to="/"> |
| 73 | + <v-icon size="x-large" to="/"> |
| 74 | + mdi-arrow-left |
| 75 | + </v-icon> |
| 76 | + </v-btn> |
| 77 | + </v-app-bar> |
| 78 | + <v-container v-if="config"> |
| 79 | + <v-card> |
| 80 | + <v-card-title>Display Configuration</v-card-title> |
| 81 | + <v-card-text> |
| 82 | + <v-select |
| 83 | + v-model="config.enabled_ui" |
| 84 | + :items="enabledUiOptions" |
| 85 | + label="Enabled UI Features" |
| 86 | + multiple |
| 87 | + chips |
| 88 | + /> |
| 89 | + <v-select |
| 90 | + v-model="config.default_tab" |
| 91 | + :items="config.enabled_ui" |
| 92 | + label="Default Tab" |
| 93 | + /> |
| 94 | + <v-select |
| 95 | + v-model="selectedLayers" |
| 96 | + :items="availableLayers" |
| 97 | + item-title="name" |
| 98 | + item-value="index" |
| 99 | + label="Default Visible Layers" |
| 100 | + multiple |
| 101 | + clearable |
| 102 | + closable-chips |
| 103 | + > |
| 104 | + <template #chip="{ item }"> |
| 105 | + <v-chip> |
| 106 | + {{ item.raw.name }}:{{ item.raw.type }} |
| 107 | + </v-chip> |
| 108 | + </template> |
| 109 | + <template #item="{ item, props }"> |
| 110 | + <v-list-item v-bind="props"> |
| 111 | + {{ item.raw.type }} |
| 112 | + </v-list-item> |
| 113 | + </template> |
| 114 | + </v-select> |
| 115 | + </v-card-text> |
| 116 | + <v-card-actions> |
| 117 | + <v-btn color="primary" @click="saveConfig"> |
| 118 | + Save |
| 119 | + </v-btn> |
| 120 | + </v-card-actions> |
| 121 | + </v-card> |
| 122 | + <v-snackbar v-model="snackbar.show" :color="snackbar.color" timeout="3000"> |
| 123 | + {{ snackbar.text }} |
| 124 | + </v-snackbar> |
| 125 | + </v-container> |
| 126 | +</template> |
| 127 | + |
| 128 | +<style scoped> |
| 129 | +</style> |
0 commit comments