1- import React from 'react' ;
2- import { Button , Card , CardBody , CardHeader , Col , Progress , Row } from "reactstrap" ;
3- import { bytesToKB , formatBytes , secondsToStr } from "../../../utils/Tools" ;
1+ import React , { useState } from 'react' ;
2+ import { Button , Card , CardBody , CardHeader , Col , Collapse , Container , Progress , Row } from "reactstrap" ;
3+ import { bytesToKB , formatBytes , groupByKey , secondsToStr } from "../../../utils/Tools" ;
44import * as PropTypes from "prop-types" ;
55import { connect } from "react-redux" ;
66import { Line } from "react-chartjs-2" ;
77import { CustomTooltips } from "@coreui/coreui-plugin-chartjs-custom-tooltips" ;
8+ import axiosInstance from "../../../utils/API/API" ;
9+ import urls from "../../../utils/API/endpoint" ;
810
911const options = {
1012 tooltips : {
@@ -47,27 +49,27 @@ function JobCard({job}) {
4749}
4850
4951function getCroppedName ( name ) {
50- const leftChars = 30 ;
51- const rightChars = 5 ;
52+ const leftChars = 30 ;
53+ const rightChars = 5 ;
5254
53- if ( name . length > leftChars ) {
54- const croppedName = name . substr ( 0 , leftChars ) + " ... " + name . substr ( - rightChars ) ;
55- return croppedName ;
56- }
57- return name ;
55+ if ( name . length > leftChars ) {
56+ const croppedName = name . substr ( 0 , leftChars ) + " ... " + name . substr ( - rightChars ) ;
57+ return croppedName ;
58+ }
59+ return name ;
5860
5961}
6062
6163function JobCardRow ( { job} ) {
6264 const { name, percentage, speed, size} = job ;
6365 return (
6466 < React . Fragment >
65- < Row className = "runningJobs" >
66- { ( size && speed ) ? (
67+ < Row className = "runningJobs" >
68+ { ( size && speed ) ? (
6769
68- < Col lg = { 12 } className = "itemName" > { getCroppedName ( name ) } { " " }
69- ({ formatBytes ( size ) } ) - { formatBytes ( speed ) } PS </ Col >
70- ) : (
70+ < Col lg = { 12 } className = "itemName" > { getCroppedName ( name ) } { " " }
71+ ({ formatBytes ( size ) } ) - { formatBytes ( speed ) } PS </ Col >
72+ ) : (
7173 < Col lg = { 12 } > Calculating</ Col > ) }
7274
7375 </ Row >
@@ -82,7 +84,7 @@ function JobCardRow({job}) {
8284}
8385
8486function GlobalStatus ( { stats} ) {
85- const { speed, bytes, checks, elapsedTime, deletes, errors, transfers} = stats ;
87+ const { speed, bytes, checks, elapsedTime, deletes, errors, transfers, lastError } = stats ;
8688 return (
8789 < Card >
8890 < CardHeader > < strong > Global Stats</ strong > </ CardHeader >
@@ -117,6 +119,11 @@ function GlobalStatus({stats}) {
117119 < td > Transfers:</ td >
118120 < td > { transfers } </ td >
119121 </ tr >
122+ < tr >
123+ < td > Last Error:</ td >
124+ < td > { lastError } </ td >
125+ </ tr >
126+
120127 </ tbody >
121128 </ table >
122129
@@ -129,17 +136,84 @@ function GlobalStatus({stats}) {
129136function TransferringJobs ( { transferring} ) {
130137 if ( transferring !== undefined ) {
131138 return transferring . map ( ( item , idx ) => {
132- return ( < JobCard key = { item . name } job = { item } /> ) ;
139+ return ( < JobCard key = { item . name } job = { item } /> ) ;
133140 } ) ;
134141 }
135142 return null ;
136143}
137144
138145function TransferringJobsRow ( { transferring} ) {
139146 if ( transferring !== undefined ) {
140- return transferring . map ( ( item , idx ) => {
141- return ( < JobCardRow key = { item . name } job = { item } /> ) ;
147+ const grouped = groupByKey ( transferring , job => job . group ) ;
148+ console . log ( grouped ) ;
149+
150+ const array = [ ] ;
151+
152+ grouped . forEach ( ( val , keys ) => {
153+ console . log ( val , keys ) ;
154+ array . push ( < JobGroup job = { val } groupId = { keys } key = { keys } /> ) ;
142155 } ) ;
156+ return array ;
157+
158+ // return grouped.values().map((item, idx) => {
159+ // return (<JobCardRow key={item.name} job={item}/>);
160+ // });
161+ }
162+ return null ;
163+ }
164+
165+ function JobGroup ( { job, groupId} ) {
166+ const [ showCollapse , setShowCollapse ] = useState ( false ) ;
167+ const [ cancelButtonEnabled , setCancelButtonEnabled ] = useState ( true ) ;
168+ console . log ( job ) ;
169+
170+ const stopJob = ( e , groupId ) => {
171+ e . stopPropagation ( ) ;
172+ if ( groupId && groupId . indexOf ( '/' ) !== - 1 ) {
173+ setCancelButtonEnabled ( false ) ;
174+ const jobid = groupId . split ( '/' ) [ 1 ] ;
175+ axiosInstance . post ( urls . stopJob , { jobid, _async :true } ) . then ( function ( res ) {
176+ console . log ( res ) ;
177+ } ) . catch ( err => {
178+ console . error ( err ) ;
179+ } )
180+ }
181+ } ;
182+ // setCancelButtonEnabled((groupId && groupId !== "undefined"));
183+ if ( job ) {
184+ return (
185+ < >
186+ { groupId &&
187+ < Card >
188+
189+ < CardHeader onClick = { ( ) => setShowCollapse ( ! showCollapse ) } >
190+ < Container >
191+ < Row >
192+ < Col sm = { 10 } >
193+ Transferring { job . length } file(s)
194+ </ Col >
195+ < Col sm = { 2 } >
196+ < Button color = { "light" } disabled = { ! cancelButtonEnabled }
197+ onClick = { ( e ) => stopJob ( e , groupId ) }
198+ className = { "btn-outline-danger btn-pill" } > < i
199+ className = "fa fa-close fa-sm" /> </ Button >
200+ </ Col >
201+ </ Row >
202+ </ Container >
203+ </ CardHeader >
204+ < Collapse isOpen = { showCollapse } >
205+ < CardBody >
206+ {
207+ job . map ( ( item , idx ) => {
208+ return ( < JobCardRow key = { item . name } job = { item } /> ) ;
209+ } )
210+ }
211+ </ CardBody >
212+ </ Collapse >
213+ </ Card >
214+ }
215+ </ >
216+ ) ;
143217 }
144218 return null ;
145219}
@@ -164,6 +238,8 @@ class RunningJobs extends React.Component {
164238
165239
166240
241+
242+
167243 render ( ) {
168244 const { jobs, isConnected, lineChartData} = this . props ;
169245 const { transferring} = jobs ;
@@ -200,7 +276,6 @@ class RunningJobs extends React.Component {
200276 } else if ( mode === "card" ) {
201277 if ( isConnected ) {
202278 return (
203-
204279 < TransferringJobsRow transferring = { transferring } />
205280 ) ;
206281 } else {
@@ -218,7 +293,7 @@ class RunningJobs extends React.Component {
218293 </ Button >
219294 </ div >
220295 </ CardHeader >
221- < CardBody className = { ! this . state . isShowing ? "d-none" : "progress-modal-body" } >
296+ < CardBody className = { ! this . state . isShowing ? "d-none" : "progress-modal-body" } style = { { overflowY : 'scroll' } } >
222297 < TransferringJobsRow transferring = { transferring } />
223298
224299 </ CardBody >
0 commit comments