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" ;
4
4
import * as PropTypes from "prop-types" ;
5
5
import { connect } from "react-redux" ;
6
6
import { Line } from "react-chartjs-2" ;
7
7
import { CustomTooltips } from "@coreui/coreui-plugin-chartjs-custom-tooltips" ;
8
+ import axiosInstance from "../../../utils/API/API" ;
9
+ import urls from "../../../utils/API/endpoint" ;
8
10
9
11
const options = {
10
12
tooltips : {
@@ -47,27 +49,27 @@ function JobCard({job}) {
47
49
}
48
50
49
51
function getCroppedName ( name ) {
50
- const leftChars = 30 ;
51
- const rightChars = 5 ;
52
+ const leftChars = 30 ;
53
+ const rightChars = 5 ;
52
54
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 ;
58
60
59
61
}
60
62
61
63
function JobCardRow ( { job} ) {
62
64
const { name, percentage, speed, size} = job ;
63
65
return (
64
66
< React . Fragment >
65
- < Row className = "runningJobs" >
66
- { ( size && speed ) ? (
67
+ < Row className = "runningJobs" >
68
+ { ( size && speed ) ? (
67
69
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
+ ) : (
71
73
< Col lg = { 12 } > Calculating</ Col > ) }
72
74
73
75
</ Row >
@@ -82,7 +84,7 @@ function JobCardRow({job}) {
82
84
}
83
85
84
86
function GlobalStatus ( { stats} ) {
85
- const { speed, bytes, checks, elapsedTime, deletes, errors, transfers} = stats ;
87
+ const { speed, bytes, checks, elapsedTime, deletes, errors, transfers, lastError } = stats ;
86
88
return (
87
89
< Card >
88
90
< CardHeader > < strong > Global Stats</ strong > </ CardHeader >
@@ -117,6 +119,11 @@ function GlobalStatus({stats}) {
117
119
< td > Transfers:</ td >
118
120
< td > { transfers } </ td >
119
121
</ tr >
122
+ < tr >
123
+ < td > Last Error:</ td >
124
+ < td > { lastError } </ td >
125
+ </ tr >
126
+
120
127
</ tbody >
121
128
</ table >
122
129
@@ -129,17 +136,84 @@ function GlobalStatus({stats}) {
129
136
function TransferringJobs ( { transferring} ) {
130
137
if ( transferring !== undefined ) {
131
138
return transferring . map ( ( item , idx ) => {
132
- return ( < JobCard key = { item . name } job = { item } /> ) ;
139
+ return ( < JobCard key = { item . name } job = { item } /> ) ;
133
140
} ) ;
134
141
}
135
142
return null ;
136
143
}
137
144
138
145
function TransferringJobsRow ( { transferring} ) {
139
146
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 } /> ) ;
142
155
} ) ;
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
+ ) ;
143
217
}
144
218
return null ;
145
219
}
@@ -164,6 +238,8 @@ class RunningJobs extends React.Component {
164
238
165
239
166
240
241
+
242
+
167
243
render ( ) {
168
244
const { jobs, isConnected, lineChartData} = this . props ;
169
245
const { transferring} = jobs ;
@@ -200,7 +276,6 @@ class RunningJobs extends React.Component {
200
276
} else if ( mode === "card" ) {
201
277
if ( isConnected ) {
202
278
return (
203
-
204
279
< TransferringJobsRow transferring = { transferring } />
205
280
) ;
206
281
} else {
@@ -218,7 +293,7 @@ class RunningJobs extends React.Component {
218
293
</ Button >
219
294
</ div >
220
295
</ 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' } } >
222
297
< TransferringJobsRow transferring = { transferring } />
223
298
224
299
</ CardBody >
0 commit comments