forked from jdhitsolutions/PSWorkItem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPSWorkItem.psm1
98 lines (84 loc) · 2.71 KB
/
PSWorkItem.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# used for culture debugging
# write-host "Importing with culture $(Get-Culture)"
Get-ChildItem $PSScriptRoot\functions\*.ps1 -Recurse |
ForEach-Object {
. $_.FullName
}
#region class definitions
<#
classes for PSWorkItem and PSWorkItemArchive
#>
#define base PSWorkItem class
class PSWorkItemBase {
[int]$ID
[String]$Name
[String]$Category
[String]$Description
[DateTime]$TaskCreated = (Get-Date)
[DateTime]$TaskModified = (Get-Date)
[boolean]$Completed
[String]$Path
#this will be last resort GUID to ensure uniqueness
hidden[guid]$TaskID = (New-Guid).Guid
}
class PSWorkItem:PSWorkItemBase {
[DateTime]$DueDate = (Get-Date).AddDays(30)
[int]$Progress = 0
PSWorkItem ([String]$Name, [String]$Category) {
$this.Name = $Name
$this.Category = $Category
}
PSWorkItem() {
$this
}
}
Class PSWorkItemArchive:PSWorkItemBase {
[DateTime]$DueDate
[int]$Progress
}
class PSWorkItemCategory {
[String]$Category
[String]$Description
#constructor
PSWorkItemCategory([String]$Category, [String]$Description) {
$this.Category = $Category
$this.Description = $Description
}
}
class PSWorkItemDatabase {
[String]$Path
[DateTime]$Created
[DateTime]$LastModified
[int32]$Size
[int32]$TaskCount
[int32]$CategoryCount
[int32]$ArchiveCount
[String]$Encoding
[int32]$PageCount
[int32]$PageSize
}
#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"
<#
Default categories when creating a new database file.
This will be a module-scoped variable
#>
$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,Remove-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" }
} |
ForEach-Object {
# completion text,ListItem text,result type,Tooltip
[System.Management.Automation.CompletionResult]::new($_.category, $_.category, 'ParameterValue', $_.description)
}
}