content.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * @author oldj
  3. * @blog http://oldj.net
  4. */
  5. 'use strict';
  6. import React from 'react';
  7. import Editor from './editor';
  8. import classnames from 'classnames';
  9. import './content.less';
  10. export default class Content extends React.Component {
  11. constructor(props) {
  12. super(props);
  13. this.codemirror = null;
  14. this.state = {
  15. is_loading: this.props.current.is_loading,
  16. code: this.props.current.content || ''
  17. };
  18. this._t = null;
  19. SH_event.on('loading', (host, flag) => {
  20. if (host === this.props.current) {
  21. this.setState({
  22. is_loading: flag
  23. });
  24. }
  25. });
  26. }
  27. setValue(v) {
  28. this.props.setHostContent(v);
  29. }
  30. componentWillReceiveProps(next_props) {
  31. this.setState({
  32. is_loading: next_props.current.is_loading,
  33. code: next_props.current.content || ''
  34. });
  35. }
  36. render() {
  37. let {current} = this.props;
  38. return (
  39. <div id="sh-content">
  40. <div className="inform">
  41. <span
  42. className={classnames({
  43. loading: 1,
  44. show: this.state.is_loading
  45. })}
  46. >loading...</span>
  47. <i
  48. className={classnames({
  49. show: current.where === 'remote',
  50. iconfont: 1,
  51. 'icon-earth': 1
  52. })}
  53. title={SH_Agent.lang.remote_hosts}
  54. />
  55. <i
  56. className={classnames({
  57. show: this.props.readonly,
  58. iconfont: 1,
  59. 'icon-lock2': 1
  60. })}
  61. title={SH_Agent.lang.readonly}
  62. />
  63. </div>
  64. <Editor
  65. code={this.state.code}
  66. readonly={this.props.readonly}
  67. setValue={this.setValue.bind(this)}/>
  68. </div>
  69. );
  70. }
  71. }