Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.51 KB | None | 0 0
  1. import React, {Component} from 'react';
  2. import '../../App.css';
  3. import './eLogBookTable.css';
  4. import ELogBookService from '../../services/eLogBookService';
  5. import {Table} from 'antd';
  6. import ReactFitText from 'react-fittext';
  7. import {ContextMenu, ContextMenuTrigger, MenuItem} from 'react-contextmenu';
  8. import Tooltip from 'rc-tooltip/es/Tooltip';
  9. import 'rc-tooltip/assets/bootstrap.css';
  10.  
  11. export default class ELogBookTable extends Component {
  12. constructor(props) {
  13. super(props);
  14. this.state = {logs: []};
  15. this.numberOfSquareColumns = this.getNumberOfSquares(this.props.acc);
  16. this.columns = this.getTableColumns();
  17. const eLogBookService = new ELogBookService();
  18.  
  19. eLogBookService.getLogbookEvents(props.acc).then(logs => {
  20. // TODO fix web service send error message
  21. // this is just to make the mockup
  22. logs.map((log) => {
  23. let n = log.id === 50 ? 2 : log.id === 60 ? 1 : 8;
  24. let index = 0;
  25. for (let i = 0; i < n; i++) {
  26. log['r' + ++index] = Math.random();
  27. console.log(log['r' + index]);
  28. }
  29. });
  30. console.log(logs);
  31. this.setState({logs: logs});
  32. }
  33. );
  34. //Comming from a predifined list maybe?
  35. this.elogbookList = {
  36. 'Open Elogbook': 'http://elogbook.cern.ch/eLogbook/eLogbook.jsp?lgbk=' + (props.acc === 'lhc' ? 60 : props.acc === 'cps' ? 10 : 50) + '',
  37. 'LHC morning meetings': 'https://indico.cern.ch/category/6386/',
  38. 'Accelerator Performance and Statistics': 'https://acc-stats.web.cern.ch/acc-stats/#lhc/overview-panel',
  39. 'Accelerator Fault Tracking': 'https://aft.cern.ch',
  40. 'Weekly and Shutdown Reports': 'https://espace.cern.ch/be-dep-workspace/op/_layouts/15/start.aspx#/Weekly%20Reports/Forms/AllItems.aspx'
  41. };
  42.  
  43. this.menuItems = [];
  44. for (let e in this.elogbookList) {
  45. console.log(`${this.elogbookList[e]}`);
  46. this.menuItems.push(<MenuItem onClick={() => window.open(this.elogbookList[e])} key={e}>{e}</MenuItem>);
  47. /*window.location.assign(this.elogbookList[e])}*/
  48. }
  49. }
  50.  
  51. getNumberOfSquares(acc) {
  52. return acc === 'lhc' ? 1 : acc === 'sps' ? 2 : 8;
  53. }
  54.  
  55. getTableColumns() {
  56. const columns = [
  57.  
  58. {
  59. title: 'ID',
  60. dataIndex: 'id',
  61. key: 'id',
  62. width: '2%',
  63. render: (value) => {
  64. return {
  65. props: {
  66. className: 'idField'
  67. },
  68. children: value
  69. };
  70. }
  71. },
  72. {
  73. title: 'Time',
  74. dataIndex: 'date',
  75. key: 'date',
  76. width: '3%',
  77. render: (value) => {
  78. let val = value.split(':');
  79. let child = val[0] + ':' + val[1];
  80. const obj = {
  81. children: child,
  82. props: {
  83. className: 'timeField'
  84. },
  85. };
  86. return obj;
  87. }
  88. }];
  89.  
  90. if (this.numberOfSquareColumns === 1) {
  91. columns.push({
  92. title: 'R1',
  93. dataIndex: 'r1',
  94. key: 'r1',
  95. width: '3%',
  96. render: (value) => {
  97. return {
  98. props: {
  99. className: value < 0.5 ? 'r1 colored' : 'greenSquare' // there it is!
  100. },
  101. children: <div><Tooltip placement="top" mouseLeaveDelay={0}
  102. overlay={value < 0.5 ?
  103. <div><p><b>PROTONPHY:</b> SETUP</p><p><b>LSA:</b> NOT DEFINED</p>
  104. </div> :
  105. <div><p><b>PROTONPHY:</b> STABLE BEAMS</p><p><b>LSA:</b> NOT DEFINED
  106. </p></div>}>
  107. <div>&nbsp;</div>
  108. </Tooltip></div>
  109. };
  110. }
  111. });
  112. } else if (this.numberOfSquareColumns === 2) {
  113. columns.push({
  114. title: 'R1',
  115. dataIndex: 'r1',
  116. key: 'r1',
  117. width: '3%',
  118. render: (value) => {
  119. return {
  120. props: {
  121. className: value < 0.5 ? 'redSquare' : 'greenSquare' // there it is!
  122. },
  123. children: value < 0.5 ? <div><Tooltip placement="top" mouseLeaveDelay={0.1}
  124. overlay={<div className="tooltipDiv"><p
  125. className="toolTipColumn"><b>SFTPRO2</b></p><p
  126. className="toolTipTitle"><b>Fault: 1</b></p>
  127. <p><b>Group:</b> Downtime, to be update</p>
  128. <p><b>Faultname:</b> VOID</p>
  129. <p>Element: NOT SPECIFIED</p>
  130. <p>...</p>
  131. </div>}>
  132. <div>&nbsp;</div>
  133. </Tooltip></div> :
  134. <div>&nbsp;</div>
  135. };
  136. }
  137. });
  138. // columns.push({
  139. // title: 'R2',
  140. // dataIndex: 'r2',
  141. // key: 'r2',
  142. // width: '3%',
  143. // render: (value) => {
  144. // return {
  145. // props: {
  146. // className: value < 0.5 ? 'redSquare' : 'greenSquare' // there it is!
  147. // },
  148. // children: value < 0.5 ? <div><Tooltip placement="top" mouseLeaveDelay={0}
  149. // overlay={<div><p className="toolTipTitle"><b>Fault: 1</b>
  150. // </p>
  151. // <p><b>Group:</b> Downtime, to be update</p>
  152. // <p><b>Faultname:</b> VOID</p>
  153. // <p>Element: NOT SPECIFIED</p>
  154. // <p>...</p>
  155. // </div>}>
  156. // <div>&nbsp;</div>
  157. // </Tooltip></div> :
  158. // <div>&nbsp;</div>
  159. // };
  160. // }
  161. // });
  162. } else {
  163. columns.push({
  164. title: 'R1',
  165. dataIndex: 'r1',
  166. key: 'r1',
  167. width: '3%',
  168. render: (value) => {
  169. return {
  170. props: {
  171. className: value < 0.5 ? 'redSquare' : 'greenSquare' // there it is!
  172. },
  173. children: value < 0.5 ? <div><Tooltip placement="top" mouseLeaveDelay={0}
  174. overlay={<div className="tooltipDiv"><p
  175. className="toolTipColumn"><b>AD</b></p><p
  176. className="toolTipTitle"><b>Fault: 1</b>
  177. </p>
  178. <p><b>Group:</b> Downtime, to be update</p>
  179. <p><b>Faultname:</b> VOID</p>
  180. <p>Element: NOT SPECIFIED</p>
  181. <p>...</p>
  182. </div>}>
  183. <div>&nbsp;</div>
  184. </Tooltip></div> :
  185. <div>&nbsp;</div>
  186. };
  187. }
  188. });
  189. columns.push({
  190. title: 'R2',
  191. dataIndex: 'r2',
  192. key: 'r2',
  193. width: '3%',
  194. render: (value) => {
  195. return {
  196. props: {
  197. className: value < 0.5 ? 'redSquare' : 'greenSquare' // there it is!
  198. },
  199. children: value < 0.5 ? <div><Tooltip placement="top" mouseLeaveDelay={0}
  200. overlay={<div className="tooltipDiv"><p
  201. className="toolTipColumn"><b>EAST1</b></p><p
  202. className="toolTipTitle"><b>Fault: 1</b>
  203. </p>
  204. <p><b>Group:</b> Downtime, to be update</p>
  205. <p><b>Faultname:</b> VOID</p>
  206. <p>Element: NOT SPECIFIED</p>
  207. <p>...</p>
  208. </div>}>
  209. <div>&nbsp;</div>
  210. </Tooltip></div> :
  211. <div>&nbsp;</div>
  212. };
  213. }
  214. });
  215. columns.push({
  216. title: 'R3',
  217. dataIndex: 'r3',
  218. key: 'r3',
  219. width: '3%',
  220. render: (value) => {
  221. return {
  222. props: {
  223. className: value < 0.5 ? 'redSquare' : 'greenSquare' // there it is!
  224. },
  225. children: value < 0.5 ? <div><Tooltip placement="top" mouseLeaveDelay={0}
  226. overlay={<div className="tooltipDiv"><p
  227. className="toolTipColumn"><b>EAST2</b></p><p
  228. className="toolTipTitle"><b>Fault: 1</b>
  229. </p>
  230. <p><b>Group:</b> Downtime, to be update</p>
  231. <p><b>Faultname:</b> VOID</p>
  232. <p>Element: NOT SPECIFIED</p>
  233. <p>...</p>
  234. </div>}>
  235. <div>&nbsp;</div>
  236. </Tooltip></div> :
  237. <div>&nbsp;</div>
  238. };
  239. }
  240. });
  241. columns.push({
  242. title: 'R4',
  243. dataIndex: 'r4',
  244. key: 'r4',
  245. width: '3%',
  246. render: (value) => {
  247. return {
  248. props: {
  249. className: value < 0.5 ? 'redSquare' : 'greenSquare' // there it is!
  250. },
  251. children: value < 0.5 ? <div><Tooltip placement="top" mouseLeaveDelay={0}
  252. overlay={<div className="tooltipDiv"><p
  253. className="toolTipColumn"><b>LHC4</b></p><p
  254. className="toolTipTitle"><b>Fault: 1</b>
  255. </p>
  256. <p><b>Group:</b> Downtime, to be update</p>
  257. <p><b>Faultname:</b> VOID</p>
  258. <p>Element: NOT SPECIFIED</p>
  259. <p>...</p>
  260. </div>}>
  261. <div>&nbsp;</div>
  262. </Tooltip></div> :
  263. <div>&nbsp;</div>
  264. };
  265. }
  266. });
  267. columns.push({
  268. title: 'R5',
  269. dataIndex: 'r5',
  270. key: 'r5',
  271. width: '3%',
  272. render: (value) => {
  273. return {
  274. props: {
  275. className: value < 0.5 ? 'redSquare' : 'greenSquare' // there it is!
  276. },
  277. children: value < 0.5 ? <div><Tooltip placement="top" mouseLeaveDelay={0}
  278. overlay={<div className="tooltipDiv"><p
  279. className="toolTipColumn"><b>SFTPRO1</b></p><p
  280. className="toolTipTitle"><b>Fault: 1</b>
  281. </p>
  282. <p><b>Group:</b> Downtime, to be update</p>
  283. <p><b>Faultname:</b> VOID</p>
  284. <p>Element: NOT SPECIFIED</p>
  285. <p>...</p>
  286. </div>}>
  287. <div>&nbsp;</div>
  288. </Tooltip></div> :
  289. <div>&nbsp;</div>
  290. };
  291. }
  292. });
  293. columns.push({
  294. title: 'R6',
  295. dataIndex: 'r6',
  296. key: 'r6',
  297. width: '3%',
  298. render: (value) => {
  299. return {
  300. props: {
  301. className: value < 0.5 ? 'redSquare' : 'greenSquare' // there it is!
  302. },
  303. children: value < 0.5 ? <div><Tooltip placement="top" mouseLeaveDelay={0}
  304. overlay={<div className="tooltipDiv"><p
  305. className="toolTipColumn"><b>TOF</b></p><p
  306. className="toolTipTitle"><b>Fault: 1</b>
  307. </p>
  308. <p><b>Group:</b> Downtime, to be update</p>
  309. <p><b>Faultname:</b> VOID</p>
  310. <p>Element: NOT SPECIFIED</p>
  311. <p>...</p>
  312. </div>}>
  313. <div>&nbsp;</div>
  314. </Tooltip></div> :
  315. <div>&nbsp;</div>
  316. };
  317. }
  318. });
  319. columns.push({
  320. title: 'R7',
  321. dataIndex: 'r7',
  322. key: 'r7',
  323. width: '3%',
  324. render: (value) => {
  325. return {
  326. props: {
  327. className: value < 0.5 ? 'redSquare' : 'greenSquare' // there it is!
  328. },
  329. children: value < 0.5 ? <div><Tooltip placement="top" mouseLeaveDelay={0}
  330. overlay={<div className="tooltipDiv"><p
  331. className="toolTipColumn"><b>COLUMN1</b></p><p
  332. className="toolTipTitle"><b>Fault: 1</b>
  333. </p>
  334. <p><b>Group:</b> Downtime, to be update</p>
  335. <p><b>Faultname:</b> VOID</p>
  336. <p>Element: NOT SPECIFIED</p>
  337. <p>...</p>
  338. </div>}>
  339. <div>&nbsp;</div>
  340. </Tooltip></div> :
  341. <div>&nbsp;</div>
  342. };
  343. }
  344. });
  345. columns.push({
  346. title: 'R8',
  347. dataIndex: 'r8',
  348. key: 'r8',
  349. width: '3%',
  350. render: (value) => {
  351. return {
  352. props: {
  353. className: value < 0.5 ? 'redSquare' : 'greenSquare' // there it is!
  354. },
  355. children: value < 0.5 ? <div><Tooltip placement="top" mouseLeaveDelay={0}
  356. overlay={<div className="tooltipDiv"><p
  357. className="toolTipColumn"><b>COLUMN2</b></p><p
  358. className="toolTipTitle"><b>Fault: 1</b>
  359. </p>
  360. <p><b>Group:</b> Downtime, to be update</p>
  361. <p><b>Faultname:</b> VOID</p>
  362. <p>Element: NOT SPECIFIED</p>
  363. <p>...</p>
  364. </div>}>
  365. <div>&nbsp;</div>
  366. </Tooltip></div> :
  367. <div>&nbsp;</div>
  368. };
  369. }
  370. });
  371. }
  372. columns.push({
  373. title: 'Comments',
  374. dataIndex: 'comment',
  375. key: 'comment', /*
  376. width: '70%',*/
  377. render: (comment, log) =>
  378. <div>
  379. {/*<Tooltip placement="topLeft" overlayClassName="commentToolTip" overlayStyle=title={log.comment} arrowPointAtCenter>*/}
  380. {/*<p className="comments">{log.comment}</p>*/}
  381. {/*</Tooltip>*/}
  382. <Tooltip placement="top" mouseLeaveDelay="0" overlay={`${comment}`}>
  383. <p className="comments">{log.comment}</p>
  384. </Tooltip>
  385. {/*<p className="comments" data-tip={`<p className="popUpComment">${log.comment}</p>`} data-for="comment-tooltip">{log.comment}</p>*/}
  386. {/*<ReactTooltip id="comment-tooltip" className="commentToolTip" html={true} place="left" type="light" effect="solid" offset={{top: 40}}>*/}
  387. {/*</ReactTooltip>*/}
  388. </div>
  389. });
  390. return columns;
  391. }
  392.  
  393.  
  394. render() {
  395. const logs = this.state.logs;
  396. // const divStyle = {
  397. // left: window.width - ,
  398. // };
  399.  
  400. if (logs) {
  401. for (let [i, v] of logs.entries()) {
  402. v.key = ++i;
  403. }
  404. }
  405.  
  406.  
  407. return (
  408. <div>
  409. <ReactFitText compressor={4} maxFontSize={12} minFontSize={8}>
  410. <ContextMenuTrigger id="MENUELOGBOOK" holdToDisplay={1000}>
  411. <Table
  412. columns={this.columns}
  413. bordered
  414. title={() => 'ELOGBOOK - ' + new Date().toLocaleString()}
  415. dataSource={logs}
  416. size="middle"
  417. scroll={{y: ( this.props.height * .84 )}}
  418. showHeader={false}
  419. pagination={false}
  420. // pagination={{pageSize: 10}}
  421. />
  422. </ContextMenuTrigger>
  423. </ReactFitText>
  424. <ContextMenu id="MENUELOGBOOK" className="react-contextmenu">
  425.  
  426. {this.menuItems}
  427.  
  428. </ContextMenu>
  429.  
  430.  
  431. </div>
  432.  
  433.  
  434. );
  435.  
  436. }
  437. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement