Skip to content

Commit

Permalink
Removal of redundant code.
Browse files Browse the repository at this point in the history
  • Loading branch information
david-i-berry committed Sep 15, 2023
1 parent a6ecb4a commit b333176
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 86 deletions.
6 changes: 3 additions & 3 deletions webapp/src/components/ImportOSCAR.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<v-text-field :rules="[rules.validWSI]" v-model="wsi" label="WIGOS Station Identifier" hint="Enter WIGOS Station Identifier" persistent-hint/>
<!-- <v-text-field v-model="token" type="password" clearable label="Auth token"/> -->
<v-card-actions align="center">
<v-btn @click="submit">Submit</v-btn>
<v-btn @click="submit">Search</v-btn>
</v-card-actions>
</v-form>
</v-card-item>
Expand Down Expand Up @@ -234,8 +234,8 @@
console.log(station.value);
}else if(data.value.error){
redirectMessage.value = "Station not found in OSCAR, unable to import," +
"please register station in OSCAR/Surface and try again." ;
redirectMessage.value = "Station not found in OSCAR, unable to import." +
" Please register station in OSCAR/Surface and try again." ;
redirectWarning.value = "For development and testing purposes stations can be created directly." +
"To add a new station to the WIS2box please click the 'create new station' button";
showRedirect.value = true;
Expand Down
84 changes: 1 addition & 83 deletions webapp/src/components/StationEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
hint="Enter the WIGOS station identifier" persistent-hint>
</v-text-field>
</v-card-item>
<!--<v-card-item v-if="(!readonly) && (!route.params.id)">
<v-btn elevation=2 @click="importOSCAR">Import from OSCAR/Surface</v-btn>
</v-card-item>
-->
<v-card-item>
<v-text-field
label="Traditional station identifier"
Expand Down Expand Up @@ -156,10 +152,6 @@
const token = ref(null);
const formValid = ref(null);
const selectedFacilityType = ref(null);
// define validation rules
const rules = ref({
validWSI: value => /^0-[0-9]{1,5}-[0-9]{0,5}-[0-9a-zA-Z]{1,16}$/.test(value) || 'Invalid WSI',
Expand Down Expand Up @@ -359,83 +351,9 @@
}
})
const importOSCAR = async () => {
if( station.value.properties.wigos_station_identifier ){
const apiURL = `${import.meta.env.VITE_API_URL}/processes/wis2box-oscar2feature/execution`;
// fetch via process
const payload = {
"inputs": {
"wigos_station_identifier": station.value.properties.wigos_station_identifier
}
}
try {
const response = await fetch(
apiURL, {
method: 'POST',
headers: {
'encode': 'json',
'Content-Type': 'application/json',
'authorization': 'Bearer '+ token.value
},
body: JSON.stringify(payload)
}
);
if( ! response.ok ){
console.log( response );
errorMessage.value = "Error fetching form OSCAR/Surface: " + response.status;
showDialog.value = true;
}else{
console.log( response );
const data = await response.json();
console.log(data)
// this is currently broken, the drop down selectors are not updated when data are loaded via this route
// we may want to import from oscar directly from the station table
if( data.feature ){
station.value = {
id: data.feature.id, // WSI
type: data.feature.type,
geometry: {
type: data.feature.geometry.type,
coordinates: data.feature.geometry.coordinates,
longitude: data.feature.geometry.coordinates[0],
latitude: data.feature.geometry.coordinates[1],
elevation: data.feature.geometry.coordinates[2]
},
properties: {
name: data.feature.properties.name,
wigos_station_identifier: data.feature.properties.wigos_station_identifier, // WSI
traditional_station_identifier: data.feature.properties.traditional_station_identifier,
territory_name: territoryOptions.value.find( (item) => item.id === data.feature.properties.territory_name ),
barometer_height: data.feature.properties.barometer_height,
wmo_region: WMORegionOptions.value.find( (item) => item.id === data.feature.properties.wmo_region ),
url: data.feature.properties.url,
topics: JSON.parse(JSON.stringify(data.feature.properties.topics)),
status: operatingStatusOptions.value.find( (item) => item.id === data.feature.properties.status ),
id: data.feature.properties.id // WSI
}
};
// update code list elements separately
selectedFacilityType.value = facilityTypeOptions.value.find( (item) => item.id === data.feature.properties.facility_type );
console.log(station.value);
}else if (data.error){
errorMessage.value = JSON.stringify(data.error);
showDialog.value = true;
}else{
errorMessage.value = "Unexpected response: " + JSON.stringify(data);
showDialog.value = true;
}
}
} catch( error ) {
errorMessage.value = "Error fetching from OSCAR/Surface: " + error;
showDialog.value = true;
}
}
};
return {station, topics, registerStation, getElevation, showDialog, msg, rules, route, router,
operatingStatusOptions, WMORegionOptions, territoryOptions, readonly, errorMessage, token, formValid,
cancelEdit, importOSCAR, selectedFacilityType
cancelEdit
};
}
});
Expand Down

0 comments on commit b333176

Please sign in to comment.