some experiments around therems, a request to update asset
This commit is contained in:
parent
374551d2bb
commit
aa815a5bd7
14 changed files with 229 additions and 59 deletions
|
@ -9,7 +9,11 @@ import magpie
|
|||
import magpie.Components as Components
|
||||
|
||||
Item {
|
||||
signal add
|
||||
signal add()
|
||||
signal edit(id: int)
|
||||
signal remove(id: int)
|
||||
|
||||
id: item
|
||||
|
||||
ColumnLayout {
|
||||
id: column
|
||||
|
@ -33,6 +37,9 @@ Item {
|
|||
delegate: Components.AssetLine {
|
||||
height: 30
|
||||
width: listView.width
|
||||
|
||||
onRemove: id => item.remove(id)
|
||||
onEdit: id => item.edit(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,9 @@ import QtQuick.Controls
|
|||
import QtQuick.Layouts
|
||||
|
||||
Item {
|
||||
signal addAsset
|
||||
signal addAsset()
|
||||
signal removeAsset(id: int)
|
||||
signal editAsset(id: int)
|
||||
|
||||
property string currentPage: "home"
|
||||
RowLayout {
|
||||
|
@ -71,6 +73,8 @@ Item {
|
|||
Assets {
|
||||
StackView.onActivating: currentPage = "assets"
|
||||
onAdd: addAsset()
|
||||
onRemove: id => removeAsset(id)
|
||||
onEdit: id => editAsset(id)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,23 @@ Item {
|
|||
id: main
|
||||
Main {
|
||||
onAddAsset: stack.push(addAssetForm);
|
||||
onEditAsset: function(id) {
|
||||
const asset = Magpie.assets.getAssetByID(id);
|
||||
stack.push(editAssetForm, {
|
||||
name: asset.title,
|
||||
icon: asset.icon,
|
||||
color: asset.color,
|
||||
currency: asset.currencyID,
|
||||
assetID: asset.assetID,
|
||||
title: qsTr("Editing asset") + " " + asset.title
|
||||
});
|
||||
}
|
||||
onRemoveAsset: function(id) {
|
||||
API.deleteAsset(id, function(err) {
|
||||
if (err)
|
||||
Magpie.displayError("Error deleting asset " + Magpie.assets.getAssetByID(id).title + ": " + err);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,6 +70,40 @@ Item {
|
|||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: editAssetForm
|
||||
|
||||
Forms.Asset {
|
||||
required property int assetID
|
||||
|
||||
onCancel: stack.pop()
|
||||
onConfirm: function (title, icon, color, currency) {
|
||||
if (modal.inProgress)
|
||||
return;
|
||||
|
||||
modal.inProgress = true;
|
||||
modal.status = qsTr("Updating asset ") + " " + Magpie.assets.getAssetByID(assetID).title + "...";
|
||||
modal.open();
|
||||
|
||||
API.updateAsset(assetID, title, icon, color, currency, function (err, result) {
|
||||
if (!modal.inProgress)
|
||||
return;
|
||||
|
||||
modal.inProgress = false;
|
||||
if (err)
|
||||
modal.status = err;
|
||||
else
|
||||
modal.status = qsTr("Success");
|
||||
|
||||
if (!!result) {
|
||||
modal.close();
|
||||
stack.pop()
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: Magpie
|
||||
function onDisplayError (err) {
|
||||
|
|
|
@ -13,13 +13,14 @@ Item {
|
|||
required property color color
|
||||
required property string balance
|
||||
required property string currency
|
||||
required property int assetId
|
||||
required property int assetID
|
||||
|
||||
signal error (err:string)
|
||||
signal remove(id: int)
|
||||
signal edit(id: int)
|
||||
|
||||
Row {
|
||||
readonly property int iconSize: height
|
||||
readonly property int freespace: width - deleteButton.width - iconSize - spacing * children.length - 1
|
||||
readonly property int freespace: width - deleteButton.width - editButton.width - iconSize - spacing * children.length - 1
|
||||
|
||||
anchors.fill: parent
|
||||
spacing: 5
|
||||
|
@ -37,29 +38,34 @@ Item {
|
|||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
Label {
|
||||
width: parent.freespace / 3
|
||||
height: parent.height
|
||||
text: title
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
color: palette.text
|
||||
font.bold: true
|
||||
}
|
||||
|
||||
Text {
|
||||
Label {
|
||||
width: parent.freespace / 3
|
||||
height: parent.height
|
||||
text: balance
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
color: palette.text
|
||||
}
|
||||
|
||||
Text {
|
||||
Label {
|
||||
width: parent.freespace / 3
|
||||
height: parent.height
|
||||
text: currency
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
color: palette.text
|
||||
}
|
||||
|
||||
Button {
|
||||
id: editButton
|
||||
text: qsTr("Edit")
|
||||
flat: true
|
||||
height: parent.height
|
||||
onClicked: edit(assetID)
|
||||
}
|
||||
|
||||
Button {
|
||||
|
@ -67,10 +73,7 @@ Item {
|
|||
text: qsTr("Delete")
|
||||
flat: true
|
||||
height: parent.height
|
||||
onClicked: API.deleteAsset(line.assetId, function(err) {
|
||||
if (err)
|
||||
Magpie.displayError("Error deleting asset " + line.title + ": " + err);
|
||||
})
|
||||
onClicked: remove(assetID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,9 +34,17 @@ ComboBox {
|
|||
|
||||
onActivated: index => box.color = model[index]
|
||||
Component.onCompleted: {
|
||||
popup.background.color = box.background.color
|
||||
popup.background.border.color = box.background.border.color
|
||||
popup.background.border.width = box.background.border.width
|
||||
if (box.background.color)
|
||||
popup.background.color = box.background.color;
|
||||
|
||||
if (!box.background.border)
|
||||
return;
|
||||
|
||||
if (box.background.border.color)
|
||||
popup.background.border.color = box.background.border.color;
|
||||
|
||||
if (box.background.border.width)
|
||||
popup.background.border.width = box.background.border.width;
|
||||
}
|
||||
|
||||
popup: Popup {
|
||||
|
@ -69,8 +77,9 @@ ComboBox {
|
|||
|
||||
highlighted: view.currentIndex === index
|
||||
contentItem: Rectangle {
|
||||
anchors.fill: parent
|
||||
color: modelData
|
||||
radius: box.background.radius
|
||||
radius: box.background.radius || 0
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
|
@ -96,7 +105,7 @@ ComboBox {
|
|||
}
|
||||
|
||||
background: Rectangle {
|
||||
radius: box.background.radius
|
||||
radius: box.background.radius || 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,10 +33,11 @@ ComboBox {
|
|||
Icon {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
iconName: icon
|
||||
color: palette.text
|
||||
color: label.color
|
||||
}
|
||||
|
||||
Label {
|
||||
id: label
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: icon
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue