fixed some issues and added label and, or capability
This commit is contained in:
@@ -800,6 +800,7 @@ class TxMetaController extends ChangeNotifier {
|
||||
List<BankTransaction> txs,
|
||||
String query, {
|
||||
Set<String> labelIds = const {},
|
||||
LabelMatchMode labelMatch = LabelMatchMode.and,
|
||||
}) {
|
||||
final needle = query.trim().toLowerCase();
|
||||
final hasText = needle.isNotEmpty;
|
||||
@@ -809,7 +810,15 @@ class TxMetaController extends ChangeNotifier {
|
||||
final labelIndex = _labelById;
|
||||
return [
|
||||
for (final tx in txs)
|
||||
if (_matchesSearch(tx, needle, hasText, labelIds, hasLabels, labelIndex))
|
||||
if (_matchesSearch(
|
||||
tx,
|
||||
needle,
|
||||
hasText,
|
||||
labelIds,
|
||||
hasLabels,
|
||||
labelMatch,
|
||||
labelIndex,
|
||||
))
|
||||
tx,
|
||||
];
|
||||
}
|
||||
@@ -820,10 +829,11 @@ class TxMetaController extends ChangeNotifier {
|
||||
bool hasText,
|
||||
Set<String> labelIds,
|
||||
bool hasLabels,
|
||||
LabelMatchMode labelMatch,
|
||||
Map<String, TxLabel> labelIndex,
|
||||
) {
|
||||
final meta = metaFor(tx);
|
||||
if (hasLabels && !_matchesLabelFilter(meta, labelIds)) {
|
||||
if (hasLabels && !_matchesLabelFilter(meta, labelIds, labelMatch)) {
|
||||
return false;
|
||||
}
|
||||
if (!hasText) return true;
|
||||
@@ -838,20 +848,33 @@ class TxMetaController extends ChangeNotifier {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// AND filter: every selected label must be on the tx.
|
||||
/// AND: every selected label must be on the tx.
|
||||
/// OR: at least one selected label (or unlabeled, if that filter is set).
|
||||
///
|
||||
/// Uncategorized alone matches unlabeled txs. Uncategorized combined with
|
||||
/// other labels matches nothing (a tx cannot be both).
|
||||
bool _matchesLabelFilter(TxMeta meta, Set<String> labelIds) {
|
||||
/// Uncategorized alone matches unlabeled txs. Uncategorized + others with
|
||||
/// AND matches nothing; with OR matches unlabeled or any of the labels.
|
||||
bool _matchesLabelFilter(
|
||||
TxMeta meta,
|
||||
Set<String> labelIds,
|
||||
LabelMatchMode mode,
|
||||
) {
|
||||
final wantUncategorized = labelIds.contains(kUncategorizedFilterId);
|
||||
final required = <String>[
|
||||
for (final id in labelIds)
|
||||
if (id != kUncategorizedFilterId) id,
|
||||
];
|
||||
if (wantUncategorized) {
|
||||
if (required.isNotEmpty) return false;
|
||||
return !meta.hasLabel;
|
||||
if (required.isEmpty) {
|
||||
if (wantUncategorized) return !meta.hasLabel;
|
||||
return true;
|
||||
}
|
||||
if (mode == LabelMatchMode.or) {
|
||||
if (wantUncategorized && !meta.hasLabel) return true;
|
||||
for (final id in required) {
|
||||
if (meta.labelIds.contains(id)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (wantUncategorized) return false;
|
||||
for (final id in required) {
|
||||
if (!meta.labelIds.contains(id)) return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user