|
1 | 1 | <template> |
2 | | - <v-card> |
3 | | - <v-card-title>{{ title }}</v-card-title> |
4 | | - <v-card-text>{{ content }}</v-card-text> |
5 | | - <v-card-text>{{ description }}</v-card-text> |
6 | | - </v-card> |
| 2 | +<v-container> |
| 3 | + <v-row> |
| 4 | + <v-col :cols="12"> |
| 5 | + <v-card> |
| 6 | + <v-card-title>Select station</v-card-title> |
| 7 | + <v-card-text><select-host v-model="selectedHost"/></v-card-text> |
| 8 | + </v-card> |
| 9 | + </v-col> |
| 10 | + </v-row> |
| 11 | + |
| 12 | + <v-row> |
| 13 | + </v-row> |
| 14 | + |
| 15 | + <v-row v-if='host'> |
| 16 | + <v-col :cols="12"> |
| 17 | + <v-card> |
| 18 | + <v-card-title>Select from available data for {{ $route.params.id }}</v-card-title> |
| 19 | + |
| 20 | + <v-card-item> |
| 21 | + <v-container> |
| 22 | + <v-row style="height: 400px;"> |
| 23 | + <v-col :cols="4"><select-observed-property/></v-col> |
| 24 | + <v-col :cols="4"><VueDatePicker :enable-time-picker="false" label="phenomenon_start" v-model="start_date" hint="Phenomenon start date" persistent-hint></VueDatePicker></v-col> |
| 25 | + <v-col :cols="4"><VueDatePicker :enable-time-picker="false" label="phenomenon_end" v-model="end_date" hint="Phenomenon end date" persistent-hint></VueDatePicker></v-col> |
| 26 | + </v-row> |
| 27 | + </v-container> |
| 28 | + </v-card-item> |
| 29 | + |
| 30 | + </v-card> |
| 31 | + </v-col> |
| 32 | + </v-row> |
| 33 | + |
| 34 | +</v-container> |
| 35 | + |
| 36 | + |
7 | 37 | </template> |
8 | 38 |
|
9 | 39 | <script> |
10 | | -import { defineComponent } from 'vue'; |
11 | | -import { VCard, VCardTitle, VCardText } from 'vuetify/lib/components'; |
| 40 | +import { defineComponent, ref, watchEffect, computed, watch } from 'vue'; |
| 41 | +import { VCard, VCardTitle, VCardText, VCardItem, VTabs, VTab, VBtn, VAutocomplete } from 'vuetify/lib/components'; |
| 42 | +import { VContainer, VCol, VRow } from 'vuetify/lib/components'; |
12 | 43 | import { onBeforeMount, onMounted, onBeforeUpdate, onUpdated, onBeforeUnmount, onUnmounted, onErrorCaptured} from 'vue'; |
| 44 | +import { useRoute, useRouter } from 'vue-router'; |
| 45 | +
|
| 46 | +import {useRepo} from 'pinia-orm'; |
| 47 | +
|
| 48 | +import SelectHost from '@/web-components/pickers/select-host.vue'; |
| 49 | +import SelectObservedProperty from '@/web-components/pickers/select-observed-property.vue'; |
| 50 | +import VueDatePicker from '@vuepic/vue-datepicker'; |
| 51 | +//import VueDatePicker from '@/web-components/pickers/date-picker.vue'; |
| 52 | +import '@vuepic/vue-datepicker/dist/main.css'; |
| 53 | +
|
| 54 | +const start_date = ref(); |
| 55 | +const end_date = ref(); |
| 56 | +
|
| 57 | +// opencdms imports |
| 58 | +import Host from '@/models/Host'; |
| 59 | +
|
13 | 60 | export default defineComponent({ |
14 | | - name: 'data-station', |
15 | | - props: { |
16 | | - title: { |
17 | | - type: String, |
18 | | - required: true, |
19 | | - }, |
20 | | - content: { |
21 | | - type: String, |
22 | | - required: true, |
23 | | - }, |
24 | | - description: { |
25 | | - type: String, |
26 | | - required: true, |
27 | | - } |
28 | | - }, |
| 61 | + name: 'station', |
29 | 62 | components: { |
30 | 63 | VCard, |
31 | 64 | VCardTitle, |
32 | 65 | VCardText, |
| 66 | + VCardItem, |
| 67 | + VTabs, |
| 68 | + VTab, |
| 69 | + VBtn, |
| 70 | + VAutocomplete, VContainer, VCol, VRow, |
| 71 | + SelectHost, |
| 72 | + SelectObservedProperty, |
| 73 | + VueDatePicker |
33 | 74 | }, |
34 | 75 | methods: {}, |
35 | | - setup() { |
36 | | - // lifecycle hooks |
37 | | - onBeforeMount( () => { |
38 | | - // This hook is called before the component is mounted to the DOM. |
39 | | - // This is a good place to do any necessary setup before the component is visible. |
40 | | - }); |
41 | | - onMounted( () => { |
42 | | - // This hook is called after the component is mounted to the DOM. |
43 | | - // This is a good place to perform any necessary DOM manipulations, initialize |
44 | | - // third-party libraries, or set up event listeners. |
45 | | - }); |
46 | | - onBeforeUpdate( () => { |
47 | | - // This hook is called when a component's data changes, but before the DOM is re-rendered. |
48 | | - // This is a good place to make any necessary calculations or changes before the component |
49 | | - // is updated. |
50 | | - }); |
51 | | - onUpdated( () => { |
52 | | - // This hook is called after the component is updated and the DOM is re-rendered. |
53 | | - // This is a good place to perform any necessary DOM manipulations or update third-party |
54 | | - // libraries. |
55 | | - }); |
56 | | - onBeforeUnmount( () => { |
57 | | - // This hook is called before the component is unmounted from the DOM. |
58 | | - // This is a good place to clean up any resources or event listeners that were set up in |
59 | | - // onMounted. |
| 76 | + setup(props) { |
| 77 | + // set up varaiables |
| 78 | + const selectedHost = ref(null) |
| 79 | + const router = useRouter(); |
| 80 | + const geom = ref(null); |
| 81 | + // set up repos |
| 82 | + const hostRepo = useRepo(Host); |
| 83 | + const hostOptions = computed(() => { return hostRepo.all() }); |
| 84 | + const host = ref(null) |
| 85 | +
|
| 86 | + const edit = () => { |
| 87 | + router.push('/data/station/'+route.params.id+'/edit'); |
| 88 | + }; |
| 89 | +
|
| 90 | + const fetchRecord = async(identifier) => { |
| 91 | + // load selected host |
| 92 | + host.value = useRepo(Host).where('id',route.params.id).first(); |
| 93 | + } |
| 94 | +
|
| 95 | + // add watch to update the geom |
| 96 | + watch(host, (newVal) => { |
| 97 | + if( newVal ){ |
| 98 | + const coords = newVal.location.match(/POINT\(([-\d\.]+)\s+([-\d\.]+)\)/); |
| 99 | + const latlng = [parseFloat(coords[1]), parseFloat(coords[2])]; |
| 100 | + geom.value = { |
| 101 | + type: 'Feature', |
| 102 | + geometry: { |
| 103 | + type: 'Point', |
| 104 | + coordinates: latlng |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | + console.log(geom.value) |
60 | 109 | }); |
61 | | - onUnmounted( () => { |
62 | | - // This hook is called after the component is unmounted from the DOM. |
63 | | - // This is a good place to perform any final cleanup or tear down of resources. |
| 110 | +
|
| 111 | + const route = useRoute(); |
| 112 | + const data = ref([]); |
| 113 | +
|
| 114 | +
|
| 115 | + onMounted( async() => { |
| 116 | + fetchRecord( route.params.id ); |
| 117 | + watchEffect( () => { |
| 118 | + fetchRecord( route.params.id ); |
| 119 | + }); |
| 120 | + watch( (selectedHost), (data) => { |
| 121 | + router.push('/data/station/'+data.id); |
| 122 | + } ) |
64 | 123 | }); |
65 | 124 | onErrorCaptured( () => {}); |
| 125 | + return {host, edit, hostOptions, selectedHost, geom}; |
66 | 126 | } |
67 | 127 |
|
68 | 128 | }); |
| 129 | +
|
69 | 130 | </script> |
0 commit comments