From fcdb30eedf250200d661441ddb5df42aa6e9b26b Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Tue, 14 Jan 2020 16:10:05 +0000 Subject: [PATCH] Updated to new API structure --- .../controlComponents/paneCapture.vue | 15 ++-- .../controlComponents/paneNavigate.vue | 17 ++--- .../controlComponents/paneStatus.vue | 10 ++- .../settingsComponents/cameraSettings.vue | 12 ++-- .../fieldComponents/numberInput.vue | 2 +- src/components/panelLeft.vue | 9 ++- src/components/panelRight.vue | 2 +- src/components/pluginComponents/JsonForm.vue | 69 +++++++++++-------- .../galleryComponents/captureCard.vue | 23 +++---- .../galleryComponents/zipDownloader.vue | 16 ++--- .../viewComponents/galleryDisplay.vue | 53 +++++++------- 11 files changed, 113 insertions(+), 115 deletions(-) diff --git a/src/components/controlComponents/paneCapture.vue b/src/components/controlComponents/paneCapture.vue index 0baf73bd..864c6cb1 100644 --- a/src/components/controlComponents/paneCapture.vue +++ b/src/components/controlComponents/paneCapture.vue @@ -313,7 +313,7 @@ export default { return `${this.$store.getters.baseUri}/api/v2/actions/camera/capture`; }, pluginsUri: function() { - return `${this.$store.getters.baseUri}/api/v2/plugins`; + return `${this.$store.getters.baseUri}/api/v2/extensions`; }, settingsFovUri: function() { return `${this.$store.getters.baseUri}/api/v2/settings/fov`; @@ -395,7 +395,7 @@ export default { // Flash the stream (capture animation) this.$root.$emit("globalFlashStream"); // Update the global capture list - this.$root.$emit("globalUpdateCaptureList"); + this.$root.$emit("globalUpdateCaptures"); }) .catch(error => { this.modalError(error); // Let mixin handle error @@ -407,12 +407,13 @@ export default { .get(this.pluginsUri) // Get a list of plugins .then(response => { var plugins = response.data; + var foundExtension = plugins.find( + e => e.title === "org.openflexure.scan" + ); // if ScanPlugin is enabled - if ("ScanPlugin" in plugins) { + if (foundExtension) { // Get plugin action link - var link = plugins.ScanPlugin.views.tile.links.self; - // Store plugin action URI - this.scanUri = `${this.$store.getters.baseUri}${link}`; + this.scanUri = foundExtension.links.tile.href; } }) .catch(error => { @@ -422,7 +423,7 @@ export default { updateScanStepSize: function() { axios - .get(this.settingsFovUri) // Get a list of plugins + .get(this.settingsFovUri) // Get the microscope FOV .then(response => { this.scanStepSize = { x: parseInt(0.5 * response.data[0]), diff --git a/src/components/controlComponents/paneNavigate.vue b/src/components/controlComponents/paneNavigate.vue index 4df04e46..ce656103 100644 --- a/src/components/controlComponents/paneNavigate.vue +++ b/src/components/controlComponents/paneNavigate.vue @@ -196,7 +196,7 @@ export default { return `${this.$store.getters.baseUri}/api/v2/status/stage/position`; }, pluginsUri: function() { - return `${this.$store.getters.baseUri}/api/v2/plugins`; + return `${this.$store.getters.baseUri}/api/v2/extensions`; } }, @@ -352,17 +352,14 @@ export default { .get(this.pluginsUri) // Get a list of plugins .then(response => { var plugins = response.data; + var foundExtension = plugins.find( + e => e.title === "org.openflexure.autofocus" + ); // if ScanPlugin is enabled - if ("AutofocusPlugin" in plugins) { + if (foundExtension) { // Get plugin action link - var fastLink = - plugins.AutofocusPlugin.views.fast_autofocus.links.self; - var normalLink = plugins.AutofocusPlugin.views.autofocus.links.self; - // Store plugin action URI - this.fastAutofocusUri = `${this.$store.getters.baseUri}${fastLink}`; - this.normalAutofocusUri = `${ - this.$store.getters.baseUri - }${normalLink}`; + this.fastAutofocusUri = foundExtension.links.fast_autofocus.href; + this.normalAutofocusUri = foundExtension.links.autofocus.href; } }) .catch(error => { diff --git a/src/components/controlComponents/paneStatus.vue b/src/components/controlComponents/paneStatus.vue index 3b770181..500e5a3c 100644 --- a/src/components/controlComponents/paneStatus.vue +++ b/src/components/controlComponents/paneStatus.vue @@ -144,16 +144,14 @@ export default { .get(this.actionsUri) .then(response => { if ("reboot" in response.data) { - this.systemActionLinks.reboot = `${this.$store.getters.baseUri}${ - response.data.reboot.links.self - }`; + this.systemActionLinks.reboot = + response.data.reboot.links.self.href; } else { delete this.systemActionLinks.reboot; } if ("shutdown" in response.data) { - this.systemActionLinks.shutdown = `${this.$store.getters.baseUri}${ - response.data.shutdown.links.self - }`; + this.systemActionLinks.shutdown = + response.data.shutdown.links.self.href; } else { delete this.systemActionLinks.shutdown; } diff --git a/src/components/controlComponents/settingsComponents/cameraSettings.vue b/src/components/controlComponents/settingsComponents/cameraSettings.vue index db0cbaf6..6b5192f9 100644 --- a/src/components/controlComponents/settingsComponents/cameraSettings.vue +++ b/src/components/controlComponents/settingsComponents/cameraSettings.vue @@ -96,7 +96,7 @@ export default { return `${this.$store.getters.baseUri}/api/v2/settings`; }, pluginsUri: function() { - return `${this.$store.getters.baseUri}/api/v2/plugins`; + return `${this.$store.getters.baseUri}/api/v2/extensions`; } }, @@ -122,13 +122,13 @@ export default { .get(this.pluginsUri) // Get a list of plugins .then(response => { var plugins = response.data; + var foundExtension = plugins.find( + e => e.title === "org.openflexure.calibration.picamera" + ); // if AutocalibrationPlugin is enabled - if ("AutocalibrationPlugin" in plugins) { + if (foundExtension) { // Get plugin action link - var link = - plugins.AutocalibrationPlugin.views.recalibrate.links.self; - // Store plugin action URI - this.recalibrationUri = `${this.$store.getters.baseUri}${link}`; + this.recalibrationUri = foundExtension.links.recalibrate.href; } }) .catch(error => { diff --git a/src/components/fieldComponents/numberInput.vue b/src/components/fieldComponents/numberInput.vue index 2bac02c2..cacab2d1 100644 --- a/src/components/fieldComponents/numberInput.vue +++ b/src/components/fieldComponents/numberInput.vue @@ -26,7 +26,7 @@ export default { placeholder: { type: Number, required: false, - default: NaN + default: 0 }, name: { type: String, diff --git a/src/components/panelLeft.vue b/src/components/panelLeft.vue index 0ef7bcf9..972da19a 100644 --- a/src/components/panelLeft.vue +++ b/src/components/panelLeft.vue @@ -114,7 +114,6 @@ :route="form.route" :is-task="form.isTask" :submit-label="form.submitLabel" - :self-update="form.selfUpdate" :schema="form.schema" @reloadForms="updatePlugins()" /> @@ -158,7 +157,7 @@ export default { data: function() { return { - plugins: {}, + plugins: [], currentTab: "status", showControlBar: true, unwatchStoreFunction: null @@ -167,15 +166,15 @@ export default { computed: { pluginsUri: function() { - return `${this.$store.getters.baseUri}/api/v2/plugins`; + return `${this.$store.getters.baseUri}/api/v2/extensions`; }, pluginsGuiList: function() { // List of plugin GUIs, obtained from this.plugins values console.log("Recalculating plugins"); var pluginGuis = []; for (let plugin of Object.values(this.plugins)) { - if (plugin.gui) { - pluginGuis.push(plugin.gui); + if (plugin.meta.gui) { + pluginGuis.push(plugin.meta.gui); } } return pluginGuis; diff --git a/src/components/panelRight.vue b/src/components/panelRight.vue index a9f4b9ef..9057247b 100644 --- a/src/components/panelRight.vue +++ b/src/components/panelRight.vue @@ -100,7 +100,7 @@ export default { // If entering the gallery if (index == "gallery") { console.log("Gallery tab entered"); - this.$root.$emit("globalUpdateCaptureList"); + this.$root.$emit("globalUpdateCaptures"); } // If entering the stream if (index == "preview") { diff --git a/src/components/pluginComponents/JsonForm.vue b/src/components/pluginComponents/JsonForm.vue index bde1468a..9ab98a8c 100644 --- a/src/components/pluginComponents/JsonForm.vue +++ b/src/components/pluginComponents/JsonForm.vue @@ -111,11 +111,6 @@ export default { type: String, required: false, default: "Submit" - }, - selfUpdate: { - type: Boolean, - required: false, - default: false } }, @@ -127,7 +122,7 @@ export default { computed: { pluginApiUri: function() { - return `${this.$store.getters.baseUri}/api/v2/plugins`; + return `${this.$store.getters.baseUri}/api/v2/extensions`; }, submitApiUri: function() { @@ -136,12 +131,15 @@ export default { } }, + watch: { + // Whenever the form schema updates, re-check server for field values + schema: function() { + this.updateFormValues(); + } + }, + created() { this.initialiseFormData(); - - if (this.selfUpdate) { - this.getFormData(); - } }, methods: { @@ -158,38 +156,49 @@ export default { var defaultValue; // Initial value of the form component for (const subfield of field) { // If a default value is given in the schema, use this - defaultValue = subfield.default ? subfield.default : null; + if (subfield.value) { + defaultValue = subfield.value; + } else if (subfield.default) { + defaultValue = subfield.default; + } else { + defaultValue = null; + } this.$set(this.formData, subfield.name, defaultValue); } } else { // If a default value is given in the schema, use this - defaultValue = field.default ? field.default : null; + if (field.value) { + defaultValue = field.value; + } else if (field.default) { + defaultValue = field.default; + } else { + defaultValue = null; + } this.$set(this.formData, field.name, defaultValue); } } }, + updateFormValues() { + for (const field of this.schema) { + if (Array.isArray(field)) { + for (const subfield of field) { + // If a default value is given in the schema, use this + if (subfield.value) { + this.$set(this.formData, subfield.name, subfield.value); + } + } + } else { + if (field.value) { + this.$set(this.formData, field.name, field.value); + } + } + } + }, + updateForm() { // Trigger a plugin form update this.$emit("reloadForms"); - // If the form can self-update (GET request to update component values) - if (this.selfUpdate) { - // Update form data values using a GET request - this.getFormData(); - } - }, - - getFormData: function() { - // Send a quick request - axios - .get(this.submitApiUri) - .then(response => { - console.log(response.data); - Object.assign(this.formData, response.data); - }) - .catch(error => { - this.modalError(error); // Let mixin handle error - }); }, newQuickRequest: function(params) { diff --git a/src/components/viewComponents/galleryComponents/captureCard.vue b/src/components/viewComponents/galleryComponents/captureCard.vue index 3c09bf84..47ef95a1 100644 --- a/src/components/viewComponents/galleryComponents/captureCard.vue +++ b/src/components/viewComponents/galleryComponents/captureCard.vue @@ -195,20 +195,19 @@ export default { return "#" + this.metadataModalID; }, thumbURL: function() { - return `${this.$store.getters.baseUri}${ - this.captureState.links.download - }?thumbnail=true`; + return `${this.captureState.links.download.href}?thumbnail=true`; }, imgURL: function() { - return `${this.$store.getters.baseUri}${ - this.captureState.links.download - }`; + return this.captureState.links.download.href; }, tagsURL: function() { - return `${this.$store.getters.baseUri}${this.captureState.links.tags}`; + return this.captureState.links.tags.href; + }, + metadataURL: function() { + return this.captureState.links.metadata.href; }, captureURL: function() { - return `${this.$store.getters.baseUri}${this.captureState.links.self}`; + return this.captureState.links.self.href; }, betterTimestring: function() { var dtSplit = this.captureState.metadata.time.split("_"); @@ -250,7 +249,7 @@ export default { .delete(this.captureURL) .then(() => { // Emit signal to update capture list - this.$root.$emit("globalUpdateCaptureList"); + this.$root.$emit("globalUpdateCaptures"); }) .catch(error => { this.modalError(error); // Let mixin handle error @@ -273,7 +272,7 @@ export default { putMetadataRequest: function(metadataObject) { // Send metadata PUT request axios - .put(this.captureURL, metadataObject) + .put(this.metadataURL, metadataObject) .then(() => { // Update metadata object this.getMetadataRequest(); @@ -319,9 +318,9 @@ export default { getMetadataRequest: function() { // Send tag request axios - .get(this.captureURL) + .get(this.metadataURL) .then(response => { - this.customMetadata = response.data.metadata.custom; + this.customMetadata = response.data.custom; }) .catch(error => { this.modalError(error); // Let mixin handle error diff --git a/src/components/viewComponents/galleryComponents/zipDownloader.vue b/src/components/viewComponents/galleryComponents/zipDownloader.vue index a6e53717..7a83c927 100644 --- a/src/components/viewComponents/galleryComponents/zipDownloader.vue +++ b/src/components/viewComponents/galleryComponents/zipDownloader.vue @@ -59,7 +59,7 @@ export default { computed: { pluginsUri: function() { - return `${this.$store.getters.baseUri}/api/v2/plugins`; + return `${this.$store.getters.baseUri}/api/v2/extensions`; } }, @@ -73,14 +73,14 @@ export default { .get(this.pluginsUri) // Get a list of plugins .then(response => { var plugins = response.data; + var foundExtension = plugins.find( + e => e.title === "org.openflexure.zipbuilder" + ); // if ZipBuilderPlugin is enabled - if ("ZipBuilderPlugin" in plugins) { - // Get plugin action link - var builderLink = plugins.ZipBuilderPlugin.views.build.links.self; - var getterLink = plugins.ZipBuilderPlugin.views.get.links.self; - // Store plugin action URI - this.zipBuilderUri = `${this.$store.getters.baseUri}${builderLink}`; - this.zipGetterUri = `${this.$store.getters.baseUri}${getterLink}`; + if (foundExtension) { + // Get plugin action links + this.zipBuilderUri = foundExtension.links.build.href; + this.zipGetterUri = foundExtension.links.get.href; } }) .catch(error => { diff --git a/src/components/viewComponents/galleryDisplay.vue b/src/components/viewComponents/galleryDisplay.vue index d5bfffbb..877a121d 100644 --- a/src/components/viewComponents/galleryDisplay.vue +++ b/src/components/viewComponents/galleryDisplay.vue @@ -110,7 +110,7 @@ export default { data: function() { return { - captures: {}, + captures: [], checkedTags: [], sortDescending: true, galleryFolder: "", @@ -123,14 +123,10 @@ export default { capturesUri: function() { return `${this.$store.getters.baseUri}/api/v2/captures`; }, - captureList: function() { - // List of captures, obtained from this.captures values - return Object.values(this.captures); - }, allTags: function() { // Return an array of unique tags across all captures var tags = []; - for (var capture of this.captureList) { + for (var capture of this.captures) { for (var tag of capture.metadata.tags) { if (!tags.includes(tag)) { tags.push(tag); @@ -140,10 +136,10 @@ export default { return tags.sort(); }, - noScanCaptureList: function() { + noScanCaptures: function() { // List of captures that are not part of a scan var captures = []; - for (var capture of this.captureList) { + for (var capture of this.captures) { // Filter by selected tags var tags = capture.metadata.tags; @@ -160,7 +156,7 @@ export default { // List of scans as capture-like objects var scans = {}; - for (var capture of this.captureList) { + for (var capture of this.captures) { var custom = capture.metadata.custom; var tags = capture.metadata.tags; @@ -171,7 +167,7 @@ export default { if (!(id in scans)) { scans[id] = {}; scans[id].isScan = true; - scans[id].captureList = []; + scans[id].captures = []; scans[id].metadata = { filename: custom.basename, time: custom.time, @@ -182,7 +178,7 @@ export default { } // Add the capture object to the scan - scans[id].captureList.push(capture); + scans[id].captures.push(capture); // Add missing scan metadata, prioritising first capture for (var key of Object.keys(custom)) { @@ -199,10 +195,9 @@ export default { } // Create a preview thumbnail - // TODO: Use URI defined in capture representation if (!("thumbnail" in scans[id])) { - scans[id].thumbnail = `${this.$store.getters.baseUri}${ - capture.links.download + scans[id].thumbnail = `${ + capture.links.download.href }?thumbnail=true`; } } @@ -220,24 +215,24 @@ export default { // If galleryFolder (ie inside a scan folder), show scan captures // Otherwise, show root captures and scan cards if (this.galleryFolder) { - console.log(this.allScans[this.galleryFolder].captureList); - return this.allScans[this.galleryFolder].captureList; + console.log(this.allScans[this.galleryFolder].captures); + return this.allScans[this.galleryFolder].captures; } else { - return this.noScanCaptureList.concat(this.scanList); + return this.noScanCaptures.concat(this.scanList); } }, filteredItems: function() { // Filter itemList by checkedTags - return this.filterCaptureList(this.itemList, this.checkedTags); + return this.filterCaptures(this.itemList, this.checkedTags); }, filteredCaptures: function() { var captures = {}; for (var item of this.filteredItems) { - if ("captureList" in item) { - for (var capture of item.captureList) { + if ("captures" in item) { + for (var capture of item.captures) { captures[capture.metadata.id] = capture; } } else { @@ -249,15 +244,15 @@ export default { }, sortedItems: function() { - // Sort filteredItems using sortCaptureList function - return this.sortCaptureList(this.filteredItems); + // Sort filteredItems using sortCaptures function + return this.sortCaptures(this.filteredItems); } }, mounted() { // A global signal listener to perform a gallery refresh - this.$root.$on("globalUpdateCaptureList", () => { - this.updateCaptureList(); + this.$root.$on("globalUpdateCaptures", () => { + this.updateCaptures(); }); // A global signal listener to set the gallery folder this.$root.$on("globalUpdateCaptureFolder", folder => { @@ -274,7 +269,7 @@ export default { ready => { if (ready) { // If the connection is now ready, update capture list - this.updateCaptureList(); + this.updateCaptures(); } else { // If the connection is now disconnected, empty capture list this.captures = {}; @@ -285,7 +280,7 @@ export default { beforeDestroy() { // Remove global signal listener to perform a gallery refresh - this.$root.$off("globalUpdateCaptureList"); + this.$root.$off("globalUpdateCaptures"); // Remove global signal listener to set the gallery folder this.$root.$off("globalUpdateCaptureFolder"); // Then we call that function here to unwatch @@ -296,7 +291,7 @@ export default { }, methods: { - updateCaptureList: function() { + updateCaptures: function() { console.log("Updating capture list..."); axios .get(this.capturesUri) @@ -308,7 +303,7 @@ export default { }); }, - filterCaptureList: function(list, filterTags) { + filterCaptures: function(list, filterTags) { // Filter a list of captures by an array of tags var result = []; for (var capture of list) { @@ -330,7 +325,7 @@ export default { return result; }, - sortCaptureList: function(list) { + sortCaptures: function(list) { // Sort a list of captures by metadata time function compare(a, b) { if (a.metadata.time < b.metadata.time) return -1;