forked from galaxyproject/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert entryPointStore to composition API + TS
- Loading branch information
Showing
3 changed files
with
104 additions
and
75 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import axios from "axios"; | ||
import isEqual from "lodash.isequal"; | ||
import { defineStore } from "pinia"; | ||
import { computed, ref } from "vue"; | ||
|
||
import { getAppRoot } from "@/onload/loadConfig"; | ||
import { rethrowSimple } from "@/utils/simple-error"; | ||
|
||
// TODO: replace with the corresponding autogenerated model when ready | ||
interface EntryPoint { | ||
model_class: "InteractiveToolEntryPoint"; | ||
id: string; | ||
job_id: string; | ||
name: string; | ||
active: boolean; | ||
created_time: string; | ||
modified_time: string; | ||
output_datasets_ids: string[]; | ||
target?: string; | ||
} | ||
|
||
export const useEntryPointStore = defineStore("entryPointStore", () => { | ||
const pollTimeout = ref<NodeJS.Timeout | undefined>(undefined); | ||
const entryPoints = ref<EntryPoint[]>([]); | ||
|
||
const entryPointsForJob = computed(() => { | ||
return (jobId: string) => entryPoints.value.filter((entryPoint) => entryPoint["job_id"] === jobId); | ||
}); | ||
|
||
const entryPointsForHda = computed(() => { | ||
return (hdaId: string) => | ||
entryPoints.value.filter((entryPoint) => entryPoint["output_datasets_ids"].includes(hdaId)); | ||
}); | ||
|
||
async function ensurePollingEntryPoints() { | ||
await fetchEntryPoints(); | ||
pollTimeout.value = setTimeout(() => { | ||
ensurePollingEntryPoints(); | ||
}, 10000); | ||
} | ||
|
||
function stopPollingEntryPoints() { | ||
clearTimeout(pollTimeout.value); | ||
pollTimeout.value = undefined; | ||
} | ||
|
||
async function fetchEntryPoints() { | ||
const url = `${getAppRoot()}api/entry_points`; | ||
const params = { running: true }; | ||
try { | ||
const response = await axios.get(url, { params: params }); | ||
updateEntryPoints(response.data); | ||
} catch (e) { | ||
rethrowSimple(e); | ||
} | ||
} | ||
|
||
function updateEntryPoints(data: EntryPoint[]) { | ||
let hasChanged = entryPoints.value.length !== data.length ? true : false; | ||
if (entryPoints.value.length === 0) { | ||
entryPoints.value = data; | ||
} else { | ||
const newEntryPoints = []; | ||
for (const ep of data) { | ||
const olderEntryPoint = entryPoints.value.filter((item) => item.id === ep.id)[0]; | ||
if (!hasChanged && !isEqual(olderEntryPoint, ep)) { | ||
hasChanged = true; | ||
} | ||
if (olderEntryPoint) { | ||
newEntryPoints.push(mergeEntryPoints(olderEntryPoint, ep)); | ||
} | ||
} | ||
if (hasChanged) { | ||
entryPoints.value = newEntryPoints; | ||
} | ||
} | ||
} | ||
|
||
function mergeEntryPoints(original: EntryPoint, updated: EntryPoint) { | ||
return { ...original, ...updated }; | ||
} | ||
|
||
function removeEntryPoint(toolId: string) { | ||
const index = entryPoints.value.findIndex((ep) => { | ||
return ep.id === toolId ? true : false; | ||
}); | ||
if (index >= 0) { | ||
entryPoints.value.splice(index, 1); | ||
} | ||
} | ||
|
||
return { | ||
entryPoints, | ||
entryPointsForJob, | ||
entryPointsForHda, | ||
fetchEntryPoints, | ||
updateEntryPoints, | ||
removeEntryPoint, | ||
pollTimeout, | ||
ensurePollingEntryPoints, | ||
stopPollingEntryPoints, | ||
}; | ||
}); |