debugging adding an asset
This commit is contained in:
parent
1597bd9522
commit
6e16292f06
10
API/api.cpp
10
API/api.cpp
@ -281,11 +281,13 @@ void API::addAsset(const QString& title, const QString& icon, const QJSValue &fi
|
|||||||
|
|
||||||
QUrlQuery params({
|
QUrlQuery params({
|
||||||
{"title", title},
|
{"title", title},
|
||||||
{"icon", icon}
|
{"icon", icon},
|
||||||
|
{"currency", "1"}
|
||||||
});
|
});
|
||||||
|
|
||||||
QNetworkRequest request(createUrl("/addAsset"));
|
QNetworkRequest request(createUrl("/addAsset"));
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, urlEncoded);
|
request.setHeader(QNetworkRequest::ContentTypeHeader, urlEncoded);
|
||||||
|
request.setRawHeader("Authorization", "Bearer " + accessToken.toUtf8());
|
||||||
QNetworkReply* reply = network.post(request, params.toString(QUrl::FullyEncoded).toUtf8());
|
QNetworkReply* reply = network.post(request, params.toString(QUrl::FullyEncoded).toUtf8());
|
||||||
connect(reply, &QNetworkReply::finished,
|
connect(reply, &QNetworkReply::finished,
|
||||||
std::bind(&API::onAssetAdded, this, reply, finished)
|
std::bind(&API::onAssetAdded, this, reply, finished)
|
||||||
@ -295,8 +297,8 @@ void API::addAsset(const QString& title, const QString& icon, const QJSValue &fi
|
|||||||
void API::onAssetAdded(QNetworkReply *reply, const QJSValue &finished) {
|
void API::onAssetAdded(QNetworkReply *reply, const QJSValue &finished) {
|
||||||
std::unique_ptr<QNetworkReply, NetworkReplyDeleter> rpl(reply);
|
std::unique_ptr<QNetworkReply, NetworkReplyDeleter> rpl(reply);
|
||||||
QNetworkReply::NetworkError error = reply->error();
|
QNetworkReply::NetworkError error = reply->error();
|
||||||
std::optional<QVariantMap> data = readResult(reply);
|
|
||||||
|
|
||||||
|
qDebug() << error;
|
||||||
if (error != QNetworkReply::NoError)
|
if (error != QNetworkReply::NoError)
|
||||||
return callCallback(finished, reply->errorString());
|
return callCallback(finished, reply->errorString());
|
||||||
|
|
||||||
@ -332,6 +334,8 @@ void API::onPollFinished() {
|
|||||||
Codes::Poll code = Codes::Poll::unknownError;
|
Codes::Poll code = Codes::Poll::unknownError;
|
||||||
if (validateResponse(data, resultStructure))
|
if (validateResponse(data, resultStructure))
|
||||||
code = Codes::convertPoll(data->value("result").toInt());
|
code = Codes::convertPoll(data->value("result").toInt());
|
||||||
|
else
|
||||||
|
qDebug() << "";
|
||||||
|
|
||||||
QString detail = Codes::description(code);
|
QString detail = Codes::description(code);
|
||||||
|
|
||||||
@ -457,7 +461,7 @@ void API::responseAssets(QNetworkReply *reply) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap::ConstIterator itr = data->find("assets");
|
QVariantMap::ConstIterator itr = data->find("assets");
|
||||||
if (itr == data->end() || !itr->canConvert<QVariantList>()) {
|
if (itr == data->constEnd() || !itr->canConvert<QVariantList>()) {
|
||||||
qDebug() << "Error receiving assets: assets are missing or not in an array";
|
qDebug() << "Error receiving assets: assets are missing or not in an array";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,48 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
|
|
||||||
|
import magpie.API
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
Label {
|
signal add
|
||||||
anchors.centerIn: parent
|
|
||||||
text: "This is Assets screen"
|
Column {
|
||||||
font {
|
anchors.fill: parent
|
||||||
pixelSize: 24
|
|
||||||
bold: true
|
Label {
|
||||||
|
text: "This is Assets screen"
|
||||||
|
font {
|
||||||
|
pixelSize: 24
|
||||||
|
bold: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ListView {
|
||||||
|
anchors.centerIn: parent
|
||||||
|
model: API.assets
|
||||||
|
delegate: Rectangle {
|
||||||
|
Text {
|
||||||
|
text: title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Button {
|
||||||
|
anchors {
|
||||||
|
bottom: parent.bottom
|
||||||
|
right: parent.right
|
||||||
|
bottomMargin: 20
|
||||||
|
rightMargin: 20
|
||||||
|
}
|
||||||
|
onClicked: add()
|
||||||
|
|
||||||
|
width: 50
|
||||||
|
height: 50
|
||||||
|
icon {
|
||||||
|
name: "list-add"
|
||||||
|
height: 50
|
||||||
|
width: 50
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ import QtQuick.Controls
|
|||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
|
signal addAsset
|
||||||
|
|
||||||
property string currentPage: "home"
|
property string currentPage: "home"
|
||||||
RowLayout {
|
RowLayout {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
@ -53,6 +55,7 @@ Item {
|
|||||||
StackView {
|
StackView {
|
||||||
id: content
|
id: content
|
||||||
initialItem: home
|
initialItem: home
|
||||||
|
clip: true
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
|
|
||||||
@ -67,6 +70,7 @@ Item {
|
|||||||
id: assets
|
id: assets
|
||||||
Assets {
|
Assets {
|
||||||
StackView.onActivating: currentPage = "assets"
|
StackView.onActivating: currentPage = "assets"
|
||||||
|
onAdd: addAsset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
|
|
||||||
|
import magpie.Forms as Forms
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
StackView {
|
StackView {
|
||||||
id: stack
|
id: stack
|
||||||
@ -14,7 +16,15 @@ Item {
|
|||||||
Component {
|
Component {
|
||||||
id: main
|
id: main
|
||||||
Main {
|
Main {
|
||||||
|
onAddAsset: stack.push(addAssetForm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: addAssetForm
|
||||||
|
Forms.AddAsset {
|
||||||
|
onCancel: stack.pop()
|
||||||
|
onSuccess: stack.pop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
106
qml/Forms/AddAsset.qml
Normal file
106
qml/Forms/AddAsset.qml
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
import QtQuick
|
||||||
|
import QtQuick.Controls
|
||||||
|
|
||||||
|
import magpie.API
|
||||||
|
import magpie.Components as Components
|
||||||
|
|
||||||
|
Item {
|
||||||
|
signal success
|
||||||
|
signal cancel
|
||||||
|
|
||||||
|
Column {
|
||||||
|
id: inner
|
||||||
|
spacing: 5
|
||||||
|
anchors.centerIn: parent
|
||||||
|
|
||||||
|
Label {
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
text: qsTr("New asset")
|
||||||
|
font.pixelSize: 14
|
||||||
|
}
|
||||||
|
|
||||||
|
Grid {
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
columns: 2
|
||||||
|
columnSpacing: 10
|
||||||
|
rowSpacing: 5
|
||||||
|
verticalItemAlignment: Grid.AlignVCenter
|
||||||
|
horizontalItemAlignment: Grid.AlignRight
|
||||||
|
|
||||||
|
Label {
|
||||||
|
text: qsTr("Title") + ":";
|
||||||
|
}
|
||||||
|
|
||||||
|
TextField {
|
||||||
|
id: titleField
|
||||||
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
|
text: qsTr("Icon") + ":";
|
||||||
|
}
|
||||||
|
|
||||||
|
TextField {
|
||||||
|
id: iconField
|
||||||
|
text: "list-add"
|
||||||
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
|
text: qsTr("Color") + ":";
|
||||||
|
}
|
||||||
|
|
||||||
|
TextField {
|
||||||
|
id: colorField
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Row {
|
||||||
|
spacing: 5
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
Button {
|
||||||
|
text: qsTr("Cancel")
|
||||||
|
onClicked: cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
Button {
|
||||||
|
text: qsTr("Create")
|
||||||
|
onClicked: inner.send(titleField.text, titleField.text, colorField.text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Components.Modal {
|
||||||
|
id: modal
|
||||||
|
}
|
||||||
|
|
||||||
|
function send (title, icon, color) {
|
||||||
|
if (modal.inProgress)
|
||||||
|
return;
|
||||||
|
|
||||||
|
titleField.text = title;
|
||||||
|
titleField.text = icon;
|
||||||
|
colorField.text = color;
|
||||||
|
|
||||||
|
modal.inProgress = true;
|
||||||
|
modal.status = qsTr("Creating new asset ") + " " + title + "...";
|
||||||
|
modal.open();
|
||||||
|
|
||||||
|
API.addAsset(title, icon, function (err, result) {
|
||||||
|
if (!modal.inProgress)
|
||||||
|
return;
|
||||||
|
|
||||||
|
modal.inProgress = false;
|
||||||
|
if (err)
|
||||||
|
modal.status = err;
|
||||||
|
else
|
||||||
|
modal.status = qsTr("Success");
|
||||||
|
|
||||||
|
if (!!result) {
|
||||||
|
modal.close();
|
||||||
|
success();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@ qt_add_qml_module(magpieForms
|
|||||||
QML_FILES
|
QML_FILES
|
||||||
Login.qml
|
Login.qml
|
||||||
Register.qml
|
Register.qml
|
||||||
|
AddAsset.qml
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(magpie PRIVATE magpieForms)
|
target_link_libraries(magpie PRIVATE magpieForms)
|
||||||
|
Loading…
Reference in New Issue
Block a user