11import _l from "utils/localization" ;
2+ import Modal from "utils/modal" ;
23import Vue from "vue" ;
34
45import { rawToTable } from "@/components/Collections/tables" ;
56
6- import { collectionCreatorModalSetup } from "./common/modal" ;
7+ const modal = new Modal ( ) ;
78
8- function ruleBasedCollectionCreatorModal ( elements , elementsType , importType , options ) {
9+ async function ruleBasedCollectionCreatorModal ( elements , elementsType , importType , options ) {
910 // importType in [datasets, collection]
1011 // elementsType in [raw, ftp, datasets]
1112 let title ;
12- if ( importType == "datasets" ) {
13+ if ( importType === "datasets" ) {
1314 title = _l ( "Build Rules for Uploading Datasets" ) ;
14- } else if ( elementsType == "collection_contents" ) {
15+ } else if ( elementsType === "collection_contents" ) {
1516 title = _l ( "Build Rules for Applying to Existing Collection" ) ;
16- } else if ( elementsType == "datasets" || elementsType == "library_datasets" ) {
17+ } else if ( elementsType === "datasets" || elementsType = == "library_datasets" ) {
1718 title = _l ( "Build Rules for Creating Collection(s)" ) ;
1819 } else {
1920 title = _l ( "Build Rules for Uploading Collections" ) ;
2021 }
21- options . title = title ;
22- // Prevents user from accidentally closing the modal by clicking outside the bounds
23- options . closing_events = false ;
24- const { promise, showEl } = collectionCreatorModalSetup ( options ) ;
25- return import ( /* webpackChunkName: "ruleCollectionBuilder" */ "components/RuleCollectionBuilder.vue" ) . then (
26- ( module ) => {
27- var ruleCollectionBuilderInstance = Vue . extend ( module . default ) ;
28- var vm = document . createElement ( "div" ) ;
29- showEl ( vm ) ;
30- new ruleCollectionBuilderInstance ( {
31- propsData : {
32- initialElements : elements ,
33- elementsType : elementsType ,
34- importType : importType ,
35- ftpUploadSite : options . ftpUploadSite ,
36- creationFn : options . creationFn ,
37- oncancel : options . oncancel ,
38- oncreate : options . oncreate ,
39- defaultHideSourceItems : options . defaultHideSourceItems ,
40- saveRulesFn : options . saveRulesFn ,
41- initialRules : options . initialRules ,
42- } ,
43- } ) . $mount ( vm ) ;
44- return promise ;
22+
23+ const promise = new Promise ( ( resolve , reject ) => {
24+ options . oncancel = function ( ) {
25+ modal . hide ( ) ;
26+ resolve ( ) ;
27+ } ;
28+ options . oncreate = function ( response ) {
29+ modal . hide ( ) ;
30+ resolve ( response ) ;
31+ } ;
32+ } ) ;
33+
34+ const module = await import ( /* webpackChunkName: "ruleCollectionBuilder" */ "components/RuleCollectionBuilder.vue" ) ;
35+ const ruleCollectionBuilderInstance = Vue . extend ( module . default ) ;
36+ const vm = document . createElement ( "div" ) ;
37+
38+ // Prepare modal
39+ const titleSuffix = options . historyName ? `From history: <b>${ options . historyName } </b>` : "" ;
40+ const titleHtml = `<div class='d-flex justify-content-between unselectable'>
41+ <span>${ title } </span>
42+ <span>${ titleSuffix } </span>
43+ </div>` ;
44+ modal . show ( {
45+ title : titleHtml ,
46+ body : vm ,
47+ width : "85%" ,
48+ height : "100%" ,
49+ } ) ;
50+
51+ // Inject rule builder component
52+ new ruleCollectionBuilderInstance ( {
53+ propsData : {
54+ initialElements : elements ,
55+ elementsType : elementsType ,
56+ importType : importType ,
57+ ftpUploadSite : options . ftpUploadSite ,
58+ creationFn : options . creationFn ,
59+ oncancel : options . oncancel ,
60+ oncreate : options . oncreate ,
61+ defaultHideSourceItems : options . defaultHideSourceItems ,
62+ saveRulesFn : options . saveRulesFn ,
63+ initialRules : options . initialRules ,
4564 } ,
46- ) ;
65+ } ) . $mount ( vm ) ;
66+
67+ return promise ;
4768}
48- function createCollectionViaRules ( selection , defaultHideSourceItems = true ) {
69+
70+ export async function createCollectionViaRules ( selection , defaultHideSourceItems = true ) {
4971 let elements ;
5072 let elementsType ;
5173 let importType ;
5274 const selectionType = selection . selectionType ;
5375 if ( ! selectionType ) {
54- // Have HDAs from the history panel.
5576 elements = selection . toJSON ( ) ;
5677 elementsType = "datasets" ;
5778 importType = "collections" ;
@@ -64,17 +85,18 @@ function createCollectionViaRules(selection, defaultHideSourceItems = true) {
6485 elementsType = selection . selectionType ;
6586 importType = selection . dataType || "collections" ;
6687 }
67- const promise = ruleBasedCollectionCreatorModal ( elements , elementsType , importType , {
68- ftpUploadSite : selection . ftpUploadSite ,
69- defaultHideSourceItems : defaultHideSourceItems ,
70- creationFn : function ( elements , collectionType , name , hideSourceItems ) {
71- return selection . createHDCA ( elements , collectionType , name , hideSourceItems ) ;
72- } ,
73- } ) ;
74- return promise ;
75- }
7688
77- export default {
78- ruleBasedCollectionCreatorModal : ruleBasedCollectionCreatorModal ,
79- createCollectionViaRules : createCollectionViaRules ,
80- } ;
89+ try {
90+ const result = await ruleBasedCollectionCreatorModal ( elements , elementsType , importType , {
91+ ftpUploadSite : selection . ftpUploadSite ,
92+ defaultHideSourceItems : defaultHideSourceItems ,
93+ creationFn : async ( elements , collectionType , name , hideSourceItems ) => {
94+ return selection . createHDCA ( elements , collectionType , name , hideSourceItems ) ;
95+ } ,
96+ } ) ;
97+ return result ;
98+ } catch ( error ) {
99+ console . error ( "Error in rule-based collection creation:" , error ) ;
100+ throw error ;
101+ }
102+ }
0 commit comments