2016-10-26 22:26:03 +00:00
import React from 'react' ;
import '../css/TaskListItem.scss' ;
2016-10-28 19:40:03 +00:00
import Console from '../Console' ;
2016-11-02 14:56:23 +00:00
import statusCodes from '../classes/StatusCodes' ;
2016-10-26 22:26:03 +00:00
class TaskListItem extends React . Component {
constructor ( ) {
super ( ) ;
2016-10-27 16:26:15 +00:00
this . state = {
expanded : false
}
this . toggleExpanded = this . toggleExpanded . bind ( this ) ;
2016-10-31 21:09:01 +00:00
this . consoleOutputUrl = this . consoleOutputUrl . bind ( this ) ;
2016-10-26 22:26:03 +00:00
}
componentDidMount ( ) {
2016-10-31 21:09:01 +00:00
2016-10-26 22:26:03 +00:00
}
2016-10-27 16:26:15 +00:00
toggleExpanded ( ) {
this . setState ( {
expanded : ! this . state . expanded
} ) ;
}
2016-10-31 21:09:01 +00:00
consoleOutputUrl ( line ) {
return ` /api/projects/ ${ this . props . data . project } /tasks/ ${ this . props . data . id } /?output_only=true&line= ${ line } ` ;
}
2016-10-26 22:26:03 +00:00
render ( ) {
2016-10-27 16:26:15 +00:00
let name = this . props . data . name !== null ? this . props . data . name : ` Task # ${ this . props . data . id } ` ;
let expanded = "" ;
if ( this . state . expanded ) {
expanded = (
2016-10-31 21:09:01 +00:00
< div className = "expanded-panel" >
< div className = "row" >
< div className = "col-md-4 no-padding" >
< div className = "labels" >
2016-11-02 14:56:23 +00:00
< strong > Status : < / strong > { statusCodes . description ( this . props . data . status ) } < br / >
2016-10-31 21:09:01 +00:00
< / div >
2016-10-27 16:26:15 +00:00
< / div >
2016-10-31 21:09:01 +00:00
< div className = "col-md-8" >
< Console
source = { this . consoleOutputUrl }
refreshInterval = { 3000 }
autoscroll = { true }
height = { 200 } / >
< / div >
< / div >
< div className = "row" >
2016-10-27 16:26:15 +00:00
< button type = "button" className = "btn btn-primary btn-sm" >
< i className = "glyphicon glyphicon-remove-circle" > < / i >
Restart
< / button > < button type = "button" className = "btn btn-primary btn-sm" >
< i className = "glyphicon glyphicon-pencil" > < / i >
Edit
< / button > < button type = "button" className = "btn btn-danger btn-sm" >
< i className = "glyphicon glyphicon-trash" > < / i >
Delete
< / button >
< / div >
2016-10-31 21:09:01 +00:00
< / div >
) ;
2016-10-27 16:26:15 +00:00
}
2016-11-02 14:56:23 +00:00
let statusLabel = "" ;
if ( this . props . data . last _error ) {
statusLabel = ( < div className = "status-label error" title = { this . props . data . last _error } > { this . props . data . last _error } < / div > ) ;
} else {
statusLabel = ( < div className = { "status-label " + ( this . props . data . status == 40 ? "done" : "" ) } title = { statusCodes . description ( this . props . data . status ) } > { statusCodes . description ( this . props . data . status ) } < / div > ) ;
}
2016-10-26 22:26:03 +00:00
return (
< div className = "task-list-item" >
2016-10-27 16:26:15 +00:00
< div className = "row" >
< div className = "col-md-5 name" >
< i onClick = { this . toggleExpanded } className = { "clickable fa " + ( this . state . expanded ? "fa-minus-square-o" : " fa-plus-square-o" ) } > < / i > < a href = "javascript:void(0);" onClick = { this . toggleExpanded } > { name } < / a >
< / div >
2016-11-02 14:56:23 +00:00
< div className = "col-md-3 details" >
2016-10-27 16:26:15 +00:00
< i className = "fa fa-clock-o" > < / i > 00 : 00 : 00
< i className = "fa fa-image" > < / i > { this . props . data . images _count }
< / div >
2016-11-02 14:56:23 +00:00
< div className = "col-md-3" >
{ statusLabel }
< / div >
< div className = "col-md-1 text-right" >
< i className = { statusCodes . icon ( this . props . data . status ) } > < / i >
2016-10-27 16:26:15 +00:00
< / div >
< / div >
{ expanded }
2016-10-26 22:26:03 +00:00
< / div >
) ;
}
}
2016-10-27 16:26:15 +00:00
export default TaskListItem ;