jdhitsolutions / PSWorkItem

A PowerShell 7 module for managing work and personal tasks or to-do items. This module uses a SQLite database to store task and category information. The module is not a full-featured project management solution, but should be fine for personal needs. The module requires a 64-bit Windows or Linux platform.
MIT License
36 stars 5 forks source link

Storing User Preferences #10

Closed jdhitsolutions closed 1 year ago

jdhitsolutions commented 1 year ago

I am debating ways to store user preferences, like the path, additional categories, and category color schemes. This could be part of the database. But in a shared database situation, some users may have different color preferences. Thinking about storing a JSON file in $HOME that would be used on module import, if found. Would need to add commands to create or update the file. Open to other suggestions that will work cross-platform.

jdhitsolutions commented 1 year ago

One potential drawback to storing preferences in the database is the need to update the database table. On the other hand, separating data from formatting seems like a standard practice.

jdhitsolutions commented 1 year ago

Leaning towards code like this to keep preferences separate from data.

#create a command called Update-PSWorkItemPreferences

$pref = [PSCustomObject]@{
    Path = $PSWorkItemPath
    Categories = $PSWorkItemCategory.GetEnumerator() | ForEach-Object { @{Category = $_.Key;ANSI = $_.value}}
}

$pref | ConvertTo-Json | Out-File C:\temp\pref.json

#on module import, test for preference file and import it if found
$importPref = Get-Content c:\temp\pref.json | ConvertFrom-Json

$PSWorkItemPath = $importPref.Path

$importPref.categories.foreach({$PSWorkItemCategory[$_.category]=$_.ansi})

#otherwise, use defaults or profile-driven settings
jdhitsolutions commented 1 year ago

Version 1.1.0 will introduce a file preferences file stored in $HOME.