Merge branch 'remove_store_getters' into 'v3'
ui_migration refactor(store) Remove lingering getters for origin and available... Closes #762 See merge request openflexure/openflexure-microscope-server!597
This commit is contained in:
commit
08b6b274a8
4 changed files with 52 additions and 60 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { ref, computed } from "vue";
|
import { ref } from "vue";
|
||||||
|
|
||||||
function getOriginFromLocation() {
|
function getOriginFromLocation() {
|
||||||
// This will default to the same origin that's serving
|
// This will default to the same origin that's serving
|
||||||
|
|
@ -13,8 +13,8 @@ export const useSettingsStore = defineStore(
|
||||||
"settings",
|
"settings",
|
||||||
() => {
|
() => {
|
||||||
// State
|
// State
|
||||||
const origin = ref(getOriginFromLocation());
|
const baseUri = ref(getOriginFromLocation());
|
||||||
const available = ref(false);
|
const ready = ref(false);
|
||||||
const waiting = ref(false);
|
const waiting = ref(false);
|
||||||
const error = ref("");
|
const error = ref("");
|
||||||
const trackWindow = ref(true);
|
const trackWindow = ref(true);
|
||||||
|
|
@ -43,14 +43,14 @@ export const useSettingsStore = defineStore(
|
||||||
// Actions
|
// Actions
|
||||||
function resetState() {
|
function resetState() {
|
||||||
waiting.value = false;
|
waiting.value = false;
|
||||||
available.value = false;
|
ready.value = false;
|
||||||
// On resetState there is no connection.
|
// On resetState there is no connection.
|
||||||
error.value = "Microscope is not connected.";
|
error.value = "Microscope is not connected.";
|
||||||
}
|
}
|
||||||
|
|
||||||
function setConnected() {
|
function setConnected() {
|
||||||
waiting.value = false;
|
waiting.value = false;
|
||||||
available.value = true;
|
ready.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addStream(id) {
|
function addStream(id) {
|
||||||
|
|
@ -59,15 +59,12 @@ export const useSettingsStore = defineStore(
|
||||||
function removeStream(id) {
|
function removeStream(id) {
|
||||||
activeStreams.value[id] = false;
|
activeStreams.value[id] = false;
|
||||||
}
|
}
|
||||||
// Getters
|
|
||||||
const baseUri = computed(() => origin.value);
|
|
||||||
const ready = computed(() => available.value);
|
|
||||||
|
|
||||||
// Export
|
// Export
|
||||||
return {
|
return {
|
||||||
//State
|
// State
|
||||||
origin,
|
baseUri,
|
||||||
available,
|
ready,
|
||||||
waiting,
|
waiting,
|
||||||
error,
|
error,
|
||||||
trackWindow,
|
trackWindow,
|
||||||
|
|
@ -79,11 +76,7 @@ export const useSettingsStore = defineStore(
|
||||||
navigationStepSize,
|
navigationStepSize,
|
||||||
navigationInvert,
|
navigationInvert,
|
||||||
|
|
||||||
//Getters
|
// Actions
|
||||||
baseUri,
|
|
||||||
ready,
|
|
||||||
|
|
||||||
//Actions
|
|
||||||
resetState,
|
resetState,
|
||||||
setConnected,
|
setConnected,
|
||||||
addStream,
|
addStream,
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,10 @@ export const useWotStore = defineStore(
|
||||||
const thingDescriptions = ref({});
|
const thingDescriptions = ref({});
|
||||||
const servient = ref(null);
|
const servient = ref(null);
|
||||||
const helpers = ref(null);
|
const helpers = ref(null);
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
const thingList = computed(() => Object.keys(thingDescriptions.value));
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
function addThingDescription(thingName, thingDescription) {
|
function addThingDescription(thingName, thingDescription) {
|
||||||
thingDescriptions.value[thingName] = thingDescription;
|
thingDescriptions.value[thingName] = thingDescription;
|
||||||
|
|
@ -42,58 +46,53 @@ export const useWotStore = defineStore(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const thingList = computed(() => Object.keys(thingDescriptions.value));
|
function thingAvailable(thingName) {
|
||||||
|
|
||||||
const thingAvailable = computed(() => (thingName) => {
|
|
||||||
return thingName in thingDescriptions.value;
|
return thingName in thingDescriptions.value;
|
||||||
});
|
}
|
||||||
|
|
||||||
const thingAffordanceAvailable = computed(() => (thing, affordanceType, affordance) => {
|
function thingAffordanceAvailable(thing, affordanceType, affordance) {
|
||||||
const td = thingDescriptions.value[thing];
|
const td = thingDescriptions.value[thing];
|
||||||
if (!td || !td[affordanceType]) return false;
|
if (!td || !td[affordanceType]) return false;
|
||||||
return affordance in td[affordanceType];
|
return affordance in td[affordanceType];
|
||||||
});
|
}
|
||||||
|
|
||||||
const thingFormUrl = computed(
|
function thingFormUrl(thing, affordanceType, affordance, op, allowUndefined = true) {
|
||||||
() =>
|
// Find the URL for a particular operation
|
||||||
(thing, affordanceType, affordance, op, allowUndefined = true) => {
|
const td = thingDescriptions.value[thing];
|
||||||
// Find the URL for a particular operation
|
if (!td) {
|
||||||
const td = thingDescriptions.value[thing];
|
if (allowUndefined) return undefined;
|
||||||
if (!td) {
|
throw `Could not find form for ${affordanceType} ${thing}/${affordance} with op ${op}`;
|
||||||
if (allowUndefined) return undefined;
|
}
|
||||||
throw `Could not find form for ${affordanceType} ${thing}/${affordance} with op ${op}`;
|
const affordances = td[affordanceType];
|
||||||
}
|
if (!affordances || !(affordance in affordances)) {
|
||||||
const affordances = td[affordanceType];
|
if (allowUndefined) return undefined;
|
||||||
if (!affordances || !(affordance in affordances)) {
|
throw `Could not find form for ${affordanceType} ${thing}/${affordance} with op ${op}`;
|
||||||
if (allowUndefined) return undefined;
|
}
|
||||||
throw `Could not find form for ${affordanceType} ${thing}/${affordance} with op ${op}`;
|
let href = findFormHref(affordances[affordance], op);
|
||||||
}
|
if (href === undefined) {
|
||||||
let href = findFormHref(affordances[affordance], op);
|
if (allowUndefined) return undefined;
|
||||||
if (href === undefined) {
|
throw `Could not find form for ${affordanceType} ${thing}/${affordance} with op ${op}`;
|
||||||
if (allowUndefined) return undefined;
|
}
|
||||||
throw `Could not find form for ${affordanceType} ${thing}/${affordance} with op ${op}`;
|
// If we've found an href, prepend the `base` URL if appropriate
|
||||||
}
|
if (href.startsWith("http")) return href;
|
||||||
// If we've found an href, prepend the `base` URL if appropriate
|
if ("base" in td) {
|
||||||
if (href.startsWith("http")) return href;
|
let base = td.base;
|
||||||
if ("base" in td) {
|
if (href.startsWith("/")) href = href.slice(1);
|
||||||
let base = td.base;
|
if (!base.endsWith("/")) base += "/";
|
||||||
if (href.startsWith("/")) href = href.slice(1);
|
return base + href;
|
||||||
if (!base.endsWith("/")) base += "/";
|
}
|
||||||
return base + href;
|
return href;
|
||||||
}
|
}
|
||||||
return href;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const thingPropertyUrl = computed(() => (thing, property, op, allowUndefined) => {
|
function thingPropertyUrl(thing, property, op, allowUndefined) {
|
||||||
// Find the URL for a particular property
|
// Find the URL for a particular property
|
||||||
return thingFormUrl.value(thing, "properties", property, op, allowUndefined);
|
return thingFormUrl(thing, "properties", property, op, allowUndefined);
|
||||||
});
|
}
|
||||||
|
|
||||||
const thingActionUrl = computed(() => (thing, action, op, allowUndefined) => {
|
function thingActionUrl(thing, action, op, allowUndefined) {
|
||||||
// Find the URL for a particular action
|
// Find the URL for a particular action
|
||||||
return thingFormUrl.value(thing, "actions", action, op, allowUndefined);
|
return thingFormUrl(thing, "actions", action, op, allowUndefined);
|
||||||
});
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
thingDescriptions,
|
thingDescriptions,
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ describe("Test LoggingContent.vue", () => {
|
||||||
createTestingPinia({
|
createTestingPinia({
|
||||||
createSpy: vi.fn,
|
createSpy: vi.fn,
|
||||||
initialState: {
|
initialState: {
|
||||||
settings: { origin: "http://microscope.local:5000/api/v3" },
|
settings: { baseUri: "http://microscope.local:5000/api/v3" },
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ export default defineConfig({
|
||||||
thresholds: {
|
thresholds: {
|
||||||
lines: 4,
|
lines: 4,
|
||||||
statements: 3,
|
statements: 3,
|
||||||
functions: 3,
|
functions: 2,
|
||||||
branches: 1,
|
branches: 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue