Skip to content

Commit

Permalink
Merge branch 'subsetter_front_clean' into develop_v2
Browse files Browse the repository at this point in the history
  • Loading branch information
devincowan committed Nov 27, 2023
2 parents c19f7d0 + e82e607 commit 786fc8e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
22 changes: 13 additions & 9 deletions app/frontend/src/components/SubmitButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

<script setup>
import { useModelsStore } from '@/stores/models'
import { useAuthStore } from '@/stores/auth'
import { ENDPOINTS } from '@/constants'
import { useMapStore } from '@/stores/map'
const mapStore = useMapStore()
const Map = mapStore.mapObject
const modelsStore = useModelsStore();
const authStore = useAuthStore();
function submit() {
const model = modelsStore.selectedModel
Expand All @@ -19,16 +21,18 @@ function submit() {
}
async function submitHucs(selected_hucs, model) {
selected_hucs = selected_hucs.map(a => a.hucid);
console.log(selected_hucs)
const hucs = selected_hucs.join(",")
const jwt = authStore.getToken()
alert(`Submitting hucs: ${hucs} for ${model} subsetting`)
const parResp = await fetch(`${ENDPOINTS.submit}/${model}?hucs=${hucs}`, {
method: "POST",
credentials: 'include',
mode: 'cors'
})
const parJson = await parResp.json()
alert(`Submitted ${parJson.workflow_name} workflow. Workflow_id: ${parJson.workflow_id}`)
const parResp = await fetch(`${ENDPOINTS.submit}/${model}?hucs=${hucs}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${jwt}`,
}
})
const parJson = await parResp.json()
alert(`Submitted ${parJson.workflow_name} workflow. Workflow_id: ${parJson.workflow_id}`)
}
</script>
17 changes: 10 additions & 7 deletions app/frontend/src/stores/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ export const useAuthStore = defineStore('auth', () => {
const user = useStorage('user', {})
const isLoggedIn = useStorage('isLoggedIn', false)

let storeToken = useStorage('storeToken', {})
const storeToken = useStorage('storeToken', {})

async function login(token) {
// update pinia state
this.storeToken = token;
storeToken.value = token;
}

async function logout() {
this.user = {}
this.isLoggedIn = false;
this.storeToken = {};
user.value = {}
isLoggedIn.value = false;
storeToken.value = {};
}

function getToken(){
return storeToken.value.access_token
}

return { isLoggedIn, user, login, logout }
return { isLoggedIn, user, login, logout, getToken, storeToken}
})
10 changes: 8 additions & 2 deletions app/frontend/src/stores/submissions.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { defineStore } from 'pinia'
import { ENDPOINTS } from '../constants'
import { ref } from 'vue'
import { useAuthStore } from '@/stores/auth'

const authStore = useAuthStore();
const jwt = authStore.getToken()

export const useSubmissionsStore = defineStore('submissions', () => {
const submissions = ref([])

async function getSubmissions() {
const submissionResp = await fetch(`${ENDPOINTS.submissions}`, {
credentials: 'include',
mode: 'cors'
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${jwt}`,
}
})
const submissionsObj = await submissionResp.json()
let submissions = submissionsObj.submissions
Expand Down

0 comments on commit 786fc8e

Please sign in to comment.