From 8afa503867351223338a505ea1e8ce7a5ce0f5ce Mon Sep 17 00:00:00 2001 From: Richard Date: Thu, 3 Jun 2021 16:09:40 +0100 Subject: [PATCH 1/6] Scan settings are now remembered This is done in local storage, and I'm quite pleased with how neat it is! Happy to be corrected on a better way to pass `this` though! --- .../captureComponents/paneCapture.vue | 67 +++++++++++-------- .../static/src/syncDataWithLocalStorage.js | 37 ++++++++++ 2 files changed, 75 insertions(+), 29 deletions(-) create mode 100644 openflexure_microscope/api/static/src/syncDataWithLocalStorage.js diff --git a/openflexure_microscope/api/static/src/components/tabContentComponents/captureComponents/paneCapture.vue b/openflexure_microscope/api/static/src/components/tabContentComponents/captureComponents/paneCapture.vue index 1c3a0c85..8e78e091 100644 --- a/openflexure_microscope/api/static/src/components/tabContentComponents/captureComponents/paneCapture.vue +++ b/openflexure_microscope/api/static/src/components/tabContentComponents/captureComponents/paneCapture.vue @@ -273,8 +273,39 @@ import axios from "axios"; import tagList from "../../fieldComponents/tagList"; import keyvalList from "../../fieldComponents/keyvalList"; - import taskSubmitter from "../../genericComponents/taskSubmitter"; +import { syncDataWithLocalStorage } from "../../../syncDataWithLocalStorage"; + +function defaultCaptureSettings() { + return { + filename: "", + temporary: false, + fullResolution: false, + storeBayer: false, + resizeCapture: false, + captureNotes: "", + scanCapture: false, + scanDeltaZ: "Fast", + scanStyle: "Raster", + namingStyle: "Coordinates", + scanStepSize: { + x: 800, + y: 640, + z: 50 + }, + scanSteps: { + x: 3, + y: 3, + z: 5 + }, + resizeDims: [640, 480], + tags: [], + annotations: { + Client: "openflexure-microscope-jsclient:builtin" + }, + scanUri: null + }; +} // Export main app export default { @@ -287,34 +318,9 @@ export default { }, data: function() { - return { - filename: "", - temporary: false, - fullResolution: false, - storeBayer: false, - resizeCapture: false, - captureNotes: "", - scanCapture: false, - scanDeltaZ: "Fast", - scanStyle: "Raster", - namingStyle: "Coordinates", - scanStepSize: { - x: 800, - y: 640, - z: 50 - }, - scanSteps: { - x: 3, - y: 3, - z: 5 - }, - resizeDims: [640, 480], - tags: [], - annotations: { - Client: "openflexure-microscope-jsclient:builtin" - }, - scanUri: null - }; + // I've split this out so I can use the keys elsewhere, and to allow + // for some data in the future that isn't in defaultCaptureSettings(); + return defaultCaptureSettings(); }, computed: { @@ -393,6 +399,9 @@ export default { mounted() { this.updateScanUri(); + // Load settings if they have been saved, and set up watchers to sync with local storage + syncDataWithLocalStorage("captureSettings", this, defaultCaptureSettings()); + // A global signal listener to perform a capture action this.$root.$on("globalCaptureEvent", () => { this.handleCapture(); diff --git a/openflexure_microscope/api/static/src/syncDataWithLocalStorage.js b/openflexure_microscope/api/static/src/syncDataWithLocalStorage.js new file mode 100644 index 00000000..3add0f80 --- /dev/null +++ b/openflexure_microscope/api/static/src/syncDataWithLocalStorage.js @@ -0,0 +1,37 @@ +/** + * This function should be called from a Vue component's "created" hook + * It will initialise a list of properties from local storage. + * It then sets up watchers for said properties to sync them back + * so that next time we load, the values persist. + * + * Arguments: + * keyName: a string, used as the key in local storage + * syncedObject: the object whose data you want to sync (usually `this`) + * syncedData: an object, the keys of which set the properties to be synced + */ +export function syncDataWithLocalStorage(keyName, syncedObject, syncedData) { + const syncedKeys = Object.keys(syncedData); + // First, we try to retrieve the stored data + const storedString = localStorage.getItem(keyName); + if (storedString) { + const storedValues = JSON.parse(storedString); + for (const item of syncedKeys) { + if (item in storedValues) syncedObject[item] = storedValues[item]; + } + } + + // This function will update local storage with current values + //const context = this; + let updateStoredValues = function() { + let newData = {}; + for (const item of syncedKeys) { + newData[item] = syncedObject[item]; + } + localStorage.setItem(keyName, JSON.stringify(newData)); + }; + + // Now, set up watchers to update local storage when things change + for (const item of syncedKeys) { + syncedObject.$watch(item, updateStoredValues, { deep: true }); + } +} From 178d6fb84b8cc67c4e1e0dee6e4052434026c584 Mon Sep 17 00:00:00 2001 From: Richard Date: Thu, 3 Jun 2021 16:09:51 +0100 Subject: [PATCH 2/6] Fix ame of CaptureContent --- .../src/components/tabContentComponents/captureContent.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openflexure_microscope/api/static/src/components/tabContentComponents/captureContent.vue b/openflexure_microscope/api/static/src/components/tabContentComponents/captureContent.vue index a1758f9b..cd057af8 100644 --- a/openflexure_microscope/api/static/src/components/tabContentComponents/captureContent.vue +++ b/openflexure_microscope/api/static/src/components/tabContentComponents/captureContent.vue @@ -15,7 +15,7 @@ import paneCapture from "./captureComponents/paneCapture"; import streamDisplay from "./streamContent.vue"; export default { - name: "NavigateContent", + name: "CaptureContent", components: { paneCapture, From 31faaaf161d74795800671ee6a936482a0886dbd Mon Sep 17 00:00:00 2001 From: Richard Date: Thu, 3 Jun 2021 16:10:03 +0100 Subject: [PATCH 3/6] Whitespace linting fixes --- .../settingsComponents/cameraSettings.vue | 12 ++++++------ .../cameraCalibrationSettings.vue | 17 +++++++++++++---- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/openflexure_microscope/api/static/src/components/tabContentComponents/settingsComponents/cameraSettings.vue b/openflexure_microscope/api/static/src/components/tabContentComponents/settingsComponents/cameraSettings.vue index 67c1fdda..d161049a 100644 --- a/openflexure_microscope/api/static/src/components/tabContentComponents/settingsComponents/cameraSettings.vue +++ b/openflexure_microscope/api/static/src/components/tabContentComponents/settingsComponents/cameraSettings.vue @@ -3,7 +3,7 @@

Manual camera settings

-
+
  • @@ -51,18 +51,18 @@
-