monero-gui/pages/History.qml

428 lines
14 KiB
QML
Raw Normal View History

2018-01-07 05:20:45 +00:00
// Copyright (c) 2014-2018, The Monero Project
2015-04-01 08:56:05 +00:00
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2014-07-07 17:08:30 +00:00
import QtQuick 2.0
import QtQuick.Layouts 1.1
import QtQuick.Dialogs 1.2
import moneroComponents.Wallet 1.0
import moneroComponents.WalletManager 1.0
2016-10-07 20:05:51 +00:00
import moneroComponents.TransactionHistory 1.0
2016-10-08 00:26:45 +00:00
import moneroComponents.TransactionInfo 1.0
2016-10-07 20:05:51 +00:00
import moneroComponents.TransactionHistoryModel 1.0
import "../components"
2014-07-07 17:08:30 +00:00
Rectangle {
id: mainLayout
property var model
property int tableHeight: !isMobile ? table.contentHeight : tableMobile.contentHeight
2016-10-02 21:03:37 +00:00
2016-11-06 12:33:41 +00:00
QtObject {
id: d
property bool initialized: false
}
color: "transparent"
function getSelectedAmount() {
if (typeof model === 'undefined' || model == null)
2016-11-10 20:14:22 +00:00
return ""
var total = 0
var count = model.rowCount()
for (var i = 0; i < count; ++i) {
var idx = model.index(i, 0)
var isout = model.data(idx, TransactionHistoryModel.TransactionIsOutRole);
var amount = model.data(idx, TransactionHistoryModel.TransactionAtomicAmountRole);
if (isout)
total = walletManager.subi(total, amount)
else
total = walletManager.addi(total, amount)
}
var sign = ""
if (total < 0) {
total = -total
sign = "-"
}
return count + qsTr(" selected: ") + sign + walletManager.displayAmount(total);
}
function resetFilter(model) {
model.dateFromFilter = "2014-04-18" // genesis block
model.dateToFilter = "9999-09-09" // fix before september 9999
// negative values disable filters here;
model.amountFromFilter = -1;
model.amountToFilter = -1;
model.directionFilter = TransactionInfo.Direction_Both;
}
2016-10-04 20:12:58 +00:00
onModelChanged: {
2017-08-08 09:07:06 +00:00
if (typeof model !== 'undefined' && model != null) {
2016-11-06 12:33:41 +00:00
if (!d.initialized) {
// setup date filter scope according to real transactions
fromDatePicker.currentDate = model.transactionHistory.firstDateTime
toDatePicker.currentDate = model.transactionHistory.lastDateTime
model.sortRole = TransactionHistoryModel.TransactionBlockHeightRole
2016-11-06 12:33:41 +00:00
model.sort(0, Qt.DescendingOrder);
d.initialized = true
}
}
2016-10-04 20:12:58 +00:00
}
2016-10-02 21:03:37 +00:00
function onFilterChanged() {
// set datepicker error states
var datesValid = fromDatePicker.currentDate <= toDatePicker.currentDate
fromDatePicker.error = !datesValid;
toDatePicker.error = !datesValid;
if(datesValid){
resetFilter(model)
if (fromDatePicker.currentDate > toDatePicker.currentDate) {
console.error("Invalid date filter set: ", fromDatePicker.currentDate, toDatePicker.currentDate)
} else {
model.dateFromFilter = fromDatePicker.currentDate
model.dateToFilter = toDatePicker.currentDate
}
model.searchFilter = searchLine.text;
tableHeader.visible = model.rowCount() > 0;
}
}
Rectangle{
id: rootLayout
visible: false
}
ColumnLayout {
id: pageRoot
anchors.margins: isMobile ? 17 : 20 * scaleRatio
anchors.topMargin: isMobile ? 0 : 40 * scaleRatio
2016-10-02 21:03:37 +00:00
anchors.left: parent.left
anchors.top: parent.top
anchors.right: parent.right
spacing: 10 * scaleRatio
GridLayout {
2018-03-21 22:58:51 +00:00
property int column_width: {
if(!isMobile){
return (parent.width / 2) - 20;
} else {
return parent.width - 20;
}
}
columns: 2
Layout.fillWidth: true
2014-07-16 16:04:34 +00:00
RowLayout {
visible: !isMobile
2018-03-21 22:58:51 +00:00
Layout.preferredWidth: parent.column_width
StandardButton {
visible: !isIOS
small: true
text: qsTr("Export") + translationManager.emptyString
onClicked: {
writeCSVFileDialog.open();
}
}
}
2016-10-07 20:05:51 +00:00
RowLayout {
2018-03-21 22:58:51 +00:00
Layout.preferredWidth: parent.column_width
LineEdit {
id: searchLine
fontSize: 14 * scaleRatio
2018-11-29 00:41:34 +00:00
inputHeight: 36 * scaleRatio
borderDisabled: true
Layout.fillWidth: true
backgroundColor: "#404040"
placeholderText: qsTr("Search") + translationManager.emptyString
placeholderCenter: true
onTextChanged: {
onFilterChanged();
}
}
}
}
2014-07-16 16:04:34 +00:00
GridLayout {
z: 6
columns: (isMobile)? 1 : 3
Layout.fillWidth: true
columnSpacing: 22 * scaleRatio
visible: !isMobile
ColumnLayout {
Layout.fillWidth: true
2014-07-16 16:04:34 +00:00
RowLayout {
Layout.fillWidth: true
id: fromDateRow
Layout.minimumWidth: 150 * scaleRatio
2014-07-16 16:04:34 +00:00
DatePicker {
visible: !isMobile
2014-07-16 16:04:34 +00:00
id: fromDatePicker
Layout.fillWidth: true
width: 100 * scaleRatio
2018-06-26 10:28:31 +00:00
inputLabel.text: qsTr("Date from") + translationManager.emptyString
onCurrentDateChanged: {
onFilterChanged()
}
}
}
}
ColumnLayout {
Layout.fillWidth: true
RowLayout {
Layout.fillWidth: true
id: toDateRow
Layout.minimumWidth: 150 * scaleRatio
DatePicker {
visible: !isMobile
id: toDatePicker
Layout.fillWidth: true
width: 100 * scaleRatio
2018-06-26 10:28:31 +00:00
inputLabel.text: qsTr("Date to") + translationManager.emptyString
onCurrentDateChanged: {
onFilterChanged()
}
}
2016-10-07 23:28:27 +00:00
}
}
ColumnLayout {
Layout.fillWidth: true
2014-07-16 16:04:34 +00:00
Label {
id: transactionPriority
Layout.minimumWidth: 120 * scaleRatio
text: qsTr("Sort") + translationManager.emptyString
2018-01-12 00:45:27 +00:00
fontSize: 14
}
2014-07-16 16:04:34 +00:00
ListModel {
id: priorityModelV5
ListElement { column1: qsTr("Block height") ; column2: "";}
ListElement { column1: qsTr("Date") ; column2: ""; }
}
StandardDropdown {
id: priorityDropdown
anchors.topMargin: 2 * scaleRatio
fontHeaderSize: 14 * scaleRatio
dropdownHeight: 28 * scaleRatio
Layout.fillWidth: true
shadowReleasedColor: "#FF4304"
shadowPressedColor: "#B32D00"
releasedColor: "#404040"
pressedColor: "#202020"
2018-04-29 22:52:48 +00:00
colorBorder: "#404040"
colorHeaderBackground: "#404040"
onChanged: {
switch(priorityDropdown.currentIndex){
case 0:
// block sort
model.sortRole = TransactionHistoryModel.TransactionBlockHeightRole;
break;
case 1:
// amount sort
model.sortRole = TransactionHistoryModel.TransactionDateRole;
break;
}
model.sort(0, Qt.DescendingOrder);
}
2014-07-16 16:04:34 +00:00
}
}
}
2016-10-07 23:28:27 +00:00
GridLayout {
Layout.topMargin: 20
visible: table.count === 0
Label {
fontSize: 16 * scaleRatio
text: qsTr("No history...") + translationManager.emptyString
}
}
GridLayout {
id: tableHeader
columns: 1
columnSpacing: 0
rowSpacing: 0
Layout.topMargin: 20
Layout.fillWidth: true
2014-07-16 16:04:34 +00:00
RowLayout{
Layout.preferredHeight: 10
Layout.fillWidth: true
2014-07-16 16:04:34 +00:00
Rectangle {
id: header
Layout.fillWidth: true
visible: table.count > 0
2014-07-16 16:04:34 +00:00
height: 10
2018-03-21 01:12:02 +00:00
color: "transparent"
Rectangle {
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.rightMargin: 10
anchors.leftMargin: 10
2014-07-16 16:04:34 +00:00
height: 1
color: "#404040"
}
2014-07-16 16:04:34 +00:00
Image {
anchors.top: parent.top
anchors.left: parent.left
width: 10
height: 10
source: "../images/historyBorderRadius.png"
}
2014-07-16 16:04:34 +00:00
Image {
anchors.top: parent.top
anchors.right: parent.right
2014-07-16 16:04:34 +00:00
width: 10
height: 10
2014-07-16 16:04:34 +00:00
source: "../images/historyBorderRadius.png"
rotation: 90
}
2016-10-08 22:40:13 +00:00
}
2014-07-16 16:04:34 +00:00
}
RowLayout {
Layout.preferredHeight: isMobile ? tableMobile.contentHeight : table.contentHeight
Layout.fillWidth: true
Layout.fillHeight: true
2014-07-16 16:04:34 +00:00
HistoryTable {
id: table
visible: !isMobile
onContentYChanged: flickableScroll.flickableContentYChanged()
model: !isMobile ? mainLayout.model : null
addressBookModel: null
2014-07-16 16:04:34 +00:00
Layout.fillWidth: true
Layout.fillHeight: true
}
2014-07-16 16:04:34 +00:00
HistoryTableMobile {
id: tableMobile
visible: isMobile
onContentYChanged: flickableScroll.flickableContentYChanged()
model: isMobile ? mainLayout.model : null
addressBookModel: null
2014-07-16 16:04:34 +00:00
Layout.fillWidth: true
Layout.fillHeight: true
2016-10-07 20:05:51 +00:00
}
}
2014-07-16 16:04:34 +00:00
}
}
FileDialog {
id: writeCSVFileDialog
title: "Please choose a folder"
selectFolder: true
onRejected: {
console.log("csv write canceled")
}
onAccepted: {
var dataDir = walletManager.urlToLocalPath(writeCSVFileDialog.fileUrl);
var written = currentWallet.history.writeCSV(currentWallet.currentSubaddressAccount, dataDir);
if(written !== ""){
informationPopup.title = qsTr("Success") + translationManager.emptyString;
var text = qsTr("CSV file written to: %1").arg(written) + "\n\n"
text += qsTr("Tip: Use your favorite spreadsheet software to sort on blockheight.") + "\n\n" + translationManager.emptyString;
informationPopup.text = text;
informationPopup.icon = StandardIcon.Information;
} else {
informationPopup.title = qsTr("Error") + translationManager.emptyString;
informationPopup.text = qsTr("Error exporting transaction data.") + "\n\n" + translationManager.emptyString;
informationPopup.icon = StandardIcon.Critical;
}
informationPopup.onCloseCallback = null;
informationPopup.open();
}
Component.onCompleted: {
var _folder = 'file://' + moneroAccountsDir;
try {
_folder = 'file://' + desktopFolder;
}
catch(err) {}
finally {
writeCSVFileDialog.folder = _folder;
}
}
}
function onPageCompleted() {
2017-08-08 09:07:06 +00:00
if(currentWallet != null && typeof currentWallet.history !== "undefined" ) {
currentWallet.history.refresh(currentWallet.currentSubaddressAccount)
2017-08-08 09:07:06 +00:00
table.addressBookModel = currentWallet ? currentWallet.addressBookModel : null
//transactionTypeDropdown.update()
2017-08-08 09:07:06 +00:00
}
priorityDropdown.dataModel = priorityModelV5;
priorityDropdown.currentIndex = 0;
priorityDropdown.update();
}
2018-12-25 00:12:14 +00:00
function update() {
currentWallet.history.refresh(currentWallet.currentSubaddressAccount)
}
2014-07-07 17:08:30 +00:00
}