Warning, /pim/itinerary/src/app/BusEditor.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2019-2023 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 import QtQuick
0007 import QtQuick.Layouts
0008 import QtQuick.Controls as QQC2
0009 import org.kde.kirigami as Kirigami
0010 import org.kde.kirigamiaddons.formcard as FormCard
0011 import org.kde.kitinerary
0012 import org.kde.kpublictransport
0013 import org.kde.itinerary
0014 
0015 EditorPage {
0016     id: root
0017     title: i18n("Edit Bus Reservation")
0018 
0019     property var departureBusStop: reservationFor.departureBusStop
0020     property var departureTime: Util.dateTimeStripTimezone(reservationFor, "departureTime")
0021     property var arrivalBusStop: reservationFor.arrivalBusStop
0022     property var arrivalTime: Util.dateTimeStripTimezone(reservationFor, "arrivalTime")
0023 
0024     function apply(reservation) {
0025         let trip = reservation.reservationFor;
0026         trip.departureBusStop = root.departureBusStop;
0027         trip = Util.setDateTimePreserveTimezone(trip, "departureTime", root.departureTime);
0028         trip.departurePlatform = departurePlatform.text;
0029         trip.arrivalBusStop = root.arrivalBusStop;
0030         trip = Util.setDateTimePreserveTimezone(trip, "arrivalTime", root.arrivalTime);
0031         trip.arrivalPlatform = arrivalPlatform.text;
0032 
0033         let ticket = reservation.reservedTicket ?? Factory.makeTicket();
0034         let seat = ticket.ticketedSeat;
0035         seat.seatNumber = seatNumber.text;
0036         ticket.ticketedSeat = seat;
0037 
0038         var newRes = reservation;
0039         newRes.reservationFor = trip;
0040         newRes.reservedTicket = ticket;
0041         bookingEdit.apply(newRes);
0042         return newRes;
0043     }
0044 
0045     IntermediateStopSelector {
0046         id: boardSheet
0047         title: i18n("Board Later")
0048         model: root.controller.journey.intermediateStops
0049         action: Kirigami.Action {
0050             text: i18n("Change departure stop")
0051             onTriggered: {
0052                 departureBusStop = PublicTransport.busStationFromLocation(root.controller.journey.intermediateStops[boardSheet.currentIndex].stopPoint)
0053                 departureTime = Util.dateTimeStripTimezone(root.controller.journey.intermediateStops[boardSheet.currentIndex], "scheduledDepartureTime");
0054                 boardSheet.close();
0055             }
0056         }
0057     }
0058     IntermediateStopSelector {
0059         id: alightSheet
0060         title: i18n("Alight Earlier")
0061         model: root.controller.journey.intermediateStops
0062         action: Kirigami.Action {
0063             text: i18n("Change arrival stop")
0064             onTriggered: {
0065                 arrivalBusStop = PublicTransport.busStationFromLocation(root.controller.journey.intermediateStops[alightSheet.currentIndex].stopPoint);
0066                 arrivalTime = Util.dateTimeStripTimezone(root.controller.journey.intermediateStops[alightSheet.currentIndex], "scheduledArrivalTime");
0067                 if (!arrivalTime) {
0068                     arrivalTime = Util.dateTimeStripTimezone(root.controller.journey.intermediateStops[alightSheet.currentIndex], "scheduledDepartureTime");
0069                 }
0070                 alightSheet.close();
0071             }
0072         }
0073     }
0074 
0075     ColumnLayout {
0076         spacing: 0
0077 
0078         CardPageTitle {
0079             emojiIcon: "🚌"
0080             text: if (reservationFor.busNumber || reservationFor.busName) {
0081                 return reservationFor.busName + " " + reservationFor.busNumber;
0082             } else {
0083                 return i18nc("@title", "Bus")
0084             }
0085         }
0086 
0087         FormCard.FormHeader {
0088             title: i18nc("bus departure", "Departure")
0089         }
0090 
0091         FormCard.FormCard {
0092             FormCard.FormTextDelegate {
0093                 text: i18nc("bus stop", "Stop")
0094                 description: root.departureBusStop.name
0095             }
0096             FormCard.FormTextFieldDelegate {
0097                 id: departurePlatform
0098                 label: i18nc("bus stop platform", "Platform")
0099                 text: reservationFor.departurePlatform
0100             }
0101             FormCard.FormButtonDelegate {
0102                 text: i18n("Board later")
0103                 icon.name: "arrow-right"
0104                 visible: root.controller.journey && root.controller.journey.intermediateStops.length > 0 // TODO also check for preceding layovers
0105                 onClicked: boardSheet.open();
0106             }
0107         }
0108 
0109         FormCard.FormHeader {
0110             title: i18nc("bus arrival", "Arrival")
0111         }
0112 
0113         FormCard.FormCard {
0114             FormCard.FormTextDelegate {
0115                 text: i18nc("bus stop", "Stop")
0116                 description: root.arrivalBusStop.name
0117             }
0118             FormCard.FormTextFieldDelegate {
0119                 id: arrivalPlatform
0120                 label: i18nc("bus stop platform", "Platform")
0121                 text: reservationFor.arrivalPlatform
0122             }
0123             FormCard.FormButtonDelegate {
0124                 text: i18n("Alight earlier")
0125                 icon.name: "arrow-left"
0126                 visible: root.controller.journey && root.controller.journey.intermediateStops.length > 0 // TODO also check for subsequent layovers
0127                 onClicked: alightSheet.open();
0128             }
0129         }
0130 
0131         // TODO the below is per reservation, not per batch, so add a selector for that!
0132         FormCard.FormHeader {
0133             title: i18n("Seat")
0134         }
0135 
0136         FormCard.FormCard {
0137             FormCard.FormTextFieldDelegate {
0138                 id: seatNumber
0139                 label: i18n("Seat")
0140                 text: reservation.reservedTicket ? reservation.reservedTicket.ticketedSeat.seatNumber : ""
0141             }
0142         }
0143 
0144         BookingEditorCard {
0145             id: bookingEdit
0146             item: root.reservation
0147         }
0148     }
0149 }