aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2020-01-25 13:31:29 +0100
committerPatrick Spek <p.spek@tyil.nl>2020-01-25 13:31:29 +0100
commit15fad7e951362a2f898ac29b41fb86dc84f2ee87 (patch)
treeef9a72bae8bc2371c905bacab0ccb317ff3eb78e
parent28b441e9879f1cf72f8373588b9da491869b7fee (diff)
downloadApp::GTD-15fad7e951362a2f898ac29b41fb86dc84f2ee87.tar.gz
App::GTD-15fad7e951362a2f898ac29b41fb86dc84f2ee87.tar.bz2
Add gtd label sorting in Clean subcommand
-rw-r--r--META6.json1
-rw-r--r--lib/App/GTD.pm617
-rw-r--r--lib/App/GTD/Bin/Clean.pm62
-rw-r--r--lib/App/GTD/Record.pm620
-rw-r--r--lib/App/GTD/Types.pm629
5 files changed, 68 insertions, 1 deletions
diff --git a/META6.json b/META6.json
index 4d2d634..06680ed 100644
--- a/META6.json
+++ b/META6.json
@@ -31,6 +31,7 @@
"App::GTD::Bin::Trash": "lib/App/GTD/Bin/Trash.pm6",
"App::GTD::GrammarActions": "lib/App/GTD/GrammarActions.pm6",
"App::GTD::Record": "lib/App/GTD/Record.pm6",
+ "App::GTD::Types": "lib/App/GTD/Types.pm6",
"gtd": "bin/gtd"
},
"resources": [
diff --git a/lib/App/GTD.pm6 b/lib/App/GTD.pm6
index 0a0860d..e639bbf 100644
--- a/lib/App/GTD.pm6
+++ b/lib/App/GTD.pm6
@@ -8,6 +8,7 @@ use IO::Path::XDG;
use Terminal::ANSIColor;
use App::GTD::GrammarActions;
+use App::GTD::Types;
unit module App::GTD;
@@ -28,6 +29,22 @@ my Config $config .= new.read: {
},
};
+multi sub cmp (
+ GtdState:D $lhs,
+ GtdState:D $rhs,
+) is export {
+ my %order =
+ GtdState::Inbox => 0,
+ GtdState::Next => 1,
+ GtdState::Someday => 2,
+ ;
+
+ return Order::Same if $lhs eq $rhs;
+ return Order::More if %order{$lhs} > %order{$rhs};
+
+ Order::Less;
+}
+
sub gtd-config-file (
--> IO::Path
) is export {
diff --git a/lib/App/GTD/Bin/Clean.pm6 b/lib/App/GTD/Bin/Clean.pm6
index 52e15ca..1a2dd27 100644
--- a/lib/App/GTD/Bin/Clean.pm6
+++ b/lib/App/GTD/Bin/Clean.pm6
@@ -15,7 +15,7 @@ multi sub MAIN (
my @records = gtd-records-read()
.grep(!*.complete)
- .sort({ .priority eq '', .priority, .creation-date, .description })
+ .sort({ .priority eq '', .priority, .label('gtd'), .creation-date, .description })
;
gtd-records-write(@records);
diff --git a/lib/App/GTD/Record.pm6 b/lib/App/GTD/Record.pm6
index 6ea8f20..de76770 100644
--- a/lib/App/GTD/Record.pm6
+++ b/lib/App/GTD/Record.pm6
@@ -2,6 +2,8 @@
use v6.d;
+use App::GTD::Types;
+
unit class App::GTD::Record;
has Int $.id;
@@ -28,6 +30,24 @@ method projects (
.grep(*.starts-with('@'))
}
+multi method label (
+ Str:D $name,
+ --> Str
+) {
+ %!labels{$name} // ''
+}
+
+multi method label (
+ 'gtd'
+ --> GtdState
+) {
+ given (%!labels<gtd>.fc) {
+ when 'inbox' { GtdState::Inbox }
+ when 'next' { GtdState::Next }
+ when 'someday' { GtdState::Someday }
+ }
+}
+
method Str (
--> Str
) {
diff --git a/lib/App/GTD/Types.pm6 b/lib/App/GTD/Types.pm6
new file mode 100644
index 0000000..c9770a9
--- /dev/null
+++ b/lib/App/GTD/Types.pm6
@@ -0,0 +1,29 @@
+#! /usr/bin/env false
+
+use v6.d;
+
+unit module App::GTD::Types;
+
+enum GtdState is export <
+ Inbox
+ Next
+ Someday
+>;
+
+=begin pod
+
+=NAME App::GTD::Types
+=AUTHOR Patrick Spek <p.spek@tyil.work>
+=VERSION 0.1.0
+
+=head1 Synopsis
+
+=head1 Description
+
+=head1 Examples
+
+=head1 See also
+
+=end pod
+
+# vim: ft=perl6 noet