aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2016-11-11 12:41:57 +0200
committerRiccardo Spagni <ric@spagni.net>2016-11-11 12:41:57 +0200
commitfc5fba23d6b793eed07cacd1fbf8b2583cd8656c (patch)
treed086ab085b3df264a185f0262681bf4f3e97e3e6
parent52fcc429cb368580b91ab98dba7f9ff2589c0fea (diff)
parent02503e44ee1cdac01f48cbc180abb9b8cfcf0bcd (diff)
downloadmonzero-gui-fc5fba23d6b793eed07cacd1fbf8b2583cd8656c.tar.gz
monzero-gui-fc5fba23d6b793eed07cacd1fbf8b2583cd8656c.tar.xz
monzero-gui-fc5fba23d6b793eed07cacd1fbf8b2583cd8656c.zip
Merge pull request #120
02503e4 History: amount and date filters validation (Ilya Kitaev) 328b7b0 History: amount filter: empty line disables filter (Ilya Kitaev) 69b4d46 DatePicker: 'error' property for indicating invalid input (Ilya Kitaev) ead7ac8 Historty: DoubleValidator applied to "amount filter" fields (Ilya Kitaev)
-rw-r--r--components/DatePicker.qml8
-rw-r--r--pages/History.qml69
2 files changed, 72 insertions, 5 deletions
diff --git a/components/DatePicker.qml b/components/DatePicker.qml
index 9d0cbf20..ac67f8ed 100644
--- a/components/DatePicker.qml
+++ b/components/DatePicker.qml
@@ -35,6 +35,10 @@ Item {
property bool expanded: false
property date currentDate
property bool showCurrentDate: true
+ property color backgroundColor : "#FFFFFF"
+ property color errorColor : "#FFDDDD"
+ property bool error: false
+
height: 37
width: 156
@@ -56,7 +60,6 @@ Item {
Item {
id: head
anchors.fill: parent
-
Rectangle {
anchors.left: parent.left
anchors.right: parent.right
@@ -64,6 +67,7 @@ Item {
//radius: 4
y: 0
color: "#DBDBDB"
+
}
Rectangle {
@@ -74,7 +78,7 @@ Item {
anchors.rightMargin: datePicker.expanded ? 1 : 0
//radius: 4
y: 1
- color: "#FFFFFF"
+ color: datePicker.error ? datePicker.errorColor : datePicker.backgroundColor
}
Item {
diff --git a/pages/History.qml b/pages/History.qml
index e31473ae..ab79084f 100644
--- a/pages/History.qml
+++ b/pages/History.qml
@@ -87,6 +87,20 @@ Rectangle {
}
}
+ function onFilterChanged() {
+ var datesValid = fromDatePicker.currentDate <= toDatePicker.currentDate
+ var amountsValid = amountFromLine.text === "" ? true :
+ amountToLine.text === "" ? true:
+ parseFloat(amountFromLine.text) <= parseFloat(amountToLine.text)
+
+ // reset error state if amount filter valid
+ if (amountsValid) {
+ amountFromLine.error = amountToLine.error = false
+ }
+
+ filterButton.enabled = datesValid && amountsValid
+ }
+
Text {
id: filterHeaderText
@@ -162,6 +176,9 @@ Rectangle {
anchors.rightMargin: 17
anchors.topMargin: 5
placeholderText: qsTr("16 or 64 hexadecimal characters") + translationManager.emptyString
+ validator: RegExpValidator {
+ regExp: /[0-9a-fA-F]+/
+ }
}
@@ -211,6 +228,10 @@ Rectangle {
anchors.leftMargin: 17
anchors.topMargin: 5
z: 2
+ onCurrentDateChanged: {
+ error = currentDate > toDatePicker.currentDate
+ onFilterChanged()
+ }
}
// DateTo picker
@@ -232,8 +253,14 @@ Rectangle {
anchors.leftMargin: 17
anchors.topMargin: 5
z: 2
+ onCurrentDateChanged: {
+ error = currentDate < fromDatePicker.currentDate
+ onFilterChanged()
+ }
}
+
+
StandardButton {
id: filterButton
anchors.bottom: toDatePicker.bottom
@@ -247,15 +274,29 @@ Rectangle {
pressedColor: "#4D0051"
onClicked: {
// Apply filter here;
+
model.paymentIdFilter = paymentIdLine.text
- model.dateFromFilter = fromDatePicker.currentDate
- model.dateToFilter = toDatePicker.currentDate
+
+ if (fromDatePicker.currentDate > toDatePicker.currentDate) {
+ console.error("Invalid date filter set: ", fromDatePicker.currentDate, toDatePicker.currentDate)
+ } else {
+ model.dateFromFilter = fromDatePicker.currentDate
+ model.dateToFilter = toDatePicker.currentDate
+ }
+
if (advancedFilteringCheckBox.checked) {
if (amountFromLine.text.length) {
model.amountFromFilter = parseFloat(amountFromLine.text)
+ } else {
+ // negative value disables filter here;
+ model.amountFromFilter = -1;
}
+
if (amountToLine.text.length) {
model.amountToFilter = parseFloat(amountToLine.text)
+ } else {
+ // negative value disables filter here;
+ model.amountToFilter = -1;
}
var directionFilter = transactionsModel.get(transactionTypeDropdown.currentIndex).value
@@ -264,7 +305,6 @@ Rectangle {
}
selectedAmount.text = getSelectedAmount()
-
}
}
@@ -336,6 +376,17 @@ Rectangle {
anchors.leftMargin: 17
anchors.topMargin: 5
width: 156
+ validator: DoubleValidator {
+ locale: "C"
+ notation: DoubleValidator.StandardNotation
+ bottom: 0
+ }
+ onTextChanged: {
+ // indicating error
+ amountFromLine.error = amountFromLine.text === "" ? false : parseFloat(amountFromLine.text) > parseFloat(amountToLine.text)
+ onFilterChanged()
+ }
+
}
Label {
@@ -357,6 +408,18 @@ Rectangle {
anchors.leftMargin: 17
anchors.topMargin: 5
width: 156
+ validator: DoubleValidator {
+ locale: "C"
+ notation: DoubleValidator.StandardNotation
+ bottom: 0.0
+ }
+
+ onTextChanged: {
+ // indicating error
+ amountToLine.error = amountToLine.text === "" ? false : parseFloat(amountFromLine.text) > parseFloat(amountToLine.text)
+ onFilterChanged()
+ }
+
}
Item {