Skip to content

Commit

Permalink
attempt #1 to create provider for collection attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
assuntad23 committed Apr 20, 2021
1 parent 6fd60f2 commit 19ead44
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 32 deletions.
40 changes: 9 additions & 31 deletions client/src/components/Collections/common/CollectionEditView.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<template>
<div>
<dataset-collection-attributes-provider :id="collection_id" v-slot="{ item, loading }">
<div v-if="!loading">
{{ loading }}
{{ item }}
</div>
</dataset-collection-attributes-provider>
<h4>{{ l("Edit Collection Attributes") }}</h4>
<b-alert show variant="info" dismissible>
{{ l("This will create a new collection in your History. Your quota usage will not increase. ") }}
Expand Down Expand Up @@ -54,10 +60,6 @@
</template> --> </multiselect
><i>original input: {{ datatypeFromElements }}</i>
</b-tab>
<b-tab>
<template v-slot:title> <font-awesome-icon icon="user" /> &nbsp;{{ l("Permissions") }}</template>
<p>WIP Permissions</p>
</b-tab>
</b-tabs>
</div>
</template>
Expand All @@ -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";
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { default as RxProviderMixin } from "./rxProviders";
import { datasetCollectionAttributesMonitor } from "./monitors";

export default {
mixins: [RxProviderMixin],
methods: {
buildMonitor() {
return datasetCollectionAttributesMonitor();
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -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))
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 19ead44

Please sign in to comment.