|
| 1 | +<template> |
| 2 | + <v-container> |
| 3 | + <v-card> |
| 4 | + <v-card-title>Import station from OSCAR/Surface</v-card-title> |
| 5 | + <v-card-text> |
| 6 | + <v-form> |
| 7 | + <v-text-field clearable :rules="[rules.validWSI]" label="WIGOS Identifier" v-model="wigos_identifier"/> |
| 8 | + <v-btn @click="search">Search</v-btn> |
| 9 | + </v-form> |
| 10 | + </v-card-text> |
| 11 | + </v-card> |
| 12 | + </v-container> |
| 13 | +</template> |
| 14 | + |
| 15 | +<script> |
| 16 | + import { defineComponent, ref, watchEffect, computed, watch } from 'vue'; |
| 17 | + import { VCard, VCardTitle, VCardText, VCardItem, VTabs, VTab, VBtn, VAutocomplete, VCardSubtitle, VTextField } from 'vuetify/lib/components'; |
| 18 | + import { VContainer, VForm } from 'vuetify/lib/components'; |
| 19 | +
|
| 20 | + // opencdms imports |
| 21 | + import Host from '@/models/Host'; |
| 22 | + import {flatten_geojson} from '@/utils/geojson.js'; |
| 23 | + import {loadData} from '@/utils/load-data.js'; |
| 24 | + import { useRoute, useRouter } from 'vue-router'; |
| 25 | + import {useRepo} from 'pinia-orm'; |
| 26 | +
|
| 27 | +
|
| 28 | + export default defineComponent({ |
| 29 | + name: 'import-wmdr-host', |
| 30 | + components: { |
| 31 | + VContainer, VBtn, VForm, VTextField, |
| 32 | + VCard, VCardTitle, VCardText |
| 33 | + }, |
| 34 | + setup(props, {context}){ |
| 35 | + const router = useRouter(); |
| 36 | + const wigos_identifier = ref(""); |
| 37 | + const rules = ref({ |
| 38 | + validWSI: value => /^0-[0-9]{1,5}-[0-9]{0,5}-[0-9a-zA-Z]{1,16}$/.test(value) || 'Invalid WSI', |
| 39 | + }); |
| 40 | +
|
| 41 | + const search = async () => { |
| 42 | + //var oscar_url = "https://oscar.wmo.int/surface/rest/api/search/station?wigosId="; |
| 43 | + //var query = oscar_url + wigos_identifier.value; |
| 44 | + //console.log(query); |
| 45 | + //var stations = await fetch(query).then(response => response.json()); |
| 46 | + //console.log(stations); |
| 47 | + var payload = { |
| 48 | + "inputs": { |
| 49 | + WIGOS_identifier: wigos_identifier.value |
| 50 | + }, |
| 51 | + "outputs": { |
| 52 | + "status": null |
| 53 | + } |
| 54 | + } |
| 55 | + payload = JSON.stringify(payload); |
| 56 | + var url_ = process.env.API + "/processes/ingestHost/execution" |
| 57 | + var response = await fetch( url_, { |
| 58 | + method: 'POST', |
| 59 | + body: payload, |
| 60 | + headers: { |
| 61 | + encode: 'json' |
| 62 | + } |
| 63 | + }); |
| 64 | +
|
| 65 | + if(response.ok){ |
| 66 | + // reload host |
| 67 | + await loadData(process.env.API + '/collections/stations/items?limit=1000&f=json', true) |
| 68 | + .then( (result) => flatten_geojson(result.features) ).then( (result) => { useRepo(Host).save(result) }); |
| 69 | + var station_url = '#/station/' + wigos_identifier.value; |
| 70 | + router.push('/station/'+wigos_identifier.value); |
| 71 | + }else{ |
| 72 | + console.log(response); |
| 73 | + } |
| 74 | + }; |
| 75 | + return {rules, search, wigos_identifier}; |
| 76 | + } |
| 77 | + }); |
| 78 | +
|
| 79 | +
|
| 80 | +</script> |
0 commit comments