From 19ead44f320c0e54a01b68805d5c2937e8e15412 Mon Sep 17 00:00:00 2001 From: Assunta DeSanto Date: Tue, 20 Apr 2021 12:18:50 -0400 Subject: [PATCH] attempt #1 to create provider for collection attributes --- .../Collections/common/CollectionEditView.vue | 40 +++++-------------- .../DatasetCollectionAttributesProvider.js | 11 +++++ .../providers/fetch.js | 7 ++++ .../providers/index.js | 1 + .../providers/monitors.js | 10 ++++- .../providers/storeProviders.js | 18 +++++++++ 6 files changed, 55 insertions(+), 32 deletions(-) create mode 100644 client/src/components/WorkflowInvocationState/providers/DatasetCollectionAttributesProvider.js diff --git a/client/src/components/Collections/common/CollectionEditView.vue b/client/src/components/Collections/common/CollectionEditView.vue index 08c9c6d7acb1..1b156f43461a 100644 --- a/client/src/components/Collections/common/CollectionEditView.vue +++ b/client/src/components/Collections/common/CollectionEditView.vue @@ -1,5 +1,11 @@ --> original input: {{ datatypeFromElements }} - - -

WIP Permissions

-
@@ -79,6 +81,7 @@ 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 { DatasetCollectionAttributesProvider } from "../../WorkflowInvocationState/providers"; //import VueObserveVisibility from "vue-observe-visibility"; @@ -96,8 +99,9 @@ export default { // this.apiCallToGetAttributes(); this.getDatatypesAndGenomes(); this.getCollectionDataAndAttributes(); + console.log("item is", this.item); }, - components: { Multiselect, DatabaseEditTab, FontAwesomeIcon }, + components: { Multiselect, DatabaseEditTab, FontAwesomeIcon, DatasetCollectionAttributesProvider }, data: function () { return { collection_data: {}, //all data from the response @@ -118,21 +122,6 @@ export default { }, }, computed: { - collectionName: { - get() { - return this.collection_data.name; - }, - //TODO : #6966 - // set(collection_name) { - // this.collection_data.name = collection_name; - // }, - }, - collectionType: { - // no setter; for display only - get() { - return this.collection_data.collection_type; - }, - }, extension: { get() { return this.selectedExtension; @@ -163,8 +152,6 @@ export default { 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); @@ -174,15 +161,6 @@ export default { 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; - }); - - //TODO error handling - }, getDatabaseKeyFromElements: function () { this.databaseKeyFromElements = this.attributes_data.dbkey; }, diff --git a/client/src/components/WorkflowInvocationState/providers/DatasetCollectionAttributesProvider.js b/client/src/components/WorkflowInvocationState/providers/DatasetCollectionAttributesProvider.js new file mode 100644 index 000000000000..147f07f2d8dc --- /dev/null +++ b/client/src/components/WorkflowInvocationState/providers/DatasetCollectionAttributesProvider.js @@ -0,0 +1,11 @@ +import { default as RxProviderMixin } from "./rxProviders"; +import { datasetCollectionAttributesMonitor } from "./monitors"; + +export default { + mixins: [RxProviderMixin], + methods: { + buildMonitor() { + return datasetCollectionAttributesMonitor(); + }, + }, +}; diff --git a/client/src/components/WorkflowInvocationState/providers/fetch.js b/client/src/components/WorkflowInvocationState/providers/fetch.js index 185bc7d07cbd..b3a6640dca84 100644 --- a/client/src/components/WorkflowInvocationState/providers/fetch.js +++ b/client/src/components/WorkflowInvocationState/providers/fetch.js @@ -23,3 +23,10 @@ export const fetchInvocationStepById = () => { mergeMap((url) => ajax.getJSON(url)) ); }; + +export const fetchDatasetCollectionAttributesById = () => { + return pipe( + map((id) => prependPath(`/api/dataset_collections/${id}/attributes`)), + mergeMap((url) => ajax.getJSON(url)) + ); +}; diff --git a/client/src/components/WorkflowInvocationState/providers/index.js b/client/src/components/WorkflowInvocationState/providers/index.js index 48ba104c87df..f617879c1e7e 100644 --- a/client/src/components/WorkflowInvocationState/providers/index.js +++ b/client/src/components/WorkflowInvocationState/providers/index.js @@ -8,4 +8,5 @@ export { // test provider export { default as DatasetProvider } from "./DatasetProvider"; export { default as DatasetCollectionProvider } from "./DatasetCollectionProvider"; +export { default as DatasetCollectionAttributesProvider } from "./DatasetCollectionAttributesProvider"; export { default as InvocationStepProvider } from "./InvocationStepProvider"; diff --git a/client/src/components/WorkflowInvocationState/providers/monitors.js b/client/src/components/WorkflowInvocationState/providers/monitors.js index 7c72b5edc441..dbef3bfbf5ae 100644 --- a/client/src/components/WorkflowInvocationState/providers/monitors.js +++ b/client/src/components/WorkflowInvocationState/providers/monitors.js @@ -2,7 +2,7 @@ import { of, race, pipe, concat, iif } from "rxjs"; import { filter, mergeMap, switchMap, delay, share, repeat, take, takeWhile } from "rxjs/operators"; import { cacheContent, monitorContentQuery } from "components/History/caching"; import { singleUpdateResult } from "components/History/caching/db/monitorQuery"; -import { fetchDatasetById, fetchDatasetCollectionById, fetchInvocationStepById } from "./fetch"; +import { fetchDatasetById, fetchDatasetCollectionById, fetchInvocationStepById, fetchDatasetCollectionAttributesById } from "./fetch"; import { loadHistoryContents } from "components/History/caching"; // prettier-ignore @@ -21,6 +21,11 @@ export const datasetCollectionMonitor = (cfg = {}) => { return pipe(switchMap((id) => createContentMonitor(id, "dataset_collection", spinUpDelay))); }; +export const datasetCollectionAttributesMonitor = (cfg = {}) => { + const { spinUpDelay } = cfg; + return pipe(switchMap((id) => createContentMonitor(id, "dataset_collection_attributes", spinUpDelay))); +}; + const createContentMonitor = (id, contentType, spinUpDelay = 250) => { let fetcher; switch (contentType) { @@ -30,6 +35,9 @@ const createContentMonitor = (id, contentType, spinUpDelay = 250) => { case "dataset_collection": fetcher = fetchDatasetCollectionById; break; + case "dataset_collection_attributes": + fetcher = fetchDatasetCollectionAttributesById; + break; default: console.error(`Can't create monitor for ${contentType}-${id}`); } diff --git a/client/src/components/WorkflowInvocationState/providers/storeProviders.js b/client/src/components/WorkflowInvocationState/providers/storeProviders.js index aacaf31cec4c..0fa242af6300 100644 --- a/client/src/components/WorkflowInvocationState/providers/storeProviders.js +++ b/client/src/components/WorkflowInvocationState/providers/storeProviders.js @@ -80,6 +80,24 @@ export const DatasetCollectionProvider = { }, }; +export const DatasetCollectionAttributesProvider = { + mixins: [SimpleProviderMixin, StoreProviderMixin], + methods: { + ...mapCacheActions("datasetCollectionAttributes", ["fetchDatasetCollectionAttributes"]), + async load() { + this.loading = true; + this.item = await this.fetchDatasetCollectionAttributes(this.id); + this.loading = false; + }, + }, + computed: { + ...mapGetters("datasetCollectionAttributes", ["getDatasetCollectionAttributesById"]), + storeItem() { + return this.getDatasetCollectionAttributesById(this.id); + }, + }, +}; + export const DatasetCollectionContentProvider = { mixins: [SimpleProviderMixin], computed: {