diff --git a/app/javascript/vue/shared/content/attachments/context_menu.vue b/app/javascript/vue/shared/content/attachments/context_menu.vue index 4e84de0c5..06f67a743 100644 --- a/app/javascript/vue/shared/content/attachments/context_menu.vue +++ b/app/javascript/vue/shared/content/attachments/context_menu.vue @@ -57,11 +57,15 @@ :fileName="attachment.attributes.file_name" @confirm="showNoPredefinedAppModal = false" /> + diff --git a/app/javascript/vue/shared/content/attachments/mixins/open_locally.js b/app/javascript/vue/shared/content/attachments/mixins/open_locally.js index f1871bb9f..99773f7eb 100644 --- a/app/javascript/vue/shared/content/attachments/mixins/open_locally.js +++ b/app/javascript/vue/shared/content/attachments/mixins/open_locally.js @@ -1,43 +1,52 @@ import axios from '../../../../../packs/custom_axios.js'; +import { satisfies } from 'compare-versions'; import editLaunchingApplicationModal from '../../modal/edit_launching_application_modal.vue'; import NoPredefinedAppModal from '../../modal/no_predefined_app_modal.vue'; +import UpdateVersionModal from '../../modal/update_version_modal.vue'; export default { data() { return { localAppName: null, scinoteEditRunning: false, + scinoteEditVersion: null, showNoPredefinedAppModal: false, + showUpdateVersionModal: false, editAppModal: false }; }, components: { editLaunchingApplicationModal, - NoPredefinedAppModal + NoPredefinedAppModal, + UpdateVersionModal }, computed: { + attributes() { + return this.attachment.attributes; + }, canOpenLocally() { - return this.scinoteEditRunning && - !!this.attachment.attributes.urls.open_locally && - this.attachment.attributes.asset_type !== 'gene_sequence' && - this.attachment.attributes.asset_type !== 'marvinjs' + return this.scinoteEditRunning + && !!this.attributes.urls.open_locally + && this.attributes.asset_type !== 'gene_sequence' + && this.attributes.asset_type !== 'marvinjs'; } }, methods: { async fetchLocalAppInfo() { try { const statusResponse = await axios.get( - `${this.attachment.attributes.urls.open_locally_api}/status` + `${this.attributes.urls.open_locally_api}/status` ); if (statusResponse.status === 200) { this.scinoteEditRunning = true; + this.scinoteEditVersion = statusResponse.data.version; } else { return; } const response = await axios.get( - `${this.attachment.attributes.urls.open_locally_api}/default-application/${this.attachment.attributes.file_extension}` + `${this.attributes.urls.open_locally_api}/default-application/${this.attributes.file_extension}` ); if (response.data.application.toLowerCase() !== 'pick an app') { @@ -48,18 +57,25 @@ export default { } }, async openLocally() { - if (this.localAppName === null) { + if (this.isWrongVersion(this.scinoteEditVersion)) { + this.showUpdateVersionModal = true; + return; + } else if (this.localAppName === null) { this.showNoPredefinedAppModal = true; return; } this.editAppModal = true; try { - const { data } = await axios.get(this.attachment.attributes.urls.open_locally); - await axios.post(this.attachment.attributes.urls.open_locally_api + '/download', data); + const { data } = await axios.get(this.attributes.urls.open_locally); + await axios.post(`${this.attributes.urls.open_locally_api}/download`, data); } catch (error) { console.error('Error in request:', error); } + }, + isWrongVersion(version) { + const { min, max } = this.attributes.edit_version_range; + return !satisfies(version, `${min} - ${max}`); } } } diff --git a/app/javascript/vue/shared/content/attachments/open_locally_menu.vue b/app/javascript/vue/shared/content/attachments/open_locally_menu.vue index 853f9227a..e4428faf3 100644 --- a/app/javascript/vue/shared/content/attachments/open_locally_menu.vue +++ b/app/javascript/vue/shared/content/attachments/open_locally_menu.vue @@ -1,11 +1,11 @@