Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F77444586
scenario.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Aug 14, 13:10
Size
1 KB
Mime Type
text/x-java
Expires
Fri, Aug 16, 13:10 (2 d)
Engine
blob
Format
Raw Data
Handle
19870258
Attached To
R12546 Sesame - Configurator
scenario.js
View Options
import axios from 'axios';
import { defineStore } from 'pinia';
import { ref } from 'vue';
import { genericFetch, genericAdd, genericUpdate, genericRemove } from './utils';
export const useScenarioStore = defineStore('scenario', () => {
const state = ref([]);
// not process.env because we use VITE and not vue cli
const endpointURL = import.meta.env.VITE_API_URL + '/scenarios';
const fetch = genericFetch(endpointURL, state);
const fetchInterferences = async (id) => {
const interferences = ref({});
await genericFetch(`${endpointURL}/${id}/interferences`, interferences)();
return interferences;
};
const exportToJSON = async ({ id, scenarioID }, { id: playerID, name }) => {
const res = await axios.post(
`${endpointURL}/${id}/export`,
{ playerID },
{ responseType: 'blob' });
const url = window.URL.createObjectURL(res.data);
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', `${scenarioID}-${name}.json`);
document.body.appendChild(link);
link.click();
window.URL.revokeObjectURL(url)
document.body.removeChild(link);
};
return {
state, fetch, fetchInterferences, exportToJSON,
add: genericAdd(endpointURL, fetch),
update: genericUpdate(endpointURL, fetch),
remove: genericRemove(endpointURL, fetch)
};
});
Event Timeline
Log In to Comment