Commit 1584d7ad authored by Volker Krause's avatar Volker Krause
Browse files

Allow to shorten train trips

That is, for an existing reservation for which we know the intermediate
stops, allow to change the departure to a later stop and the arrival to
an earlier one. This is useful when having to react to disruptions or
having to do creative bookings for discounts, and is more convenient
compared to manually editing arrival/departures (and which we can't even
do yet at all anyway).
parent cbd5fbeb
......@@ -14,7 +14,8 @@ import "." as App
Kirigami.ScrollablePage {
id: root
property var batchId
property var batchId: controller ? controller.batchId : undefined
property QtObject controller: null
property var resIds: ReservationManager.reservationsForBatch(root.batchId)
readonly property var reservation: ReservationManager.reservation(root.batchId);
......
......@@ -9,6 +9,7 @@ import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1 as QQC2
import org.kde.kirigami 2.17 as Kirigami
import org.kde.kitinerary 1.0
import org.kde.kpublictransport 1.0
import org.kde.itinerary 1.0
import "." as App
......@@ -16,9 +17,33 @@ App.EditorPage {
id: root
title: i18n("Edit Train Reservation")
property var departureStation: reservationFor.departureStation
property var departureTime: Util.dateTimeStripTimezone(reservationFor, "departureTime")
property var arrivalStation: reservationFor.arrivalStation
property var arrivalTime: Util.setDateTimePreserveTimezone(reservationFor, "arrivalTime")
actions.contextualActions: [
Kirigami.Action {
text: i18n("Board later")
icon.name: "arrow-left"
enabled: root.controller.journey && root.controller.journey.intermediateStops.length > 0 // TODO also check for preceding layovers
onTriggered: boardSheet.open();
},
Kirigami.Action {
text: i18n("Alight earlier")
icon.name: "arrow-right"
enabled: root.controller.journey && root.controller.journey.intermediateStops.length > 0 // TODO also check for subsequent layovers
onTriggered: alightSheet.open();
}
]
function save(resId, reservation) {
var trip = reservation.reservationFor;
trip.departureStation = root.departureStation;
trip = Util.setDateTimePreserveTimezone(trip, "departureTime", root.departureTime);
trip.departurePlatform = departurePlatform.text;
trip.arrivalStation = root.arrivalStation;
trip = Util.setDateTimePreserveTimezone(trip, "arrivalTime", root.arrivalTime);
trip.arrivalPlatform = arrivalPlatform.text;
var seat = reservation.reservedTicket.ticketedSeat;
......@@ -36,6 +61,62 @@ App.EditorPage {
ReservationManager.updateReservation(resId, newRes);
}
Component {
id: intermediateStopDelegate
Kirigami.BasicListItem {
text: Localizer.formatTime(modelData, "scheduledDepartureTime") + " " + modelData.stopPoint.name
enabled: modelData.disruptionEffect != Disruption.NoService
}
}
Kirigami.OverlaySheet {
id: boardSheet
header: Kirigami.Heading {
text: i18n("Board Later")
}
ListView {
id: boardStopSelector
model: root.controller.journey.intermediateStops
delegate: intermediateStopDelegate
}
footer: QQC2.Button {
text: i18n("Change departure station")
enabled: boardStopSelector.currentIndex >= 0
onClicked: {
departureStation = PublicTransport.trainStationFromLocation(root.controller.journey.intermediateStops[boardStopSelector.currentIndex].stopPoint)
departureTime = Util.dateTimeStripTimezone(root.controller.journey.intermediateStops[alightStopSelector.currentIndex], "scheduledDepartureTime");
boardSheet.close();
}
}
}
Kirigami.OverlaySheet {
id: alightSheet
header: Kirigami.Heading {
text: i18n("Alight Earlier")
}
ListView {
id: alightStopSelector
model: root.controller.journey.intermediateStops
delegate: intermediateStopDelegate
}
footer: QQC2.Button {
text: i18n("Change arrival station")
enabled: stopSelector.currentIndex >= 0
onClicked: {
arrivalStation = PublicTransport.trainStationFromLocation(root.controller.journey.intermediateStops[alightStopSelector.currentIndex].stopPoint);
arrivalTime = Util.dateTimeStripTimezone(root.controller.journey.intermediateStops[alightStopSelector.currentIndex], "scheduledArrivalTime");
if (!arrivalTime) {
arrivalTime = Util.dateTimeStripTimezone(root.controller.journey.intermediateStops[alightStopSelector.currentIndex], "scheduledDepartureTime");
}
alightSheet.close();
}
}
}
Kirigami.FormLayout {
width: parent.width
......@@ -47,8 +128,8 @@ App.EditorPage {
// TODO time
QQC2.Label {
Kirigami.FormData.label: i18n("Station:")
text: reservationFor.departureStation.name
Kirigami.FormData.label: i18nc("train station", "Station:")
text: root.departureStation.name
}
QQC2.TextField {
id: departurePlatform
......@@ -64,8 +145,8 @@ App.EditorPage {
// TODO time
QQC2.Label {
Kirigami.FormData.label: i18n("Station:")
text: reservationFor.arrivalStation.name
Kirigami.FormData.label: i18nc("train station", "Station:")
text: root.arrivalStation.name
}
QQC2.TextField {
id: arrivalPlatform
......
......@@ -18,7 +18,7 @@ App.DetailsPage {
title: i18n("Train Ticket")
editor: Component {
App.TrainEditor {
batchId: root.batchId
controller: root.controller
}
}
......
......@@ -90,6 +90,11 @@ KPublicTransport::Location PublicTransport::locationFromPlace(const QVariant& pl
return loc;
}
QVariant PublicTransport::trainStationFromLocation(const KPublicTransport::Location &loc) const
{
return PublicTransport::placeFromLocation<KItinerary::TrainStation>(loc);
}
QString PublicTransport::lineIcon(const QVariant &line) const
{
using namespace KPublicTransport;
......
......@@ -42,6 +42,9 @@ public:
template <typename T>
static T placeFromLocation(const KPublicTransport::Location &loc);
/** Same as the above, but usable from QML. */
Q_INVOKABLE QVariant trainStationFromLocation(const KPublicTransport::Location &loc) const;
/** Applies information from @p location to the given KItinerary place.
* Unlike mergeStation(), this does not assume both sides refer to the same location, and @p location has precedence.
* Data from @p station is only considered if both sides refer to the same location.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment