Commit 2ec193f7 authored by Volker Krause's avatar Volker Krause

Proof-of-concept for element editing

parent 35149aaa
......@@ -28,6 +28,7 @@ Kirigami.ScrollablePage {
property string resId
property variant reservation
property string passId
property variant editor
Kirigami.OverlaySheet {
id: deleteWarningSheet
......@@ -52,16 +53,22 @@ Kirigami.ScrollablePage {
actions {
contextualActions: [
Kirigami.Action {
iconName: "edit-delete"
text: i18n("Delete")
onTriggered: deleteWarningSheet.sheetOpen = true
},
Kirigami.Action {
iconSource: root.passId !== "" ? "image://org.kde.pkpass/" + passId + "/icon" : ""
text: i18n("Boarding Pass")
text: i18n("Show Boarding Pass")
visible: root.passId !== ""
onTriggered: applicationWindow().pageStack.push(pkpassComponent, {"passId": root.passId });
},
Kirigami.Action {
iconName: "document-edit"
text: i18n("Edit")
visible: root.editor != undefined
onTriggered: applicationWindow().pageStack.push(editor);
},
Kirigami.Action {
iconName: "edit-delete"
text: i18n("Delete")
onTriggered: deleteWarningSheet.sheetOpen = true
}
]
}
......
/*
Copyright (C) 2018 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.5
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1 as QQC2
import org.kde.kirigami 2.0 as Kirigami
import org.kde.kitinerary 1.0
import org.kde.itinerary 1.0
import "." as App
Kirigami.ScrollablePage {
id: root
property string resId
property variant reservation
actions {
main: Kirigami.Action {
iconName: "document-save"
onTriggered: {
root.save(resId, reservation);
pageStack.pop();
}
}
}
onBackRequested: pageStack.pop()
}
/*
Copyright (C) 2018 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.5
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1 as QQC2
import org.kde.kirigami 2.0 as Kirigami
import org.kde.kitinerary 1.0
import org.kde.itinerary 1.0
import "." as App
App.EditorPage {
id: root
title: i18n("Edit Flight")
function save(resId, reservation) {
var flight = reservation.reservationFor;
flight.departureTerminal = departureTerminal.text
flight.departureGate = departureGate.text
var newRes = reservation;
newRes.reservationFor = flight;
_reservationManager.updateReservation(resId, newRes);
}
GridLayout {
id: grid
width: parent.width
columns: 2
QQC2.Label {
Layout.columnSpan: 2
Layout.fillWidth: true
text: reservation.reservationFor.airline.iataCode + " " + reservation.reservationFor.flightNumber
horizontalAlignment: Qt.AlignHCenter
font.bold: true
}
// departure data
QQC2.Label {
Layout.columnSpan: 2
Layout.fillWidth: true
text: i18n("Departure")
horizontalAlignment: Qt.AlignHCenter
}
QQC2.Label {
text: i18n("Departure terminal:")
}
QQC2.TextField {
id: departureTerminal
text: reservation.reservationFor.departureTerminal
}
QQC2.Label {
text: i18n("Departure gate:")
}
QQC2.TextField {
id: departureGate
text: reservation.reservationFor.departureGate
}
}
}
......@@ -26,6 +26,12 @@ import "." as App
App.DetailsPage {
id: root
title: i18n("Flight")
editor: Component {
App.FlightEditor {
reservation: root.reservation
resId: root.resId
}
}
GridLayout {
id: grid
......
......@@ -9,7 +9,9 @@
<file>BusPage.qml</file>
<file>CountryInfoDelegate.qml</file>
<file>DetailsPage.qml</file>
<file>EditorPage.qml</file>
<file>FlightDelegate.qml</file>
<file>FlightEditor.qml</file>
<file>FlightPage.qml</file>
<file>HotelDelegate.qml</file>
<file>HotelPage.qml</file>
......
......@@ -187,7 +187,21 @@ void ReservationManager::addReservation(const QVariant &res)
f.write(QJsonDocument(JsonLdDocument::toJson({res})).toJson());
m_reservations.insert(resId, res);
emit reservationAdded(resId);
}
void ReservationManager::updateReservation(const QString &resId, const QVariant &res)
{
const QString basePath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/reservations/");
QDir::root().mkpath(basePath);
const QString path = basePath + resId + QLatin1String(".jsonld");
QFile f(path);
if (!f.open(QFile::WriteOnly)) {
qCWarning(Log) << "Unable to open file:" << f.errorString();
return;
}
f.write(QJsonDocument(JsonLdDocument::toJson({res})).toJson());
m_reservations.insert(resId, res);
emit reservationUpdated(resId);
}
void ReservationManager::removeReservation(const QString& id)
......
......@@ -43,6 +43,7 @@ public:
Q_INVOKABLE void importReservation(const QUrl &filename);
Q_INVOKABLE void addReservation(const QVariant &res);
Q_INVOKABLE void updateReservation(const QString &resId, const QVariant &res);
Q_INVOKABLE void removeReservation(const QString &id);
void importReservation(const QByteArray &data);
......
Markdown is supported
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