Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const allRiidesUrl = 'https://frozen-mesa-95948.herokuapp.com/api/v1/rides';
  2.  
  3. const logOut = document.querySelector('#logOut');
  4. logOut.addEventListener('click', signOut);
  5.  
  6. function signOut(event) {
  7.     event.preventDefault();
  8.     sessionStorage.clear();
  9.     alert('You have successfully log out. Good Bye!');
  10.     window.location.replace('index.html');
  11. }
  12.  
  13. // const allRides = document.getElementById('allRides');
  14.  
  15. const fetchAllRides = {
  16.     method: 'GET',
  17.     mode: 'cors',
  18.     headers: {
  19.         'Access-Control-Allow-Origin': '*',
  20.         Accept: 'application/json, text/plain, */*',
  21.         'Content-type': 'application/json; charset=utf-8',
  22.         authorization: sessionStorage.token,  
  23.     }
  24. };
  25.  
  26. fetch(allRiidesUrl, fetchAllRides)
  27.     .then((res) => res.json())
  28.     .then((rides) => {
  29.         let rideOutput = '';
  30.        
  31.  
  32.         console.log(rides);
  33.         if(rides.message === 'You do not have permission to this page.'){
  34.             alert('You do not have permission to this page.');
  35.             window.location.href = 'index.html';
  36.         }
  37.         rides.rides.map(ride => {
  38.             rideOutput += `
  39.             <div class="column">
  40.             <div class="card" >
  41.             <div class="container">
  42.             <h2>rides</h2>
  43.             <p class="title">
  44.             From: Destination Start Point.
  45.             </p>
  46.             <p>${ride.startpoint}</p>
  47.             <p class="title"> To: Destination Stop Point.
  48.             </p>
  49.             <p>${ride.stoppoint}</p>
  50.             <p>Departure Time: ${ride.departuretime}</p>
  51.             <p>Departure Date: ${ride.departuredate}</p>
  52.             <div style="text-align: center; content: '' ; clear: both; display: flex; justify-content: center; ">
  53.             <button class="button" style="border: none; display: inline-block; padding: '8px'; background-color: #000; text-align: center; cusor: pointer; width: 100%; margin-bottom: 20%"  onclick="document.getElementById('id02').style.display='block'"> View Details</button>
  54.         </div>
  55.             </div>
  56.             </div>
  57.             </div>
  58.            
  59.             `;
  60.            
  61.             let rideId = ride.id;
  62.             //console.log(rideId);
  63.             const rideUrl = `https://frozen-mesa-95948.herokuapp.com/api/v1/rides/${rideId}`;
  64.  
  65.             const fetchRide = {
  66.                 method: 'GET',
  67.                 mode: 'cors',
  68.                 headers: {
  69.                     'Access-Control-Allow-Origin': '*',
  70.                     Accept: 'application/json, text/plain, */*',
  71.                     'Content-type': 'application/json; charset=utf-8',
  72.                     authorization: sessionStorage.token,  
  73.                 }
  74.             };
  75.            
  76.             fetch(rideUrl, fetchRide)
  77.                 .then((res) => res.json())
  78.                 .then(ride => {
  79.                     let rideList = [ride.ride];
  80.                     console.log([ride.ride]);
  81.                     let viewOutput = '';
  82.                     for (const [key] of Object.entries(rideList)){
  83.                        
  84.                         if(rideList[key].id === rideId){
  85.                             viewOutput += `
  86.                     <span onclick="document.getElementById('id02').style.display='none'" class="close" title="Close Modal">&times;</span>
  87.                     <div style="overflow-x:auto; background-color: white; padding: 20px; width: 60%; margin: 0 auto;">
  88.                     <table>
  89.                     <h1>Ride Details</h1>
  90.                     <thead>
  91.                     <tr>
  92.                           <th> Rides</th>
  93.                           <th> Details</th>
  94.                         </tr>
  95.                     </thread>
  96.                     <tr>
  97.                     <td> Start destintion </td>
  98.                     <td>${ride.ride.startpoint}</td>
  99.                   </tr>
  100.                   <tr>
  101.                     <td> Final destination </td>
  102.                     <td>${ride.ride.stoppoint}</td>
  103.                   </tr>
  104.                   <tr>
  105.                     <td>Departure Time</td>
  106.                     <td>${ride.ride.departuretime}</td>
  107.                   </tr>
  108.                   <tr>
  109.                     <td>Departure Date</td>
  110.                     <td>${ride.ride.departuredate}</td>
  111.                   </tr>
  112.                     </table>
  113.                     <div style="text-align: center; content: '' ; clear: both; display: flex; justify-content: center; ">
  114.                     <button style="background-color: green; color: white; padding: 10px 22px; margin: 9px 0; border: none; cursor: pointer; width: auto">Join</button>
  115.                     </div>
  116.                     </div>
  117.                    
  118.                     `;
  119.                             // if(viewOutput.length > 0){
  120.                             //     document.getElementById('id02').innerHTML = viewOutput;
  121.                             // }
  122.                         }
  123.                        
  124.                     }
  125.                     document.getElementById('id02').innerHTML = viewOutput;
  126.                 });
  127.              
  128.         });
  129.        
  130.         document.getElementById('allRides').innerHTML = rideOutput;
  131.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement