2015-10-08 08:28:45 +08:00
|
|
|
classNames = require 'classnames'
|
2016-03-29 16:41:24 +08:00
|
|
|
React = require 'react'
|
2015-02-25 08:19:47 +08:00
|
|
|
|
2015-05-20 06:59:37 +08:00
|
|
|
class DeveloperBarCurlItem extends React.Component
|
|
|
|
@displayName: 'DeveloperBarCurlItem'
|
2015-02-25 08:19:47 +08:00
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
render: =>
|
2015-10-08 08:28:45 +08:00
|
|
|
classes = classNames
|
|
|
|
"item": true
|
|
|
|
"error-code": @_isError()
|
|
|
|
<div className={classes}>
|
|
|
|
<div className="code">{@props.item.statusCode}{@_errorMessage()}</div>
|
2015-09-04 07:29:33 +08:00
|
|
|
<span className="timestamp">{@props.item.startMoment.format("HH:mm:ss")} </span>
|
2015-02-25 08:19:47 +08:00
|
|
|
<a onClick={@_onRunCommand}>Run</a>
|
|
|
|
<a onClick={@_onCopyCommand}>Copy</a>
|
|
|
|
{@props.item.command}
|
|
|
|
</div>
|
|
|
|
|
2015-05-15 05:12:53 +08:00
|
|
|
shouldComponentUpdate: (nextProps) =>
|
|
|
|
return @props.item isnt nextProps.item
|
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
_onCopyCommand: =>
|
2016-04-14 06:35:01 +08:00
|
|
|
clipboard = require('electron').clipboard
|
2015-02-25 08:19:47 +08:00
|
|
|
clipboard.writeText(@props.item.command)
|
|
|
|
|
2015-10-08 08:28:45 +08:00
|
|
|
_isError: ->
|
|
|
|
return false if @props.item.statusCode is "pending"
|
|
|
|
return not (parseInt(@props.item.statusCode) <= 399)
|
|
|
|
|
|
|
|
_errorMessage: ->
|
|
|
|
if (@props.item.errorMessage ? "").length > 0
|
|
|
|
return " | #{@props.item.errorMessage}"
|
|
|
|
else
|
|
|
|
return ""
|
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
_onRunCommand: =>
|
2015-11-12 02:25:11 +08:00
|
|
|
curlFile = "#{NylasEnv.getConfigDirPath()}/curl.command"
|
2015-02-25 08:19:47 +08:00
|
|
|
fs = require 'fs-plus'
|
|
|
|
if fs.existsSync(curlFile)
|
|
|
|
fs.unlinkSync(curlFile)
|
|
|
|
fs.writeFileSync(curlFile, @props.item.command)
|
|
|
|
fs.chmodSync(curlFile, '777')
|
2015-11-24 14:09:17 +08:00
|
|
|
{shell} = require 'electron'
|
2015-02-25 08:19:47 +08:00
|
|
|
shell.openItem(curlFile)
|
2015-05-01 04:08:29 +08:00
|
|
|
|
|
|
|
|
2015-05-20 06:59:37 +08:00
|
|
|
module.exports = DeveloperBarCurlItem
|