Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.97 KB | None | 0 0
  1. import React, { PropTypes, Component } from 'react';
  2. import ReactDOM from 'react-dom';
  3. import './blank.css';
  4. import Details from './Details';
  5. import {
  6. Panel,
  7. Button,
  8. PageHeader,
  9. ControlLabel,
  10. FormControl,
  11. Pagination,
  12. FormGroup
  13. } from 'react-bootstrap';
  14. import JwPagination from 'jw-react-pagination';
  15. import IdleTimer from 'react-idle-timer';
  16. import history from '../../../core/history';
  17.  
  18. var API_URL; // end_point url
  19.  
  20. // This really needs a more descriptive name. It seems like it toggles article visibility?
  21. function myFunction(details) {
  22. var x = document.getElementById("article-lookup");
  23. var y = document.getElementById("articledetails");
  24. if (details === true) {
  25. x.style.display = "none";
  26. y.style.display = "block";
  27. } else {
  28. y.style.display = "none";
  29. x.style.display = "block";
  30. }
  31. }
  32.  
  33. function newFunction(isActive) {
  34. var x = document.getElementById("article-lookup");
  35. var y = document.getElementById("articledetails");
  36. if (isActive) {
  37. x.style.display = "block";
  38. y.style.display = "none";
  39. //history.push('/blank');
  40. } else {
  41. x.style.display = "none";
  42. y.style.display = "block";
  43. }
  44. }
  45.  
  46.  
  47.  
  48. const customStyles = {
  49. ul: {
  50. backgroundColor: 'red'
  51. },
  52. li: {
  53. border: '1px solid green'
  54. },
  55. a: {
  56. color: 'blue'
  57. }
  58. };
  59. const title = 'Customer-LookUp';
  60. const spacing = {
  61. marginRight: "20px",
  62. marginbottom: "20px"
  63. }
  64. const buttonalignment = {
  65. marginLeft: "20px",
  66. marginbottom: "20px"
  67. }
  68.  
  69. class displayBlank extends Component {
  70. constructor(props) {
  71. super(props);
  72. this.state = {
  73. Data: [],
  74. filteredData: [],
  75. pageOfItems: [],
  76. respData: [],
  77. // showResults:false,
  78. sort: {
  79. column: null,
  80. direction: 'desc',
  81. },
  82. filterVal: '',
  83. };
  84. this.handleSubmit = this.handleSubmit.bind(this);
  85. this.setArrow = this.setArrow.bind(this);
  86. this.onSort = this.onSort.bind(this);
  87. this.onChangePage = this.onChangePage.bind(this);
  88. this.handleClick = this.handleClick.bind(this);
  89. this.afterUpdate = this.afterUpdate.bind(this);
  90. this._onActive = this._onActive.bind(this);
  91. this._onIdle = this._onIdle.bind(this);
  92. this._onAction = this._onAction.bind(this);
  93. var hasStorage = (function () {
  94. try {
  95. return true;
  96. } catch (exception) {
  97. return false;
  98. }
  99. }());
  100. var host = JSON.parse(localStorage.getItem('host'));
  101. var url = JSON.parse(localStorage.getItem('url'));
  102.  
  103. var login = sessionStorage.getItem('login');
  104. if (!login) {
  105. history.push('/');
  106. }
  107.  
  108. };
  109. componentDidMount() {
  110. myFunction(false);
  111. }
  112.  
  113. _onAction(e) {
  114. //console.log('user did something', e);
  115. }
  116.  
  117. _onActive(e) {
  118. //console.log('user is active', e);
  119. //console.log('time remaining', this.idleTimer.getRemainingTime());
  120. }
  121.  
  122. _onIdle(e) {
  123. //console.log('user is idle', e)
  124. //console.log('last active', this.idleTimer.getLastActiveTime());
  125. //console.log('elapsed time in blank', this.idleTimer.getElapsedTime());
  126. //var eltime = this.idleTimer.getElapsedTime();
  127. var minutes = 1000 * 60;
  128. var hours = minutes * 60;
  129. var days = hours * 24;
  130. var years = days * 365;
  131. var d = new Date();
  132. var t = d.getTime();
  133. //console.log('current time in icons',t);
  134. var last_active = this.idleTimer.getLastActiveTime();
  135. var eltime = t - last_active;
  136. //console.log('eltime in blank', eltime);
  137. if (eltime >= 1800000) {
  138. history.push('/'); window.location = '/'; sessionStorage.setItem('login', '');
  139. }
  140.  
  141. }
  142. /*shouldComponentUpdate(){
  143. myFunction(false);
  144. }*/
  145.  
  146. afterUpdate() {
  147. //console.log('In afterupdate');
  148. //myFunction(false);
  149. //componentDidMount();
  150. myFunction(false);
  151. }
  152. onChangePage(pageOfItems) {
  153. // update local state with new page of items
  154. this.setState({ pageOfItems });
  155. }
  156. handleSubmit(event) {
  157. event.preventDefault();
  158. //myFunction();
  159. const form = event.target;
  160. const data = new FormData(form);
  161. const arrayValue = [];
  162. var i = 0;
  163. for (let name of data.keys()) {
  164. const input = form.elements[name];
  165. const parserName = input.dataset.parse;
  166. const parsedValue = data.get(name);
  167. if (typeof (parsedValue) == 'undefined' || parsedValue == null) {
  168. arrayValue[i] = "";
  169. data.set(name, arrayValue[i]);
  170. }
  171. else {
  172. data.set(name, parsedValue);
  173. arrayValue[i] = parsedValue;
  174. }
  175. i = i + 1;
  176. }
  177.  
  178. var response_data = "";
  179. var response_jsonObj;
  180. var txt = "";
  181. var req = {
  182. "ArticleErrorsRequest": [{
  183. "col_1": arrayValue[1],
  184. "col_2": arrayValue[0],
  185. "col_3": arrayValue[2],
  186. "col_4": arrayValue[3],
  187. "col_5": arrayValue[4],
  188. "col_6": arrayValue[5],
  189. }]
  190. };
  191. if (data.get('col_1') === '') {
  192. swal({
  193. title: "Column 1 is required!",
  194. icon: "error",
  195. confirmButtonText: 'OK'
  196. }).then((okay) => {
  197. if (okay) {
  198.  
  199. history.push('/grid');
  200. history.push('/blank');
  201. }
  202. });
  203. }
  204. else {
  205.  
  206. fetch(API_URL, {
  207. headers: {
  208. 'Accept': '*/*',
  209. 'Content-Type': 'application/json',
  210. },
  211. method: 'POST',
  212. body: JSON.stringify(req)
  213. }
  214. ).then(response => {
  215. if (response.status !== 200) {
  216. return;
  217. }
  218. response.text().then(data => {
  219. if (data.length == 2) {
  220. swal({
  221. title: "Item Not Found!",
  222. icon: "error",
  223. confirmButtonText: 'OK'
  224. }).then((okay) => {
  225. if (okay) {
  226.  
  227. history.push('/grid');
  228. history.push('/blank');
  229. }
  230. });
  231. }
  232. response_data = data;
  233. response_jsonObj = JSON.parse(response_data);
  234. this.setState({ Data: response_jsonObj });
  235. });
  236. }).catch(error => this.setState({ error }));
  237.  
  238. }
  239. //console.log('req string :', JSON.stringify(req));
  240.  
  241. }
  242.  
  243. handleClick(col_1, col_2, col_3, col_4) {
  244.  
  245. myFunction(true);
  246. var newresponse_jsonObj, response_data;
  247. var req = {
  248. "ArticleErrorsRequest": [{
  249. "col_1": col_1,
  250. "col_2": col_2,
  251. "col_3": col_3,
  252. "col_4": col_4
  253. }]
  254. };
  255. //console.log('req string :', JSON.stringify(req));
  256. fetch(API_URL, {
  257. headers: {
  258. 'Accept': '*/*',
  259. 'Content-Type': 'application/json',
  260. },
  261. method: 'POST',
  262. body: JSON.stringify(req)
  263. }
  264. ).then(response => {
  265. if (response.status !== 200) {
  266. return;
  267. }
  268. response.text().then(data => {
  269. response_data = data;
  270. newresponse_jsonObj = JSON.parse(response_data);
  271. this.setState({ respData: newresponse_jsonObj });
  272. });
  273. }).catch(error => this.setState({ error }));
  274. }
  275.  
  276. onSort = (column) => (e) => {
  277. const direction = this.state.sort.column ? (this.state.sort.direction === 'asc' ? 'desc' : 'asc') : 'desc';
  278. const sortedData = this.state.pageOfItems.sort((a, b) => {
  279. if (column === 'First Name') {
  280. return a.FIRST_NAME.toUpperCase().localeCompare(b.COL_1.toUpperCase());
  281. }
  282.  
  283. else if (column === 'Last Name') {
  284. return a.LAST_NAME.toUpperCase().localeCompare(b.COL_2.toUpperCase());
  285. }
  286.  
  287. });
  288.  
  289.  
  290. if (direction === 'desc') {
  291. sortedData.reverse();
  292. }
  293.  
  294. this.setState({
  295. pageOfItems: sortedData,
  296. sort: {
  297. direction,
  298. column,
  299. }
  300. });
  301. };
  302.  
  303. setArrow = (column, className) => {
  304. let current_className = className;
  305.  
  306. if (this.state.sort.column === column) {
  307. current_className += this.state.sort.direction === 'asc' ? ' asc' : ' desc';
  308. }
  309.  
  310.  
  311. return current_className;
  312. };
  313.  
  314. onFilterChange = (e) => {
  315. const filterVal = e.target.value;
  316. this.setState({ filterVal });
  317. }
  318.  
  319. render() {
  320.  
  321.  
  322. //myFunction(false);
  323. return (
  324. <div id="id1">
  325. <div id="article-lookup">
  326. <div className="row">
  327. <div className="col-lg-12">
  328. <PageHeader>Header Name </PageHeader>
  329. </div>
  330. </div>
  331. <form className="form-horizontal" onSubmit={this.handleSubmit}>
  332. <table>
  333. <tr>
  334. <td>
  335. <div className="form-group col-xs-12" style={{ marginRight: 20 + "px", marginbottom: 8 + "px" }}>
  336. <label className="control-label" >Value</label>
  337. <input className="form-control"
  338. id="Value" name="Value" />
  339. </div>
  340. </td>
  341. <td>
  342. <div className="form-group col-xs-12" style={{ marginRight: 20 + "px", marginbottom: 8 + "px" }}>
  343. <label className="control-label">Value1</label>
  344. <select className="form-control" id="Value1" name="Value1">
  345. <option value=""></option>
  346. <option value="column1">column1</option>
  347. <option value="column2">column2</option>
  348. <option value="column3">column3</option>
  349. <option value="column4">column4</option>
  350. </select>
  351. </div>
  352. </td>
  353.  
  354. </tr>
  355. <tr>
  356. <td>
  357. <div className="form-group col-xs-12" style={{ marginRight: 20 + "px", marginbottom: 8 + "px" }}>
  358. <label className="control-label">Style Code</label>
  359. <input className="form-control"
  360. id="style_code" name="style_code" />
  361. </div>
  362. </td>
  363. <td>
  364. <div className="form-group required col-xs-12" style={spacing}>
  365. <label className="control-label">Value2</label>
  366. <select className="form-control" id="Value2" name="Value2">
  367. <option value=""></option>
  368. <option value="column1">column1</option>
  369. <option value="column2">column2</option>
  370. <option value="column3">column3</option>
  371. <option value="column4">column4</option>
  372. <option value="column5">column5</option>
  373. <option value="column6">column6</option>
  374. <option value="column7">column7</option>
  375. <option value="column8">column8</option>
  376. </select>
  377. </div>
  378.  
  379. </td>
  380. </tr>
  381. <tr>
  382. <td>
  383. <div className="form-group col-xs-12" style={{ marginRight: 20 + "px", marginbottom: 8 + "px" }}>
  384. <label className="control-label">From Date</label>
  385. <input className="form-control"
  386. id="from_date" name="from_date"
  387. type="date"
  388. placeholder="Enter Date"
  389. />
  390. </div>
  391. </td>
  392. <td>
  393. <div className="form-group col-xs-12" style={{ marginRight: 20 + "px", marginbottom: 8 + "px" }}>
  394. <label className="control-label">To Date</label>
  395. <input className="form-control"
  396. id="to_date" name="to_date"
  397. type="date"
  398. placeholder="Enter Date"
  399. />
  400. </div>
  401. </td>
  402. </tr>
  403. <tr>
  404. <td></td>
  405. <td></td>
  406. <td>
  407. <FormGroup style={buttonalignment}>
  408. <Button bsStyle="primary" type="submit" >Search </Button>
  409. {' '}
  410. <Button className="btn btn-secondary" bsStyle="primary" type="reset">Clear </Button>
  411. </FormGroup>
  412. </td>
  413. </tr>
  414. </table>
  415.  
  416. <div className="row ng-scope">
  417. <div className="col-lg-15">
  418. <Panel header={<span> Search Results</span>} >
  419. <div id="dataTables-example_filter" className="dataTables_filter">
  420. <label htmlFor={'search'}>Search:
  421. <input
  422. type="text"
  423. className="form-control input-sm"
  424. placeholder="Search-Term"
  425. aria-controls="dataTables-example"
  426. id="search"
  427. value={this.state.filterVal}
  428. onChange={this.onFilterChange}
  429. />
  430. </label>
  431. </div><br></br>
  432. <div id="Search-Table" className="table-responsive">
  433. <table className="table table-striped table-bordered table-hover dataTable no-footer" id="dataTables-example" role="grid" aria-describedby="dataTables-example_info">
  434. <thead>
  435. <tr role="row">
  436. <th className="col-lg-1">Column1</th>
  437. <th className="col-lg-1">Column2</th>
  438. <th className="col-lg-1">Column3</th>
  439. <th className="col-lg-1">Column4</th>
  440. <th className="col-lg-1">Column5</th>
  441. <th className="col-lg-1">Column6</th>
  442. <th className="col-lg-1">Column7</th>
  443. </tr>
  444. </thead>
  445. <tbody>
  446. {this.state.pageOfItems.map((item, i) => {
  447. return (
  448. <tr key={i} onClick={() => this.handleClick(item.Column1, item.Column2, item.Column3, item.Column3)}>
  449. <td className="col-lg-1">{item.Column1}</td>
  450. <td className="col-lg-1">{item.Column2}</td>
  451. <td className="col-lg-1"> {item.Column3}</td>
  452. <td className="col-lg-1"> {item.Column4}</td>
  453. <td className="col-lg-1"> {item.Column5}</td>
  454. <td className="col-lg-1"> {item.Column6}</td>
  455. <td > {item.Column7}</td>
  456. </tr>
  457. );
  458. })}
  459.  
  460. </tbody>
  461. </table>
  462. <div className="col-sm-6 pullRight " >
  463. <JwPagination items={this.state.Data.filter(item => item.Column1.indexOf(this.state.filterVal) > -1)} onChangePage={this.onChangePage} />
  464. </div>
  465. </div>
  466. </Panel>
  467. </div>
  468. </div>
  469. </form>
  470. </div>
  471. <div id="articledetails">
  472. <Details respData={this.state.respData} afterUpdate={this.afterUpdate} />
  473. </div>
  474. <IdleTimer
  475. ref={ref => { this.idleTimer = ref }}
  476. element={document}
  477. onActive={this._onActive}
  478. onIdle={this._onIdle}
  479. onAction={this._onAction}
  480. debounce={250}
  481. timeout={1800000} />
  482. </div>
  483. );
  484. }
  485.  
  486.  
  487. }
  488. export default displayBlank;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement