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

Commit

Permalink
v1.3.1
Browse files Browse the repository at this point in the history
fixed bug with Show-Task when no entries are found (Issue #16)
Updated README
  • Loading branch information
jdhitsolutions committed Jan 10, 2018
1 parent d11c09d commit 6ac4929
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 70 deletions.
Binary file modified MyTasks.psd1
Binary file not shown.
130 changes: 71 additions & 59 deletions MyTasksFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Class MyTask {
if ($This.completed) {
$this.Overdue = $False
}
elseif ((Get-Date) -gt $this.DueDate) {
elseif ((Get-Date) -gt $this.DueDate) {
$this.Overdue = $True
}
else {
Expand Down Expand Up @@ -128,7 +128,7 @@ Function New-MyTask {
)]
[string]$Name,

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

Expand Down Expand Up @@ -594,40 +594,48 @@ Function Get-MyTask {
"Name" {
if ($Name -match "\w+") {
Write-Verbose "[PROCESS] Retrieving task: $Name"
$tasks.Where( {$_.Name -like $Name})
$results = $tasks.Where( {$_.Name -like $Name})
}
else {
#write all tasks to the pipeline
Write-Verbose "[PROCESS] Retrieving all incomplete tasks"
$tasks.Where( {-Not $_.Completed})
$results = $tasks.Where( {-Not $_.Completed})
}
} #name

"ID" {
Write-Verbose "[PROCESS] Retrieving Task by ID: $ID"
$tasks.where( {$_.id -eq $ID})
$results = $tasks.where( {$_.id -eq $ID})
} #id

"All" {
Write-Verbose "[PROCESS] Retrieving all tasks"
$Tasks
$results = $Tasks
} #all

"Completed" {
Write-Verbose "[PROCESS] Retrieving completed tasks"
$tasks.Where( {$_.Completed})
$results = $tasks.Where( {$_.Completed})
} #completed

"Category" {
Write-Verbose "[PROCESS] Retrieving tasks for category $Category"
$tasks.Where( {$_.Category -eq $Category -AND (-Not $_.Completed)})
$results = $tasks.Where( {$_.Category -eq $Category -AND (-Not $_.Completed)})
} #category

"Days" {
Write-Verbose "[PROCESS] Retrieving tasks due in $DaysDue days or before"
$tasks.Where( {($_.DueDate -le (Get-Date).AddDays($DaysDue)) -AND (-Not $_.Completed)})
$results = $tasks.Where( {($_.DueDate -le (Get-Date).AddDays($DaysDue)) -AND (-Not $_.Completed)})
}
} #switch

#display tasks if found otherwise display a warning
if ($results.count -ge 1) {
$results
}
else {
Write-Warning "No tasks found matching your criteria"
}
} #process

End {
Expand Down Expand Up @@ -697,64 +705,68 @@ Function Show-MyTask {
#run Get-MyTask
Write-Verbose "[PROCESS] Getting Tasks"
$tasks = Get-MyTask @PSBoundParameters
if ($tasks.count -gt 0) {
#convert tasks to a text table
$table = ($tasks | Format-Table -AutoSize | Out-String -Stream).split("`r`n")

#convert tasks to a text table
$table = ($tasks | Format-Table -AutoSize | Out-String -Stream).split("`r`n")
#define a regular expression pattern to match the due date
[regex]$rx = "\b\d{1,2}\/\d{1,2}\/\d{4}\b"

#define a regular expression pattern to match the due date
[regex]$rx = "\b\d{1,2}\/\d{1,2}\/\d{4}\b"
Write-Host "`n"
Write-Host $table[1] -ForegroundColor Cyan
Write-Host $table[2] -ForegroundColor Cyan

Write-Host "`n"
Write-Host $table[1] -ForegroundColor Cyan
Write-Host $table[2] -ForegroundColor Cyan

#define a parameter hashtable to splat to Write-Host to better
#handle colors in the PowerShell ISE under Windows 10
$phash = @{
Object = $Null
}
$table[3..$table.count] | foreach-object {

#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
#define a parameter hashtable to splat to Write-Host to better
#handle colors in the PowerShell ISE under Windows 10
$phash = @{
Object = $Null
}
$table[3..$table.count] | foreach-object {

#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
}
#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 ($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
}
else {
if ($pHash.ContainsKey("foregroundcolor")) {
#remove foreground color so that Write-Host uses
#the current default
$pHash.Remove("foregroundcolor")
#select a different color for overdue tasks
if ($complete) {
#display completed tasks in green
$phash.ForegroundColor = "Green"
}
}
Write-Host @pHash
elseif ($_ -match "\bTrue\b") {
$phash.ForegroundColor = "Red"
}
elseif ($hours -le 24 -AND (-Not $complete)) {
$phash.ForegroundColor = "Yellow"
$hours = 999
}
else {
if ($pHash.ContainsKey("foregroundcolor")) {
#remove foreground color so that Write-Host uses
#the current default
$pHash.Remove("foregroundcolor")
}
}
Write-Host @pHash

} #foreach
} #foreach
} #if tasks are found
else {
Write-Verbose "[PROCESS] No tasks returned from Get-MyTask."
}
} #Process

End {
Expand Down
64 changes: 53 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,43 @@
# MyTasks #
# MyTasks

This PowerShell module is designed as a task or simple To-Do manager. The module contains several commands for working with tasks. It should work with both Windows PowerShell and PowerShell Core. You can install the latest version from the PowerShell Gallery. You will need the -Scope parameter for PowerShell Core.

Install-Module MyTasks [-scope currentuser]
Task data is stored in an XML file in the user's Documents folder. Here are a few highlights.

## Class based ##
## Class based
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 ##
## XML Data
All of the task information is stored in an XML file. The commands in this module will read in, update, and remove items as needed using PowerShell commands such as `Select-XML`.

## 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:

+ Add-MyTaskCategory
+ 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`.
## Basic Usage
You create a task with at least a name and category. The default due date will be 7 days from the current date and time.
```
New-MyTask "return library books" -Category personal
```
You can also specify a due date.
```
New-MyTask "Pluralsight" -duedate "2/1/2018" -description "renew subscription" -category other
```
You can use `Set-MyTask` to modify a task.
```
Get-MyTask Pluralsight | Set-Mytask -DueDate 3/1/2018
```
Because the task has a Progress property, you can use `Set-MyTask` to update that as well.
```
Set-Mytask "book review" -Progress 60
```

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

```
PS S:\> get-mytask -name MemoryTools
Expand All @@ -29,12 +46,37 @@ ID Name Description DueDate OverDue Category Progress
-- ---- ----------- ------- ------- -------- --------
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.
The default behavior is to display incomplete tasks due in the next 30 days. Look at the help for [Get-MyTask](.\docs\Get-MyTask.md) for more information.

There is also a command called `Show-MyTask` which is really nothing more than a wrapper to `Get-MyTask`. The "Show" command 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.


![](./images/show-mytask-1.png)

When a task is finished you can mark it as complete.
```
Complete-MyTask -name "order coffee"
```
The task will remain but be marked as 100% complete. You can still see the task when using the -All parameter with `Get-MyTask` or `Show-MyTask`. At some point you might want to remove completed tasks from the master XML file. You can use `Remove-MyTask` to permanently delete them. Or use the `Archive-MyTask` command to move them to an archive xml file.




## 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`.

![](./images/show-mytask-2.png)

## Archiving and Removing ##
Over time your task file might get quite large. Even though the default behavior is to ignore completed tasks, you have an option to archive them to a separate XML file using `Save-MyTask` or when you run `Complete-MyTask`. Or you can completely delete a task with `Remove-MyTask`.
Over time your task file might get quite large. Even though the default behavior is to ignore completed tasks, you have an option to archive them to a separate XML file using `Save-MyTask` which has an alias of `Archive-MyTask`:

```
Get-Mytask -Completed | Archive-MyTask
```

There is an option to archive tasks when you run `Complete-MyTask`. There are no commands in this module for working with the archived XML file at this time. Or you can completely delete a task with `Remove-MyTask`.

You should read full help and examples for all commands as well as the about_MyTasks help file.
You should read full help and examples for all commands as well as the [about_MyTasks](./docs/about_MyTasks.md) help file.

- [Add-MyTaskCategory](https://github.com/jdhitsolutions/MyTasks/blob/master/docs/Add-MyTaskCategory.md)
- [Backup-MyTaskFile](https://github.com/jdhitsolutions/MyTasks/blob/master/docs/Backup-MyTaskFile.md)
Expand All @@ -52,4 +94,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 9 January 2018*
*last updated 10 January 2018*
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Changelog for MyTasks

v1.3.1
fixed bug with Show-Task when no entries are found (Issue #16)
Updated README

v1.3.0
Updated README
Added 'task' as an alias for New-MyTask
Expand Down
Binary file added images/show-mytask-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/show-mytask-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6ac4929

Please sign in to comment.