list-item.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * @author oldj
  3. * @blog https://oldj.net
  4. */
  5. 'use strict'
  6. import React from 'react'
  7. import classnames from 'classnames'
  8. import Agent from '../Agent'
  9. import './list-item.less'
  10. export default class ListItem extends React.Component {
  11. constructor (props) {
  12. super(props)
  13. this.is_sys = !!this.props.sys
  14. this.state = {}
  15. }
  16. getTitle () {
  17. let {lang} = this.props
  18. return this.is_sys ? lang.sys_host_title : this.props.data.title ||
  19. lang.untitled
  20. }
  21. beSelected () {
  22. this.props.setCurrent(this.props.data)
  23. }
  24. toggle () {
  25. let on = !this.props.data.on
  26. Agent.emit('toggle-hosts', this.props.data, on)
  27. }
  28. render () {
  29. let {data, sys, current} = this.props
  30. let is_selected = data === current
  31. if (!data) return null
  32. return (
  33. <div className={classnames({
  34. 'list-item': 1
  35. //, 'hidden': !this.isMatched()
  36. , 'sys-host': sys
  37. , 'selected': is_selected
  38. })}
  39. onClick={this.beSelected.bind(this)}
  40. >
  41. {sys ? null : (
  42. <div>
  43. <i className={classnames({
  44. 'switch': 1
  45. , 'iconfont': 1
  46. , 'icon-on': data.on
  47. , 'icon-off': !data.on
  48. })}
  49. onClick={this.toggle.bind(this)}
  50. />
  51. <i
  52. className="iconfont icon-edit"
  53. //onClick={this.toEdit.bind(this)}
  54. />
  55. </div>
  56. )}
  57. <i className={classnames({
  58. 'iconfont': 1
  59. , 'item-icon': 1
  60. , 'icon-warn': !!data.error
  61. , 'icon-file': !sys && !data.error && data.where !== 'group'
  62. , 'icon-files': data.where === 'group'
  63. , 'icon-sysserver': sys && !data.error
  64. })}
  65. title={data.error || ''}
  66. />
  67. <span>{this.getTitle()}</span>
  68. </div>
  69. )
  70. }
  71. }