@@ -6,6 +6,7 @@ import {loadData} from '@/utils/load-data.js';
66
77// import models for pinia-orm
88import { useRepo } from 'pinia-orm' ;
9+ import ApplicationState from '@/models/ApplicationState' ;
910// referencee data
1011import ClimateZone from '@/models/ClimateZone' ;
1112import ControlSchedule from '@/models/ControlSchedule' ;
@@ -48,31 +49,32 @@ const router = createRouter({
4849} )
4950
5051router . beforeEach ( async ( ) => {
51- if ( useRepo ( ClimateZone ) . all ( ) . length === 0 ) { await loadData ( 'http://localhost:5000/vocabularies/climate_zone/items?f=csv' , true ) . then ( ( result ) => { useRepo ( ClimateZone ) . save ( result ) } ) } ;
52- if ( useRepo ( ControlSchedule ) . all ( ) . length === 0 ) { await loadData ( '/data/reference-data/control_schedule.psv' ) . then ( ( result ) => { useRepo ( ControlSchedule ) . save ( result ) } ) } ;
53- if ( useRepo ( Exposure ) . all ( ) . length === 0 ) { await loadData ( 'http://localhost:5000/vocabularies/exposure/items?f=csv' , true ) . then ( ( result ) => { useRepo ( Exposure ) . save ( result ) } ) } ;
54- if ( useRepo ( FacilityType ) . all ( ) . length === 0 ) { await loadData ( 'http://localhost:5000/vocabularies/facility_type/items?f=csv' , true ) . then ( ( result ) => { useRepo ( FacilityType ) . save ( result ) } ) } ;
55- if ( useRepo ( FeatureType ) . all ( ) . length === 0 ) { await loadData ( 'http://localhost:5000/vocabularies/feature_type/items?f=csv' , true ) . then ( ( result ) => { useRepo ( FeatureType ) . save ( result ) } ) } ;
56- if ( useRepo ( MaintenanceSchedule ) . all ( ) . length === 0 ) { await loadData ( '/data/reference-data/maintenance_schedule.psv' ) . then ( ( result ) => { useRepo ( MaintenanceSchedule ) . save ( result ) } ) } ;
57- if ( useRepo ( MediaType ) . all ( ) . length === 0 ) { await loadData ( 'http://localhost:5000/vocabularies/media_type/items?f=csv' , true ) . then ( ( result ) => { useRepo ( MediaType ) . save ( result ) } ) } ;
58- if ( useRepo ( ObservationType ) . all ( ) . length === 0 ) { await loadData ( 'http://localhost:5000/vocabularies/observation_type/items?f=csv' , true ) . then ( ( result ) => { useRepo ( ObservationType ) . save ( result ) } ) } ;
59- if ( useRepo ( ObservedProperty ) . all ( ) . length === 0 ) { await loadData ( 'http://localhost:5000/vocabularies/observed_property/items?f=csv' , true ) . then ( ( result ) => { useRepo ( ObservedProperty ) . save ( result ) } ) } ;
60- if ( useRepo ( ObservingMethod ) . all ( ) . length === 0 ) { await loadData ( 'http://localhost:5000/vocabularies/observing_method/items?f=csv' , true ) . then ( ( result ) => { useRepo ( ObservingMethod ) . save ( result ) } ) } ;
61- if ( useRepo ( ObservingProcedure ) . all ( ) . length === 0 ) { await loadData ( 'http://localhost:5000/vocabularies/observing_procedure/items?f=csv' , true ) . then ( ( result ) => { useRepo ( ObservingProcedure ) . save ( result ) } ) } ;
62- if ( useRepo ( Programme ) . all ( ) . length === 0 ) { await loadData ( 'http://localhost:5000/vocabularies/programme/items?f=csv' , true ) . then ( ( result ) => { useRepo ( Programme ) . save ( result ) } ) } ;
63- if ( useRepo ( ReferenceSurface ) . all ( ) . length === 0 ) { await loadData ( 'http://localhost:5000/vocabularies/reference_surface/items?f=csv' , true ) . then ( ( result ) => { useRepo ( ReferenceSurface ) . save ( result ) } ) } ;
64- if ( useRepo ( Season ) . all ( ) . length === 0 ) { await loadData ( 'http://localhost:5000/vocabularies/season/items?f=csv' , true ) . then ( ( result ) => { useRepo ( Season ) . save ( result ) } ) } ;
65- if ( useRepo ( SourceType ) . all ( ) . length === 0 ) { await loadData ( 'http://localhost:5000/vocabularies/source_type/items?f=csv' , true ) . then ( ( result ) => { useRepo ( SourceType ) . save ( result ) } ) } ;
66- if ( useRepo ( Status ) . all ( ) . length === 0 ) { await loadData ( 'http://localhost:5000/vocabularies/status/items?f=csv' , true ) . then ( ( result ) => { useRepo ( Status ) . save ( result ) } ) } ;
67- if ( useRepo ( SurfaceCover ) . all ( ) . length === 0 ) { await loadData ( 'http://localhost:5000/vocabularies/surface_cover/items?f=csv' , true ) . then ( ( result ) => { useRepo ( SurfaceCover ) . save ( result ) } ) } ;
68- if ( useRepo ( SurfaceRoughness ) . all ( ) . length === 0 ) { await loadData ( 'http://localhost:5000/vocabularies/surface_roughness/items?f=csv' , true ) . then ( ( result ) => { useRepo ( SurfaceRoughness ) . save ( result ) } ) } ;
69- if ( useRepo ( Territory ) . all ( ) . length === 0 ) { await loadData ( 'http://localhost:5000/vocabularies/territory/items?f=csv' , true ) . then ( ( result ) => { useRepo ( Territory ) . save ( result ) } ) } ;
70- if ( useRepo ( TimeZone ) . all ( ) . length === 0 ) { await loadData ( 'http://localhost:5000/vocabularies/time_zone/items?f=csv' , true ) . then ( ( result ) => { useRepo ( TimeZone ) . save ( result ) } ) } ;
71- if ( useRepo ( Topography ) . all ( ) . length === 0 ) { await loadData ( 'http://localhost:5000/vocabularies/topography/items?f=csv' , true ) . then ( ( result ) => { useRepo ( Topography ) . save ( result ) } ) } ;
72- if ( useRepo ( WmoRegion ) . all ( ) . length === 0 ) { await loadData ( 'http://localhost:5000/vocabularies/wmo_region/items?f=csv' , true ) . then ( ( result ) => { useRepo ( WmoRegion ) . save ( result ) } ) } ;
73- if ( useRepo ( User ) . all ( ) . length === 0 ) { await loadData ( 'http://localhost:5000/vocabularies/user/items?f=csv' , true ) . then ( ( result ) => { useRepo ( User ) . save ( result ) } ) } ;
74- if ( useRepo ( Host ) . all ( ) . length === 0 ) { await loadData ( 'http://localhost:5000/collections/stations/items?f=json' , true ) . then ( ( result ) => flatten_geojson ( result . features ) ) . then ( ( result ) => { useRepo ( Host ) . save ( result ) } ) } ;
75- if ( useRepo ( Feature ) . all ( ) . length === 0 ) { await loadData ( '/data/features.psv' ) . then ( ( result ) => { useRepo ( Feature ) . save ( result ) } ) } ;
52+ if ( useRepo ( ClimateZone ) . all ( ) . length === 0 ) { await loadData ( process . env . API + '/vocabularies/climate_zone/items?f=csv' , true ) . then ( ( result ) => { useRepo ( ClimateZone ) . save ( result ) } ) } ;
53+ if ( useRepo ( ControlSchedule ) . all ( ) . length === 0 ) { await loadData ( '/data/reference-data/control_schedule.psv' ) . then ( ( result ) => { useRepo ( ControlSchedule ) . save ( result ) } ) } ; // TODO
54+ if ( useRepo ( Exposure ) . all ( ) . length === 0 ) { await loadData ( process . env . API + '/vocabularies/exposure/items?f=csv' , true ) . then ( ( result ) => { useRepo ( Exposure ) . save ( result ) } ) } ;
55+ if ( useRepo ( FacilityType ) . all ( ) . length === 0 ) { await loadData ( process . env . API + '/vocabularies/facility_type/items?f=csv' , true ) . then ( ( result ) => { useRepo ( FacilityType ) . save ( result ) } ) } ;
56+ if ( useRepo ( FeatureType ) . all ( ) . length === 0 ) { await loadData ( process . env . API + '/vocabularies/feature_type/items?f=csv' , true ) . then ( ( result ) => { useRepo ( FeatureType ) . save ( result ) } ) } ;
57+ if ( useRepo ( MaintenanceSchedule ) . all ( ) . length === 0 ) { await loadData ( '/data/reference-data/maintenance_schedule.psv' ) . then ( ( result ) => { useRepo ( MaintenanceSchedule ) . save ( result ) } ) } ; // TODO
58+ if ( useRepo ( MediaType ) . all ( ) . length === 0 ) { await loadData ( process . env . API + '/vocabularies/media_type/items?f=csv' , true ) . then ( ( result ) => { useRepo ( MediaType ) . save ( result ) } ) } ;
59+ if ( useRepo ( ObservationType ) . all ( ) . length === 0 ) { await loadData ( process . env . API + '/vocabularies/observation_type/items?f=csv' , true ) . then ( ( result ) => { useRepo ( ObservationType ) . save ( result ) } ) } ;
60+ if ( useRepo ( ObservedProperty ) . all ( ) . length === 0 ) { await loadData ( process . env . API + '/vocabularies/observed_property/items?f=csv' , true ) . then ( ( result ) => { useRepo ( ObservedProperty ) . save ( result ) } ) } ;
61+ if ( useRepo ( ObservingMethod ) . all ( ) . length === 0 ) { await loadData ( process . env . API + '/vocabularies/observing_method/items?f=csv' , true ) . then ( ( result ) => { useRepo ( ObservingMethod ) . save ( result ) } ) } ;
62+ if ( useRepo ( ObservingProcedure ) . all ( ) . length === 0 ) { await loadData ( process . env . API + '/vocabularies/observing_procedure/items?f=csv' , true ) . then ( ( result ) => { useRepo ( ObservingProcedure ) . save ( result ) } ) } ;
63+ if ( useRepo ( Programme ) . all ( ) . length === 0 ) { await loadData ( process . env . API + '/vocabularies/programme/items?f=csv' , true ) . then ( ( result ) => { useRepo ( Programme ) . save ( result ) } ) } ;
64+ if ( useRepo ( ReferenceSurface ) . all ( ) . length === 0 ) { await loadData ( process . env . API + '/vocabularies/reference_surface/items?f=csv' , true ) . then ( ( result ) => { useRepo ( ReferenceSurface ) . save ( result ) } ) } ;
65+ if ( useRepo ( Season ) . all ( ) . length === 0 ) { await loadData ( process . env . API + '/vocabularies/season/items?f=csv' , true ) . then ( ( result ) => { useRepo ( Season ) . save ( result ) } ) } ;
66+ if ( useRepo ( SourceType ) . all ( ) . length === 0 ) { await loadData ( process . env . API + '/vocabularies/source_type/items?f=csv' , true ) . then ( ( result ) => { useRepo ( SourceType ) . save ( result ) } ) } ;
67+ if ( useRepo ( Status ) . all ( ) . length === 0 ) { await loadData ( process . env . API + '/vocabularies/status/items?f=csv' , true ) . then ( ( result ) => { useRepo ( Status ) . save ( result ) } ) } ;
68+ if ( useRepo ( SurfaceCover ) . all ( ) . length === 0 ) { await loadData ( process . env . API + '/vocabularies/surface_cover/items?f=csv' , true ) . then ( ( result ) => { useRepo ( SurfaceCover ) . save ( result ) } ) } ;
69+ if ( useRepo ( SurfaceRoughness ) . all ( ) . length === 0 ) { await loadData ( process . env . API + '/vocabularies/surface_roughness/items?f=csv' , true ) . then ( ( result ) => { useRepo ( SurfaceRoughness ) . save ( result ) } ) } ;
70+ if ( useRepo ( Territory ) . all ( ) . length === 0 ) { await loadData ( process . env . API + '/vocabularies/territory/items?f=csv' , true ) . then ( ( result ) => { useRepo ( Territory ) . save ( result ) } ) } ;
71+ if ( useRepo ( TimeZone ) . all ( ) . length === 0 ) { await loadData ( process . env . API + '/vocabularies/time_zone/items?f=csv' , true ) . then ( ( result ) => { useRepo ( TimeZone ) . save ( result ) } ) } ;
72+ if ( useRepo ( Topography ) . all ( ) . length === 0 ) { await loadData ( process . env . API + '/vocabularies/topography/items?f=csv' , true ) . then ( ( result ) => { useRepo ( Topography ) . save ( result ) } ) } ;
73+ if ( useRepo ( WmoRegion ) . all ( ) . length === 0 ) { await loadData ( process . env . API + '/vocabularies/wmo_region/items?f=csv' , true ) . then ( ( result ) => { useRepo ( WmoRegion ) . save ( result ) } ) } ;
74+ if ( useRepo ( User ) . all ( ) . length === 0 ) { await loadData ( process . env . API + '/vocabularies/user/items?f=csv' , true ) . then ( ( result ) => { useRepo ( User ) . save ( result ) } ) } ;
75+ if ( useRepo ( Host ) . all ( ) . length === 0 ) { await loadData ( process . env . API + '/collections/stations/items?f=json' , true ) . then ( ( result ) => flatten_geojson ( result . features ) ) . then ( ( result ) => { useRepo ( Host ) . save ( result ) } ) } ;
76+ if ( useRepo ( Feature ) . all ( ) . length === 0 ) { await loadData ( '/data/features.psv' ) . then ( ( result ) => { useRepo ( Feature ) . save ( result ) } ) } ; // TODO
77+ useRepo ( ApplicationState ) . save ( { 'key' : 'databaseReady' , 'value' : 'ready' } )
7678} ) ;
7779
7880export default router
0 commit comments