Skip to content
TheChatArchiveThe Chat Archive
gpt-4-1106-preview· openaiHugging Face Suzhen/CodeChat

make the deparutre time and arrival time in single column, arrivaltime on top and…

  1. User

    make the deparutre time and arrival time in single column, arrivaltime on top and departure just below arrival time

      .station {
        position: relative;
        margin: 10px 0px;
        display: flex;
        flex-direction: row;
        align-items: center;
      }
    
      .timeline {
        content: "";
        position: absolute;
        top: 50%;
        bottom: -100%;
        /* bottom: -65% or 65  or 100 i dont rememeber ; */
        border-left: 4px solid #4c51bf;
        z-index: 1;
      }
    
      .hoi {
        content: "";
        position: relative;
        width: 16px;
        height: 16px;
        left: 2px;
        background-color: #fff;
        border: 4px solid #4c51bf;
        border-radius: 50%;
        transform: translateX(-50%);
        z-index: 2;
      }
    
      .time-wrapper {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        z-index: 3;
        width: 20px;
      }
    
      .station-time {
        padding: 5px 10px;
        background-color: #4c51bf;
        color: #fff;
        border-radius: 12px;
        white-space: nowrap;
        z-index: 3;
        margin-right: 20px;
      }
    
      .station-name {
        flex-grow: 1;
        margin-left: 20px;
        margin-right: 20px;
        z-index: 3;
      }
    
      .header-row {
        display: flex;
        justify-content: space-between;
        padding: 10px;
        font-weight: bold;
      }
      .green-bg {
        background-color: #10b981;
      }
    
      .green-border {
        border-color: #10b981;
      }
    
      .green-line {
        border-left-color: #10b981;
      }
      .rotate-180 {
        transform: rotate(180deg);
      }
    </style>
    
    <div class="bg-gray-100 font-roboto">
      <div class="max-w-xl mx-auto py-12 px-4 sm:px-6 lg:px-2">
        <div class="mt-8" id="scheduleContainer"></div>
      </div>
    </div>
    
    <script>
      let stationNames = [];
    
      fetch(
        "https://raw.githubusercontent.com/amith-vp/Kerala-Private-Bus-Timing/main/data%20conversion%20scripts/stations.txt"
      )
        .then((response) => response.text())
        .then((data) => {
          stationNames = data.split("\n");
    
          $("#departure").autocomplete({
            source: stationNames,
          });
          $("#destination").autocomplete({
            source: stationNames,
          });
        });
      async function submitForm() {
        const departure = document.getElementById("departure").value;
        const destination = document.getElementById("destination").value;
        const time = document.getElementById("time").value;
        // const time = "12:24";
    
        // Make API request
        const apiUrl = `https://busapi.amithv.xyz/api/v1/schedules?departure=${encodeURIComponent(
          departure
        )}&destination=${encodeURIComponent(destination)}`;
    
        try {
          const response = await fetch(apiUrl);
          const scheduleData = await response.json();
    
          updateSchedule(scheduleData, departure, destination);
        } catch (error) {
          console.error("Error fetching data:", error);
        }
      }
    
      function updateSchedule(scheduleData, departure, destination) {
        departure = departure.toUpperCase();
        destination = destination.toUpperCase();
    
        const scheduleContainer = document.getElementById("scheduleContainer");
        scheduleContainer.innerHTML = "";
    
        scheduleData.forEach((trip, index, array) => {
          const tripDetails = document.createElement("details");
          tripDetails.classList.add(
            "bg-white",
            "rounded-md",
            "shadow-md",
            "my-4",
            "overflow-hidden"
          );
    
          const departureStation = trip.stations.find((station) =>
            station.station.toUpperCase().startsWith(departure)
          );
          const arrivalStation = trip.stations.find((station) =>
            station.station.toUpperCase().startsWith(destination)
          );
          const departureTime = departureStation
            ? departureStation.departureTime
            : "N/A";
          const arrivalTime = arrivalStation
            ? arrivalStation.arrivalTime
            : "N/A";
          const tripSummary = document.createElement("summary");
          tripSummary.classList.add(
            "flex",
            "justify-between",
            "items-center",
            "px-4",
            "py-2",
            "cursor-pointer",
            "bg-blue-500",
            "text-white"
          );
          tripSummary.innerHTML = `
          <div class="flex justify-between items-center w-full">
    

    departureTime➡️{departureTime} ➡️ {arrivalTime} ${trip.vehicle_number}

          tripDetails.appendChild(tripSummary);
    
          let vehicleDiv = document.createElement("div");
          //   vehicleDiv.textContent = `Vehicle Number: ${trip.vehicle_number}, Trip: ${trip.trip}`;
          scheduleContainer.appendChild(vehicleDiv);
    
          let hasDeparted = false;
          let hasArrived = false;
    
          trip.stations.forEach((station, stationIndex) => {
            let stationDiv = document.createElement("div");
            stationDiv.classList.add("station");
    
            if (station.station.toUpperCase().startsWith(departure)) {
              hasDeparted = true;
            }
    
            let arrivalTimeDiv = document.createElement("div");
            arrivalTimeDiv.classList.add("station-time");
            if (hasDeparted && !hasArrived) {
              arrivalTimeDiv.classList.add("green-bg");
            }
            arrivalTimeDiv.textContent = station.arrivalTime;
            stationDiv.appendChild(arrivalTimeDiv);
            stationDiv.classList.add(
              "px-4",
              "py-2",
              "border-b",
              "flex",
              "justify-between",
              "items-center",
              "last:border-b-0"
            );
    
            let timeWrapperDiv = document.createElement("div");
            timeWrapperDiv.classList.add("time-wrapper");
    
            let hoiDiv = document.createElement("div");
            hoiDiv.classList.add("hoi");
            if (hasDeparted && !hasArrived) {
              hoiDiv.classList.add("green-border");
            }
            timeWrapperDiv.appendChild(hoiDiv);
    
            if (stationIndex !== trip.stations.length - 1) {
              let timelineDiv = document.createElement("div");
              timelineDiv.classList.add("timeline");
              if (
                hasDeparted &&
                !hasArrived &&
                station.station.toUpperCase().startsWith(destination) === false
              ) {
                timelineDiv.classList.add("green-line");
              } else {
                timelineDiv.classList.add("blue-line");
              }
              timeWrapperDiv.appendChild(timelineDiv);
            }
    
            stationDiv.appendChild(timeWrapperDiv);
    
            let stationNameDiv = document.createElement("div");
            stationNameDiv.classList.add("station-name");
            stationNameDiv.textContent = station.station;
            stationDiv.appendChild(stationNameDiv);
    
            let departureTimeDiv = document.createElement("div");
            departureTimeDiv.classList.add("station-time");
            if (hasDeparted && !hasArrived) {
              departureTimeDiv.classList.add("green-bg");
            }
            departureTimeDiv.textContent = station.departureTime;
            stationDiv.appendChild(departureTimeDiv);
    
            scheduleContainer.appendChild(stationDiv);
    
            if (station.station.toUpperCase().startsWith(destination)) {
              hasArrived = true;
            }
            tripDetails.appendChild(stationDiv);
          });
          scheduleContainer.appendChild(tripDetails);
        });
      }
    </script>
    
  2. Assistant

    To have the arrival and departure times in a single column with arrival time on top and departure time just below, you need to modify the presentation of the times within each stationDiv. This means changing the layout for the times within the .time-wrapper class. However, in your current structure, you are adding .station-time as siblings to .time-wrapper, which makes it difficult to align them in a single column.

    To fix this, we will include the arrival and departure times inside the .time-wrapper and adjust their CSS styles accordingly. Let's also clean up a bit of the code to align with our new requirements.

    Here is how the CSS modifications would look:

    /* CSS changes */
    .time-wrapper {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      z-index: 3;
      position: relative;
    }
    
    .station-name {
      flex-grow: 1;
      padding-left: 20px; /* Alignment adjustment */
      z-index: 3;
    }
    
    /* Remove styles from .station-time that are no longer needed */
    .station-time {
      background-color: #4c51bf;
      color: #fff;
      padding: 2px 10px;
      border-radius: 12px;
      white-space: nowrap;
      z-index: 3;
    }
    
    /* Add specific styles for arrival and departure times */
    .arrival-time, .departure-time {
      margin: 2px 0; /* spacing between arrival and departure times */
    }
    

    Next, modify the JavaScript part that creates each station's display within the updateSchedule function:

    // Inside the forEach loop that iterates over trip.stations
    trip.stations.forEach((station, stationIndex) => {
      // ...
      let timeWrapperDiv = document.createElement("div");
      timeWrapperDiv.classList.add("time-wrapper");
    
      let arrivalTimeDiv = document.createElement("div");
      arrivalTimeDiv.classList.add("station-time", "arrival-time");
      arrivalTimeDiv.textContent = station.arrivalTime;
      timeWrapperDiv.appendChild(arrivalTimeDiv);
    
      let hoiDiv = document.createElement("div");
      hoiDiv.classList.add("hoi");
      timeWrapperDiv.appendChild(hoiDiv);
    
      let departureTimeDiv = document.createElement("div");
      departureTimeDiv.classList.add("station-time", "departure-time");
      departureTimeDiv.textContent = station.departureTime;
      timeWrapperDiv.appendChild(departureTimeDiv);
    
      // ...
    
      stationDiv.appendChild(timeWrapperDiv);
      // ...
    
      // Remove the previously separate addition of arrivalTimeDiv and departureTimeDiv 
      // since we now add them inside timeWrapperDiv
      // ...
    
      // Append stationDiv to tripDetails as before
      tripDetails.appendChild(stationDiv);
    });
    

    Make sure to remove any references to the old .station-time elements being added outside the .time-wrapper from the existing code to ensure you only have the adjusted elements within .time-wrapper.

    Applying these changes will place the arrival time above the departure time within a single column as part of the timeline. The .hoi div continues to represent the station point with both times neatly positioned above and below it.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.