From 6fd60f21ef934b1ab6b0860b6784cf1183250082 Mon Sep 17 00:00:00 2001 From: Assunta DeSanto Date: Tue, 13 Apr 2021 18:18:31 -0400 Subject: [PATCH] added upload utils and collection attributes to a store, other formatting, test fixing --- .../Collections/common/CollectionEditView.vue | 95 +++++++++---------- .../Collections/common/DatabaseEditTab.vue | 37 ++++++-- client/src/store/collectionStore.js | 65 +++++++++++++ client/src/store/index.js | 2 + 4 files changed, 138 insertions(+), 61 deletions(-) create mode 100644 client/src/store/collectionStore.js diff --git a/client/src/components/Collections/common/CollectionEditView.vue b/client/src/components/Collections/common/CollectionEditView.vue index 9ad9c199890b..08c9c6d7acb1 100644 --- a/client/src/components/Collections/common/CollectionEditView.vue +++ b/client/src/components/Collections/common/CollectionEditView.vue @@ -10,18 +10,13 @@ - - - {{ l("Name: ") }} {{ collectionName }} -
- {{ l("Collection Type: ") }} {{ collectionType }} -
- {{ l("Elements: ") }}
-
{{ element.element_identifier }}
-
- + @@ -72,7 +67,6 @@ import Vue from "vue"; import BootstrapVue from "bootstrap-vue"; import axios from "axios"; import { prependPath } from "utils/redirect"; -import UploadUtils from "mvc/upload/upload-utils"; import _l from "utils/localization"; import Multiselect from "vue-multiselect"; import { errorMessageAsString } from "utils/simple-error"; @@ -84,6 +78,7 @@ import { faTable } from "@fortawesome/free-solid-svg-icons"; import { faBars } from "@fortawesome/free-solid-svg-icons"; import { faUser } from "@fortawesome/free-solid-svg-icons"; import { faCog } from "@fortawesome/free-solid-svg-icons"; +import store from "../../../store/index"; //import VueObserveVisibility from "vue-observe-visibility"; @@ -97,22 +92,10 @@ library.add(faUser); Vue.use(BootstrapVue); export default { created() { - this.apiCallToGetData(); - this.apiCallToGetAttributes(); - UploadUtils.getUploadDatatypes(true, UploadUtils.AUTO_EXTENSION) - .then((extensions) => { - this.extensions = extensions; - }) - .catch((err) => { - console.log("Error in CollectionEditor, unable to load datatypes", err); - }); - UploadUtils.getUploadGenomes(UploadUtils.DEFAULT_GENOME) - .then((genomes) => { - this.genomes = genomes; - }) - .catch((err) => { - console.log("Error in CollectionEditor, unable to load genomes", err); - }); + // this.apiCallToGetData(); + // this.apiCallToGetAttributes(); + this.getDatatypesAndGenomes(); + this.getCollectionDataAndAttributes(); }, components: { Multiselect, DatabaseEditTab, FontAwesomeIcon }, data: function () { @@ -145,20 +128,11 @@ export default { // }, }, collectionType: { + // no setter; for display only get() { return this.collection_data.collection_type; }, }, - collectionElements: { - get() { - return this.collection_data.elements; - }, - }, - numberOfCollectionElements: { - get() { - return this.collection_data.element_count; - }, - }, extension: { get() { return this.selectedExtension; @@ -173,48 +147,65 @@ export default { // _l conflicts private methods of Vue internals, expose as l instead return _l(str); }, + getDatatypesAndGenomes: async function () { + let datatypes = store.getters.getUploadDatatypes(); + if (!datatypes || datatypes.length == 0) { + await store.dispatch("fetchUploadDatatypes"); + datatypes = store.getters.getUploadDatatypes(); + } + this.extensions = datatypes; + + let genomes = store.getters.getUploadGenomes(); + if (!genomes || genomes.length == 0) { + await store.dispatch("fetchUploadGenomes"); + genomes = store.getters.getUploadGenomes(); + } + this.genomes = genomes; + }, + getCollectionDataAndAttributes: async function () { + this.apiCallToGetData(); + + let attributesGet = store.getters.getCollectionAttributes(this.collection_id); + if (attributesGet == null) { + await store.dispatch("fetchCollectionAttributes", this.collection_id); + attributesGet = store.getters.getCollectionAttributes(this.collection_id); + } + this.attributes_data = attributesGet; + this.getDatabaseKeyFromElements(); + this.getExtensionFromElements(); + }, apiCallToGetData: function () { axios .get(prependPath("/api/dataset_collections/" + this.collection_id + "?instance_type=history")) .then((response) => { this.collection_data = response.data; - this.getDatabaseKeyFromElements(); - this.getExtensionFromElements(); }); //TODO error handling }, - apiCallToGetAttributes: function () { - axios - .get(prependPath("/api/dataset_collections/" + this.collection_id + "/attributes")) - .then((response) => { - this.attributes_data = response.data; - this.getDatabaseKeyFromElements(); - this.getExtensionFromElements(); - }); - //TODO error handling - }, getDatabaseKeyFromElements: function () { this.databaseKeyFromElements = this.attributes_data.dbkey; - // this.selectedGenome = this.genomes.find((element) => element.id == this.databaseKeyFromElements); }, getExtensionFromElements: function () { this.datatypeFromElements = this.attributes_data.extension; this.selectedExtension = this.extensions.find((element) => element.id == this.datatypeFromElements); }, clickedSave: function (attribute, newValue) { + console.log("user clicked Save.... genome is", newValue); const url = prependPath("/api/dataset_collections/" + this.collection_id); const data = {}; if (attribute == "dbkey") { - data.add({ dbkey: newValue.id }); + data["dbkey"] = newValue.id; } else if (attribute == "file_ext") { - data.add({ file_ext: newValue.id }); + data["file_ext"] = newValue.id; } axios .put(url, data) .then((response) => { this.apiCallToGetData(); + this.getDatabaseKeyFromElements(); + this.getExtensionFromElements(); }) .catch(this.handleError); }, diff --git a/client/src/components/Collections/common/DatabaseEditTab.vue b/client/src/components/Collections/common/DatabaseEditTab.vue index 6ec80e682451..928d5673fe45 100644 --- a/client/src/components/Collections/common/DatabaseEditTab.vue +++ b/client/src/components/Collections/common/DatabaseEditTab.vue @@ -6,7 +6,7 @@ @@ -28,12 +28,17 @@