Skip to content

Commit

Permalink
Merge commit 'a20ccdcbb77361f39fcfd8ef723cec7a2f420c6f' into develop_v2
Browse files Browse the repository at this point in the history
  • Loading branch information
devincowan committed Nov 27, 2023
2 parents 8987695 + a20ccdc commit 708031d
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 20 deletions.
2 changes: 2 additions & 0 deletions app/api/subsetter/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Settings(BaseSettings):
oauth2_client_secret: str
oauth2_redirect_url: str
vite_oauth2_redirect_url: str
vite_app_api_url: str
allow_origins: str

minio_access_key: str
minio_secret_key: str
Expand Down
4 changes: 2 additions & 2 deletions app/api/subsetter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"swagger_ui_client_id": cuahsi_oauth_client.client_id,
}

app = FastAPI(servers=[{"url": os.path.expandvars(os.environ['VITE_APP_API_URL'])}], swagger_ui_parameters=swagger_params)
app = FastAPI(servers=[{"url": get_settings().vite_app_api_url}], swagger_ui_parameters=swagger_params)

origins = [os.path.expandvars(os.environ['ALLOW_ORIGINS'])]
origins = [get_settings().allow_origins]

app.add_middleware(
CORSMiddleware,
Expand Down
4 changes: 3 additions & 1 deletion app/frontend/src/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export async function logIn(callback) {

// alter redirect uri
const authUrl = new URL(json.authorization_url)
authUrl.searchParams.set('redirect_uri', `${APP_URL}/#/auth-redirect`)
// TODO: use an env var for auth redirect instead of hard-coding
// "#" hash routing was not passed from github env secret so had to hard code here.
authUrl.searchParams.set('redirect_uri', `${APP_URL}#/auth-redirect`)
window.open(
authUrl.toString(),
'_blank',
Expand Down
3 changes: 2 additions & 1 deletion app/frontend/src/components/ModelSelectDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ const modelsStore = useModelsStore();
const models = modelsStore.models
function selectModel(model, toggle) {
modelsStore.selectedModel = model
// modelsStore.selectedModel = model
modelsStore.updateModel(model)
toggle()
}
Expand Down
1 change: 0 additions & 1 deletion app/frontend/src/components/SubmitButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ function submit() {
const model = modelsStore.selectedModel
const hucsArray = Map.selected_hucs
submitHucs(hucsArray, model.shortName)
modelsStore.selectedModel
}
async function submitHucs(selected_hucs, model) {
selected_hucs = selected_hucs.map(a => a.hucid);
Expand Down
7 changes: 0 additions & 7 deletions app/frontend/src/components/TheFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<v-footer app color="navbar" class="d-flex flex-column">
<div class="d-flex w-100 align-center">
<ThemeButton/>
<v-btn v-for="icon in icons" :key="icon" class="mx-4" :icon="icon" variant="plain" size="small"></v-btn>
<div class="text-center w-100">
{{ new Date().getFullYear() }} — <strong>Subsetter</strong>
</div>
Expand All @@ -16,12 +15,6 @@
<script setup>
import ThemeButton from './ThemeButton.vue';
import SubmitButton from './SubmitButton.vue';
const icons = [
'mdi-atom',
'mdi-mastodon',
'mdi-dna',
'mdi-biohazard',
]
</script>

<style lang="scss" scoped></style>
54 changes: 47 additions & 7 deletions app/frontend/src/components/TheLeafletMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,42 @@ import L from 'leaflet'
import "leaflet-easybutton/src/easy-button";
import { onMounted } from 'vue'
import { useMapStore } from '@/stores/map'
import { useModelsStore } from '@/stores/models'
const mapStore = useMapStore()
const modelsStore = useModelsStore();
const modelAction = modelsStore.$onAction(
({
name, // name of the action
store, // store instance, same as `someStore`
args, // array of parameters passed to the action
after, // hook after the action returns or resolves
onError, // hook if the action throws or rejects
}) => {
// this will trigger if the action succeeds and after it has fully run.
// it waits for any returned promised
after((result) => {
console.log(store.selectedModel.input)
if( store.selectedModel.input != "bbox" ){
removeBbox()
}else{
updateMapBBox()
}
})
// this will trigger if the action throws or returns a promise that rejects
onError((error) => {
console.warn(
`Failed "${name}" after ${Date.now() - startTime}ms.\nError: ${error}.`
)
})
}
)
// manually remove the listener
// modelAction()
const Map = mapStore.mapObject
onMounted(() => {
Expand Down Expand Up @@ -902,12 +936,7 @@ function updateMapBBox() {
Map.bbox = [xmin, ymin, xmax, ymax];
// remove the bbox layer if it exists
if ('BBOX' in Map.huclayers) {
// remove the polygon overlay
Map.huclayers['BBOX'].clearLayers();
delete Map.huclayers['BBOX'];
}
removeBbox()
// redraw the bbox layer with new coordinates
let coords = [[[xmin, ymin],
Expand All @@ -932,11 +961,22 @@ function updateMapBBox() {
// save the layer
Map.huclayers['BBOX'] = json_polygon;
json_polygon.addTo(Map.map);
if (modelsStore.selectedModel.input == "bbox"){
json_polygon.addTo(Map.map);
}
return bbox.is_valid
}
function removeBbox(){
// remove the bbox layer if it exists
if ('BBOX' in Map.huclayers) {
// remove the polygon overlay
Map.huclayers['BBOX'].clearLayers();
delete Map.huclayers['BBOX'];
}
}
/**
* Toggles HUC boundaries on the map, on/off.
Expand Down
6 changes: 5 additions & 1 deletion app/frontend/src/stores/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@ export const useModelsStore = defineStore('models', () => {
])
const selectedModel = ref({})

return { models, selectedModel }
function updateModel(model) {
this.selectedModel = model
}

return { models, selectedModel, updateModel }
})

0 comments on commit 708031d

Please sign in to comment.