Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.60 KB | None | 0 0
  1. constructor(props) {
  2. super(props);
  3. this.state = {
  4. patientId: props.patientId ? props.patientId : null,
  5. FromDate: new Date(),
  6. time: null,
  7. isStart: [],
  8. isSave: [],
  9. secondsElapsed: [],
  10. incrementer: [],
  11. }
  12. }
  13.  
  14. renderLoading() {
  15. if (this.state.isLoading) {
  16. return (
  17. <div className="full_loader">
  18. <div className="circle_loader page_loader">
  19. <img src={Loader} alt="" />
  20. </div>
  21. </div>
  22. );
  23. }
  24. }
  25.  
  26. componentWillMount = () => {
  27. this.props.PatientRecordDurationDataList(this.state.patientId)
  28. }
  29.  
  30. componentWillReceiveProps = (nextProps) => {
  31. if( nextProps.recordDurationDataList.data !== undefined) {
  32. let clikcedData = this.state.isStart
  33. let saveData = this.state.isSave
  34. let counterData = this.state.secondsElapsed
  35. let patientBehaviorsReductionData = nextProps.recordDurationDataList.data.PatientBehaviorsReductionData;
  36. patientBehaviorsReductionData.map((obj, index) => {
  37. return saveData[index] = false;
  38. })
  39. patientBehaviorsReductionData.map((obj, index) => {
  40. return clikcedData[index] = false;
  41. })
  42. patientBehaviorsReductionData.map((obj, index) => {
  43. return counterData[index] = 0;
  44. })
  45. this.setState({
  46. isStart: clikcedData,
  47. isSave: saveData,
  48. secondsElapsed: counterData
  49. })
  50. }
  51. }
  52.  
  53. componentWillUnmount = () => {
  54. this.state.incrementer.map((obj, index) => {
  55. return clearInterval(this.state.incrementer[index]);
  56. })
  57. }
  58.  
  59. handleStart = (index) => {
  60. var _this = this;
  61. const isStart = this.state.isStart
  62. isStart[index] = true
  63. _this.setState({
  64. isStart: isStart
  65. });
  66.  
  67. let incrementer = this.state.incrementer
  68.  
  69. incrementer[index] = setInterval(() => {
  70. let secondsElapsed = _this.state.secondsElapsed
  71. secondsElapsed[index] = secondsElapsed[index] + 1
  72. _this.setState({
  73. secondsElapsed : secondsElapsed
  74. })
  75. }, 1000)
  76.  
  77. _this.setState({
  78. incrementer: incrementer
  79. });
  80.  
  81. }
  82.  
  83. handleStop = (index) => {
  84. let isStart = this.state.isStart
  85. let isSave = this.state.isSave
  86. let counterData = this.state.secondsElapsed
  87. isStart[index] = false
  88. isSave[index] = true
  89. counterData[index];
  90. this.setState({
  91. isStart: isStart,
  92. isSave: isSave,
  93. secondsElapsed: counterData
  94. },clearInterval(this.state.incrementer[index]));
  95. }
  96.  
  97. handleCancel = (index) => {
  98. let clikcedData = this.state.isStart
  99. let isSave = this.state.isSave
  100. let counterData = this.state.secondsElapsed
  101. clikcedData[index] = false
  102. isSave[index] = false
  103. counterData[index] = 0;
  104. this.setState({
  105. isStart: clikcedData,
  106. isSave: isSave,
  107. secondsElapsed: counterData
  108. }, clearInterval(this.state.incrementer[index]));
  109.  
  110. }
  111.  
  112.  
  113. handleSave = (index) => {
  114.  
  115. }
  116.  
  117. getSeconds = (index) => {
  118. return ('0' + this.state.secondsElapsed[index] % 60).slice(-2)
  119. }
  120.  
  121. getMinutes = (index) => {
  122. return Math.floor(this.state.secondsElapsed[index] / 60)
  123. }
  124.  
  125.  
  126. renderData = (dataList) => {
  127. let PatientRecordFrequencyData = dataList || [];
  128. if (!PatientRecordFrequencyData.length) {
  129. return (
  130. <tr>
  131. <td>
  132. <div className="text-center no-record">{this.props.loading ? 'Loading please wait...' : 'No record found.'}</div>
  133. </td>
  134. </tr>
  135. );
  136. }
  137. return PatientRecordFrequencyData.map((Obj, index) => {
  138. return (
  139. <tr key={index}>
  140. <td>
  141. {Obj.behaviorName}
  142. <div className="row">
  143. <div className="col-sm-12 btn_lt reset-btn mt-10">
  144. {(this.state.isStart[index] === false && this.state.isSave[index] === false) &&
  145. <RaisedButton
  146. label="START"
  147. primary={true}
  148. onTouchTap={() => this.handleStart(index)} />
  149. }
  150. {(this.state.isStart[index] === true && this.state.isSave[index] === false) &&
  151. <div>
  152. <span>
  153. <RaisedButton
  154. label="STOP"
  155. primary={true}
  156. onTouchTap={() => this.handleStop(index)} />
  157. </span>
  158. <span style={{ marginLeft: '20px' }}>
  159. <RaisedButton
  160. label="CANCEL"
  161. primary={true}
  162. onTouchTap={() => this.handleCancel(index)} />
  163. </span>
  164. </div>
  165. }
  166. {this.state.isSave[index] === true &&
  167. <div>
  168. <span>
  169. <RaisedButton
  170. label="SAVE"
  171. primary={true}
  172. onTouchTap={() => this.handleSave(index)} />
  173. </span>
  174. <span style={{ marginLeft: '20px' }}>
  175. <RaisedButton
  176. label="CANCEL"
  177. primary={true}
  178. onTouchTap={() => this.handleCancel(index)} />
  179. </span>
  180. </div>
  181. }
  182. </div>
  183. </div>
  184. </td>
  185. <td>
  186. {Obj.description}
  187. </td>
  188. <td>
  189. {this.getMinutes(index)}:{this.getSeconds(index)}
  190. </td>
  191. </tr>
  192. )
  193. })
  194. }
  195.  
  196. renderRecordDuration = () => {
  197. const tableClass = classNames({
  198. 'table': true,
  199. 'table-striped': this.props.condensed,
  200. 'table-bordered': this.props.bordered,
  201. 'table-hover': true,
  202. 'table-condensed': this.props.condensed,
  203. 'customtable': true,
  204. });
  205. const { recordDurationDataList } = this.props;
  206. let PatientRecordDurationList = (recordDurationDataList && recordDurationDataList.data) || [];
  207. return (
  208. <div className="table-responsive mt-15">
  209. <table className={tableClass}>
  210. <thead>
  211. <tr>
  212. <th width="40%">Duration</th>
  213. <th width="40%"></th>
  214. <th width="20%"></th>
  215. </tr>
  216. </thead>
  217. <tbody>
  218. {this.renderData(PatientRecordDurationList.PatientBehaviorsReductionData)}
  219. </tbody>
  220. </table>
  221. </div>
  222. )
  223. }
  224.  
  225.  
  226. render() {
  227.  
  228. return (
  229. <div>
  230. {this.renderLoading()}
  231.  
  232. <div className="clearfix"></div>
  233. <div className="readmin-panel">
  234. <div className="panel-body">
  235. <div className="row">
  236. {this.renderRecordDuration()}
  237. </div>
  238. </div>
  239. </div>
  240. </div>
  241. )
  242. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement