@@ -251,12 +251,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
251251 return ;
252252 }
253253
254- osparc . data . Resources . get ( "tasks" )
255- . then ( tasks => {
256- if ( tasks && tasks . length ) {
257- this . __tasksReceived ( tasks ) ;
258- }
259- } ) ;
254+ this . __tasksToCards ( ) ;
260255
261256 this . _loadingResourcesBtn . setFetching ( true ) ;
262257 this . _loadingResourcesBtn . setVisibility ( "visible" ) ;
@@ -1889,18 +1884,6 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
18891884 return this . _resourcesList . find ( study => study . uuid === id ) ;
18901885 } ,
18911886
1892- __createDuplicateCard : function ( studyName ) {
1893- const isGrid = this . _resourcesContainer . getMode ( ) === "grid" ;
1894- const duplicatingStudyCard = isGrid ? new osparc . dashboard . GridButtonPlaceholder ( ) : new osparc . dashboard . ListButtonPlaceholder ( ) ;
1895- duplicatingStudyCard . buildLayout (
1896- this . tr ( "Duplicating " ) + studyName ,
1897- osparc . task . Duplicate . ICON + ( isGrid ? "60" : "24" ) ,
1898- null ,
1899- true
1900- ) ;
1901- return duplicatingStudyCard ;
1902- } ,
1903-
19041887 __duplicateStudy : function ( studyData ) {
19051888 const text = this . tr ( "Duplicate process started and added to the background tasks" ) ;
19061889 osparc . FlashMessenger . logAs ( text , "INFO" ) ;
@@ -1915,54 +1898,53 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
19151898 } ;
19161899 const fetchPromise = osparc . data . Resources . fetch ( "studies" , "duplicate" , params , options ) ;
19171900 const interval = 1000 ;
1918- const pollTasks = osparc . data . PollTasks . getInstance ( ) ;
1901+ const pollTasks = osparc . store . PollTasks . getInstance ( ) ;
19191902 pollTasks . createPollingTask ( fetchPromise , interval )
19201903 . then ( task => this . __taskDuplicateReceived ( task , studyData [ "name" ] ) )
19211904 . catch ( err => osparc . FlashMessenger . logError ( err , this . tr ( "Something went wrong while duplicating" ) ) ) ;
19221905 } ,
19231906
19241907 __exportStudy : function ( studyData ) {
1925- const exportTask = new osparc . task . Export ( studyData ) ;
1926- exportTask . start ( ) ;
1927- exportTask . setSubtitle ( this . tr ( "Preparing files" ) ) ;
1908+ const exportTaskUI = new osparc . task . Export ( studyData ) ;
1909+ exportTaskUI . setSubtitle ( this . tr ( "Preparing files" ) ) ;
1910+
1911+ osparc . task . TasksContainer . getInstance ( ) . addTaskUI ( exportTaskUI ) ;
1912+
19281913 const text = this . tr ( "Exporting process started and added to the background tasks" ) ;
19291914 osparc . FlashMessenger . logAs ( text , "INFO" ) ;
19301915
19311916 const url = window . location . href + "v0/projects/" + studyData [ "uuid" ] + ":xport" ;
19321917 const progressCB = ( ) => {
19331918 const textSuccess = this . tr ( "Download started" ) ;
1934- exportTask . setSubtitle ( textSuccess ) ;
1919+ exportTaskUI . setSubtitle ( textSuccess ) ;
19351920 } ;
19361921 osparc . utils . Utils . downloadLink ( url , "POST" , null , progressCB )
19371922 . catch ( err => {
19381923 const msg = osparc . data . Resources . getErrorMsg ( JSON . parse ( err . response ) ) || this . tr ( "Something went wrong while exporting the study" ) ;
19391924 osparc . FlashMessenger . logError ( err , msg ) ;
19401925 } )
1941- . finally ( ( ) => {
1942- exportTask . stop ( ) ;
1943- } ) ;
1926+ . finally ( ( ) => osparc . task . TasksContainer . getInstance ( ) . removeTaskUI ( exportTaskUI ) ) ;
19441927 } ,
19451928
19461929 __importStudy : function ( file ) {
19471930 const uploadingLabel = this . tr ( "Uploading file" ) ;
1948- const importTask = new osparc . task . Import ( ) ;
1949- importTask . start ( ) ;
1950- importTask . setSubtitle ( uploadingLabel ) ;
1931+ const importTaskUI = new osparc . task . Import ( ) ;
1932+ importTaskUI . setSubtitle ( uploadingLabel ) ;
1933+
1934+ osparc . task . TasksContainer . getInstance ( ) . addTaskUI ( importTaskUI ) ;
19511935
19521936 const text = this . tr ( "Importing process started and added to the background tasks" ) ;
19531937 osparc . FlashMessenger . logAs ( text , "INFO" ) ;
19541938
1955- const isGrid = this . _resourcesContainer . getMode ( ) === "grid" ;
1956- const importingStudyCard = isGrid ? new osparc . dashboard . GridButtonPlaceholder ( ) : new osparc . dashboard . ListButtonPlaceholder ( ) ;
1957- importingStudyCard . buildLayout (
1958- this . tr ( "Importing Study..." ) ,
1959- "@FontAwesome5Solid/cloud-upload-alt/" + ( isGrid ? "60" : "24" ) ,
1960- uploadingLabel ,
1961- true
1962- ) ;
1963- importingStudyCard . subscribeToFilterGroup ( "searchBarFilter" ) ;
1964- this . _resourcesContainer . addNonResourceCard ( importingStudyCard ) ;
1939+ const cardTitle = this . tr ( "Importing Study..." ) ;
1940+ const cardIcon = "@FontAwesome5Solid/cloud-upload-alt" ;
1941+ const importingStudyCard = this . _addTaskCard ( null , cardTitle , cardIcon ) ;
1942+ if ( importingStudyCard ) {
1943+ this . __attachImportEventHandler ( file , importTaskUI , importingStudyCard ) ;
1944+ }
1945+ } ,
19651946
1947+ __attachImportEventHandler : function ( file , importTaskUI , importingStudyCard ) {
19661948 const body = new FormData ( ) ;
19671949 body . append ( "fileName" , file ) ;
19681950
@@ -1975,7 +1957,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
19751957 if ( percentComplete === 100 ) {
19761958 const processingLabel = this . tr ( "Processing study" ) ;
19771959 importingStudyCard . getChildControl ( "state-label" ) . setValue ( processingLabel ) ;
1978- importTask . setSubtitle ( processingLabel ) ;
1960+ importTaskUI . setSubtitle ( processingLabel ) ;
19791961 importingStudyCard . getChildControl ( "progress-bar" ) . exclude ( ) ;
19801962 }
19811963 } else {
@@ -1987,7 +1969,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
19871969 if ( req . status == 200 ) {
19881970 const processingLabel = this . tr ( "Processing study" ) ;
19891971 importingStudyCard . getChildControl ( "state-label" ) . setValue ( processingLabel ) ;
1990- importTask . setSubtitle ( processingLabel ) ;
1972+ importTaskUI . setSubtitle ( processingLabel ) ;
19911973 importingStudyCard . getChildControl ( "progress-bar" ) . exclude ( ) ;
19921974 const data = JSON . parse ( req . responseText ) ;
19931975 const params = {
@@ -1999,26 +1981,26 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
19991981 . then ( studyData => this . _updateStudyData ( studyData ) )
20001982 . catch ( err => osparc . FlashMessenger . logError ( err , this . tr ( "Something went wrong while fetching the study" ) ) )
20011983 . finally ( ( ) => {
2002- importTask . stop ( ) ;
1984+ osparc . task . TasksContainer . getInstance ( ) . removeTaskUI ( importTaskUI ) ;
20031985 this . _resourcesContainer . removeNonResourceCard ( importingStudyCard ) ;
20041986 } ) ;
20051987 } else if ( req . status == 400 ) {
2006- importTask . stop ( ) ;
1988+ osparc . task . TasksContainer . getInstance ( ) . removeTaskUI ( importTaskUI ) ;
20071989 this . _resourcesContainer . removeNonResourceCard ( importingStudyCard ) ;
20081990 const msg = osparc . data . Resources . getErrorMsg ( JSON . parse ( req . response ) ) || this . tr ( "Something went wrong while importing the study" ) ;
20091991 osparc . FlashMessenger . logError ( msg ) ;
20101992 }
20111993 } ) ;
20121994 req . addEventListener ( "error" , e => {
20131995 // transferFailed
2014- importTask . stop ( ) ;
1996+ osparc . task . TasksContainer . getInstance ( ) . removeTaskUI ( importTaskUI ) ;
20151997 this . _resourcesContainer . removeNonResourceCard ( importingStudyCard ) ;
20161998 const msg = osparc . data . Resources . getErrorMsg ( e ) || this . tr ( "Something went wrong while importing the study" ) ;
20171999 osparc . FlashMessenger . logError ( msg ) ;
20182000 } ) ;
20192001 req . addEventListener ( "abort" , e => {
20202002 // transferAborted
2021- importTask . stop ( ) ;
2003+ osparc . task . TasksContainer . getInstance ( ) . removeTaskUI ( importTaskUI ) ;
20222004 this . _resourcesContainer . removeNonResourceCard ( importingStudyCard ) ;
20232005 const msg = osparc . data . Resources . getErrorMsg ( e ) || this . tr ( "Something went wrong while importing the study" ) ;
20242006 osparc . FlashMessenger . logError ( msg ) ;
@@ -2133,42 +2115,33 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
21332115 } ,
21342116
21352117 // TASKS //
2136- __tasksReceived : function ( tasks ) {
2137- tasks . forEach ( taskData => this . _taskDataReceived ( taskData ) ) ;
2138- } ,
2139-
2140- _taskDataReceived : function ( taskData ) {
2141- // a bit hacky
2142- if ( taskData [ "task_id" ] . includes ( "from_study" ) && ! taskData [ "task_id" ] . includes ( "as_template" ) ) {
2143- const interval = 1000 ;
2144- const pollTasks = osparc . data . PollTasks . getInstance ( ) ;
2145- const task = pollTasks . addTask ( taskData , interval ) ;
2146- if ( task === null ) {
2147- return ;
2148- }
2149- // ask backend for studyData?
2118+ __tasksToCards : function ( ) {
2119+ const tasks = osparc . store . PollTasks . getInstance ( ) . getDuplicateStudyTasks ( ) ;
2120+ tasks . forEach ( task => {
21502121 const studyName = "" ;
21512122 this . __taskDuplicateReceived ( task , studyName ) ;
2152- }
2123+ } ) ;
21532124 } ,
21542125
21552126 __taskDuplicateReceived : function ( task , studyName ) {
21562127 const duplicateTaskUI = new osparc . task . Duplicate ( studyName ) ;
21572128 duplicateTaskUI . setTask ( task ) ;
2158- duplicateTaskUI . start ( ) ;
2159- const duplicatingStudyCard = this . __createDuplicateCard ( studyName ) ;
2160- duplicatingStudyCard . setTask ( task ) ;
2161- duplicatingStudyCard . subscribeToFilterGroup ( "searchBarFilter" ) ;
2162- this . _resourcesContainer . addNonResourceCard ( duplicatingStudyCard ) ;
2163- this . __attachDuplicateEventHandler ( task , duplicateTaskUI , duplicatingStudyCard ) ;
2129+
2130+ osparc . task . TasksContainer . getInstance ( ) . addTaskUI ( duplicateTaskUI ) ;
2131+
2132+ const cardTitle = this . tr ( "Duplicating " ) + studyName ;
2133+ const duplicatingStudyCard = this . _addTaskCard ( task , cardTitle , osparc . task . Duplicate . ICON ) ;
2134+ if ( duplicatingStudyCard ) {
2135+ this . __attachDuplicateEventHandler ( task , duplicateTaskUI , duplicatingStudyCard ) ;
2136+ }
21642137 } ,
21652138
21662139 __attachDuplicateEventHandler : function ( task , taskUI , duplicatingStudyCard ) {
21672140 const finished = ( msg , msgLevel ) => {
21682141 if ( msg ) {
21692142 osparc . FlashMessenger . logAs ( msg , msgLevel ) ;
21702143 }
2171- taskUI . stop ( ) ;
2144+ osparc . task . TasksContainer . getInstance ( ) . removeTaskUI ( taskUI ) ;
21722145 this . _resourcesContainer . removeNonResourceCard ( duplicatingStudyCard ) ;
21732146 } ;
21742147
0 commit comments