Skip to content

Commit

Permalink
Merge pull request #14638 from guerler/revise_history_view
Browse files Browse the repository at this point in the history
Remove legacy history usage from js-modules
  • Loading branch information
mvdbeek authored Sep 21, 2022
2 parents 926677d + 542be34 commit d5c9cc6
Show file tree
Hide file tree
Showing 19 changed files with 139 additions and 412 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function listCollectionCreatorModal(elements, options) {
/** Use a modal to create a list collection, then add it to the given history contents.
* @returns {Promise} resolved when the collection is added to the history.
*/
function createListCollection(contents, defaultHideSourceItems) {
function createListCollection(contents, defaultHideSourceItems = true) {
const elements = contents.toJSON();
let copyElements;
const promise = listCollectionCreatorModal(elements, {
Expand All @@ -36,7 +36,7 @@ function createListCollection(contents, defaultHideSourceItems) {
id: element.id,
name: element.name,
//TODO: this allows for list:list even if the filter above does not - reconcile
src: element.history_content_type === "dataset" ? "hda" : "hdca",
src: element.src || (element.history_content_type == "dataset" ? "hda" : "hdca"),
}));
copyElements = !hideSourceItems;
return contents.createHDCA(elements, "list", name, hideSourceItems, copyElements);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ function pairCollectionCreatorModal(elements, options) {
return promise;
});
}
function createPairCollection(contents, defaultHideSourceItems) {
function createPairCollection(contents, defaultHideSourceItems = true) {
var elements = contents.toJSON();
var copyElements;
var promise = pairCollectionCreatorModal(elements, {
defaultHideSourceItems: defaultHideSourceItems,
creationFn: function (elements, name, hideSourceItems) {
elements = [
{ name: "forward", src: "hda", id: elements[0].id },
{ name: "reverse", src: "hda", id: elements[1].id },
{ name: "forward", src: elements[0].src || "hda", id: elements[0].id },
{ name: "reverse", src: elements[1].src || "hda", id: elements[1].id },
];
copyElements = !hideSourceItems;
return contents.createHDCA(elements, "paired", name, hideSourceItems, copyElements);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function ruleBasedCollectionCreatorModal(elements, elementsType, importType, opt
}
);
}
function createCollectionViaRules(selection, defaultHideSourceItems) {
function createCollectionViaRules(selection, defaultHideSourceItems = true) {
let elements;
let elementsType;
let importType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export default {
await this.buildNewCollection("rules");
},
async buildNewCollection(collectionType) {
const modalResult = await buildCollectionModal(collectionType, this.history.id, this.contentSelection);
const modalResult = await buildCollectionModal(collectionType, this.contentSelection, this.history.id);
await createDatasetCollection(this.history, modalResult);
// have to hide the source items if that was requested
Expand Down
89 changes: 89 additions & 0 deletions client/src/components/History/HistoryView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<template>
<CurrentUser v-slot="{ user }">
<UserHistories v-if="user" v-slot="{ handlers }" :user="user">
<div v-if="history" class="d-flex flex-column h-100">
<b-alert v-if="history.purged" variant="info" show>This history has been purged.</b-alert>
<div v-else class="flex-row flex-grow-0">
<b-button
v-if="user.id == history.user_id"
size="sm"
variant="outline-info"
title="Switch to this history"
@click="handlers.setCurrentHistory(history)">
Switch to this history
</b-button>
<b-button
v-else
size="sm"
variant="outline-info"
title="Import this history"
v-b-modal:copy-history-modal>
Import this history
</b-button>
</div>
<CollectionPanel
v-if="selectedCollections.length && selectedCollections[0].history_id == id"
:history="history"
:selected-collections.sync="selectedCollections"
:show-controls="false"
@view-collection="onViewCollection" />
<HistoryPanel
v-else
v-on="handlers"
:history="history"
:show-controls="false"
@view-collection="onViewCollection" />
<CopyModal id="copy-history-modal" :history="history" />
</div>
<b-alert v-else class="m-2" variant="info" show>
<LoadingSpan message="Loading History" />
</b-alert>
</UserHistories>
</CurrentUser>
</template>

<script>
import { mapGetters } from "vuex";
import CurrentUser from "components/providers/CurrentUser";
import UserHistories from "components/providers/UserHistories";
import LoadingSpan from "components/LoadingSpan";
import CollectionPanel from "./CurrentCollection/CollectionPanel";
import HistoryPanel from "./CurrentHistory/HistoryPanel";
import CopyModal from "./Modals/CopyModal";
export default {
components: {
LoadingSpan,
HistoryPanel,
CollectionPanel,
CurrentUser,
UserHistories,
CopyModal,
},
props: {
id: {
type: String,
required: true,
},
},
data() {
return {
selectedCollections: [],
};
},
created() {
this.$store.dispatch("history/loadHistoryById", this.id);
},
computed: {
...mapGetters({ getHistoryById: "history/getHistoryById" }),
history() {
return this.getHistoryById(this.id);
},
},
methods: {
onViewCollection(collection) {
this.selectedCollections = [...this.selectedCollections, collection];
},
},
};
</script>
13 changes: 4 additions & 9 deletions client/src/components/History/adapters/HistoryPanelProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ export class HistoryPanelProxy {
this.model.id = historyId;
store.dispatch("history/setCurrentHistory", historyId);
}
async buildCollection(collectionType, selection, hideSourceItems, fromRulesInput = false) {
async buildCollection(collectionType, selection, historyId = null, fromRulesInput = false) {
let selectionContent = null;
historyId = historyId || this.model.id;
if (fromRulesInput) {
selectionContent = selection;
} else {
Expand All @@ -71,16 +72,10 @@ export class HistoryPanelProxy {
selectionContent.set(obj.id, obj);
});
}
const modalResult = await buildCollectionModal(
collectionType,
this.model.id,
selectionContent,
hideSourceItems,
fromRulesInput
);
const modalResult = await buildCollectionModal(collectionType, selectionContent, historyId, fromRulesInput);
if (modalResult) {
console.debug("Submitting collection build request.", modalResult);
await createDatasetCollection({ id: this.model.id }, modalResult);
await createDatasetCollection({ id: historyId }, modalResult);
}
}
}
14 changes: 4 additions & 10 deletions client/src/components/History/adapters/buildCollectionModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ import LIST_OF_PAIRS_COLLECTION_CREATOR from "components/Collections/PairedListC
import RULE_BASED_COLLECTION_CREATOR from "components/Collections/RuleBasedCollectionCreatorModal";

// stand-in for buildCollection from history-view-edit.js
export async function buildCollectionModal(
collectionType,
history_id,
selectedContent,
hideSourceItems = true,
fromRulesInput = false
) {
export async function buildCollectionModal(collectionType, selectedContent, historyId, fromRulesInput = false) {
// select legacy function
let createFunc;
if (collectionType == "list") {
Expand All @@ -37,10 +31,10 @@ export async function buildCollectionModal(
}
// pull up cached content by type_ids;
if (fromRulesInput) {
return await createFunc(selectedContent, hideSourceItems);
return await createFunc(selectedContent);
} else {
const fakeBackboneContent = createBackboneContent(history_id, selectedContent);
return await createFunc(fakeBackboneContent, hideSourceItems);
const fakeBackboneContent = createBackboneContent(historyId, selectedContent);
return await createFunc(fakeBackboneContent);
}
}

Expand Down
119 changes: 0 additions & 119 deletions client/src/components/HistoryView.vue

This file was deleted.

Loading

0 comments on commit d5c9cc6

Please sign in to comment.