Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

Commit

Permalink
v1.3.0
Browse files Browse the repository at this point in the history
Updated README
Added 'task' as an alias for New-MyTask
Added CompletedDate parameter to Complete-MyTask (Issue #13)
Added option to complete a task by ID (Issue #11)
Changed default for Get-MyTask and Show-MyTask to display tasks due in next 30 days. (Issue #12)
fixed bug in Show-Mytask where completed tasks were displaying in red
Made parameters for New-MyTask more positional (Issue #14)
Updated help documentation
  • Loading branch information
jdhitsolutions committed Jan 9, 2018
1 parent f8816aa commit d11c09d
Show file tree
Hide file tree
Showing 20 changed files with 408 additions and 151 deletions.
Binary file modified MyTasks.psd1
Binary file not shown.
18 changes: 10 additions & 8 deletions MyTasks.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,23 @@ $myTaskDefaultCategories = "Work","Personal","Other","Customer"
. $psscriptroot\MyTasksFunctions.ps1

#define some aliases
Set-Alias -Name gmt -Value Get-MyTask
Set-Alias -Name smt -Value Set-MyTask
Set-Alias -Name shmt -Value Show-MyTask
Set-Alias -Name rmt -Value Remove-MyTask
Set-Alias -Name cmt -Value Complete-MyTask
Set-Alias -Name nmt -Value New-MyTask
Set-Alias -Name Archive-MyTask -Value Save-MyTask
$aliases = @()
$aliases+= Set-Alias -Name gmt -Value Get-MyTask -PassThru
$aliases+= Set-Alias -Name smt -Value Set-MyTask -PassThru
$aliases+= Set-Alias -Name shmt -Value Show-MyTask -PassThru
$aliases+= Set-Alias -Name rmt -Value Remove-MyTask -PassThru
$aliases+= Set-Alias -Name cmt -Value Complete-MyTask -PassThru
$aliases+= Set-Alias -Name nmt -Value New-MyTask -PassThru
$aliases+= Set-Alias -name task -value New-MyTask -PassThru
$aliases+= Set-Alias -Name Archive-MyTask -Value Save-MyTask -PassThru

#define a hashtable of parameters to splat to Export-ModuleMember
$exportParams = @{
Variable = "myTaskPath","myTaskDefaultCategories","myTaskArchivePath","mytaskhome"
Function = "New-MyTask","Set-MyTask","Remove-MyTask","Get-MyTask",
"Show-MyTask","Complete-MyTask","Get-MyTaskCategory","Add-MyTaskCategory",
"Remove-MyTaskCategory","Backup-MyTaskFile","Save-MyTask"
Alias = "gmt","rmt","shmt","smt","cmt","nmt","Archive-MyTask"
Alias = $aliases.Name
}

#exported via manifest
Expand Down
61 changes: 45 additions & 16 deletions MyTasksFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ Class MyTask {

#set task as completed

[void]CompleteTask() {
[void]CompleteTask([datetime]$CompletedDate) {
write-verbose "[CLASS ] Completing task: $($this.name)"
$this.Completed = $True
$this.Progress = 100
$this.Overdue = $False
$this.TaskModified = Get-Date
$this.TaskModified = $CompletedDate
}

#check if task is overdue and update
Expand All @@ -41,7 +41,10 @@ Class MyTask {
#only mark as overdue if not completed and today is greater than the due date
Write-Verbose "[CLASS ] Comparing $($this.DueDate) due date to $(Get-Date)"

if (((Get-Date) -gt $this.DueDate) -AND (-Not $this.completed)) {
if ($This.completed) {
$this.Overdue = $False
}
elseif ((Get-Date) -gt $this.DueDate) {
$this.Overdue = $True
}
else {
Expand Down Expand Up @@ -125,7 +128,7 @@ Function New-MyTask {
)]
[string]$Name,

[Parameter(ValueFromPipelineByPropertyName, ParameterSetName = "Date")]
[Parameter(Position = 1,ValueFromPipelineByPropertyName, ParameterSetName = "Date")]
[ValidateNotNullorEmpty()]
[dateTime]$DueDate = (Get-Date).AddDays(7),

Expand All @@ -151,6 +154,7 @@ Function New-MyTask {
$ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
$ParameterAttribute.Mandatory = $true
$ParameterAttribute.ValueFromPipelineByPropertyName = $True
$ParameterAttribute.Position = 2

# Add the attributes to the attributes collection
$AttributeCollection.Add($ParameterAttribute)
Expand Down Expand Up @@ -508,7 +512,7 @@ Function Remove-MyTask {
} #Remove-MyTask

Function Get-MyTask {
[cmdletbinding(DefaultParameterSetName = "Name")]
[cmdletbinding(DefaultParameterSetName = "Days")]

Param(
[Parameter(
Expand All @@ -523,7 +527,7 @@ Function Get-MyTask {
[Parameter(ParameterSetName = "Completed")]
[switch]$Completed,
[Parameter(ParameterSetName = "Days")]
[int]$DaysDue
[int]$DaysDue = 30
)

DynamicParam {
Expand Down Expand Up @@ -637,10 +641,12 @@ Function Show-MyTask {
#colorize output using Write-Host
#this may not work in the PowerShell ISE

[cmdletbinding(DefaultParameterSetName = "none")]
[cmdletbinding(DefaultParameterSetName = "Days")]
Param(
[Parameter(ParameterSetName = "all")]
[switch]$All
[switch]$All,
[Parameter(ParameterSetName = "Days")]
[int32]$DaysDue = 30
)

DynamicParam {
Expand Down Expand Up @@ -689,6 +695,7 @@ Function Show-MyTask {

Process {
#run Get-MyTask
Write-Verbose "[PROCESS] Getting Tasks"
$tasks = Get-MyTask @PSBoundParameters

#convert tasks to a text table
Expand All @@ -710,33 +717,34 @@ Function Show-MyTask {

#add the incoming object as the object for Write-Host
$pHash.object = $_

Write-Verbose "[PROCESS] Analyzing $_ "
#test if DueDate is within 24 hours
if ($rx.IsMatch($_)) {
$hours = (($rx.Match($_).Value -as [datetime]) - (Get-Date)).totalhours
}

#test if task is complete
if ($_ -match '\b100\b$') {
Write-Verbose "[PROCESS] Detected as completed"
$complete = $True

}
else {
Write-Verbose "[PROCESS] Detected as incomplete"
$complete = $False
}

#select a different color for overdue tasks
if ($_ -match "\bTrue\b") {
if ($complete) {
#display completed tasks in green
$phash.ForegroundColor = "Green"
}
elseif ($_ -match "\bTrue\b") {
$phash.ForegroundColor = "Red"
}
elseif ($hours -le 24 -AND (-Not $complete)) {
$phash.ForegroundColor = "Yellow"
$hours = 999
}
elseif ($complete) {
#display completed tasks in green
$phash.ForegroundColor = "Green"
}
else {
if ($pHash.ContainsKey("foregroundcolor")) {
#remove foreground color so that Write-Host uses
Expand Down Expand Up @@ -772,6 +780,15 @@ Function Complete-MyTask {
[ValidateNotNullorEmpty()]
[string]$Name,

[Parameter(
Mandatory,
HelpMessage = "Enter the task ID",
ParameterSetName = "ID"
)]
[int32]$ID,

[datetime]$CompletedDate = $(Get-Date),

[switch]$Archive,

[switch]$Passthru
Expand Down Expand Up @@ -803,11 +820,23 @@ Function Complete-MyTask {
Return
}
}
elseif ($ID) {
#get the task
Try {
Write-Verbose "[PROCESS] Retrieving task ID: $ID"
$Task = Get-MyTask -ID $ID -ErrorAction Stop
}
Catch {
Write-Error $_
#bail out
Return
}
}

If ($Task) {
Write-Verbose "[PROCESS] Marking task as completed"
#invoke CompleteTask() method
$task.CompleteTask()
$task.CompleteTask($CompletedDate)
Write-Verbose "[PROCESS] $($task | Select-Object *,Completed,TaskModified,TaskID | Out-String)"

#find matching XML node and replace it
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This PowerShell module is designed as a task or simple To-Do manager. The module
Task data is stored in an XML file in the user's Documents folder. Here are a few highlights.

## Class based ##
This module requires PowerShell version 5.0 since is uses a class definition for the task object. While you could use the object's properties and methods directly, you should use the appropriate module command.
This module requires at least PowerShell version 5.0 since is uses a class definition for the task object. While you could use the object's properties and methods directly, you should use the appropriate module command.

## Categories ##
The Task object includes a Category property. The module will define a default set of categories, but users can create their own by using the MyTaskCategory commands:
Expand All @@ -16,6 +16,9 @@ The Task object includes a Category property. The module will define a default s
+ Get-MyTaskCategory
+ Remove-MyTaskCategory

## Format Views
The module includes a format.ps1xml file that defines a default display when you run `Get-MyTask`. You will get a slightly different set of properties when you run `Get-MyTask | Format-List`. There is also a custom table view called Category which will create a table grouped by the Category property. You should sort the tasks first: `Get-MyTask | Sort-Object Category | Format-Table -view category`.

## Colorized Output ##
Normally, you will use `Get-MyTask` to display tasks, all, some or a single item:

Expand All @@ -24,7 +27,7 @@ PS S:\> get-mytask -name MemoryTools
ID Name Description DueDate OverDue Category Progress
-- ---- ----------- ------- ------- -------- --------
8 MemoryTools update module ```7/22/2018 False Projects 10
8 MemoryTools update module 7/22/2018 False Projects 10
```
But there is also a command called `Show-MyTask` which will write output directly to the host. Incomplete tasks that are overdue will be displayed in red text. Tasks that will be due in 24 hours will be displayed in yellow. If you select all tasks then completed items will be displayed in green. This command may not work in the PowerShell ISE.

Expand All @@ -49,4 +52,4 @@ You should read full help and examples for all commands as well as the about_MyT
Please post any issues, questions or feature requests in the [Issues](https://github.com/jdhitsolutions/MyTasks/issues) section.


*last updated 3 January 2018*
*last updated 9 January 2018*
29 changes: 13 additions & 16 deletions Tests/MyTasks.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ $theModule = get-module -name mytasks
$theModule.exportedfunctions.count | should be 11
}

It "Should have 7 aliases command" {
$theModule.ExportedAliases.count | should be 7
It "Should have 8 aliases command" {
$theModule.ExportedAliases.count | should be 8
}

It "Should export 3 variables by default" {
$theModule.ExportedVariables.Count | Should be 3
It "Should export 4 variables by default" {
$theModule.ExportedVariables.Count | Should be 4
}

It "Should have a formatting xml file" {
Expand Down Expand Up @@ -74,13 +74,13 @@ Describe Tasks {
#need absolute path for XML files
new-Item -Name Documents -ItemType Directory -path $TestDrive
$home = $TestDrive
$mytaskhome = "$home\Documents"
$mytaskPath = Join-Path $home\Documents -child "myTasks.xml"
$myTaskArchivePath = Join-Path -Path $home\Documents -ChildPath "myTasksArchive.xml"
$myTaskCategory = Join-Path -path $home\Documents -childpath "myTaskCategory.txt"

Add-MyTaskCategory -Category Work,Personal,Other,Training,Testing


It "Should create a new task" {
$a = New-MyTask -Name Test1 -DueDate $Due -Category Testing -Passthru
$a.id | Should be 1
Expand Down Expand Up @@ -144,25 +144,21 @@ Add-MyTaskCategory -Category Work,Personal,Other,Training,Testing
}

It "Should Complete a task" {

{Complete-Mytask -Name Test1 -ErrorAction Stop} | Should Not Throw
(Get-MyTask | Measure-Object).Count | Should be 4
(Get-MyTask -Completed | Measure-Object).Count | Should be 1

}

It "Should complete and archive a task" {

{Complete-Mytask -Name Test2 -Archive -ErrorAction Stop} | Should Not Throw
(Get-MyTask).count | Should be 3
(Get-MyTask -all | where-object {-not $_.completed}).count | Should be 3
}

It "Should archive or save a task" {
$save = Join-path $TestDrive -ChildPath "Archive.xml"
Get-MyTask -Completed | Save-MyTask -Path $save
Test-Path $save | should Be $True
Get-MyTask -Name Test1 | Should Be $null
(Get-MyTask).count | Should be 3
(Get-MyTask -all).count | Should be 3
}

It "Should have an Archive-MyTask alias for Save-MyTask" {
Expand All @@ -172,14 +168,15 @@ Add-MyTaskCategory -Category Work,Personal,Other,Training,Testing
}

It "Should remove a task and backup the task file" {

# Mock Get-Date { return "20171001" } -ParameterFilter {$format -eq "yyyyMMdd"}
{Remove-myTask -Name Alice } | Should not Throw
{Get-MyTask -Name Bob | Remove-MyTask } | should not Throw
(Get-MyTask).count | Should be 1
# dir $TestDrive -Recurse | out-string | write-host
(Get-MyTask -all).count | Should be 1
}

It "Should backup the task file" {
{Backup-MyTaskFile -ErrorAction Stop} | Should Not Throw
#dir $TestDrive -Recurse | out-string | write-host
Test-Path $TestDrive\documents\MyTasks_Backup_*.xml | Should be $True

}

} #describe my tasks
Expand Down
10 changes: 10 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
Changelog for MyTasks

v1.3.0
Updated README
Added 'task' as an alias for New-MyTask
Added CompletedDate parameter to Complete-MyTask (Issue #13)
Added option to complete a task by ID (Issue #11)
Changed default for Get-MyTask and Show-MyTask to display tasks due in next 30 days. (Issue #12)
fixed bug in Show-Mytask where completed tasks were displaying in red
Made parameters for New-MyTask more positional (Issue #14)
Updated help documentation

v1.2.0
Modified files to support PowerShell Core
Update help documentation
Expand Down
9 changes: 5 additions & 4 deletions docs/Add-MyTaskCategory.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
external help file: MyTasks-help.xml
Module Name: MyTasks
online version:
online version:
schema: 2.0.0
---

Expand All @@ -21,14 +21,14 @@ By default the MyTasks module ships with default categories of Work, Personal, C

## EXAMPLES

### -------------------------- EXAMPLE 1 --------------------------
### EXAMPLE 1
```
PS C:\> Add-MyTaskCategory -Category Training
```

Add a Training category.

### -------------------------- EXAMPLE 2 --------------------------
### EXAMPLE 2
```
PS C:\> Add-MyTaskCategory -Category Other,Work,Personal,Team
PS C:\> Get-MyTaskCategory
Expand All @@ -50,7 +50,7 @@ Enter a new task category.
```yaml
Type: String[]
Parameter Sets: (All)
Aliases:
Aliases:

Required: True
Position: 0
Expand Down Expand Up @@ -101,6 +101,7 @@ Learn more about PowerShell:
http://jdhitsolutions.com/blog/essential-powershell-resources/

## RELATED LINKS

[Get-MyTaskCategory]()

[Remove-MyTaskCategory]()
Loading

0 comments on commit d11c09d

Please sign in to comment.