monero-gui/pages/History.qml

358 lines
12 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 {
2016-10-02 21:03:37 +00:00
id: root
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: 0
GridLayout {
columns: (isMobile)? 1 : 2
Layout.fillWidth: true
columnSpacing: 26 * scaleRatio
2014-07-16 16:04:34 +00:00
RowLayout {
visible: !isMobile
}
2016-10-07 20:05:51 +00:00
RowLayout {
LineEdit {
id: searchLine
fontSize: 14 * scaleRatio
inputHeight: 28 * 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
inputLabel.text: "Date from"
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
inputLabel.text: "Date to"
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
fontBold: true
}
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"
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 {
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
2014-07-16 16:04:34 +00:00
height: 10
color: "#CC000000"
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 ? root.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 ? root.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
}
}
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();
}
2014-07-07 17:08:30 +00:00
}