Skip to content

Commit

Permalink
v0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhitsolutions committed Aug 3, 2022
1 parent 2daaca7 commit 0afa1c4
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 23 deletions.
4 changes: 2 additions & 2 deletions PSWorkItem.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@{
RootModule = 'PSWorkItem.psm1'
ModuleVersion = '0.4.0'
ModuleVersion = '0.5.0'
CompatiblePSEditions = 'Core'
GUID = '4d3ff215-69ea-4fe6-8ad6-97ffc3a15bfb'
Author = 'Jeff Hicks'
Expand Down Expand Up @@ -33,7 +33,7 @@
# ReleaseNotes = ''
# Prerelease = ''
# RequireLicenseAcceptance = $false
ExternalModuleDependencies = @(@{ModuleName="mySQLite";ModuleVersion="0.9.2"})
ExternalModuleDependencies = "MySQLite"
} # End of PSData hashtable

} # End of PrivateData hashtable
Expand Down
38 changes: 23 additions & 15 deletions PSWorkItem.psm1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Get-Childitem $psscriptroot\functions\*.ps1 -recurse |
Foreach-Object {
. $_.FullName
Get-ChildItem $psscriptroot\functions\*.ps1 -Recurse |
ForEach-Object {
. $_.FullName
}

#region class definitions
Expand All @@ -20,7 +20,7 @@ class PSWorkItem {
#this will be last resort GUID to ensure uniqueness
hidden[guid]$TaskID = (New-Guid).Guid

PSWorkItem ([string]$Name,[string]$Category) {
PSWorkItem ([string]$Name, [string]$Category) {
$this.Name = $Name
$this.Category = $Category
}
Expand Down Expand Up @@ -51,28 +51,36 @@ class PSWorkItemDatabase {
}

#Add a dynamic type extension to the PSWorkItem class
Update-TypeData -TypeName PSWorkitem -MemberType ScriptProperty -MemberName OverDue -Value {$this.DueDate -le (Get-Date)} -Force
Update-TypeData -TypeName PSWorkItem -MemberType ScriptProperty -MemberName "TimeRemaining" -Value {New-Timespan -end $this.DueDate -start (Get-Date)} -force
Update-TypeData -TypeName PSWorkItemArchive -MemberType AliasProperty -MemberName "CompletedDate" -Value 'TaskModified' -force
Update-TypeData -TypeName PSWorkitem -MemberType ScriptProperty -MemberName OverDue -Value { $this.DueDate -le (Get-Date) } -Force
Update-TypeData -TypeName PSWorkItem -MemberType ScriptProperty -MemberName "TimeRemaining" -Value { New-TimeSpan -End $this.DueDate -Start (Get-Date) } -Force
Update-TypeData -TypeName PSWorkItemArchive -MemberType AliasProperty -MemberName "CompletedDate" -Value 'TaskModified' -Force

#endregion

#make this variable global instead of exporting so that I don't have to use Export-ModuleMember 7/28/2022 JDH
$global:PSWorkItemPath = Join-Path -path $HOME -childpath "PSWorkItem.db"
$global:PSWorkItemPath = Join-Path -Path $HOME -ChildPath "PSWorkItem.db"


<#
Default categories when creating a new database file.
This will be a module-scoped variable
Default categories when creating a new database file.
This will be a module-scoped variable
#>

$PSWorkItemDefaultCategories = "Work","Personal","Project","Other"
$PSWorkItemDefaultCategories = "Work", "Personal", "Project", "Other"

#a global hashtable used for formatting PSWorkItems
$global:PSWorkItemCategory = @{
"Work" = $PSStyle.Foreground.Cyan
"Personal" = $PSStyle.Foreground.Green
}

Register-ArgumentCompleter -CommandName New-PSWorkItem,Get-PSWorkItem,Set-PSWorkItem,Get-PSWorkItemArchive -ParameterName Category -ScriptBlock {
Register-ArgumentCompleter -CommandName New-PSWorkItem, Get-PSWorkItem, Set-PSWorkItem, Get-PSWorkItemArchive -ParameterName Category -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
#PowerShell code to populate $wordtoComplete
Get-PSWorkItemCategory | Where-Object {$_.category -Like "$wordToComplete*"} |
Select-Object -Property Category,@{Name="Description";Expression={
$_.description -match "\w+" ? $_.description : "no description"}} |
Get-PSWorkItemCategory | Where-Object { $_.category -Like "$wordToComplete*" } |
Select-Object -Property Category, @{Name = "Description"; Expression = {
$_.description -match "\w+" ? $_.description : "no description" }
} |
ForEach-Object {
# completion text,listitem text,result type,Tooltip
[System.Management.Automation.CompletionResult]::new($_.category, $_.category, 'ParameterValue', $_.description)
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,31 @@ If you are running the command in the PowerShell console or VSCode, overdue task

Read the examples for [Get-PSWorkItem](docs/Get-PSWorkItem.md) for other ways to use this command including custom format views.

### PSWorkItemCategory

In addition to formatting overdue and imminent due dates, the module also provides a mechanism to add highlighting of specific categores. Importing the module will create a global variable called `PSWorkItemCategory`. The key will be a category name. The value will be a $PSStyle or ANSI escape sequence. These are the module defaults.

```powershell
$global:PSWorkItemCategory = @{
"Work" = $PSStyle.Foreground.Cyan
"Personal" = $PSStyle.Foreground.Green
}
```

You can modify this hashtable as you would any other hashtable.

```powershell
$PSWorkItemCategory.Add("Event","`e[38;5;153m")
```

The entry will have no effect unless the category is definied in the database.

> Note that when you view the hashtable, you won't see any values because they escape sequences are non-printable.,
![colorized categories](images/psworkitemcategory.png)

Category highlighting is only available in the default view.

## Updating Tasks

Use [Set-PSWorkItem](docs/Set-PSWorkItem.md) or its alias `swi` to update a task based on its ID.
Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog for PSWorkItem

## 0.5.0

+ Fixed module manifest. [Issue #1](https://github.com/jdhitsolutions/PSWorkItem/issues/1)
+ Added a feature to highlight tasks based on category. The module defines a global variable, `$PSWorkItemCategory`, which is a hashtable. The key is the category and the value is the `$PSStyle` or ANSI sequence. The default format view is configured to use these settings.
+ Updated `README.md`.

## 0.4.0

+ Updated `README`.
Expand Down
25 changes: 20 additions & 5 deletions formats/psworkitem.format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ https://github.com/jdhitsolutions/PSScriptTools
"{0}{1}{2}" -f $psstyle.Foreground.brightyellow, $_.name, $psstyle.reset
}
else {
$_.name
<!--use the PSWorkItemCategory hastable to add custom highlights-->
"$($PSWorkItemCategory["$($_.category)"])$($_.name)$($PSStyle.Reset)"
}
}
else {
Expand All @@ -89,7 +90,7 @@ https://github.com/jdhitsolutions/PSScriptTools
"{0}{1}{2}" -f $psstyle.Foreground.brightyellow, $_.Description, $psstyle.reset
}
else {
$_.Description
"$($PSWorkItemCategory["$($_.category)"])$($_.Description)$($PSStyle.Reset)"
}
}
else {
Expand All @@ -108,7 +109,7 @@ https://github.com/jdhitsolutions/PSScriptTools
"{0}{1}{2}" -f $psstyle.Foreground.brightyellow, $_.DueDate, $psstyle.reset
}
else {
$_.DueDate
"$($PSWorkItemCategory["$($_.category)"])$($_.duedate)$($PSStyle.Reset)"
}
}
else {
Expand All @@ -117,10 +118,24 @@ https://github.com/jdhitsolutions/PSScriptTools
</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Category</PropertyName>
<ScriptBlock>
if ($host.name -match "console|code") {
"$($PSWorkItemCategory["$($_.category)"])$($_.category)$($PSStyle.Reset)"
}
else {
$_.category
}
</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Progress</PropertyName>
<ScriptBlock>
if ($host.name -match "console|code") {
"$($PSWorkItemCategory["$($_.category)"])$($_.progress)$($PSStyle.Reset)"
}
else {
$_.progress
}
</ScriptBlock>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
Expand Down
1 change: 0 additions & 1 deletion formats/psworkitemdatabase.format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ https://github.com/jdhitsolutions/PSScriptTools
<Configuration>
<ViewDefinitions>
<View>
<!--Created 07/25/2022 13:54:12 by THINKX1-JH\Jeff-->
<Name>default</Name>
<ViewSelectedBy>
<TypeName>PSWorkItemDatabase</TypeName>
Expand Down
Binary file added images/psworkitemcategory.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 0afa1c4

Please sign in to comment.