Advertisement
Guest User

my-lots

a guest
Sep 25th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Editor = require("../../../../../react/Mixins/Editor");
  2. const moment = require("moment");
  3. const Platform = require("platform-react");
  4. const React = require("react");
  5. const Slider = require("react-slick").default;
  6.  
  7. /**
  8.  * HyperBolts ϟ (https://hyperbolts.io)
  9.  *
  10.  * Copyright © 2015-present Pace IT Systems Ltd.
  11.  * All rights reserved.
  12.  *
  13.  * @author  Pace IT Systems Ltd
  14.  * @license MIT
  15.  */
  16.  
  17. module.exports = React.createClass({
  18.   mixins: [Editor, Platform.connect("api/user/lots"), Platform.cacheable()],
  19.  
  20.     // Set initial state
  21.     getInitialState() {
  22.             return {
  23.                 auctionDate: '',
  24.                 quickSearch: '',
  25.                 currentPage: 1
  26.             };
  27.     },
  28.    
  29.     // Handle auction date change
  30.     handleAuctionDateChange(event) {
  31.         this.setState({
  32.             auctionDate: event.target.value
  33.         });
  34.     },
  35.  
  36.     // Handle search
  37.     handleSearchChange(event) {  
  38.         // Update state with search value
  39.         this.setState({
  40.             quickSearch: event.target.value
  41.         });
  42.     },
  43.  
  44.     // Handle page change
  45.     handlePageChange(event) {
  46.         this.setState({
  47.             currentPage: event.target.id
  48.         })
  49.     },
  50.  
  51.     // Render auction date dropdown list
  52.     renderAuctionDropdown(lots) {
  53.         let options = [];
  54.  
  55.         // Loop to get distinct auction dates
  56.         for (let i = 0; i < lots.length; i++) {
  57.             if (options[lots[i].allsop_auction.allsop_auctiondate]) continue;
  58.             options[lots[i].allsop_auction.allsop_auctiondate] = true;
  59.             options.push(lots[i].allsop_auction.allsop_auctiondate);
  60.         }
  61.  
  62.         // Return options
  63.         return options.map((option, i) => {
  64.             return <option key={i} value={option}>{moment(option).format('dddd Do MMM YYYY')}</option>
  65.         });
  66.     },
  67.  
  68.     // Render lot features list
  69.     renderLotFeatures(featuresArray) {
  70.         const features = featuresArray || [];
  71.  
  72.         // Return if we have no features
  73.         if (features.length === 0) {
  74.         return null;
  75.         }
  76.  
  77.         return features.map((feature, i) => {
  78.             return <li key={i}>{feature.value}</li>;
  79.         });
  80.     },
  81.  
  82.     // Render menu buttons
  83.     renderLotDetails(lotsArray) {
  84.        
  85.         lotsArray = lotsArray || [];
  86.      
  87.         // Filter results if we have a search term
  88.         const lots = lotsArray.filter((lot) => {
  89.  
  90.             // Convert to lowercase for comparison
  91.             const lotName = lot.allsop_name.toLowerCase();
  92.  
  93.             // Format address for search
  94.             const address = [
  95.                 lot.allsop_propertyname,
  96.                 lot.allsop_propertyaddress1 ,
  97.                 lot.allsop_propertyaddress2,
  98.                 lot.allsop_propertyaddress3,
  99.                 lot.allsop_propertycounty,
  100.                 lot.allsop_propertypostcode
  101.             ].filter(val => val).join(' ').toLowerCase();
  102.            
  103.             // Check if we have search value
  104.             if (this.state.quickSearch !== undefined && this.state.quickSearch !== '') {    
  105.                 // Return true if we have a match
  106.                 if (lotName.indexOf(this.state.quickSearch) > -1 || address.indexOf(this.state.quickSearch.toLowerCase()) > -1) {
  107.                     return true;
  108.                 }
  109.  
  110.                 return false;
  111.             }
  112.  
  113.             // Check if we have auctionDate value
  114.             if (this.state.auctionDate !== undefined && this.state.auctionDate !== '') {
  115.                 // Return true if we have auction date match
  116.                 if (lot.allsop_auction.allsop_auctiondate === this.state.auctionDate) {
  117.                     return true;
  118.                 }
  119.  
  120.                 return false;
  121.             }
  122.  
  123.             return true;
  124.         });
  125.  
  126.         // Return parsed articles
  127.         return lots.map((lotDetails, i) => {
  128.  
  129.             const auction = lotDetails.allsop_auction || {};
  130.             let lotRef, lotType, label;
  131.  
  132.             // Use lotnumber or allsop name
  133.             if (lotDetails.allsop_lotnumber) {
  134.                  lotRef = lotDetails.allsop_lotnumber;
  135.             } else {
  136.                  lotRef = lotDetails.allsop_name;
  137.             }
  138.  
  139.             // Commercial or Resi
  140.             switch (lotDetails.allsop_name[0]) {
  141.                 case "R":
  142.                     lotType = "Residential";
  143.                 break;
  144.                 case "C":
  145.                     lotType = "Commercial";
  146.                 break;
  147.             }
  148.  
  149.             // Format address for display
  150.             const address = [
  151.                 lotDetails.allsop_propertyname,
  152.                 lotDetails.allsop_propertyaddress1 ,
  153.                 lotDetails.allsop_propertyaddress2,
  154.                 lotDetails.allsop_propertyaddress3,
  155.                 lotDetails.allsop_propertycounty,
  156.                 lotDetails.allsop_propertypostcode
  157.             ].filter(val => val).join(', ');
  158.  
  159.             // Format labels
  160.             if (lotDetails.reserve === null) {
  161.                 label = <span className="label label-danger __small">No Reserve</span>;
  162.             }
  163.  
  164.         // Return the images
  165.         return (
  166.             <div
  167.             className={`__lot_container ${"__" + lotType.toLowerCase()}`}
  168.             key={i}
  169.             >
  170.             <div className="__lot_wrapper">
  171.                 <div className="__lot_image">
  172.                 <a href="#">
  173.                     <div className="__tag">{lotType + " - " + lotRef}</div>
  174.                     <img
  175.                     src={
  176.                         Platform.getAssetBase() +
  177.                         "images/packages/platform/frontend/demo/lot-image-43.jpg"
  178.                     }
  179.                     className="img-responsive"
  180.                     />
  181.                 </a>
  182.                 <div className="__lot_info __price">
  183.                     <div className="__price_wrapper">
  184.                     {label}
  185.                     <span className="text-uppercase __f_s_12">Guide Price</span>
  186.                     <h3 className="__m_0 __bold __lot_price">
  187.                         {lotDetails.guide_price_text}
  188.                         <small>{lotDetails.yield}</small>
  189.                     </h3>
  190.                     </div>
  191.                 </div>
  192.                 </div>
  193.                 <div className="__lot_info_section">
  194.                 <div className="__extra_info">
  195.                     <span className={lotDetails.featuredClass}>
  196.                     {lotDetails.featuredText}
  197.                     </span>
  198.                     <span className="__lot_address">{address}</span>
  199.                 </div>
  200.                 <div className="__lot_description">
  201.                     <div className="__info_header __clear">
  202.                     <span
  203.                         className={`label __label_status ${lotDetails.statusColour}`}
  204.                     >
  205.                         <i className={lotDetails.statusIcon} />
  206.                         {lotDetails.statusText}
  207.                     </span>
  208.                     <h4 className="__bold h5">
  209.                         {lotDetails.allsop_propertybyline}
  210.                     </h4>
  211.                     </div>
  212.                     <div>
  213.                     <ul>{this.renderLotFeatures(lotDetails.features)}</ul>
  214.                     Current Rent Reserved<br />
  215.                     £24,000 pa<br />
  216.                     SIX WEEK COMPLETION AVAILABLE
  217.                     </div>
  218.                 </div>
  219.                 <div className="__lot_bottom_section visible-xl">
  220.                     <div className="__bottom_info btn-group btn-group-justified">
  221.                     <div className="__lot_info btn">
  222.                         <i className="icon-placeholder" />
  223.                         {lotDetails.allsop_propertytown}
  224.                     </div>
  225.                     <div className="__lot_info btn">
  226.                         <a href="#">
  227.                         <i className="icon-calendar2" />
  228.                         Auction Date:{" "}
  229.                         {moment(auction.allsop_auctiondate).format(
  230.                             "dddd Do MMM YYYY"
  231.                         )}
  232.                         </a>
  233.                     </div>
  234.                     <div className="__lot_info btn">
  235.                         <a href="lot-overview">
  236.                         <i className="icon-info" />
  237.                         View Lot Details
  238.                         </a>
  239.                     </div>
  240.                     <div className="__lot_info btn">
  241.                         <a href="#">
  242.                         <i className="icon-note" />
  243.                         Add Note
  244.                         </a>
  245.                     </div>
  246.                     <div className="__lot_info btn">
  247.                         <a href="#">
  248.                         <i className={lotDetails.actionButtonIcon} />
  249.                         {lotDetails.actionButtonText}
  250.                         </a>
  251.                     </div>
  252.                     </div>
  253.                 </div>
  254.                 </div>
  255.             </div>
  256.             <div className="__lot_bottom_section hidden-xl">
  257.                 <div className="__bottom_info btn-group btn-group-justified">
  258.                 <div className="__lot_info btn hidden-sm hidden-md">
  259.                     <i className="icon-placeholder" />
  260.                     {lotDetails.location}
  261.                 </div>
  262.                 <div className="__lot_info btn hidden-sm">
  263.                     <a href="#">
  264.                     <i className="icon-calendar2" />
  265.                     {lotDetails.auction}
  266.                     </a>
  267.                 </div>
  268.                 <div className="__lot_info btn">
  269.                     <a href="lot-overview">
  270.                     <i className="icon-info" />
  271.                     View Lot Details
  272.                     </a>
  273.                 </div>
  274.                 <div className="__lot_info btn">
  275.                     <a href="#">
  276.                     <i className="icon-note" />
  277.                     Add Note
  278.                     </a>
  279.                 </div>
  280.                 <div className="__lot_info btn">
  281.                     <a href="#">
  282.                     <i className={lotDetails.actionButtonIcon} />
  283.                     {lotDetails.actionButtonText}
  284.                     </a>
  285.                 </div>
  286.                 </div>
  287.             </div>
  288.             </div>
  289.         );
  290.         });
  291.     },
  292.  
  293.     renderPageNumbers(totalPages, currentPage) {
  294.         const pageNumbers = [];
  295.  
  296.         // Loop to create page numbers
  297.         for (let i = 0; i < totalPages; i++) {
  298.  
  299.             let activeClass = '';
  300.  
  301.             // Set active class
  302.             if (i == currentPage - 1) {
  303.                 activeClass = 'active';
  304.             }
  305.  
  306.             pageNumbers.push(
  307.                 <li key={i} className={activeClass}>
  308.                     <a id={i+1} onClick={this.handlePageChange}>{i+1}</a>
  309.                 </li>
  310.             );
  311.         }
  312.  
  313.         return pageNumbers;
  314.     },
  315.  
  316.     render() {
  317.         const data = this.props.data;
  318.         const apiData = this.state || {};
  319.         const lots = apiData.lots || [];
  320.         let lotsSpliced = [];
  321.         const size = 2;
  322.  
  323.         // Loop to split lots into chunks
  324.         while (lots.length > 0) {
  325.             lotsSpliced.push(lots.splice(0, size));
  326.         }
  327.  
  328.         // Store total page count
  329.         const totalPages = lotsSpliced.length;
  330.  
  331.         let currentPage = this.state.currentPage - 1;
  332.  
  333.         console.log(currentPage);
  334.         console.log(lotsSpliced);
  335.  
  336.         return (
  337.             <div>
  338.                 <div className="__section __p_b_30">
  339.                     <div className="container-fluid">
  340.                         <h3 className="display-3 __m_0 __p_b_30" data-editable="pageTitle">
  341.                         {data.pageTitle}
  342.                         </h3>
  343.                         <div className="row __filters">
  344.                         <div className="col-md-4">
  345.                             <div className="__filter_box">
  346.                                 <div className="form-group">
  347.                                     <label className="control-label">Keywords</label>
  348.                                     <input className="form-control" type="text" onChange={this.handleSearchChange} />
  349.                                 </div>
  350.                             </div>
  351.                         </div>
  352.                         <div className="col-md-4">
  353.                             <div className="__filter_box">
  354.                                 <div className="form-group">
  355.                                     <label className="control-label">Auction Date</label>
  356.                                     <select className="form-control" onChange={this.handleAuctionDateChange}>
  357.                                         <option value="">Please Select</option>
  358.                                         {this.renderAuctionDropdown(lots)}
  359.                                     </select>
  360.                                 </div>
  361.                             </div>
  362.                         </div>
  363.                         <div className="col-md-4">
  364.                             <div className="__filter_box">
  365.                                 <div className="form-group">
  366.                                     <label className="control-label">Lot Status</label>
  367.                                     <select className="form-control">
  368.                                     <option>Please Select</option>
  369.                                     </select>
  370.                                 </div>
  371.                             </div>
  372.                         </div>
  373.                         </div>
  374.                     </div>
  375.                     </div>
  376.                     <div className="__section __p_b_0 __p_t_30 __border_top __bg_grey">
  377.                     <div className="container-fluid">
  378.                         <div className="__results_options __clear">
  379.                         1-8 of 15 Results
  380.                         <span className="__v_sep" />
  381.                         <span>
  382.                             View:
  383.                             <select className="form-control __no_border">
  384.                                 <option>8</option>
  385.                             </select>
  386.                         </span>
  387.                         <span className="pull-right">
  388.                             Sort By:
  389.                             <select className="form-control __no_border">
  390.                                 <option>Newest</option>
  391.                             </select>
  392.                         </span>
  393.                         </div>
  394.                         <div>
  395.                         <div className="__list_view">{this.renderLotDetails(lotsSpliced[this.state.currentPage - 1])}</div>
  396.                         </div>
  397.                         <ul className="pagination">
  398.                             <li className="disabled">
  399.                                 <a href="#">
  400.                                 <i className="fa fa-angle-left" />Previous
  401.                                 </a>
  402.                             </li>
  403.                            {this.renderPageNumbers(totalPages, this.state.currentPage)}
  404.                             <li>
  405.                                 <a href="#">
  406.                                 Next<i className="fa fa-angle-right" />
  407.                                 </a>
  408.                             </li>
  409.                         </ul>
  410.                     </div>
  411.                 </div>
  412.         </div>
  413.         );
  414.     }
  415. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement