| <template> |
| <PluginComponent v-model="open" :infoPayload="infoPayload" actionBtnTxt="Clone" @onPopupDone="onPopupDone" |
| :hideIfDisabled="true" @onUserArgChanged="onUserArgChanged" @onMolCountsChanged="onMolCountsChanged"> |
| </PluginComponent> |
| </template> |
|
|
| <script lang="ts"> |
| import { Options } from "vue-class-component"; |
| import { |
| IContributorCredit, |
| ISoftwareCredit, |
| } from "@/Plugins/PluginInterfaces"; |
| |
| import { TreeNodeList } from "@/TreeNodes/TreeNodeList/TreeNodeList"; |
| import FormWrapper from "@/UI/Forms/FormWrapper.vue"; |
| import FormInput from "@/UI/Forms/FormInput.vue"; |
| import { cloneMolsWithAncestry } from "@/UI/Navigation/TreeView/TreeUtils"; |
| import PluginComponent from "@/Plugins/Parents/PluginComponent/PluginComponent.vue"; |
| import { PluginParentClass } from "@/Plugins/Parents/PluginParentClass/PluginParentClass"; |
| import { getDefaultNodeToActOn, setNodesToActOn } from "./EditBarUtils"; |
| import { UserArg, IUserArgText } from "@/UI/Forms/FormFull/FormFullInterfaces"; |
| import { checkOneMolSelected } from "../../CheckUseAllowedUtils"; |
| import { ITest } from "@/Testing/TestInterfaces"; |
| import { TestCmdList } from "@/Testing/TestCmdList"; |
| import { Tag } from "@/Plugins/Core/ActivityFocus/ActivityFocusUtils"; |
| |
| |
| @Options({ |
| components: { |
| FormInput, |
| FormWrapper, |
| PluginComponent, |
| }, |
| }) |
| export default class CloneMolPlugin extends PluginParentClass { |
| menuPath = ["Edit", "Molecules", "Clone..."]; |
| title = "Clone Molecule"; |
| softwareCredits: ISoftwareCredit[] = []; |
| contributorCredits: IContributorCredit[] = [ |
| // { |
| // name: "Jacob D. Durrant", |
| // url: "http://durrantlab.com/", |
| // }, |
| ]; |
| pluginId = "clonemol"; |
| intro = `Clone (copy) the selected molecule.`; |
| details = "This plugin creates an identical, independent copy of the selected molecule within the current project."; |
| tags = [Tag.All]; |
| |
| userArgDefaults: UserArg[] = [ |
| { |
| id: "newName", |
| label: "", |
| val: "", |
| placeHolder: "Name of new cloned molecule...", |
| description: "The name of the new, cloned molecule.", |
| validateFunc: (newName: string): boolean => { |
| return newName.length > 0; |
| }, |
| } as IUserArgText, |
| ]; |
| |
| nodesToActOn = new TreeNodeList([getDefaultNodeToActOn()]); |
| |
| logJob = false; |
| |
| |
| |
| |
| |
| {any} payload The payload (node id) |
| */ |
| async onBeforePopupOpen(payload: any) { |
| setNodesToActOn(this, payload); |
| |
| const nodeToActOn = (this.nodesToActOn as TreeNodeList).get(0); |
| |
| // Get top of molecule title. |
| let title = nodeToActOn |
| .getAncestry(this.$store.state.molecules) |
| .get(0).title; |
| |
| this.setUserArg("newName", title + ":cloned"); |
| } |
| |
| |
| |
| |
| {string | null} If it returns a string, show that as an error |
| * message. If null, proceed to run the plugin. |
| */ |
| checkPluginAllowed(): string | null { |
| return checkOneMolSelected(); |
| } |
| |
| |
| |
| |
| {Promise<void>} A promise that resolves when the job is done. |
| */ |
| runJobInBrowser(): Promise<void> { |
| if (!this.nodesToActOn) { |
| // Nothing to do. |
| return Promise.resolve(); |
| } |
| |
| |
| return cloneMolsWithAncestry(this.nodesToActOn, true) |
| .then((treeNodeList: TreeNodeList) => { |
| const node = treeNodeList.get(0); |
| node.title = this.getUserArg("newName"); |
| treeNodeList.addToMainTree(this.pluginId); |
| // this.$store.commit("pushToMolecules", node); |
| return; |
| }) |
| .catch((err) => { |
| throw err; |
| }); |
| |
| |
| |
| |
| <TreeNode>; |
| |
| |
| |
| { |
| // return newestNode; |
| // }); |
| |
| |
| { |
| // // Get the nodes ancestory |
| // let nodeGenealogy: TreeNode[] = getNodeAncestory( |
| // node.id as string, |
| // this.$store.state.molecules |
| // ); |
| |
| // // Make copies of all the nodes in the ancestory, emptying the nodes |
| // // except for the last one. |
| // for (let i = 0; i < nodeGenealogy.length; i++) { |
| // nodeGenealogy[i] = { |
| // ...nodeGenealogy[i], |
| // }; |
| |
| { |
| // nodeGenealogy[i].nodes = []; |
| // } |
| |
| |
| |
| { |
| // nodeGenealogy[i].nodes?.push(nodeGenealogy[i + 1]); |
| |
| // // Also, parentId |
| // nodeGenealogy[i + 1].parentId = nodeGenealogy[i].id; |
| // } |
| |
| |
| |
| |
| |
| |
| { |
| // allNodesFlattened.push(...getAllNodesFlattened(topNode.nodes)); |
| // } |
| |
| { |
| // oldIdToNewId.set(node.id as string, randomID()); |
| // } |
| { |
| // node.id = oldIdToNewId.get(node.id as string); |
| // if (node.parentId) { |
| // node.parentId = oldIdToNewId.get(node.parentId); |
| // } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| { |
| // throw err; |
| // }); |
| } |
| |
| |
| |
| |
| |
| |
| {ITest[]} The selenium test commandss. |
| */ |
| async getTests(): Promise<ITest[]> { |
| return [ |
| // First test cloning |
| { |
| beforePluginOpens: () => new TestCmdList() |
| .loadExampleMolecule(true) |
| .selectMoleculeInTree("Protein"), |
| pluginOpen: () => new TestCmdList().setUserArg("newName", "Cloned Protein", this.pluginId), |
| afterPluginCloses: () => new TestCmdList() |
| .waitUntilRegex("#navigator", "Cloned Protein") |
| .wait(0.5) |
| |
| // Also check clicking in title bar |
| .selectMoleculeInTree("Compounds") |
| .wait(0.5) |
| .click('#navigator div[data-label="Compounds"] span.cloneextract') |
| .text("#newName-clonemol-item", "Compounds-cloned") |
| .pressPopupButton(".action-btn", this.pluginId) |
| .wait(2) |
| .waitUntilRegex("#navigator", "Compounds-cloned"), |
| }, |
| |
| { |
| beforePluginOpens: () => new TestCmdList().loadExampleMolecule(), |
| // No selection is made, checkPluginAllowed should fail. |
| // This test is expected to fail at the checkPluginAllowed stage, so it won't open its own popup. |
| // We provide an empty closePlugin to override the default, which would fail. |
| closePlugin: () => new TestCmdList(), |
| afterPluginCloses: () => new TestCmdList() |
| .waitUntilRegex( |
| "#modal-simplemsg", |
| "First select one" |
| ) |
| // Also need to close the simple message popup to continue. |
| .click("#modal-simplemsg .cancel-btn"), |
| }, |
| |
| { |
| beforePluginOpens: () => new TestCmdList() |
| .loadExampleMolecule(true) |
| .selectMoleculeInTree("Protein") |
| .selectMoleculeInTree("Compounds", true), // shift-click to select a second |
| // This test is also expected to fail at the checkPluginAllowed stage. |
| closePlugin: () => new TestCmdList(), |
| afterPluginCloses: () => new TestCmdList() |
| .waitUntilRegex( |
| "#modal-simplemsg", |
| "First select one" |
| ) |
| // Also need to close the simple message popup to continue. |
| .click("#modal-simplemsg .cancel-btn"), |
| }, |
| ]; |
| } |
| } |
| </script> |
| |
| <style scoped lang="scss"></style> |
| |