2015-02-25 08:19:47 +08:00
|
|
|
React = require 'react/addons'
|
|
|
|
|
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-02-25 08:19:47 +08:00
|
|
|
<div className={"item status-code-#{@props.item.statusCode}"}>
|
|
|
|
<div className="code">{@props.item.statusCode}</div>
|
|
|
|
<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: =>
|
2015-02-25 08:19:47 +08:00
|
|
|
clipboard = require('clipboard')
|
|
|
|
clipboard.writeText(@props.item.command)
|
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
_onRunCommand: =>
|
2015-02-25 08:19:47 +08:00
|
|
|
curlFile = "#{atom.getConfigDirPath()}/curl.command"
|
|
|
|
fs = require 'fs-plus'
|
|
|
|
if fs.existsSync(curlFile)
|
|
|
|
fs.unlinkSync(curlFile)
|
|
|
|
fs.writeFileSync(curlFile, @props.item.command)
|
|
|
|
fs.chmodSync(curlFile, '777')
|
|
|
|
shell = require 'shell'
|
|
|
|
shell.openItem(curlFile)
|
2015-05-01 04:08:29 +08:00
|
|
|
|
|
|
|
|
2015-05-20 06:59:37 +08:00
|
|
|
module.exports = DeveloperBarCurlItem
|