Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b7e50a955 | ||
|
|
9ea551b600 | ||
|
|
8a7c6fe8d6 | ||
|
|
d8a4dd6190 | ||
|
|
0fdd94d109 | ||
|
|
830f1153fd | ||
|
|
f36561cb7f | ||
|
|
22a0f61cb5 | ||
|
|
941e22c7ff | ||
|
|
c2ee02c209 | ||
|
|
a5edad4aad | ||
|
|
93ea102d89 |
No files matched your search
+1
-1
@@ -18,7 +18,7 @@ indent_size = 4
|
|||||||
tab_width = 4
|
tab_width = 4
|
||||||
|
|
||||||
# New line preferences
|
# New line preferences
|
||||||
insert_final_newline = false
|
insert_final_newline = true
|
||||||
|
|
||||||
#### .NET Coding Conventions ####
|
#### .NET Coding Conventions ####
|
||||||
[*.{cs,vb}]
|
[*.{cs,vb}]
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
name: Build
|
||||||
|
|
||||||
|
# Manual trigger only. There is no push/pull_request trigger on purpose:
|
||||||
|
# the project must not depend on push-triggered CI.
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
# Least privilege: the workflow only reads the repository and uploads artifacts.
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: ${{ matrix.rid }}
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
# One failing RID must not cancel the others.
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- rid: win-x64
|
||||||
|
os: windows-latest
|
||||||
|
- rid: linux-x64
|
||||||
|
os: ubuntu-latest
|
||||||
|
- rid: osx-arm64
|
||||||
|
os: macos-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup .NET
|
||||||
|
uses: actions/setup-dotnet@v4
|
||||||
|
with:
|
||||||
|
dotnet-version: 9.0.x
|
||||||
|
|
||||||
|
- name: Restore
|
||||||
|
run: dotnet restore YKanBan.slnx
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: dotnet build YKanBan.slnx -c Release --no-restore
|
||||||
|
|
||||||
|
# A failing test fails the job, so the publish and upload steps below are
|
||||||
|
# skipped and this RID produces no artifact.
|
||||||
|
- name: Test
|
||||||
|
run: dotnet test YKanBan.slnx -c Release --no-build --no-restore
|
||||||
|
|
||||||
|
- name: Publish
|
||||||
|
run: dotnet publish YKanBan/YKanBan.csproj -c Release -r ${{ matrix.rid }} --self-contained true -o publish/${{ matrix.rid }}
|
||||||
|
|
||||||
|
- name: Upload artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: YKanBan-${{ matrix.rid }}
|
||||||
|
path: publish/${{ matrix.rid }}
|
||||||
|
if-no-files-found: error
|
||||||
@@ -1,5 +1,14 @@
|
|||||||
# YKanBan
|
# YKanBan
|
||||||
|
|
||||||
My personal used local/offline kanban.
|
A personal, local/offline kanban board. Cross-platform desktop app built with Avalonia UI and MVVM. Each workspace stores its data in a `.ykanban` folder at the project root, Git-style.
|
||||||
|
|
||||||
WIP.
|
See [USAGE.md](USAGE.md) for workspaces, backups, the search syntax and command-line usage.
|
||||||
|
|
||||||
|
## Build and test
|
||||||
|
|
||||||
|
```
|
||||||
|
dotnet build YKanBan.slnx
|
||||||
|
dotnet test YKanBan.slnx
|
||||||
|
```
|
||||||
|
|
||||||
|
Packages are pinned in `YKanBan/YKanBan.csproj`.
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
# YKanBan Usage
|
||||||
|
|
||||||
|
YKanBan is a local/offline kanban board. It works like Git in one respect: all data for a managed project lives in a `.ykanban` folder at the project root, so the board travels with the project folder.
|
||||||
|
|
||||||
|
## 1. Workspace
|
||||||
|
|
||||||
|
- A **workspace** is a folder that directly contains a `.ykanban` directory. Only the given folder is checked; parent folders are never searched.
|
||||||
|
- `.ykanban` contains `ykanban.db` (the SQLite database with the board, cards and tags) and `ykanban.lock` (the exclusive lock file).
|
||||||
|
- A workspace is opened by exactly one YKanBan instance at a time. Opening the same workspace a second time shows the lock-conflict page.
|
||||||
|
|
||||||
|
### Command line
|
||||||
|
|
||||||
|
```
|
||||||
|
ykanban <path>
|
||||||
|
```
|
||||||
|
|
||||||
|
- `<path>` is the workspace folder to open.
|
||||||
|
- Starting without arguments, or with invalid arguments, shows the argument error page.
|
||||||
|
- If the path does not exist, the folder-missing page is shown.
|
||||||
|
- If the folder exists but has no `.ykanban`, the not-initialized page is shown with an **Initialize Workspace** button. Initializing creates the database and seeds the preset columns and tags in the current interface language.
|
||||||
|
|
||||||
|
## 2. Do not commit `.ykanban` to Git
|
||||||
|
|
||||||
|
`.ykanban` holds machine-local state and a lock file; it should not be committed. Add it to your **global** gitignore so it is ignored in every repository:
|
||||||
|
|
||||||
|
```
|
||||||
|
# ~/.gitignore_global (or %USERPROFILE%\.gitignore_global on Windows)
|
||||||
|
.ykanban/
|
||||||
|
```
|
||||||
|
|
||||||
|
Then enable the global ignore file once:
|
||||||
|
|
||||||
|
```
|
||||||
|
git config --global core.excludesFile ~/.gitignore_global
|
||||||
|
```
|
||||||
|
|
||||||
|
## 3. Backing up and migrating a workspace
|
||||||
|
|
||||||
|
The database runs in SQLite WAL mode. A workspace is therefore **three files**, not one: `ykanban.db`, `ykanban.db-wal` and `ykanban.db-shm`.
|
||||||
|
|
||||||
|
To back up or move a workspace, copy **all three files together** while YKanBan is closed. Copying only `ykanban.db` can lose the most recent changes.
|
||||||
|
|
||||||
|
## 4. Search syntax
|
||||||
|
|
||||||
|
The board search runs only when you press the search button (or press Enter in the search box); there is no live search. A blank query shows everything. The clear button (×) empties the box and restores the full board.
|
||||||
|
|
||||||
|
Search keywords (`AND`, `OR`) and qualifier keys are fixed English grammar and are **never localized**.
|
||||||
|
|
||||||
|
### 4.1 Grammar
|
||||||
|
|
||||||
|
```
|
||||||
|
query := orExpr
|
||||||
|
orExpr := andExpr ( OR andExpr )*
|
||||||
|
andExpr := operand ( (AND)? operand )* // adjacent terms are an implicit AND
|
||||||
|
operand := atom | '(' orExpr ')'
|
||||||
|
atom := word | phrase | qualifier
|
||||||
|
qualifier := key ':' (word | phrase)
|
||||||
|
key := tag | title | content | id | column
|
||||||
|
phrase := '"' any text '"' // escapes: \" to literal quote and \\ to literal backslash
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4.2 Semantics
|
||||||
|
|
||||||
|
- `AND` (explicit or by adjacency) binds tighter than `OR`; parentheses force grouping.
|
||||||
|
- Only uppercase `AND` / `OR` are operators. Lowercase `and` / `or` are plain words. To search for the literal words `AND` or `OR`, quote them, for example `"AND"`.
|
||||||
|
- A bare word or phrase matches a **substring of the title OR the content**.
|
||||||
|
- `tag:NAME` matches a tag by its **exact** name.
|
||||||
|
- `column:TITLE` matches a column by its **exact** title.
|
||||||
|
- `title:TEXT` matches a substring of the card title, and `content:TEXT` matches a substring of the card content.
|
||||||
|
- `id:N` matches a card by its **exact** numeric id.
|
||||||
|
- All matching is case-insensitive (SQLite ASCII semantics).
|
||||||
|
- Quotes allow values with spaces, for example `tag:"release notes"` or `column:"In Progress"`.
|
||||||
|
- Inside a phrase, `\"` produces a literal quote and `\\` a literal backslash.
|
||||||
|
|
||||||
|
### 4.3 Strict validation
|
||||||
|
|
||||||
|
An invalid expression opens a modal error dialog and **does not run the search**. The error dialog is centered on the parent window; its text is a localized "query expression is invalid" message plus the parser's non-localized English detail. After closing it, the search box keeps what you typed and the board keeps the previous results.
|
||||||
|
|
||||||
|
The following are invalid:
|
||||||
|
|
||||||
|
- unbalanced parentheses, for example `(a` or `a)`;
|
||||||
|
- a dangling operator, for example `bug AND`;
|
||||||
|
- consecutive operators, for example `a AND OR b`;
|
||||||
|
- a qualifier without a value, for example `tag:`;
|
||||||
|
- an unterminated phrase, for example `"abc`;
|
||||||
|
- an invalid escape inside a phrase (a backslash not followed by `"` or `\`), for example `tag:"a\x"`;
|
||||||
|
- an unknown qualifier key. Only `tag`, `title`, `content`, `id` and `column` are valid, and the key is case-sensitive, so `Tag:x` is an error. A word whose colon is not preceded by an identifier (for example `:foo`) is treated as plain text.
|
||||||
|
|
||||||
|
## 5. Export
|
||||||
|
|
||||||
|
The **Export** button writes a human-readable Markdown snapshot of the whole board (columns, cards and the tag table) to a file you choose. The suggested file name and the timestamps in the document follow the current interface language. The export is read-only; there is no import.
|
||||||
@@ -0,0 +1,189 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
using YKanBan.Export;
|
||||||
|
using YKanBan.Models;
|
||||||
|
|
||||||
|
namespace YKanBan.Tests.Export;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests for the Markdown exporter. Mutates the global
|
||||||
|
/// <see cref="Resources.Culture"/>, therefore marked do-not-parallelize.
|
||||||
|
/// Expected documents are assembled from the same ResX template keys as the
|
||||||
|
/// exporter (plus fixed fixture values), so no localized text is hard-coded
|
||||||
|
/// here.
|
||||||
|
/// </summary>
|
||||||
|
[TestClass]
|
||||||
|
[DoNotParallelize]
|
||||||
|
public class MarkdownExporterTests {
|
||||||
|
private static readonly DateTimeOffset ExportedAt = new(2026, 9, 30, 14, 25, 37, TimeSpan.Zero);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Builds a local wall-clock moment, matching the exporter's conversion path.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="year">The year.</param>
|
||||||
|
/// <param name="month">The month.</param>
|
||||||
|
/// <param name="day">The day.</param>
|
||||||
|
/// <param name="hour">The hour.</param>
|
||||||
|
/// <param name="minute">The minute.</param>
|
||||||
|
/// <returns>The local time.</returns>
|
||||||
|
private static DateTimeOffset Local(int year, int month, int day, int hour, int minute) =>
|
||||||
|
new DateTimeOffset(new DateTime(year, month, day, hour, minute, 0)).ToLocalTime();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a local wall-clock time to Unix seconds.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="year">The year.</param>
|
||||||
|
/// <param name="month">The month.</param>
|
||||||
|
/// <param name="day">The day.</param>
|
||||||
|
/// <param name="hour">The hour.</param>
|
||||||
|
/// <param name="minute">The minute.</param>
|
||||||
|
/// <returns>The Unix timestamp.</returns>
|
||||||
|
private static long UnixTimeOf(int year, int month, int day, int hour, int minute) =>
|
||||||
|
Local(year, month, day, hour, minute).ToUnixTimeSeconds();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Builds the board fixture: one working column with two cards, one empty column and two tags.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The columns, cards and tag/usage tuples.</returns>
|
||||||
|
private static (IReadOnlyList<ColumnModel> Columns, IReadOnlyList<CardModel> Cards, IReadOnlyList<(TagModel, long)> Tags) CreateBoard() {
|
||||||
|
long created = UnixTimeOf(2026, 9, 1, 10, 0);
|
||||||
|
long updated = UnixTimeOf(2026, 9, 28, 18, 30);
|
||||||
|
|
||||||
|
var columns = new List<ColumnModel>
|
||||||
|
{
|
||||||
|
new(1, "In Progress", "The work column", 100, 100),
|
||||||
|
new(2, "Empty", string.Empty, 100, 100),
|
||||||
|
};
|
||||||
|
var bug = new TagModel(1, "bug", RgbColor.Parse("#ff0000"), string.Empty);
|
||||||
|
var ui = new TagModel(2, "ui", RgbColor.Parse("#00ff00"), "Interface work");
|
||||||
|
var cards = new List<CardModel>
|
||||||
|
{
|
||||||
|
new(61, 1, "Fix login", "Body text", created, updated, [bug, ui]),
|
||||||
|
new(62, 1, string.Empty, string.Empty, created, updated, []),
|
||||||
|
};
|
||||||
|
var tags = new List<(TagModel, long)> { (bug, 1), (ui, 1) };
|
||||||
|
return (columns, cards, tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Renders the fixture board with the exporter under the current culture.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The produced Markdown document.</returns>
|
||||||
|
private static string ExportBoard() {
|
||||||
|
(IReadOnlyList<ColumnModel> columns, IReadOnlyList<CardModel> cards, IReadOnlyList<(TagModel, long)> tags) = CreateBoard();
|
||||||
|
return MarkdownExporter.Export("MyRepo", columns, cards, tags, ExportedAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Assembles the expected document from the ResX template keys under the current culture.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="culture">The UI culture.</param>
|
||||||
|
/// <returns>The expected Markdown document.</returns>
|
||||||
|
private static string BuildExpected(CultureInfo culture) {
|
||||||
|
string created = Local(2026, 9, 1, 10, 0).ToString(Resources.Export_CardTimePattern, culture);
|
||||||
|
string updated = Local(2026, 9, 28, 18, 30).ToString(Resources.Export_CardTimePattern, culture);
|
||||||
|
|
||||||
|
var builder = new StringBuilder();
|
||||||
|
|
||||||
|
// Header: workspace name and the export timestamp.
|
||||||
|
builder.AppendLine(string.Format(culture, Resources.Export_WorkspaceHeading, "MyRepo"));
|
||||||
|
builder.AppendLine(string.Format(
|
||||||
|
culture, Resources.Export_ExportedAtLine, ExportedAt.ToString(Resources.Export_TimePattern, culture)));
|
||||||
|
builder.AppendLine();
|
||||||
|
|
||||||
|
// First column with its two cards.
|
||||||
|
builder.AppendLine(string.Format(culture, Resources.Export_ColumnHeading, "In Progress", 2));
|
||||||
|
builder.AppendLine("The work column");
|
||||||
|
builder.AppendLine();
|
||||||
|
builder.AppendLine("### #61 Fix login");
|
||||||
|
builder.AppendLine("Body text");
|
||||||
|
builder.AppendLine(string.Format(culture, Resources.Export_TagsLine, "`bug` `ui`"));
|
||||||
|
builder.AppendLine(string.Format(culture, Resources.Export_CreatedModifiedLine, created, updated));
|
||||||
|
builder.AppendLine();
|
||||||
|
builder.AppendLine("### #62");
|
||||||
|
builder.AppendLine(string.Format(culture, Resources.Export_CreatedModifiedLine, created, updated));
|
||||||
|
builder.AppendLine();
|
||||||
|
|
||||||
|
// Empty column is kept.
|
||||||
|
builder.AppendLine(string.Format(culture, Resources.Export_ColumnHeading, "Empty", 0));
|
||||||
|
builder.AppendLine();
|
||||||
|
|
||||||
|
// Tag summary table.
|
||||||
|
builder.AppendLine(Resources.Export_TagsSummaryHeading);
|
||||||
|
builder.AppendLine(Resources.Export_TagsTableHeader);
|
||||||
|
builder.AppendLine("|---|---|---|---|");
|
||||||
|
builder.AppendLine("| bug | #ff0000 | | 1 |");
|
||||||
|
builder.AppendLine("| ui | #00ff00 | Interface work | 1 |");
|
||||||
|
|
||||||
|
return builder.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Normalizes CRLF line endings so expected and actual compare consistently.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">The text to normalize.</param>
|
||||||
|
/// <returns>The text with normalized line endings.</returns>
|
||||||
|
private static string Normalize(string text) => text.Replace("\r\n", "\n");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Asserts that the exporter output matches the resource-built expected document.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="culture">The UI culture to test.</param>
|
||||||
|
private static void AssertOutputMatches(CultureInfo culture) {
|
||||||
|
CultureInfo? original = Resources.Culture;
|
||||||
|
try {
|
||||||
|
Resources.Culture = culture;
|
||||||
|
Assert.AreEqual(Normalize(BuildExpected(culture)), Normalize(ExportBoard()));
|
||||||
|
} finally {
|
||||||
|
Resources.Culture = original;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void EnglishOutputMatchesTemplate() {
|
||||||
|
AssertOutputMatches(new CultureInfo("en"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ChineseOutputMatchesTemplate() {
|
||||||
|
AssertOutputMatches(new CultureInfo("zh-Hans"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void FileNameFollowsLanguage() {
|
||||||
|
CultureInfo? original = Resources.Culture;
|
||||||
|
try {
|
||||||
|
Resources.Culture = new CultureInfo("en");
|
||||||
|
Assert.AreEqual(
|
||||||
|
string.Format(Resources.Culture, Resources.Export_FileNamePattern, "MyRepo", ExportedAt),
|
||||||
|
MarkdownExporter.BuildFileName("MyRepo", ExportedAt));
|
||||||
|
|
||||||
|
Resources.Culture = new CultureInfo("zh-Hans");
|
||||||
|
Assert.AreEqual(
|
||||||
|
string.Format(Resources.Culture, Resources.Export_FileNamePattern, "MyRepo", ExportedAt),
|
||||||
|
MarkdownExporter.BuildFileName("MyRepo", ExportedAt));
|
||||||
|
} finally {
|
||||||
|
Resources.Culture = original;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TagTableCellsEscapePipesAndLineBreaks() {
|
||||||
|
CultureInfo? original = Resources.Culture;
|
||||||
|
try {
|
||||||
|
Resources.Culture = new CultureInfo("en");
|
||||||
|
var tag = new TagModel(1, "a|b", RgbColor.Parse("#112233"), "first\nsecond");
|
||||||
|
string markdown = MarkdownExporter.Export(
|
||||||
|
"W",
|
||||||
|
[new ColumnModel(1, "C", string.Empty, 1, 1)],
|
||||||
|
[],
|
||||||
|
[(tag, 0L)],
|
||||||
|
ExportedAt);
|
||||||
|
|
||||||
|
StringAssert.Contains(markdown, "| a\\|b | #112233 | first second | 0 |");
|
||||||
|
} finally {
|
||||||
|
Resources.Culture = original;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
using YKanBan.Launching;
|
||||||
|
|
||||||
|
namespace YKanBan.Tests.Launching;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests for the <c>ykanban <path></c> command-line contract across its
|
||||||
|
/// three branches: no argument, one valid path, and invalid input.
|
||||||
|
/// </summary>
|
||||||
|
[TestClass]
|
||||||
|
public class LaunchArgumentsTests {
|
||||||
|
[TestMethod]
|
||||||
|
public void NoArgumentsIsRejected() {
|
||||||
|
Assert.IsFalse(LaunchArguments.TryParse([], out string? path));
|
||||||
|
Assert.IsNull(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void BlankArgumentIsRejected() {
|
||||||
|
Assert.IsFalse(LaunchArguments.TryParse([" "], out string? path));
|
||||||
|
Assert.IsNull(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void MoreThanOneArgumentIsRejected() {
|
||||||
|
Assert.IsFalse(LaunchArguments.TryParse(["a", "b"], out string? path));
|
||||||
|
Assert.IsNull(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void SinglePathIsAccepted() {
|
||||||
|
bool parsed = LaunchArguments.TryParse([@"C:\Repo\MyProject"], out string? path);
|
||||||
|
Assert.IsTrue(parsed);
|
||||||
|
Assert.AreEqual(@"C:\Repo\MyProject", path);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
using YKanBan.Models;
|
||||||
|
|
||||||
|
namespace YKanBan.Tests.Models;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests for the RGB color value type: component storage and the text
|
||||||
|
/// boundary in both directions.
|
||||||
|
/// </summary>
|
||||||
|
[TestClass]
|
||||||
|
public class RgbColorTests {
|
||||||
|
[TestMethod]
|
||||||
|
public void ParseSplitsComponents() {
|
||||||
|
RgbColor color = RgbColor.Parse("#102030");
|
||||||
|
Assert.AreEqual((byte)0x10, color.R);
|
||||||
|
Assert.AreEqual((byte)0x20, color.G);
|
||||||
|
Assert.AreEqual((byte)0x30, color.B);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[DataRow("#a1B2c3")]
|
||||||
|
[DataRow("#A1B2C3")]
|
||||||
|
[DataRow("#a1b2c3")]
|
||||||
|
public void ParseIsCaseInsensitive(string text) {
|
||||||
|
Assert.AreEqual(new RgbColor(0xA1, 0xB2, 0xC3), RgbColor.Parse(text));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[DataRow("")]
|
||||||
|
[DataRow("112233")]
|
||||||
|
[DataRow("#11223")]
|
||||||
|
[DataRow("#1122334")]
|
||||||
|
[DataRow("#GGGGGG")]
|
||||||
|
[DataRow("#12345g")]
|
||||||
|
[DataRow(" #112233")]
|
||||||
|
[DataRow("#112233 ")]
|
||||||
|
public void ParseRejectsMalformedText(string text) {
|
||||||
|
Assert.ThrowsExactly<FormatException>(() => RgbColor.Parse(text));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TryParseRejectsNull() {
|
||||||
|
Assert.IsFalse(RgbColor.TryParse(null, out RgbColor color));
|
||||||
|
Assert.AreEqual(default, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TryParseAcceptsValidText() {
|
||||||
|
Assert.IsTrue(RgbColor.TryParse("#010203", out RgbColor color));
|
||||||
|
Assert.AreEqual(new RgbColor(1, 2, 3), color);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ToStringUsesCanonicalLowercase() {
|
||||||
|
Assert.AreEqual("#ff0a00", new RgbColor(0xFF, 0x0A, 0x00).ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TextRoundTrips() {
|
||||||
|
var color = new RgbColor(0x12, 0xAB, 0xCD);
|
||||||
|
Assert.AreEqual(color, RgbColor.Parse(color.ToString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void EqualityComparesComponents() {
|
||||||
|
Assert.AreEqual(new RgbColor(1, 2, 3), new RgbColor(1, 2, 3));
|
||||||
|
Assert.AreNotEqual(new RgbColor(1, 2, 3), new RgbColor(1, 2, 4));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
||||||
|
namespace YKanBan.Tests;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Smoke tests verifying that the test project is correctly wired to the
|
||||||
|
/// application project and that the test runner can discover and execute tests.
|
||||||
|
/// </summary>
|
||||||
|
[TestClass]
|
||||||
|
public class ProjectReferenceTests {
|
||||||
|
/// <summary>
|
||||||
|
/// Verifies that a type defined in the application assembly can be
|
||||||
|
/// referenced from the test project.
|
||||||
|
/// </summary>
|
||||||
|
[TestMethod]
|
||||||
|
public void ApplicationAssemblyIsReferenceable() {
|
||||||
|
Assert.IsNotNull(typeof(App));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
using YKanBan.Search;
|
||||||
|
|
||||||
|
namespace YKanBan.Tests.Search;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Structural comparer for search AST nodes, used by assertions only. The AST
|
||||||
|
/// records compare by reference for their Terms collections by design (see the
|
||||||
|
/// YYC MARK note in SearchNodes.cs), so tests provide equality explicitly.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class SearchNodeComparer : IEqualityComparer<SearchNode> {
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the shared comparer instance.
|
||||||
|
/// </summary>
|
||||||
|
public static SearchNodeComparer Instance { get; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines structural equality of two nodes.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">The first node.</param>
|
||||||
|
/// <param name="y">The second node.</param>
|
||||||
|
/// <returns><see langword="true"/> when the nodes are structurally equal.</returns>
|
||||||
|
public bool Equals(SearchNode? x, SearchNode? y) {
|
||||||
|
if (ReferenceEquals(x, y)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (x is null || y is null || x.GetType() != y.GetType()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (x, y) switch {
|
||||||
|
(SearchNode.Or a, SearchNode.Or b) => SequencesEqual(a.Terms, b.Terms),
|
||||||
|
(SearchNode.And a, SearchNode.And b) => SequencesEqual(a.Terms, b.Terms),
|
||||||
|
(SearchNode.FreeText a, SearchNode.FreeText b) => a.Text == b.Text,
|
||||||
|
(SearchNode.FieldText a, SearchNode.FieldText b) => a.Field == b.Field && a.Text == b.Text,
|
||||||
|
(SearchNode.TagName a, SearchNode.TagName b) => a.Name == b.Name,
|
||||||
|
(SearchNode.ColumnTitle a, SearchNode.ColumnTitle b) => a.Title == b.Title,
|
||||||
|
(SearchNode.CardId a, SearchNode.CardId b) => a.Id == b.Id,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Not supported: the comparer exists for assertions, not hashing.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">The node.</param>
|
||||||
|
/// <returns>Never returns.</returns>
|
||||||
|
public int GetHashCode(SearchNode obj) =>
|
||||||
|
throw new NotSupportedException("Structural comparison for assertions only; hashing is not supported.");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Order-sensitive element-wise comparison.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">The first sequence.</param>
|
||||||
|
/// <param name="y">The second sequence.</param>
|
||||||
|
/// <returns><see langword="true"/> when both sequences match element-wise.</returns>
|
||||||
|
private static bool SequencesEqual(IReadOnlyList<SearchNode> x, IReadOnlyList<SearchNode> y) {
|
||||||
|
if (x.Count != y.Count) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return x.Zip(y).All(pair => Instance.Equals(pair.First, pair.Second));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,253 @@
|
|||||||
|
using YKanBan.Search;
|
||||||
|
|
||||||
|
namespace YKanBan.Tests.Search;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests for the search parser: the full grammar branches plus the strict
|
||||||
|
/// failure behavior (malformed input always throws
|
||||||
|
/// <see cref="SearchSyntaxException"/>).
|
||||||
|
/// </summary>
|
||||||
|
[TestClass]
|
||||||
|
public class SearchQueryParserTests {
|
||||||
|
/// <summary>
|
||||||
|
/// Parses and asserts structural equality against the expected AST.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="expected">The expected AST.</param>
|
||||||
|
/// <param name="text">The search text.</param>
|
||||||
|
private static void AssertParsesTo(SearchNode expected, string text) {
|
||||||
|
SearchNode? parsed = SearchQueryParser.Parse(text);
|
||||||
|
Assert.IsNotNull(parsed, $"Blank-looking input: '{text}'.");
|
||||||
|
Assert.AreEqual(expected, parsed, SearchNodeComparer.Instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Asserts that the input violates the grammar.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">The search text.</param>
|
||||||
|
private static void AssertSyntaxError(string text) {
|
||||||
|
Assert.ThrowsExactly<SearchSyntaxException>(() => SearchQueryParser.Parse(text));
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Successful parses
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void BlankInputReturnsNull() {
|
||||||
|
Assert.IsNull(SearchQueryParser.Parse(string.Empty));
|
||||||
|
Assert.IsNull(SearchQueryParser.Parse(" "));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void SingleWordIsFreeText() {
|
||||||
|
AssertParsesTo(new SearchNode.FreeText("login"), "login");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void AdjacentWordsAreImplicitAnd() {
|
||||||
|
AssertParsesTo(
|
||||||
|
new SearchNode.And([new SearchNode.FreeText("fix"), new SearchNode.FreeText("login")]),
|
||||||
|
"fix login");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ExplicitAndKeyword() {
|
||||||
|
AssertParsesTo(
|
||||||
|
new SearchNode.And([new SearchNode.FreeText("a"), new SearchNode.FreeText("b")]),
|
||||||
|
"a AND b");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void OrKeyword() {
|
||||||
|
AssertParsesTo(
|
||||||
|
new SearchNode.Or([new SearchNode.FreeText("a"), new SearchNode.FreeText("b")]),
|
||||||
|
"a OR b");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ImplicitAndBindsTighterThanOr() {
|
||||||
|
AssertParsesTo(
|
||||||
|
new SearchNode.Or([
|
||||||
|
new SearchNode.And([new SearchNode.FreeText("a"), new SearchNode.FreeText("b")]),
|
||||||
|
new SearchNode.FreeText("c")]),
|
||||||
|
"a b OR c");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ParenthesesForceGrouping() {
|
||||||
|
AssertParsesTo(
|
||||||
|
new SearchNode.And([
|
||||||
|
new SearchNode.FreeText("a"),
|
||||||
|
new SearchNode.Or([new SearchNode.FreeText("b"), new SearchNode.FreeText("c")])]),
|
||||||
|
"a (b OR c)");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void NestedParenthesesCollapse() {
|
||||||
|
AssertParsesTo(
|
||||||
|
new SearchNode.Or([new SearchNode.FreeText("a"), new SearchNode.FreeText("b")]),
|
||||||
|
"((a OR b))");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void LowercaseKeywordsArePlainWords() {
|
||||||
|
AssertParsesTo(
|
||||||
|
new SearchNode.And([
|
||||||
|
new SearchNode.FreeText("a"),
|
||||||
|
new SearchNode.FreeText("and"),
|
||||||
|
new SearchNode.FreeText("or"),
|
||||||
|
new SearchNode.FreeText("b")]),
|
||||||
|
"a and or b");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void PhraseIsFreeText() {
|
||||||
|
AssertParsesTo(new SearchNode.FreeText("hello world"), "\"hello world\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void QuotedOperatorKeywordIsFreeText() {
|
||||||
|
// A quoted AND/OR is literal text, not an operator.
|
||||||
|
AssertParsesTo(new SearchNode.FreeText("AND"), "\"AND\"");
|
||||||
|
AssertParsesTo(
|
||||||
|
new SearchNode.And([new SearchNode.FreeText("a"), new SearchNode.FreeText("OR")]),
|
||||||
|
"a \"OR\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void PhraseSupportsEscapes() {
|
||||||
|
// Escaped quote and escaped backslash.
|
||||||
|
AssertParsesTo(new SearchNode.FreeText("a\"b"), "\"a\\\"b\"");
|
||||||
|
AssertParsesTo(new SearchNode.FreeText("a\\b"), "\"a\\\\b\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TagQualifier() {
|
||||||
|
AssertParsesTo(new SearchNode.TagName("bug"), "tag:bug");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TagQualifierAcceptsPhraseValue() {
|
||||||
|
AssertParsesTo(new SearchNode.TagName("a b"), "tag:\"a b\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void QualifierValueMayContainColons() {
|
||||||
|
AssertParsesTo(new SearchNode.TagName("a:b"), "tag:a:b");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TitleAndContentQualifiers() {
|
||||||
|
AssertParsesTo(new SearchNode.FieldText(SearchField.Title, "foo"), "title:foo");
|
||||||
|
AssertParsesTo(new SearchNode.FieldText(SearchField.Content, "foo"), "content:foo");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ColumnQualifierAcceptsPhraseValue() {
|
||||||
|
AssertParsesTo(new SearchNode.ColumnTitle("To Do"), "column:\"To Do\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void IdQualifierParsesNumber() {
|
||||||
|
AssertParsesTo(new SearchNode.CardId(42), "id:42");
|
||||||
|
AssertParsesTo(new SearchNode.CardId(12), "id:\"12\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ColonWithoutKeyPrefixIsFreeText() {
|
||||||
|
AssertParsesTo(new SearchNode.FreeText(":foo"), ":foo");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Strict failures
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void UnterminatedPhraseIsAnError() {
|
||||||
|
AssertSyntaxError("\"abc def");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TrailingUnterminatedPhraseIsAnError() {
|
||||||
|
AssertSyntaxError("a \"abc");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void InvalidEscapeInPhraseIsAnError() {
|
||||||
|
// A bare backslash (not followed by a quote or another backslash) is invalid.
|
||||||
|
AssertSyntaxError("\"a\\b\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void InvalidEscapeInQualifierPhraseIsAnError() {
|
||||||
|
AssertSyntaxError("tag:\"a\\x\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void UnbalancedOpenParenIsAnError() {
|
||||||
|
AssertSyntaxError("(a");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void StrayCloseParenIsAnError() {
|
||||||
|
AssertSyntaxError("a)");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void EmptyParensAreAnError() {
|
||||||
|
AssertSyntaxError("()");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void DanglingOrIsAnError() {
|
||||||
|
AssertSyntaxError("a OR");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void DanglingAndIsAnError() {
|
||||||
|
AssertSyntaxError("a AND");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void LeadingAndIsAnError() {
|
||||||
|
AssertSyntaxError("AND a");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void OperatorAtOperandPositionIsAnError() {
|
||||||
|
AssertSyntaxError("a AND OR b");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void QualifierWithoutValueIsAnError() {
|
||||||
|
AssertSyntaxError("tag:");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void SpacedQualifierValueIsAnError() {
|
||||||
|
AssertSyntaxError("tag: bug");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void NonNumericIdIsAnError() {
|
||||||
|
AssertSyntaxError("id:12x");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void UnknownQualifierKeyIsAnError() {
|
||||||
|
AssertSyntaxError("foo:bar");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void QualifierKeysAreCaseSensitive() {
|
||||||
|
// "Tag" is a key-like prefix but not the known lowercase "tag", so it is unknown.
|
||||||
|
AssertSyntaxError("Tag:x");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void SyntaxErrorCarriesDescriptiveMessage() {
|
||||||
|
SearchSyntaxException exception = Assert.ThrowsExactly<SearchSyntaxException>(
|
||||||
|
() => SearchQueryParser.Parse("a AND"));
|
||||||
|
Assert.IsFalse(string.IsNullOrEmpty(exception.Message));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
|
||||||
|
using YKanBan.Search;
|
||||||
|
using YKanBan.Storage.Workspace;
|
||||||
|
using YKanBan.Tests.TestUtilities;
|
||||||
|
|
||||||
|
namespace YKanBan.Tests.Search;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests for the query-to-SQL compiler, executed end-to-end against a fixture
|
||||||
|
/// workspace database.
|
||||||
|
/// </summary>
|
||||||
|
[TestClass]
|
||||||
|
public class SearchSqlCompilerTests {
|
||||||
|
/// <summary>
|
||||||
|
/// Owns a workspace with a fixed card/tag fixture.
|
||||||
|
/// </summary>
|
||||||
|
private sealed class SearchFixture : IDisposable {
|
||||||
|
public TempDirectory Directory { get; } = new();
|
||||||
|
|
||||||
|
public SqliteConnection Connection { get; }
|
||||||
|
|
||||||
|
public SearchFixture() {
|
||||||
|
WorkspaceInitializer.Initialize(Directory.FullPath);
|
||||||
|
using (SqliteConnection setup = SqliteTestHelper.OpenWorkspace(Directory.FullPath)) {
|
||||||
|
// Columns: 1 "To Do", 2 "In Progress".
|
||||||
|
SqliteTestHelper.Exec(setup, "INSERT INTO columns (title, description, created_at, updated_at) VALUES ('To Do', '', 1, 1);");
|
||||||
|
SqliteTestHelper.Exec(setup, "INSERT INTO columns (title, description, created_at, updated_at) VALUES ('In Progress', '', 1, 1);");
|
||||||
|
|
||||||
|
// Cards: 1 titled, 2 title-or-content matches, 3 untitled, 4 wildcard chars.
|
||||||
|
SqliteTestHelper.Exec(setup, "INSERT INTO cards (column_id, title, content, created_at, updated_at) VALUES (1, 'Fix login', 'Cannot sign in', 1, 1);");
|
||||||
|
SqliteTestHelper.Exec(setup, "INSERT INTO cards (column_id, title, content, created_at, updated_at) VALUES (2, 'Green apple', 'the apple pie', 1, 1);");
|
||||||
|
SqliteTestHelper.Exec(setup, "INSERT INTO cards (column_id, title, content, created_at, updated_at) VALUES (2, '', 'banana split', 1, 1);");
|
||||||
|
SqliteTestHelper.Exec(setup, "INSERT INTO cards (column_id, title, content, created_at, updated_at) VALUES (1, '100% done', 'a_b test', 1, 1);");
|
||||||
|
|
||||||
|
// Tags: mixed case names plus one containing spaces.
|
||||||
|
SqliteTestHelper.Exec(setup, "INSERT INTO tags (name, color, description) VALUES ('Bug', '#ff0000', '');");
|
||||||
|
SqliteTestHelper.Exec(setup, "INSERT INTO tags (name, color, description) VALUES ('UI', '#00ff00', '');");
|
||||||
|
SqliteTestHelper.Exec(setup, "INSERT INTO tags (name, color, description) VALUES ('release notes', '#0000ff', '');");
|
||||||
|
SqliteTestHelper.Exec(setup, "INSERT INTO card_tags (card_id, tag_id) VALUES (1, 1);");
|
||||||
|
SqliteTestHelper.Exec(setup, "INSERT INTO card_tags (card_id, tag_id) VALUES (2, 2);");
|
||||||
|
SqliteTestHelper.Exec(setup, "INSERT INTO card_tags (card_id, tag_id) VALUES (3, 2);");
|
||||||
|
SqliteTestHelper.Exec(setup, "INSERT INTO card_tags (card_id, tag_id) VALUES (4, 3);");
|
||||||
|
}
|
||||||
|
|
||||||
|
Connection = SqliteTestHelper.OpenWorkspace(Directory.FullPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Runs a query and returns the ids of the matching cards.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="queryText">The search text.</param>
|
||||||
|
/// <returns>The matching card ids in id order.</returns>
|
||||||
|
public List<long> Search(string queryText) {
|
||||||
|
SearchNode? query = SearchQueryParser.Parse(queryText);
|
||||||
|
Assert.IsNotNull(query, "Blank fixture queries are not expected here.");
|
||||||
|
CompiledSearch compiled = SearchSqlCompiler.Compile(query);
|
||||||
|
|
||||||
|
using var command = Connection.CreateCommand();
|
||||||
|
command.CommandText = $"SELECT c.id FROM cards c WHERE {compiled.Predicate} ORDER BY c.id ASC;";
|
||||||
|
foreach ((string name, object value) in compiled.Parameters) {
|
||||||
|
command.Parameters.AddWithValue(name, value);
|
||||||
|
}
|
||||||
|
using var reader = command.ExecuteReader();
|
||||||
|
|
||||||
|
var ids = new List<long>();
|
||||||
|
while (reader.Read()) {
|
||||||
|
ids.Add(reader.GetInt64(0));
|
||||||
|
}
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose() {
|
||||||
|
Connection.Dispose();
|
||||||
|
Directory.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void FreeTextMatchesTitleOrContentCaseInsensitively() {
|
||||||
|
using var fixture = new SearchFixture();
|
||||||
|
CollectionAssert.AreEqual(new[] { 2L }, fixture.Search("apple"));
|
||||||
|
CollectionAssert.AreEqual(new[] { 1L }, fixture.Search("login"));
|
||||||
|
CollectionAssert.AreEqual(new[] { 2L }, fixture.Search("APPLE"));
|
||||||
|
CollectionAssert.AreEqual(new[] { 2L }, fixture.Search("pie"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void FieldQualifiersScopeToTheirField() {
|
||||||
|
using var fixture = new SearchFixture();
|
||||||
|
CollectionAssert.AreEqual(new[] { 2L }, fixture.Search("title:apple"));
|
||||||
|
CollectionAssert.AreEqual(new[] { 3L }, fixture.Search("content:banana"));
|
||||||
|
Assert.AreEqual(0, fixture.Search("title:pie").Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TagQualifierMatchesExactlyAndCaseInsensitively() {
|
||||||
|
using var fixture = new SearchFixture();
|
||||||
|
CollectionAssert.AreEqual(new[] { 1L }, fixture.Search("tag:bug"));
|
||||||
|
CollectionAssert.AreEqual(new[] { 2L, 3L }, fixture.Search("tag:ui"));
|
||||||
|
CollectionAssert.AreEqual(new[] { 4L }, fixture.Search("tag:\"release notes\""));
|
||||||
|
|
||||||
|
// Exact match: prefixes and substrings do not hit.
|
||||||
|
Assert.AreEqual(0, fixture.Search("tag:bu").Count);
|
||||||
|
Assert.AreEqual(0, fixture.Search("tag:release").Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ColumnQualifierMatchesColumnTitleExactly() {
|
||||||
|
using var fixture = new SearchFixture();
|
||||||
|
CollectionAssert.AreEqual(new[] { 1L, 4L }, fixture.Search("column:\"to do\""));
|
||||||
|
CollectionAssert.AreEqual(new[] { 2L, 3L }, fixture.Search("column:\"in progress\""));
|
||||||
|
|
||||||
|
// Not a prefix or substring match.
|
||||||
|
Assert.AreEqual(0, fixture.Search("column:To").Count);
|
||||||
|
Assert.AreEqual(0, fixture.Search("column:progress").Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void IdQualifierMatchesExactly() {
|
||||||
|
using var fixture = new SearchFixture();
|
||||||
|
CollectionAssert.AreEqual(new[] { 3L }, fixture.Search("id:3"));
|
||||||
|
Assert.AreEqual(0, fixture.Search("id:99").Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void AndOrCombination() {
|
||||||
|
using var fixture = new SearchFixture();
|
||||||
|
CollectionAssert.AreEqual(new[] { 2L, 3L }, fixture.Search("apple OR banana"));
|
||||||
|
CollectionAssert.AreEqual(new[] { 2L }, fixture.Search("apple AND id:2"));
|
||||||
|
Assert.AreEqual(0, fixture.Search("apple AND id:1").Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ParenthesizedGrouping() {
|
||||||
|
using var fixture = new SearchFixture();
|
||||||
|
|
||||||
|
// (apple OR banana) hits cards 2,3; intersected with column "In Progress" (2,3).
|
||||||
|
CollectionAssert.AreEqual(new[] { 2L, 3L }, fixture.Search("(apple OR banana) AND column:\"In Progress\""));
|
||||||
|
|
||||||
|
// ...while column "To Do" holds cards 1,4 — the intersection is empty.
|
||||||
|
Assert.AreEqual(0, fixture.Search("(apple OR banana) AND column:\"To Do\"").Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void LikeWildcardsInUserTextMatchLiterally() {
|
||||||
|
using var fixture = new SearchFixture();
|
||||||
|
CollectionAssert.AreEqual(new[] { 4L }, fixture.Search("100%"));
|
||||||
|
CollectionAssert.AreEqual(new[] { 4L }, fixture.Search("a_b"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void CompiledPredicateUsesNamedParameters() {
|
||||||
|
CompiledSearch compiled = SearchSqlCompiler.Compile(new SearchNode.FreeText("x"));
|
||||||
|
|
||||||
|
StringAssert.Contains(compiled.Predicate, "$p0");
|
||||||
|
StringAssert.Contains(compiled.Predicate, "$p1");
|
||||||
|
Assert.AreEqual(2, compiled.Parameters.Count);
|
||||||
|
Assert.AreEqual("%x%", compiled.Parameters[0].Value);
|
||||||
|
Assert.AreEqual("%x%", compiled.Parameters[1].Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,166 @@
|
|||||||
|
using YKanBan.Storage.AppData;
|
||||||
|
using YKanBan.Tests.TestUtilities;
|
||||||
|
|
||||||
|
namespace YKanBan.Tests.Storage.AppData;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests for app.json round-tripping, kebab-case naming and graceful
|
||||||
|
/// degradation on a missing or corrupt file.
|
||||||
|
/// </summary>
|
||||||
|
[TestClass]
|
||||||
|
public class AppConfigStoreTests {
|
||||||
|
[TestMethod]
|
||||||
|
public void LoadMissingFileReturnsDefaults() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
var store = new AppConfigStore(Path.Combine(directory.FullPath, "app.json"));
|
||||||
|
|
||||||
|
AppConfig config = store.Load();
|
||||||
|
|
||||||
|
Assert.AreEqual(AppConfig.CurrentFormatVersion, config.Version);
|
||||||
|
Assert.AreEqual(AppConfig.DefaultLanguage, config.Language);
|
||||||
|
Assert.AreEqual(ThemeOption.FollowSystem, config.Theme);
|
||||||
|
Assert.AreEqual(SortOption.IdAscending, config.Display.CardSort);
|
||||||
|
Assert.AreEqual(SortOption.IdAscending, config.Display.ColumnSort);
|
||||||
|
Assert.AreEqual(ColumnWidthPreset.Standard, config.Display.ColumnWidth.Preset);
|
||||||
|
Assert.AreEqual(320, config.Display.ColumnWidth.CustomPixels);
|
||||||
|
Assert.IsTrue(config.Confirmations.DeleteCard);
|
||||||
|
Assert.IsTrue(config.Confirmations.DeleteColumn);
|
||||||
|
Assert.IsTrue(config.Confirmations.DeleteTag);
|
||||||
|
Assert.IsTrue(config.Confirmations.DiscardEdit);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void LoadCorruptFileBacksUpAndReturnsDefaults() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
string path = Path.Combine(directory.FullPath, "app.json");
|
||||||
|
File.WriteAllText(path, "{ this is not valid json");
|
||||||
|
var store = new AppConfigStore(path);
|
||||||
|
|
||||||
|
AppConfig config = store.Load();
|
||||||
|
|
||||||
|
Assert.AreEqual(AppConfig.CurrentFormatVersion, config.Version);
|
||||||
|
Assert.IsTrue(File.Exists(path + ".bak"));
|
||||||
|
Assert.AreEqual("{ this is not valid json", File.ReadAllText(path + ".bak"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void LoadJsonNullReturnsDefaults() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
string path = Path.Combine(directory.FullPath, "app.json");
|
||||||
|
File.WriteAllText(path, "null");
|
||||||
|
var store = new AppConfigStore(path);
|
||||||
|
|
||||||
|
Assert.AreEqual(AppConfig.CurrentFormatVersion, store.Load().Version);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void LoadReadsKebabCaseKeysAndEnumValues() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
string path = Path.Combine(directory.FullPath, "app.json");
|
||||||
|
File.WriteAllText(path, $$"""
|
||||||
|
{
|
||||||
|
"version": {{AppConfig.CurrentFormatVersion}},
|
||||||
|
"language": "zh-Hans",
|
||||||
|
"theme": "dark",
|
||||||
|
"display": {
|
||||||
|
"column-width": { "preset": "custom", "custom-pixels": 400 },
|
||||||
|
"card-sort": "title-asc",
|
||||||
|
"column-sort": "id-desc"
|
||||||
|
},
|
||||||
|
"confirmations": {
|
||||||
|
"delete-card": false,
|
||||||
|
"delete-column": false,
|
||||||
|
"delete-tag": false,
|
||||||
|
"discard-edit": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""");
|
||||||
|
var store = new AppConfigStore(path);
|
||||||
|
|
||||||
|
AppConfig config = store.Load();
|
||||||
|
|
||||||
|
Assert.AreEqual("zh-Hans", config.Language);
|
||||||
|
Assert.AreEqual(ThemeOption.Dark, config.Theme);
|
||||||
|
Assert.AreEqual(SortOption.TitleAscending, config.Display.CardSort);
|
||||||
|
Assert.AreEqual(SortOption.IdDescending, config.Display.ColumnSort);
|
||||||
|
Assert.AreEqual(ColumnWidthPreset.Custom, config.Display.ColumnWidth.Preset);
|
||||||
|
Assert.AreEqual(400, config.Display.ColumnWidth.CustomPixels);
|
||||||
|
Assert.IsFalse(config.Confirmations.DeleteCard);
|
||||||
|
Assert.IsFalse(config.Confirmations.DeleteColumn);
|
||||||
|
Assert.IsFalse(config.Confirmations.DeleteTag);
|
||||||
|
Assert.IsFalse(config.Confirmations.DiscardEdit);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void LoadMissingSectionsFillsDefaults() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
string path = Path.Combine(directory.FullPath, "app.json");
|
||||||
|
File.WriteAllText(path, $$"""{ "version": {{AppConfig.CurrentFormatVersion}} }""");
|
||||||
|
var store = new AppConfigStore(path);
|
||||||
|
|
||||||
|
AppConfig config = store.Load();
|
||||||
|
|
||||||
|
Assert.IsNotNull(config.Display);
|
||||||
|
Assert.IsNotNull(config.Display.ColumnWidth);
|
||||||
|
Assert.IsNotNull(config.Confirmations);
|
||||||
|
Assert.AreEqual(ColumnWidthPreset.Standard, config.Display.ColumnWidth.Preset);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void SaveWritesKebabCaseKeysAndEnumValues() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
string path = Path.Combine(directory.FullPath, "app.json");
|
||||||
|
var store = new AppConfigStore(path);
|
||||||
|
|
||||||
|
var config = new AppConfig {
|
||||||
|
Theme = ThemeOption.FollowSystem,
|
||||||
|
Display = new DisplaySettings {
|
||||||
|
CardSort = SortOption.UpdatedDescending,
|
||||||
|
ColumnSort = SortOption.CreatedAscending,
|
||||||
|
ColumnWidth = new ColumnWidthSettings { Preset = ColumnWidthPreset.Custom, CustomPixels = 500 },
|
||||||
|
},
|
||||||
|
Confirmations = new ConfirmationSettings { DeleteColumn = false },
|
||||||
|
};
|
||||||
|
store.Save(config);
|
||||||
|
|
||||||
|
string json = File.ReadAllText(path);
|
||||||
|
StringAssert.Contains(json, "\"delete-column\"");
|
||||||
|
StringAssert.Contains(json, "\"discard-edit\"");
|
||||||
|
StringAssert.Contains(json, "\"card-sort\"");
|
||||||
|
StringAssert.Contains(json, "\"column-sort\"");
|
||||||
|
StringAssert.Contains(json, "\"custom-pixels\"");
|
||||||
|
StringAssert.Contains(json, "\"follow-system\"");
|
||||||
|
StringAssert.Contains(json, "\"updated-desc\"");
|
||||||
|
StringAssert.Contains(json, "\"created-asc\"");
|
||||||
|
// No member-name CamelCase must leak into the file.
|
||||||
|
Assert.IsFalse(json.Contains("deleteColumn", StringComparison.Ordinal));
|
||||||
|
Assert.IsFalse(json.Contains("CustomPixels", StringComparison.Ordinal));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void SaveThenLoadRoundTrips() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
string path = Path.Combine(directory.FullPath, "app.json");
|
||||||
|
var store = new AppConfigStore(path);
|
||||||
|
|
||||||
|
var config = new AppConfig {
|
||||||
|
Language = "zh-Hans",
|
||||||
|
Theme = ThemeOption.Light,
|
||||||
|
Display = new DisplaySettings {
|
||||||
|
CardSort = SortOption.CreatedDescending,
|
||||||
|
ColumnSort = SortOption.TitleAscending,
|
||||||
|
ColumnWidth = new ColumnWidthSettings { Preset = ColumnWidthPreset.Wide },
|
||||||
|
},
|
||||||
|
Confirmations = new ConfirmationSettings { DiscardEdit = false },
|
||||||
|
};
|
||||||
|
store.Save(config);
|
||||||
|
|
||||||
|
AppConfig reloaded = store.Load();
|
||||||
|
Assert.AreEqual(config.Language, reloaded.Language);
|
||||||
|
Assert.AreEqual(config.Theme, reloaded.Theme);
|
||||||
|
Assert.AreEqual(config.Display.CardSort, reloaded.Display.CardSort);
|
||||||
|
Assert.AreEqual(config.Display.ColumnSort, reloaded.Display.ColumnSort);
|
||||||
|
Assert.AreEqual(config.Display.ColumnWidth.Preset, reloaded.Display.ColumnWidth.Preset);
|
||||||
|
Assert.AreEqual(config.Confirmations.DiscardEdit, reloaded.Confirmations.DiscardEdit);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
|
||||||
|
using YKanBan.Storage;
|
||||||
|
using YKanBan.Storage.Workspace;
|
||||||
|
using YKanBan.Tests.TestUtilities;
|
||||||
|
|
||||||
|
namespace YKanBan.Tests.Storage;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests for the shared SQLite plumbing: mandatory PRAGMAs and the
|
||||||
|
/// user_version-driven migration runner.
|
||||||
|
/// </summary>
|
||||||
|
[TestClass]
|
||||||
|
public class SqliteDatabaseTests {
|
||||||
|
[TestMethod]
|
||||||
|
public void OpenAppliesMandatoryPragmas() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
string databasePath = Path.Combine(directory.FullPath, "pragmas.db");
|
||||||
|
|
||||||
|
using SqliteConnection connection = SqliteDatabase.Open(databasePath, []);
|
||||||
|
Assert.AreEqual("wal", SqliteTestHelper.ScalarString(connection, "PRAGMA journal_mode;"));
|
||||||
|
Assert.AreEqual(1L, SqliteTestHelper.ScalarLong(connection, "PRAGMA synchronous;"));
|
||||||
|
Assert.AreEqual(1L, SqliteTestHelper.ScalarLong(connection, "PRAGMA foreign_keys;"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void OpenSetsUserVersionToLatestMigration() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
string databasePath = Path.Combine(directory.FullPath, "version.db");
|
||||||
|
|
||||||
|
using SqliteConnection connection = SqliteDatabase.Open(databasePath, WorkspaceSchema.Migrations);
|
||||||
|
Assert.AreEqual(WorkspaceSchema.CurrentVersion, SqliteDatabase.ReadUserVersion(connection));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ReopenKeepsWalJournalMode() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
string databasePath = Path.Combine(directory.FullPath, "wal.db");
|
||||||
|
|
||||||
|
using (SqliteConnection connection = SqliteDatabase.Open(databasePath, WorkspaceSchema.Migrations)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// WAL mode is stored in the database header, so a fresh connection keeps it.
|
||||||
|
using SqliteConnection reopened = SqliteDatabase.Open(databasePath, WorkspaceSchema.Migrations);
|
||||||
|
Assert.AreEqual("wal", SqliteTestHelper.ScalarString(reopened, "PRAGMA journal_mode;"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void OpenRejectsNewerStoredSchemaVersion() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
string databasePath = Path.Combine(directory.FullPath, "newer.db");
|
||||||
|
|
||||||
|
long newerVersion = WorkspaceSchema.CurrentVersion + 1;
|
||||||
|
using (SqliteConnection connection = SqliteDatabase.Open(databasePath, WorkspaceSchema.Migrations)) {
|
||||||
|
SqliteTestHelper.Exec(connection, $"PRAGMA user_version={newerVersion};");
|
||||||
|
}
|
||||||
|
|
||||||
|
SchemaVersionException exception = Assert.ThrowsExactly<SchemaVersionException>(
|
||||||
|
() => SqliteDatabase.Open(databasePath, WorkspaceSchema.Migrations));
|
||||||
|
Assert.AreEqual(newerVersion, exception.StoredVersion);
|
||||||
|
Assert.AreEqual(WorkspaceSchema.CurrentVersion, exception.SupportedVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void OpenRejectsNonContiguousMigrationList() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
string databasePath = Path.Combine(directory.FullPath, "gap.db");
|
||||||
|
|
||||||
|
SchemaMigration[] broken =
|
||||||
|
[
|
||||||
|
new SchemaMigration(2, "starts too high", "SELECT 1;"),
|
||||||
|
];
|
||||||
|
|
||||||
|
Assert.ThrowsExactly<ArgumentException>(() => SqliteDatabase.Open(databasePath, broken));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
|
||||||
|
using YKanBan.Storage;
|
||||||
|
using YKanBan.Storage.Workspace;
|
||||||
|
using YKanBan.Tests.TestUtilities;
|
||||||
|
|
||||||
|
namespace YKanBan.Tests.Storage.Workspace;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests for workspace detection and initialization. Initialization creates
|
||||||
|
/// the structure and an empty migrated database, but deliberately adds no
|
||||||
|
/// content.
|
||||||
|
/// </summary>
|
||||||
|
[TestClass]
|
||||||
|
public class WorkspaceInitializerTests {
|
||||||
|
[TestMethod]
|
||||||
|
public void IsWorkspaceReflectsInitializationState() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
Assert.IsFalse(WorkspaceInitializer.IsWorkspace(directory.FullPath));
|
||||||
|
|
||||||
|
WorkspaceInitializer.Initialize(directory.FullPath);
|
||||||
|
Assert.IsTrue(WorkspaceInitializer.IsWorkspace(directory.FullPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void InitializeCreatesStructureAndMigratedEmptyDatabase() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
WorkspaceInitializer.Initialize(directory.FullPath);
|
||||||
|
|
||||||
|
Assert.IsTrue(Directory.Exists(WorkspacePaths.Root(directory.FullPath)));
|
||||||
|
Assert.IsTrue(File.Exists(WorkspacePaths.Database(directory.FullPath)));
|
||||||
|
|
||||||
|
using SqliteConnection connection = SqliteTestHelper.OpenWorkspace(directory.FullPath);
|
||||||
|
Assert.AreEqual(WorkspaceSchema.CurrentVersion, SqliteDatabase.ReadUserVersion(connection));
|
||||||
|
Assert.IsTrue(SqliteTestHelper.TableExists(connection, "columns"));
|
||||||
|
Assert.IsTrue(SqliteTestHelper.TableExists(connection, "cards"));
|
||||||
|
Assert.IsTrue(SqliteTestHelper.TableExists(connection, "tags"));
|
||||||
|
Assert.IsTrue(SqliteTestHelper.TableExists(connection, "card_tags"));
|
||||||
|
// Initialization does not add preset content.
|
||||||
|
Assert.AreEqual(0L, SqliteTestHelper.ScalarLong(connection, "SELECT COUNT(*) FROM columns;"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void InitializeMissingFolderThrows() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
string missing = Path.Combine(directory.FullPath, "not-created");
|
||||||
|
|
||||||
|
WorkspaceDirectoryMissingException exception = Assert.ThrowsExactly<WorkspaceDirectoryMissingException>(
|
||||||
|
() => WorkspaceInitializer.Initialize(missing));
|
||||||
|
Assert.AreEqual(missing, exception.FolderPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void InitializeTwiceThrows() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
WorkspaceInitializer.Initialize(directory.FullPath);
|
||||||
|
|
||||||
|
Assert.ThrowsExactly<InvalidOperationException>(() => WorkspaceInitializer.Initialize(directory.FullPath));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
using YKanBan.Storage;
|
||||||
|
using YKanBan.Storage.Workspace;
|
||||||
|
using YKanBan.Tests.TestUtilities;
|
||||||
|
|
||||||
|
namespace YKanBan.Tests.Storage.Workspace;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests for exclusive lock acquisition and release.
|
||||||
|
/// </summary>
|
||||||
|
[TestClass]
|
||||||
|
public class WorkspaceLockTests {
|
||||||
|
[TestMethod]
|
||||||
|
public void AcquireThenDisposeThenAcquireAgainSucceeds() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
WorkspaceInitializer.Initialize(directory.FullPath);
|
||||||
|
|
||||||
|
WorkspaceLock.Acquire(directory.FullPath).Dispose();
|
||||||
|
// Re-acquiring after release works: no stale lock residue survives.
|
||||||
|
WorkspaceLock.Acquire(directory.FullPath).Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void SecondAcquireWhileHeldThrows() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
WorkspaceInitializer.Initialize(directory.FullPath);
|
||||||
|
|
||||||
|
using WorkspaceLock first = WorkspaceLock.Acquire(directory.FullPath);
|
||||||
|
WorkspaceLockException exception = Assert.ThrowsExactly<WorkspaceLockException>(
|
||||||
|
() => WorkspaceLock.Acquire(directory.FullPath));
|
||||||
|
Assert.AreEqual(WorkspacePaths.LockFile(directory.FullPath), exception.LockFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void AcquireWithoutYkanbanThrowsNotInitialized() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
Assert.ThrowsExactly<WorkspaceNotInitializedException>(
|
||||||
|
() => WorkspaceLock.Acquire(directory.FullPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void LockFileIsEmptyAfterRelease() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
WorkspaceInitializer.Initialize(directory.FullPath);
|
||||||
|
|
||||||
|
using (WorkspaceLock.Acquire(directory.FullPath)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// The lock file survives release but carries no content; only the OS handle matters.
|
||||||
|
Assert.AreEqual(0L, new FileInfo(WorkspacePaths.LockFile(directory.FullPath)).Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
|
||||||
|
using YKanBan.Storage.Workspace;
|
||||||
|
using YKanBan.Tests.TestUtilities;
|
||||||
|
|
||||||
|
namespace YKanBan.Tests.Storage.Workspace;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verifies that the preset columns and tags follow the UI language active when
|
||||||
|
/// they are added and then live as ordinary data. These tests mutate the global
|
||||||
|
/// <see cref="Resources.Culture"/>, so they are marked do-not-parallelize.
|
||||||
|
/// </summary>
|
||||||
|
[TestClass]
|
||||||
|
[DoNotParallelize]
|
||||||
|
public class WorkspacePresetTests {
|
||||||
|
[TestMethod]
|
||||||
|
public void AddPresetColumnsStoresEnglishTextUnderEnglishCulture() {
|
||||||
|
CultureInfo? original = Resources.Culture;
|
||||||
|
try {
|
||||||
|
Resources.Culture = new CultureInfo("en");
|
||||||
|
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
WorkspaceInitializer.Initialize(directory.FullPath);
|
||||||
|
WorkspacePreset.AddPresetColumns(directory.FullPath);
|
||||||
|
|
||||||
|
using SqliteConnection connection = SqliteTestHelper.OpenWorkspace(directory.FullPath);
|
||||||
|
CollectionAssert.AreEqual(
|
||||||
|
new[]
|
||||||
|
{
|
||||||
|
Resources.PresetColumn_Todo,
|
||||||
|
Resources.PresetColumn_InProgress,
|
||||||
|
Resources.PresetColumn_Done,
|
||||||
|
},
|
||||||
|
SqliteTestHelper.GetColumnTitles(connection));
|
||||||
|
CollectionAssert.AreEqual(
|
||||||
|
new[]
|
||||||
|
{
|
||||||
|
Resources.PresetColumn_Todo_Description,
|
||||||
|
Resources.PresetColumn_InProgress_Description,
|
||||||
|
Resources.PresetColumn_Done_Description,
|
||||||
|
},
|
||||||
|
SqliteTestHelper.GetColumnDescriptions(connection));
|
||||||
|
} finally {
|
||||||
|
Resources.Culture = original;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void AddPresetColumnsStoresChineseTextUnderChineseCulture() {
|
||||||
|
CultureInfo? original = Resources.Culture;
|
||||||
|
try {
|
||||||
|
Resources.Culture = new CultureInfo("zh-Hans");
|
||||||
|
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
WorkspaceInitializer.Initialize(directory.FullPath);
|
||||||
|
WorkspacePreset.AddPresetColumns(directory.FullPath);
|
||||||
|
|
||||||
|
using SqliteConnection connection = SqliteTestHelper.OpenWorkspace(directory.FullPath);
|
||||||
|
CollectionAssert.AreEqual(
|
||||||
|
new[]
|
||||||
|
{
|
||||||
|
Resources.PresetColumn_Todo,
|
||||||
|
Resources.PresetColumn_InProgress,
|
||||||
|
Resources.PresetColumn_Done,
|
||||||
|
},
|
||||||
|
SqliteTestHelper.GetColumnTitles(connection));
|
||||||
|
// Chinese resources must resolve to different text than English.
|
||||||
|
Assert.AreEqual("待办", Resources.PresetColumn_Todo);
|
||||||
|
Assert.AreEqual("已完成的任务。", Resources.PresetColumn_Done_Description);
|
||||||
|
} finally {
|
||||||
|
Resources.Culture = original;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void AddPresetTagsStoresEightTagsUnderEnglishCulture() {
|
||||||
|
CultureInfo? original = Resources.Culture;
|
||||||
|
try {
|
||||||
|
Resources.Culture = new CultureInfo("en");
|
||||||
|
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
WorkspaceInitializer.Initialize(directory.FullPath);
|
||||||
|
WorkspacePreset.AddPresetTags(directory.FullPath);
|
||||||
|
|
||||||
|
using SqliteConnection connection = SqliteTestHelper.OpenWorkspace(directory.FullPath);
|
||||||
|
List<(string Name, string Color, string Description)> tags = SqliteTestHelper.GetTags(connection);
|
||||||
|
|
||||||
|
Assert.AreEqual(8, tags.Count);
|
||||||
|
Assert.AreEqual(("bug", "#d73a4a", "Something isn't working"), tags[0]);
|
||||||
|
Assert.AreEqual(("documentation", "#0075ca", "Improvements or additions to documentation"), tags[1]);
|
||||||
|
Assert.AreEqual(("wontfix", "#ffffff", "This will not be worked on"), tags[7]);
|
||||||
|
} finally {
|
||||||
|
Resources.Culture = original;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void AddPresetTagsStoresChineseNamesUnderChineseCulture() {
|
||||||
|
CultureInfo? original = Resources.Culture;
|
||||||
|
try {
|
||||||
|
Resources.Culture = new CultureInfo("zh-Hans");
|
||||||
|
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
WorkspaceInitializer.Initialize(directory.FullPath);
|
||||||
|
WorkspacePreset.AddPresetTags(directory.FullPath);
|
||||||
|
|
||||||
|
using SqliteConnection connection = SqliteTestHelper.OpenWorkspace(directory.FullPath);
|
||||||
|
List<(string Name, string Color, string Description)> tags = SqliteTestHelper.GetTags(connection);
|
||||||
|
|
||||||
|
Assert.AreEqual(8, tags.Count);
|
||||||
|
Assert.AreEqual("缺陷", tags[0].Name);
|
||||||
|
Assert.AreEqual("功能没有正常工作", tags[0].Description);
|
||||||
|
} finally {
|
||||||
|
Resources.Culture = original;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void PresetContentIsDataAndIgnoresLaterCultureChanges() {
|
||||||
|
CultureInfo? original = Resources.Culture;
|
||||||
|
try {
|
||||||
|
Resources.Culture = new CultureInfo("en");
|
||||||
|
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
WorkspaceInitializer.Initialize(directory.FullPath);
|
||||||
|
WorkspacePreset.AddPresetColumns(directory.FullPath);
|
||||||
|
WorkspacePreset.AddPresetTags(directory.FullPath);
|
||||||
|
|
||||||
|
// Switching the language after adding the presets must not rewrite stored data.
|
||||||
|
Resources.Culture = new CultureInfo("zh-Hans");
|
||||||
|
using SqliteConnection connection = SqliteTestHelper.OpenWorkspace(directory.FullPath);
|
||||||
|
Assert.AreEqual("To Do", SqliteTestHelper.GetColumnTitles(connection)[0]);
|
||||||
|
Assert.AreEqual("bug", SqliteTestHelper.GetTags(connection)[0].Name);
|
||||||
|
} finally {
|
||||||
|
Resources.Culture = original;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,265 @@
|
|||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
|
||||||
|
using YKanBan.Models;
|
||||||
|
using YKanBan.Search;
|
||||||
|
using YKanBan.Storage.Workspace;
|
||||||
|
using YKanBan.Tests.TestUtilities;
|
||||||
|
|
||||||
|
namespace YKanBan.Tests.Storage.Workspace;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests for workspace CRUD, the three cascade chains, edit-confirm
|
||||||
|
/// transaction atomicity and the timestamp refresh rules.
|
||||||
|
/// </summary>
|
||||||
|
[TestClass]
|
||||||
|
public class WorkspaceRepositoryTests {
|
||||||
|
/// <summary>
|
||||||
|
/// Owns a workspace with fixed-timestamp fixture data (one column, one
|
||||||
|
/// card, two tags linked to the card) plus the repository under test.
|
||||||
|
/// Fixture timestamps are small literal values so that any real write,
|
||||||
|
/// which stamps the current Unix time, is observable.
|
||||||
|
/// </summary>
|
||||||
|
private sealed class RepositoryFixture : IDisposable {
|
||||||
|
public TempDirectory Directory { get; } = new();
|
||||||
|
|
||||||
|
public WorkspaceRepository Repository { get; }
|
||||||
|
|
||||||
|
public long ColumnId { get; } = 1;
|
||||||
|
|
||||||
|
public long CardId { get; } = 1;
|
||||||
|
|
||||||
|
public long BugTagId { get; } = 1;
|
||||||
|
|
||||||
|
public long UiTagId { get; } = 2;
|
||||||
|
|
||||||
|
public RepositoryFixture() {
|
||||||
|
WorkspaceInitializer.Initialize(Directory.FullPath);
|
||||||
|
|
||||||
|
using (SqliteConnection connection = SqliteTestHelper.OpenWorkspace(Directory.FullPath)) {
|
||||||
|
SqliteTestHelper.Exec(connection, "INSERT INTO columns (title, description, created_at, updated_at) VALUES ('Col', '', 100, 100);");
|
||||||
|
SqliteTestHelper.Exec(connection, "INSERT INTO cards (column_id, title, content, created_at, updated_at) VALUES (1, 'T', 'C', 100, 100);");
|
||||||
|
SqliteTestHelper.Exec(connection, "INSERT INTO tags (name, color, description) VALUES ('bug', '#ff0000', '');");
|
||||||
|
SqliteTestHelper.Exec(connection, "INSERT INTO tags (name, color, description) VALUES ('ui', '#00ff00', '');");
|
||||||
|
SqliteTestHelper.Exec(connection, "INSERT INTO card_tags (card_id, tag_id) VALUES (1, 1);");
|
||||||
|
SqliteTestHelper.Exec(connection, "INSERT INTO card_tags (card_id, tag_id) VALUES (1, 2);");
|
||||||
|
}
|
||||||
|
|
||||||
|
Repository = new WorkspaceRepository(Directory.FullPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose() {
|
||||||
|
Repository.Dispose();
|
||||||
|
Directory.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void GetColumnsReturnsTheSeededColumn() {
|
||||||
|
using var fixture = new RepositoryFixture();
|
||||||
|
ColumnModel column = fixture.Repository.GetColumn(fixture.ColumnId)!;
|
||||||
|
Assert.AreEqual("Col", column.Title);
|
||||||
|
Assert.AreEqual(1, fixture.Repository.GetColumns().Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void AddColumnSetsEqualTimestamps() {
|
||||||
|
using var fixture = new RepositoryFixture();
|
||||||
|
ColumnModel column = fixture.Repository.AddColumn("New", "desc");
|
||||||
|
Assert.IsTrue(column.CreatedAt > 0L);
|
||||||
|
Assert.AreEqual(column.CreatedAt, column.UpdatedAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void UpdateColumnWithoutChangeWritesNothing() {
|
||||||
|
using var fixture = new RepositoryFixture();
|
||||||
|
|
||||||
|
ColumnModel result = fixture.Repository.UpdateColumn(fixture.ColumnId, "Col", "");
|
||||||
|
|
||||||
|
// A no-op must not refresh the fixed fixture timestamp.
|
||||||
|
Assert.AreEqual(100L, result.UpdatedAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void UpdateColumnChangeRefreshesTimestamp() {
|
||||||
|
using var fixture = new RepositoryFixture();
|
||||||
|
|
||||||
|
ColumnModel updated = fixture.Repository.UpdateColumn(fixture.ColumnId, "Col2", "desc");
|
||||||
|
|
||||||
|
Assert.IsTrue(updated.UpdatedAt > 100L);
|
||||||
|
Assert.AreEqual(100L, updated.CreatedAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void DeleteColumnCascadesToCardsAndTagLinks() {
|
||||||
|
using var fixture = new RepositoryFixture();
|
||||||
|
|
||||||
|
Assert.IsTrue(fixture.Repository.DeleteColumn(fixture.ColumnId));
|
||||||
|
|
||||||
|
Assert.AreEqual(0, fixture.Repository.GetCards().Count);
|
||||||
|
// The tags themselves survive the column deletion.
|
||||||
|
Assert.AreEqual(2, fixture.Repository.GetTags().Count);
|
||||||
|
using SqliteConnection connection = SqliteTestHelper.OpenWorkspace(fixture.Directory.FullPath);
|
||||||
|
Assert.AreEqual(0L, SqliteTestHelper.ScalarLong(connection, "SELECT COUNT(*) FROM card_tags;"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void DeleteCardRemovesTagLinksButKeepsTags() {
|
||||||
|
using var fixture = new RepositoryFixture();
|
||||||
|
|
||||||
|
Assert.IsTrue(fixture.Repository.DeleteCard(fixture.CardId));
|
||||||
|
|
||||||
|
Assert.IsNull(fixture.Repository.GetCard(fixture.CardId));
|
||||||
|
Assert.AreEqual(2, fixture.Repository.GetTags().Count);
|
||||||
|
using SqliteConnection connection = SqliteTestHelper.OpenWorkspace(fixture.Directory.FullPath);
|
||||||
|
Assert.AreEqual(0L, SqliteTestHelper.ScalarLong(connection, "SELECT COUNT(*) FROM card_tags;"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void DeleteTagDetachesFromCardsButKeepsCards() {
|
||||||
|
using var fixture = new RepositoryFixture();
|
||||||
|
|
||||||
|
Assert.IsTrue(fixture.Repository.DeleteTag(fixture.BugTagId));
|
||||||
|
|
||||||
|
Assert.AreEqual(1, fixture.Repository.GetTags().Count);
|
||||||
|
CardModel card = fixture.Repository.GetCard(fixture.CardId)!;
|
||||||
|
Assert.AreEqual(1, card.Tags.Count);
|
||||||
|
Assert.AreEqual("ui", card.Tags[0].Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void UpdateCardWithoutEffectiveChangeWritesNothing() {
|
||||||
|
using var fixture = new RepositoryFixture();
|
||||||
|
|
||||||
|
CardModel result = fixture.Repository.UpdateCard(
|
||||||
|
fixture.CardId, "T", "C", [fixture.BugTagId, fixture.UiTagId]);
|
||||||
|
|
||||||
|
Assert.AreEqual(100L, result.UpdatedAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void UpdateCardTitleChangeRefreshesTimestamp() {
|
||||||
|
using var fixture = new RepositoryFixture();
|
||||||
|
|
||||||
|
CardModel updated = fixture.Repository.UpdateCard(
|
||||||
|
fixture.CardId, "T2", "C", [fixture.BugTagId, fixture.UiTagId]);
|
||||||
|
|
||||||
|
Assert.IsTrue(updated.UpdatedAt > 100L);
|
||||||
|
Assert.AreEqual(100L, updated.CreatedAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void UpdateCardTagSetOnlyChangeStillRefreshesTimestamp() {
|
||||||
|
using var fixture = new RepositoryFixture();
|
||||||
|
|
||||||
|
CardModel updated = fixture.Repository.UpdateCard(fixture.CardId, "T", "C", [fixture.BugTagId]);
|
||||||
|
|
||||||
|
Assert.IsTrue(updated.UpdatedAt > 100L);
|
||||||
|
Assert.AreEqual(1, updated.Tags.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void UpdateCardWithUnknownTagRollsBackAtomically() {
|
||||||
|
using var fixture = new RepositoryFixture();
|
||||||
|
|
||||||
|
// Tag 999 does not exist: the FK fires mid-transaction and the whole edit must roll back.
|
||||||
|
Assert.ThrowsExactly<SqliteException>(() =>
|
||||||
|
fixture.Repository.UpdateCard(fixture.CardId, "TX", "CX", [fixture.BugTagId, 999]));
|
||||||
|
|
||||||
|
CardModel after = fixture.Repository.GetCard(fixture.CardId)!;
|
||||||
|
Assert.AreEqual("T", after.Title);
|
||||||
|
Assert.AreEqual("C", after.Content);
|
||||||
|
Assert.AreEqual(100L, after.UpdatedAt);
|
||||||
|
Assert.AreEqual(2, after.Tags.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void MoveCardUpdatesColumnWithoutRefreshingTimestamp() {
|
||||||
|
using var fixture = new RepositoryFixture();
|
||||||
|
long target = fixture.Repository.AddColumn("Target", "").Id;
|
||||||
|
|
||||||
|
Assert.IsTrue(fixture.Repository.MoveCard(fixture.CardId, target));
|
||||||
|
|
||||||
|
CardModel moved = fixture.Repository.GetCard(fixture.CardId)!;
|
||||||
|
Assert.AreEqual(target, moved.ColumnId);
|
||||||
|
// The move is a write but deliberately leaves the card's updated_at alone.
|
||||||
|
Assert.AreEqual(100L, moved.UpdatedAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void MoveCardToCurrentColumnIsNoOp() {
|
||||||
|
using var fixture = new RepositoryFixture();
|
||||||
|
|
||||||
|
Assert.IsFalse(fixture.Repository.MoveCard(fixture.CardId, fixture.ColumnId));
|
||||||
|
|
||||||
|
Assert.AreEqual(100L, fixture.Repository.GetCard(fixture.CardId)!.UpdatedAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void AddCardCreatesWithEqualTimestampsAndLinkedTags() {
|
||||||
|
using var fixture = new RepositoryFixture();
|
||||||
|
|
||||||
|
CardModel card = fixture.Repository.AddCard(fixture.ColumnId, "N", "body", [fixture.UiTagId]);
|
||||||
|
|
||||||
|
Assert.IsTrue(card.CreatedAt > 0L);
|
||||||
|
Assert.AreEqual(card.CreatedAt, card.UpdatedAt);
|
||||||
|
Assert.AreEqual(1, card.Tags.Count);
|
||||||
|
Assert.AreEqual("ui", card.Tags[0].Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void UpdateTagWithoutChangeWritesNothing() {
|
||||||
|
using var fixture = new RepositoryFixture();
|
||||||
|
|
||||||
|
TagModel result = fixture.Repository.UpdateTag(
|
||||||
|
fixture.BugTagId, "bug", RgbColor.Parse("#ff0000"), "");
|
||||||
|
|
||||||
|
Assert.AreEqual("bug", result.Name);
|
||||||
|
Assert.AreEqual(new RgbColor(0xFF, 0x00, 0x00), result.Color);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void UpdateTagChangeWrites() {
|
||||||
|
using var fixture = new RepositoryFixture();
|
||||||
|
|
||||||
|
TagModel updated = fixture.Repository.UpdateTag(
|
||||||
|
fixture.BugTagId, "defect", RgbColor.Parse("#ee0a0a"), "desc");
|
||||||
|
|
||||||
|
Assert.AreEqual("defect", updated.Name);
|
||||||
|
Assert.AreEqual(new RgbColor(0xEE, 0x0A, 0x0A), updated.Color);
|
||||||
|
Assert.AreEqual("desc", updated.Description);
|
||||||
|
Assert.AreEqual("defect", fixture.Repository.GetTags().Single(tag => tag.Id == fixture.BugTagId).Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void AddTagWithDuplicateNameIsRejected() {
|
||||||
|
using var fixture = new RepositoryFixture();
|
||||||
|
Assert.ThrowsExactly<SqliteException>(() =>
|
||||||
|
fixture.Repository.AddTag("bug", RgbColor.Parse("#123456"), ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void GetCardIdsMatchingRunsTheCompiledSearch() {
|
||||||
|
using var fixture = new RepositoryFixture();
|
||||||
|
CompiledSearch compiled = SearchSqlCompiler.Compile(new SearchNode.FreeText("T"));
|
||||||
|
|
||||||
|
IReadOnlyCollection<long> ids = fixture.Repository.GetCardIdsMatching(compiled);
|
||||||
|
|
||||||
|
CollectionAssert.AreEquivalent(new[] { fixture.CardId }, ids.ToList());
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void GetTagsWithUsageCountsAssignments() {
|
||||||
|
using var fixture = new RepositoryFixture();
|
||||||
|
|
||||||
|
IReadOnlyList<(TagModel Tag, long UsageCount)> before = fixture.Repository.GetTagsWithUsage();
|
||||||
|
Assert.AreEqual(1L, before.Single(entry => entry.Tag.Name == "bug").UsageCount);
|
||||||
|
Assert.AreEqual(1L, before.Single(entry => entry.Tag.Name == "ui").UsageCount);
|
||||||
|
|
||||||
|
// Detaching one tag via an edit confirmation drops its usage to zero but keeps the tag.
|
||||||
|
fixture.Repository.UpdateCard(fixture.CardId, "T", "C", [fixture.UiTagId]);
|
||||||
|
|
||||||
|
IReadOnlyList<(TagModel Tag, long UsageCount)> after = fixture.Repository.GetTagsWithUsage();
|
||||||
|
Assert.AreEqual(0L, after.Single(entry => entry.Tag.Name == "bug").UsageCount);
|
||||||
|
Assert.AreEqual(1L, after.Single(entry => entry.Tag.Name == "ui").UsageCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,204 @@
|
|||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
|
||||||
|
using YKanBan.Storage;
|
||||||
|
using YKanBan.Storage.Workspace;
|
||||||
|
using YKanBan.Tests.TestUtilities;
|
||||||
|
|
||||||
|
namespace YKanBan.Tests.Storage.Workspace;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verifies that the workspace DDL constraints reject invalid data at the door
|
||||||
|
/// and that the cascading delete chains work as specified.
|
||||||
|
/// </summary>
|
||||||
|
[TestClass]
|
||||||
|
public class WorkspaceSchemaTests {
|
||||||
|
/// <summary>
|
||||||
|
/// Owns a temp directory plus a fresh workspace-schema database for a single test.
|
||||||
|
/// </summary>
|
||||||
|
private sealed class FreshDatabase : IDisposable {
|
||||||
|
public TempDirectory Directory { get; } = new();
|
||||||
|
|
||||||
|
public SqliteConnection Connection { get; }
|
||||||
|
|
||||||
|
public FreshDatabase() {
|
||||||
|
Connection = SqliteDatabase.Open(
|
||||||
|
Path.Combine(Directory.FullPath, "ws.db"), WorkspaceSchema.Migrations);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Closes the connection before removing the temporary directory.
|
||||||
|
/// </summary>
|
||||||
|
public void Dispose() {
|
||||||
|
Connection.Dispose();
|
||||||
|
Directory.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void EmptyColumnTitleIsRejected() {
|
||||||
|
using var db = new FreshDatabase();
|
||||||
|
Assert.ThrowsExactly<SqliteException>(() =>
|
||||||
|
SqliteTestHelper.Exec(db.Connection, "INSERT INTO columns (title, created_at, updated_at) VALUES ('', 1, 1);"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void WhitespaceColumnTitleIsAccepted() {
|
||||||
|
using var db = new FreshDatabase();
|
||||||
|
// No trimming: a single space is a non-empty title as far as the DDL is concerned.
|
||||||
|
int affected = SqliteTestHelper.Exec(
|
||||||
|
db.Connection, "INSERT INTO columns (title, created_at, updated_at) VALUES (' ', 1, 1);");
|
||||||
|
Assert.AreEqual(1, affected);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void DuplicateColumnTitleIsRejected() {
|
||||||
|
using var db = new FreshDatabase();
|
||||||
|
SqliteTestHelper.Exec(db.Connection, "INSERT INTO columns (title, created_at, updated_at) VALUES ('Foo', 1, 1);");
|
||||||
|
Assert.ThrowsExactly<SqliteException>(() =>
|
||||||
|
SqliteTestHelper.Exec(db.Connection, "INSERT INTO columns (title, created_at, updated_at) VALUES ('Foo', 1, 1);"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ColumnTitlesCompareCaseSensitively() {
|
||||||
|
using var db = new FreshDatabase();
|
||||||
|
// BINARY collation: 'Foo' and 'foo' are distinct titles.
|
||||||
|
SqliteTestHelper.Exec(db.Connection, "INSERT INTO columns (title, created_at, updated_at) VALUES ('Foo', 1, 1);");
|
||||||
|
SqliteTestHelper.Exec(db.Connection, "INSERT INTO columns (title, created_at, updated_at) VALUES ('foo', 1, 1);");
|
||||||
|
Assert.AreEqual(2L, SqliteTestHelper.ScalarLong(db.Connection, "SELECT COUNT(*) FROM columns;"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void EmptyTagNameIsRejected() {
|
||||||
|
using var db = new FreshDatabase();
|
||||||
|
Assert.ThrowsExactly<SqliteException>(() =>
|
||||||
|
SqliteTestHelper.Exec(db.Connection, "INSERT INTO tags (name, color) VALUES ('', '#112233');"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TagNamesAcceptSpacesEmojiAndReservedWords() {
|
||||||
|
using var db = new FreshDatabase();
|
||||||
|
// Tag names are fully open: no charset or length rules, no trimming.
|
||||||
|
foreach (string name in new[] { " ", "a b", "🏷️", "AND", "tag:with:colons" }) {
|
||||||
|
SqliteTestHelper.Exec(db.Connection, "INSERT INTO tags (name, color) VALUES ($n, '#112233');", ("$n", name));
|
||||||
|
}
|
||||||
|
Assert.AreEqual(5L, SqliteTestHelper.ScalarLong(db.Connection, "SELECT COUNT(*) FROM tags;"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void DuplicateTagNameIsRejected() {
|
||||||
|
using var db = new FreshDatabase();
|
||||||
|
SqliteTestHelper.Exec(db.Connection, "INSERT INTO tags (name, color) VALUES ('bug', '#112233');");
|
||||||
|
Assert.ThrowsExactly<SqliteException>(() =>
|
||||||
|
SqliteTestHelper.Exec(db.Connection, "INSERT INTO tags (name, color) VALUES ('bug', '#445566');"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[DataRow("#000000")]
|
||||||
|
[DataRow("#FFFFFF")]
|
||||||
|
[DataRow("#a1B2c3")]
|
||||||
|
public void ValidTagColorsAreAccepted(string color) {
|
||||||
|
using var db = new FreshDatabase();
|
||||||
|
int affected = SqliteTestHelper.Exec(
|
||||||
|
db.Connection, "INSERT INTO tags (name, color) VALUES ('x', $c);", ("$c", color));
|
||||||
|
Assert.AreEqual(1, affected);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[DataRow("112233")]
|
||||||
|
[DataRow("#11223")]
|
||||||
|
[DataRow("#1122334")]
|
||||||
|
[DataRow("#G1B2C3")]
|
||||||
|
[DataRow("#a1b2g3")]
|
||||||
|
[DataRow(" #112233")]
|
||||||
|
[DataRow("#112233 ")]
|
||||||
|
[DataRow("")]
|
||||||
|
public void InvalidTagColorsAreRejected(string color) {
|
||||||
|
using var db = new FreshDatabase();
|
||||||
|
Assert.ThrowsExactly<SqliteException>(() =>
|
||||||
|
SqliteTestHelper.Exec(db.Connection, "INSERT INTO tags (name, color) VALUES ('x', $c);", ("$c", color)));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void CardRequiresExistingColumn() {
|
||||||
|
using var db = new FreshDatabase();
|
||||||
|
// foreign_keys=ON makes the FK enforceable; this is the DDL contract behind the cascades.
|
||||||
|
Assert.ThrowsExactly<SqliteException>(() =>
|
||||||
|
SqliteTestHelper.Exec(db.Connection, "INSERT INTO cards (column_id, created_at, updated_at) VALUES (999, 1, 1);"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void CardDefaultsToEmptyTitleAndContent() {
|
||||||
|
using var db = new FreshDatabase();
|
||||||
|
SqliteTestHelper.Exec(db.Connection, "INSERT INTO columns (title, created_at, updated_at) VALUES ('c', 1, 1);");
|
||||||
|
SqliteTestHelper.Exec(db.Connection, "INSERT INTO cards (column_id, created_at, updated_at) VALUES (1, 1, 1);");
|
||||||
|
|
||||||
|
// No title is represented by the empty string.
|
||||||
|
Assert.AreEqual(string.Empty, SqliteTestHelper.ScalarString(db.Connection, "SELECT title FROM cards WHERE id = 1;"));
|
||||||
|
Assert.AreEqual(string.Empty, SqliteTestHelper.ScalarString(db.Connection, "SELECT content FROM cards WHERE id = 1;"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void CardTagDuplicateAssignmentIsRejected() {
|
||||||
|
using var db = new FreshDatabase();
|
||||||
|
SqliteTestHelper.Exec(db.Connection, "INSERT INTO columns (title, created_at, updated_at) VALUES ('c', 1, 1);");
|
||||||
|
SqliteTestHelper.Exec(db.Connection, "INSERT INTO cards (column_id, created_at, updated_at) VALUES (1, 1, 1);");
|
||||||
|
SqliteTestHelper.Exec(db.Connection, "INSERT INTO tags (name, color) VALUES ('bug', '#112233');");
|
||||||
|
SqliteTestHelper.Exec(db.Connection, "INSERT INTO card_tags (card_id, tag_id) VALUES (1, 1);");
|
||||||
|
|
||||||
|
// Composite primary key: the same (card, tag) pair cannot be inserted twice.
|
||||||
|
Assert.ThrowsExactly<SqliteException>(() =>
|
||||||
|
SqliteTestHelper.Exec(db.Connection, "INSERT INTO card_tags (card_id, tag_id) VALUES (1, 1);"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void DeletingColumnCascadesToCardsAndCardTags() {
|
||||||
|
using var db = new FreshDatabase();
|
||||||
|
InsertBoardRow(db.Connection);
|
||||||
|
|
||||||
|
SqliteTestHelper.Exec(db.Connection, "DELETE FROM columns WHERE id = 1;");
|
||||||
|
|
||||||
|
Assert.AreEqual(0L, SqliteTestHelper.ScalarLong(db.Connection, "SELECT COUNT(*) FROM columns;"));
|
||||||
|
Assert.AreEqual(0L, SqliteTestHelper.ScalarLong(db.Connection, "SELECT COUNT(*) FROM cards;"));
|
||||||
|
Assert.AreEqual(0L, SqliteTestHelper.ScalarLong(db.Connection, "SELECT COUNT(*) FROM card_tags;"));
|
||||||
|
// Tags are never cleaned up automatically.
|
||||||
|
Assert.AreEqual(1L, SqliteTestHelper.ScalarLong(db.Connection, "SELECT COUNT(*) FROM tags;"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void DeletingCardCascadesToCardTagsOnly() {
|
||||||
|
using var db = new FreshDatabase();
|
||||||
|
InsertBoardRow(db.Connection);
|
||||||
|
|
||||||
|
SqliteTestHelper.Exec(db.Connection, "DELETE FROM cards WHERE id = 1;");
|
||||||
|
|
||||||
|
Assert.AreEqual(1L, SqliteTestHelper.ScalarLong(db.Connection, "SELECT COUNT(*) FROM columns;"));
|
||||||
|
Assert.AreEqual(0L, SqliteTestHelper.ScalarLong(db.Connection, "SELECT COUNT(*) FROM cards;"));
|
||||||
|
Assert.AreEqual(0L, SqliteTestHelper.ScalarLong(db.Connection, "SELECT COUNT(*) FROM card_tags;"));
|
||||||
|
Assert.AreEqual(1L, SqliteTestHelper.ScalarLong(db.Connection, "SELECT COUNT(*) FROM tags;"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void DeletingTagRemovesAssignmentsButKeepsCards() {
|
||||||
|
using var db = new FreshDatabase();
|
||||||
|
InsertBoardRow(db.Connection);
|
||||||
|
|
||||||
|
SqliteTestHelper.Exec(db.Connection, "DELETE FROM tags WHERE id = 1;");
|
||||||
|
|
||||||
|
Assert.AreEqual(0L, SqliteTestHelper.ScalarLong(db.Connection, "SELECT COUNT(*) FROM tags;"));
|
||||||
|
Assert.AreEqual(0L, SqliteTestHelper.ScalarLong(db.Connection, "SELECT COUNT(*) FROM card_tags;"));
|
||||||
|
// The card merely loses the tag.
|
||||||
|
Assert.AreEqual(1L, SqliteTestHelper.ScalarLong(db.Connection, "SELECT COUNT(*) FROM cards;"));
|
||||||
|
Assert.AreEqual(1L, SqliteTestHelper.ScalarLong(db.Connection, "SELECT COUNT(*) FROM columns;"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Inserts one column, one card, one tag and their assignment, ready for a cascade test.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connection">An open workspace-schema connection.</param>
|
||||||
|
private static void InsertBoardRow(SqliteConnection connection) {
|
||||||
|
SqliteTestHelper.Exec(connection, "INSERT INTO columns (title, created_at, updated_at) VALUES ('c', 1, 1);");
|
||||||
|
SqliteTestHelper.Exec(connection, "INSERT INTO cards (column_id, created_at, updated_at) VALUES (1, 1, 1);");
|
||||||
|
SqliteTestHelper.Exec(connection, "INSERT INTO tags (name, color) VALUES ('bug', '#112233');");
|
||||||
|
SqliteTestHelper.Exec(connection, "INSERT INTO card_tags (card_id, tag_id) VALUES (1, 1);");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
using YKanBan.Models;
|
||||||
|
using YKanBan.Storage;
|
||||||
|
using YKanBan.Storage.Workspace;
|
||||||
|
using YKanBan.Tests.TestUtilities;
|
||||||
|
|
||||||
|
namespace YKanBan.Tests.Storage.Workspace;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests for the workspace session lifecycle: the exclusive lock is held for
|
||||||
|
/// the whole session and the repository is usable through it.
|
||||||
|
/// </summary>
|
||||||
|
[TestClass]
|
||||||
|
public class WorkspaceSessionTests {
|
||||||
|
[TestMethod]
|
||||||
|
public void OpenHoldsLockUntilDisposed() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
WorkspaceInitializer.Initialize(directory.FullPath);
|
||||||
|
|
||||||
|
using WorkspaceSession session = WorkspaceSession.Open(directory.FullPath);
|
||||||
|
|
||||||
|
// A second open while the session is alive must fail on the lock.
|
||||||
|
Assert.ThrowsExactly<WorkspaceLockException>(() => WorkspaceSession.Open(directory.FullPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void DisposeReleasesLockForReopen() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
WorkspaceInitializer.Initialize(directory.FullPath);
|
||||||
|
|
||||||
|
WorkspaceSession.Open(directory.FullPath).Dispose();
|
||||||
|
|
||||||
|
using WorkspaceSession reopened = WorkspaceSession.Open(directory.FullPath);
|
||||||
|
Assert.AreEqual(directory.FullPath, reopened.FolderPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void OpenUninitializedFolderThrowsNotInitialized() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
|
||||||
|
Assert.ThrowsExactly<WorkspaceNotInitializedException>(
|
||||||
|
() => WorkspaceSession.Open(directory.FullPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void RepositoryIsUsableThroughSession() {
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
WorkspaceInitializer.Initialize(directory.FullPath);
|
||||||
|
|
||||||
|
using WorkspaceSession session = WorkspaceSession.Open(directory.FullPath);
|
||||||
|
TagModel tag = session.Repository.AddTag("bug", RgbColor.Parse("#112233"), "");
|
||||||
|
|
||||||
|
Assert.AreEqual("bug", session.Repository.GetTags().Single().Name);
|
||||||
|
Assert.AreEqual(tag.Id, session.Repository.GetTags().Single().Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
|
||||||
|
using YKanBan.Storage;
|
||||||
|
using YKanBan.Storage.Workspace;
|
||||||
|
|
||||||
|
namespace YKanBan.Tests.TestUtilities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shared helpers for the storage tests: small SQL conveniences plus opening a
|
||||||
|
/// workspace database with the real migration list.
|
||||||
|
/// </summary>
|
||||||
|
public static class SqliteTestHelper {
|
||||||
|
/// <summary>
|
||||||
|
/// Executes a non-query SQL statement and returns the affected row count.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connection">An open database connection.</param>
|
||||||
|
/// <param name="sql">The statement to execute.</param>
|
||||||
|
/// <param name="parameters">Name/value pairs bound as SQL parameters.</param>
|
||||||
|
/// <returns>The number of affected rows.</returns>
|
||||||
|
public static int Exec(SqliteConnection connection, string sql, params (string Name, object? Value)[] parameters) {
|
||||||
|
using var command = connection.CreateCommand();
|
||||||
|
command.CommandText = sql;
|
||||||
|
foreach ((string name, object? value) in parameters) {
|
||||||
|
command.Parameters.AddWithValue(name, value);
|
||||||
|
}
|
||||||
|
return command.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the scalar result of a SQL query as a string.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connection">An open database connection.</param>
|
||||||
|
/// <param name="sql">The query to execute.</param>
|
||||||
|
/// <returns>The scalar result cast to a string.</returns>
|
||||||
|
public static string ScalarString(SqliteConnection connection, string sql) {
|
||||||
|
using var command = connection.CreateCommand();
|
||||||
|
command.CommandText = sql;
|
||||||
|
return (string)command.ExecuteScalar()!;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the scalar result of a SQL query as a long.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connection">An open database connection.</param>
|
||||||
|
/// <param name="sql">The query to execute.</param>
|
||||||
|
/// <returns>The scalar result cast to a long.</returns>
|
||||||
|
public static long ScalarLong(SqliteConnection connection, string sql) {
|
||||||
|
using var command = connection.CreateCommand();
|
||||||
|
command.CommandText = sql;
|
||||||
|
return (long)command.ExecuteScalar()!;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns whether a table with the given name exists in the database.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connection">An open database connection.</param>
|
||||||
|
/// <param name="tableName">The table name to look for.</param>
|
||||||
|
/// <returns><see langword="true"/> when the table exists.</returns>
|
||||||
|
public static bool TableExists(SqliteConnection connection, string tableName) {
|
||||||
|
using var command = connection.CreateCommand();
|
||||||
|
command.CommandText = "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name=$name;";
|
||||||
|
command.Parameters.AddWithValue("$name", tableName);
|
||||||
|
return (long)command.ExecuteScalar()! == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the titles of all columns, ordered by id ascending.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connection">An open database connection.</param>
|
||||||
|
/// <returns>The column titles in id order.</returns>
|
||||||
|
public static List<string> GetColumnTitles(SqliteConnection connection) {
|
||||||
|
using var command = connection.CreateCommand();
|
||||||
|
command.CommandText = "SELECT title FROM columns ORDER BY id ASC;";
|
||||||
|
using var reader = command.ExecuteReader();
|
||||||
|
|
||||||
|
var titles = new List<string>();
|
||||||
|
while (reader.Read()) {
|
||||||
|
titles.Add(reader.GetString(0));
|
||||||
|
}
|
||||||
|
return titles;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the descriptions of all columns, ordered by id ascending.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connection">An open database connection.</param>
|
||||||
|
/// <returns>The column descriptions in id order.</returns>
|
||||||
|
public static List<string> GetColumnDescriptions(SqliteConnection connection) {
|
||||||
|
using var command = connection.CreateCommand();
|
||||||
|
command.CommandText = "SELECT description FROM columns ORDER BY id ASC;";
|
||||||
|
using var reader = command.ExecuteReader();
|
||||||
|
|
||||||
|
var descriptions = new List<string>();
|
||||||
|
while (reader.Read()) {
|
||||||
|
descriptions.Add(reader.GetString(0));
|
||||||
|
}
|
||||||
|
return descriptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns all tags as name/color/description tuples, ordered by id ascending.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connection">An open database connection.</param>
|
||||||
|
/// <returns>The tags in id order.</returns>
|
||||||
|
public static List<(string Name, string Color, string Description)> GetTags(SqliteConnection connection) {
|
||||||
|
using var command = connection.CreateCommand();
|
||||||
|
command.CommandText = "SELECT name, color, description FROM tags ORDER BY id ASC;";
|
||||||
|
using var reader = command.ExecuteReader();
|
||||||
|
|
||||||
|
var tags = new List<(string, string, string)>();
|
||||||
|
while (reader.Read()) {
|
||||||
|
tags.Add((reader.GetString(0), reader.GetString(1), reader.GetString(2)));
|
||||||
|
}
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens a workspace database with the real workspace migration list.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The workspace folder path.</param>
|
||||||
|
/// <returns>An open, migrated connection.</returns>
|
||||||
|
public static SqliteConnection OpenWorkspace(string folderPath) {
|
||||||
|
return SqliteDatabase.Open(WorkspacePaths.Database(folderPath), WorkspaceSchema.Migrations);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
namespace YKanBan.Tests.TestUtilities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a unique temporary directory per test instance and removes it on
|
||||||
|
/// disposal. The removal is retried once because SQLite WAL sidecar files can
|
||||||
|
/// linger for a moment after the connections close.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class TempDirectory : IDisposable {
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the unique directory path managed by this instance.
|
||||||
|
/// </summary>
|
||||||
|
public string FullPath { get; }
|
||||||
|
|
||||||
|
public TempDirectory() {
|
||||||
|
FullPath = Path.Combine(Path.GetTempPath(), "ykanban-tests-" + Guid.NewGuid().ToString("N"));
|
||||||
|
Directory.CreateDirectory(FullPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes the directory tree, retrying once after a short delay.
|
||||||
|
/// </summary>
|
||||||
|
public void Dispose() {
|
||||||
|
try {
|
||||||
|
// SAFETY: Recursive directory delete is safe: FullPath is the
|
||||||
|
// read-only, GUID-named directory this instance created under the
|
||||||
|
// OS temp folder, so it can never target user data or the temp root.
|
||||||
|
Directory.Delete(FullPath, recursive: true);
|
||||||
|
} catch (IOException) {
|
||||||
|
Thread.Sleep(100);
|
||||||
|
try {
|
||||||
|
// SAFETY: Retry of the same recursive delete, still confined to
|
||||||
|
// this instance's own temp directory.
|
||||||
|
Directory.Delete(FullPath, recursive: true);
|
||||||
|
} catch (IOException) {
|
||||||
|
// Leftovers in the OS temp folder are harmless; never fail a test over cleanup.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
<IsTestProject>true</IsTestProject>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MSTest" Version="4.4.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\YKanBan\YKanBan.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
<Solution>
|
<Solution>
|
||||||
<Project Path="YKanBan/YKanBan.csproj" />
|
<Project Path="YKanBan/YKanBan.csproj" />
|
||||||
|
<Project Path="YKanBan.Tests/YKanBan.Tests.csproj" />
|
||||||
</Solution>
|
</Solution>
|
||||||
+37
-4
@@ -2,14 +2,47 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
x:Class="YKanBan.App"
|
x:Class="YKanBan.App"
|
||||||
xmlns:local="using:YKanBan"
|
xmlns:local="using:YKanBan"
|
||||||
|
xmlns:semi="https://irihi.tech/semi"
|
||||||
RequestedThemeVariant="Default">
|
RequestedThemeVariant="Default">
|
||||||
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
|
|
||||||
|
|
||||||
<Application.DataTemplates>
|
<Application.DataTemplates>
|
||||||
<local:ViewLocator/>
|
<local:ViewLocator/>
|
||||||
</Application.DataTemplates>
|
</Application.DataTemplates>
|
||||||
|
|
||||||
<Application.Styles>
|
<Application.Styles>
|
||||||
<FluentTheme />
|
<!-- Semi.Avalonia provides the light and dark palettes; icons need their own theme. -->
|
||||||
|
<semi:SemiTheme/>
|
||||||
|
<semi:ColorPickerSemiTheme/>
|
||||||
|
<StyleInclude Source="avares://IconPacks.Avalonia.Lucide/Lucide.axaml"/>
|
||||||
</Application.Styles>
|
</Application.Styles>
|
||||||
</Application>
|
|
||||||
|
<!--
|
||||||
|
Custom colors are declared as Light/Dark pairs and consumed through
|
||||||
|
DynamicResource, so a theme switch restyles every surface. Tag colors are
|
||||||
|
user data and stay as their literal #RRGGBB value.
|
||||||
|
-->
|
||||||
|
<Application.Resources>
|
||||||
|
<ResourceDictionary>
|
||||||
|
<ResourceDictionary.ThemeDictionaries>
|
||||||
|
<ResourceDictionary x:Key="Light">
|
||||||
|
<SolidColorBrush x:Key="TopBarBackgroundBrush" Color="#F6F7F9"/>
|
||||||
|
<SolidColorBrush x:Key="TopBarBorderBrush" Color="#E2E4EA"/>
|
||||||
|
<SolidColorBrush x:Key="BoardColumnBackgroundBrush" Color="#F1F2F5"/>
|
||||||
|
<SolidColorBrush x:Key="BoardColumnBorderBrush" Color="#E2E4EA"/>
|
||||||
|
<SolidColorBrush x:Key="CardBackgroundBrush" Color="#FFFFFF"/>
|
||||||
|
<SolidColorBrush x:Key="CardBorderBrush" Color="#E2E4EA"/>
|
||||||
|
<SolidColorBrush x:Key="ErrorTextBrush" Color="#C0392B"/>
|
||||||
|
</ResourceDictionary>
|
||||||
|
<ResourceDictionary x:Key="Dark">
|
||||||
|
<SolidColorBrush x:Key="TopBarBackgroundBrush" Color="#1C1E24"/>
|
||||||
|
<SolidColorBrush x:Key="TopBarBorderBrush" Color="#2C2F37"/>
|
||||||
|
<SolidColorBrush x:Key="BoardColumnBackgroundBrush" Color="#17181C"/>
|
||||||
|
<SolidColorBrush x:Key="BoardColumnBorderBrush" Color="#2C2F37"/>
|
||||||
|
<SolidColorBrush x:Key="CardBackgroundBrush" Color="#23252B"/>
|
||||||
|
<SolidColorBrush x:Key="CardBorderBrush" Color="#33363F"/>
|
||||||
|
<SolidColorBrush x:Key="ErrorTextBrush" Color="#FF6B6B"/>
|
||||||
|
</ResourceDictionary>
|
||||||
|
</ResourceDictionary.ThemeDictionaries>
|
||||||
|
</ResourceDictionary>
|
||||||
|
</Application.Resources>
|
||||||
|
</Application>
|
||||||
+76
-22
@@ -1,47 +1,101 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls.ApplicationLifetimes;
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
using Avalonia.Data.Core;
|
|
||||||
using Avalonia.Data.Core.Plugins;
|
using Avalonia.Data.Core.Plugins;
|
||||||
using System.Linq;
|
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
|
using Avalonia.Media;
|
||||||
|
using Avalonia.Styling;
|
||||||
|
|
||||||
|
using YKanBan.Services;
|
||||||
|
using YKanBan.Storage.AppData;
|
||||||
using YKanBan.ViewModels;
|
using YKanBan.ViewModels;
|
||||||
using YKanBan.Views;
|
using YKanBan.Views;
|
||||||
|
|
||||||
|
using Resx = YKanBan.Resources;
|
||||||
|
|
||||||
namespace YKanBan;
|
namespace YKanBan;
|
||||||
|
|
||||||
public partial class App : Application
|
public partial class App : Application {
|
||||||
{
|
/// <summary>
|
||||||
public override void Initialize()
|
/// Gets the process-wide composition root, created at startup.
|
||||||
{
|
/// </summary>
|
||||||
|
public static AppServices? Services { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the language applied at startup; a live selection differing from it
|
||||||
|
/// needs a restart.
|
||||||
|
/// </summary>
|
||||||
|
public static string StartupLanguage { get; private set; } = AppConfig.DefaultLanguage;
|
||||||
|
|
||||||
|
public override void Initialize() {
|
||||||
AvaloniaXamlLoader.Load(this);
|
AvaloniaXamlLoader.Load(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnFrameworkInitializationCompleted()
|
public override void OnFrameworkInitializationCompleted() {
|
||||||
{
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
|
||||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
|
||||||
{
|
|
||||||
// Avoid duplicate validations from both Avalonia and the CommunityToolkit.
|
|
||||||
// More info: https://docs.avaloniaui.net/docs/guides/development-guides/data-validation#manage-validationplugins
|
|
||||||
DisableAvaloniaDataAnnotationValidation();
|
DisableAvaloniaDataAnnotationValidation();
|
||||||
desktop.MainWindow = new MainWindow
|
|
||||||
{
|
// Startup order: apply the configured culture, its RTL flow direction
|
||||||
DataContext = new MainWindowViewModel(),
|
// and the theme BEFORE creating the main window.
|
||||||
|
Services = new AppServices();
|
||||||
|
CultureInfo culture = ResolveCulture(Services.Config.Language);
|
||||||
|
StartupLanguage = Services.Config.Language;
|
||||||
|
Resx.Culture = culture;
|
||||||
|
ApplyTheme(Services.Config.Theme);
|
||||||
|
|
||||||
|
var viewModel = new MainWindowViewModel(Services, desktop.Args ?? []);
|
||||||
|
desktop.MainWindow = new MainWindow {
|
||||||
|
DataContext = viewModel,
|
||||||
|
|
||||||
|
// RTL detection drives the whole window flow direction; the two
|
||||||
|
// supported languages are LTR, but the infrastructure stays in
|
||||||
|
// place for future languages.
|
||||||
|
FlowDirection = culture.TextInfo.IsRightToLeft
|
||||||
|
? FlowDirection.RightToLeft
|
||||||
|
: FlowDirection.LeftToRight,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
base.OnFrameworkInitializationCompleted();
|
base.OnFrameworkInitializationCompleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DisableAvaloniaDataAnnotationValidation()
|
/// <summary>
|
||||||
{
|
/// Resolves a configured language to a culture, falling back to English.
|
||||||
// Get an array of plugins to remove
|
/// </summary>
|
||||||
|
/// <param name="language">The language code from app.json.</param>
|
||||||
|
/// <returns>The resolved culture.</returns>
|
||||||
|
public static CultureInfo ResolveCulture(string language) {
|
||||||
|
try {
|
||||||
|
return new CultureInfo(language);
|
||||||
|
} catch (CultureNotFoundException) {
|
||||||
|
return new CultureInfo(AppConfig.DefaultLanguage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Applies a theme selection immediately; <see cref="ThemeOption.FollowSystem"/>
|
||||||
|
/// inherits the operating system preference.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="option">The theme selection.</param>
|
||||||
|
public static void ApplyTheme(ThemeOption option) {
|
||||||
|
if (Current is null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Current.RequestedThemeVariant = option switch {
|
||||||
|
ThemeOption.Light => ThemeVariant.Light,
|
||||||
|
ThemeOption.Dark => ThemeVariant.Dark,
|
||||||
|
_ => ThemeVariant.Default,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void DisableAvaloniaDataAnnotationValidation() {
|
||||||
var dataValidationPluginsToRemove =
|
var dataValidationPluginsToRemove =
|
||||||
BindingPlugins.DataValidators.OfType<DataAnnotationsValidationPlugin>().ToArray();
|
BindingPlugins.DataValidators.OfType<DataAnnotationsValidationPlugin>().ToArray();
|
||||||
|
|
||||||
// remove each entry found
|
foreach (var plugin in dataValidationPluginsToRemove) {
|
||||||
foreach (var plugin in dataValidationPluginsToRemove)
|
|
||||||
{
|
|
||||||
BindingPlugins.DataValidators.Remove(plugin);
|
BindingPlugins.DataValidators.Remove(plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,448 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
English (neutral) resources. Any key missing from a satellite culture falls back to here.
|
||||||
|
This file is processed by the cross-platform MSBuild strongly-typed resource generator; see YKanBan.csproj.
|
||||||
|
-->
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<data name="App_Name" xml:space="preserve">
|
||||||
|
<value>YKanBan</value>
|
||||||
|
</data>
|
||||||
|
<data name="Common_Ok" xml:space="preserve">
|
||||||
|
<value>OK</value>
|
||||||
|
</data>
|
||||||
|
<data name="Common_Cancel" xml:space="preserve">
|
||||||
|
<value>Cancel</value>
|
||||||
|
</data>
|
||||||
|
<data name="Common_Delete" xml:space="preserve">
|
||||||
|
<value>Delete</value>
|
||||||
|
</data>
|
||||||
|
<data name="Common_Edit" xml:space="preserve">
|
||||||
|
<value>Edit</value>
|
||||||
|
</data>
|
||||||
|
<data name="Main_Export" xml:space="preserve">
|
||||||
|
<value>Export</value>
|
||||||
|
</data>
|
||||||
|
<data name="Main_Settings" xml:space="preserve">
|
||||||
|
<value>Settings</value>
|
||||||
|
</data>
|
||||||
|
<data name="Main_About" xml:space="preserve">
|
||||||
|
<value>About</value>
|
||||||
|
</data>
|
||||||
|
<data name="Tab_Tags" xml:space="preserve">
|
||||||
|
<value>Tags</value>
|
||||||
|
</data>
|
||||||
|
<data name="Tab_Board" xml:space="preserve">
|
||||||
|
<value>Board</value>
|
||||||
|
</data>
|
||||||
|
<data name="Board_SearchPlaceholder" xml:space="preserve">
|
||||||
|
<value>Search…</value>
|
||||||
|
</data>
|
||||||
|
<data name="Board_Search" xml:space="preserve">
|
||||||
|
<value>Search</value>
|
||||||
|
</data>
|
||||||
|
<data name="Board_ClearSearch" xml:space="preserve">
|
||||||
|
<value>Clear</value>
|
||||||
|
</data>
|
||||||
|
<data name="Board_AddColumn" xml:space="preserve">
|
||||||
|
<value>Add Column</value>
|
||||||
|
</data>
|
||||||
|
<data name="Board_ColumnWidth" xml:space="preserve">
|
||||||
|
<value>Column Width</value>
|
||||||
|
</data>
|
||||||
|
<data name="Board_SortCard" xml:space="preserve">
|
||||||
|
<value>Card Sort</value>
|
||||||
|
</data>
|
||||||
|
<data name="Board_SortColumn" xml:space="preserve">
|
||||||
|
<value>Column Sort</value>
|
||||||
|
</data>
|
||||||
|
<data name="Board_Display" xml:space="preserve">
|
||||||
|
<value>Display</value>
|
||||||
|
</data>
|
||||||
|
<data name="Board_NoColumns" xml:space="preserve">
|
||||||
|
<value>No columns yet.</value>
|
||||||
|
</data>
|
||||||
|
<data name="Board_FilterActive" xml:space="preserve">
|
||||||
|
<value>Board is filtered</value>
|
||||||
|
</data>
|
||||||
|
<data name="Board_FilterInactive" xml:space="preserve">
|
||||||
|
<value>Board is not filtered</value>
|
||||||
|
</data>
|
||||||
|
<data name="Search_Error_Title" xml:space="preserve">
|
||||||
|
<value>Invalid search</value>
|
||||||
|
</data>
|
||||||
|
<data name="Search_Error_Message" xml:space="preserve">
|
||||||
|
<value>The query expression is invalid. Details: {0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="Sort_IdAsc" xml:space="preserve">
|
||||||
|
<value>ID Ascending</value>
|
||||||
|
</data>
|
||||||
|
<data name="Sort_IdDesc" xml:space="preserve">
|
||||||
|
<value>ID Descending</value>
|
||||||
|
</data>
|
||||||
|
<data name="Sort_CreatedAsc" xml:space="preserve">
|
||||||
|
<value>Created Ascending</value>
|
||||||
|
</data>
|
||||||
|
<data name="Sort_CreatedDesc" xml:space="preserve">
|
||||||
|
<value>Created Descending</value>
|
||||||
|
</data>
|
||||||
|
<data name="Sort_UpdatedAsc" xml:space="preserve">
|
||||||
|
<value>Modified Ascending</value>
|
||||||
|
</data>
|
||||||
|
<data name="Sort_UpdatedDesc" xml:space="preserve">
|
||||||
|
<value>Modified Descending</value>
|
||||||
|
</data>
|
||||||
|
<data name="Sort_TitleAsc" xml:space="preserve">
|
||||||
|
<value>Title Ascending</value>
|
||||||
|
</data>
|
||||||
|
<data name="Sort_TitleDesc" xml:space="preserve">
|
||||||
|
<value>Title Descending</value>
|
||||||
|
</data>
|
||||||
|
<data name="Column_AddCard" xml:space="preserve">
|
||||||
|
<value>New Card</value>
|
||||||
|
</data>
|
||||||
|
<data name="Column_Edit" xml:space="preserve">
|
||||||
|
<value>Edit</value>
|
||||||
|
</data>
|
||||||
|
<data name="Column_Delete" xml:space="preserve">
|
||||||
|
<value>Delete</value>
|
||||||
|
</data>
|
||||||
|
<data name="Card_Delete" xml:space="preserve">
|
||||||
|
<value>Delete</value>
|
||||||
|
</data>
|
||||||
|
<data name="Card_Move" xml:space="preserve">
|
||||||
|
<value>Move to Column…</value>
|
||||||
|
</data>
|
||||||
|
<data name="ColumnDialog_AddTitle" xml:space="preserve">
|
||||||
|
<value>New Column</value>
|
||||||
|
</data>
|
||||||
|
<data name="ColumnDialog_EditTitle" xml:space="preserve">
|
||||||
|
<value>Edit Column</value>
|
||||||
|
</data>
|
||||||
|
<data name="ColumnDialog_Title" xml:space="preserve">
|
||||||
|
<value>Title</value>
|
||||||
|
</data>
|
||||||
|
<data name="ColumnDialog_Description" xml:space="preserve">
|
||||||
|
<value>Description</value>
|
||||||
|
</data>
|
||||||
|
<data name="ColumnDialog_InvalidTitle" xml:space="preserve">
|
||||||
|
<value>The title is empty or already used.</value>
|
||||||
|
</data>
|
||||||
|
<data name="CardDialog_AddTitle" xml:space="preserve">
|
||||||
|
<value>New Card</value>
|
||||||
|
</data>
|
||||||
|
<data name="CardDialog_EditTitle" xml:space="preserve">
|
||||||
|
<value>Edit Card</value>
|
||||||
|
</data>
|
||||||
|
<data name="CardDialog_Title" xml:space="preserve">
|
||||||
|
<value>Title</value>
|
||||||
|
</data>
|
||||||
|
<data name="CardDialog_Content" xml:space="preserve">
|
||||||
|
<value>Content</value>
|
||||||
|
</data>
|
||||||
|
<data name="CardDialog_Tags" xml:space="preserve">
|
||||||
|
<value>Tags</value>
|
||||||
|
</data>
|
||||||
|
<data name="CardDialog_AddTag" xml:space="preserve">
|
||||||
|
<value>Add Tag</value>
|
||||||
|
</data>
|
||||||
|
<data name="CardDialog_Id" xml:space="preserve">
|
||||||
|
<value>ID: {0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="CardDialog_Created" xml:space="preserve">
|
||||||
|
<value>Created: {0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="CardDialog_Modified" xml:space="preserve">
|
||||||
|
<value>Modified: {0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="CardDialog_TimePattern" xml:space="preserve">
|
||||||
|
<value>yyyy-MM-dd HH:mm</value>
|
||||||
|
</data>
|
||||||
|
<data name="CardDialog_Error" xml:space="preserve">
|
||||||
|
<value>Could not save the card.</value>
|
||||||
|
</data>
|
||||||
|
<data name="TagDialog_Title" xml:space="preserve">
|
||||||
|
<value>Add Tag</value>
|
||||||
|
</data>
|
||||||
|
<data name="TagDialog_Target" xml:space="preserve">
|
||||||
|
<value>Tag</value>
|
||||||
|
</data>
|
||||||
|
<data name="TagDialog_NoTargets" xml:space="preserve">
|
||||||
|
<value>There are no more tags to add.</value>
|
||||||
|
</data>
|
||||||
|
<data name="Tags_AddTag" xml:space="preserve">
|
||||||
|
<value>Add Tag</value>
|
||||||
|
</data>
|
||||||
|
<data name="Tags_Empty" xml:space="preserve">
|
||||||
|
<value>No tags yet.</value>
|
||||||
|
</data>
|
||||||
|
<data name="Tags_Usage" xml:space="preserve">
|
||||||
|
<value>{0} cards</value>
|
||||||
|
</data>
|
||||||
|
<data name="TagEditor_AddTitle" xml:space="preserve">
|
||||||
|
<value>New Tag</value>
|
||||||
|
</data>
|
||||||
|
<data name="TagEditor_EditTitle" xml:space="preserve">
|
||||||
|
<value>Edit Tag</value>
|
||||||
|
</data>
|
||||||
|
<data name="TagEditor_Name" xml:space="preserve">
|
||||||
|
<value>Name</value>
|
||||||
|
</data>
|
||||||
|
<data name="TagEditor_Color" xml:space="preserve">
|
||||||
|
<value>Color</value>
|
||||||
|
</data>
|
||||||
|
<data name="TagEditor_Description" xml:space="preserve">
|
||||||
|
<value>Description</value>
|
||||||
|
</data>
|
||||||
|
<data name="TagEditor_InvalidName" xml:space="preserve">
|
||||||
|
<value>The name is empty or already used.</value>
|
||||||
|
</data>
|
||||||
|
<data name="DeleteTag_Confirm_Title" xml:space="preserve">
|
||||||
|
<value>Delete Tag</value>
|
||||||
|
</data>
|
||||||
|
<data name="DeleteTag_Confirm_Message" xml:space="preserve">
|
||||||
|
<value>Delete tag "{0}"? It will be removed from {1} card(s).</value>
|
||||||
|
</data>
|
||||||
|
<data name="MoveDialog_Title" xml:space="preserve">
|
||||||
|
<value>Move Card</value>
|
||||||
|
</data>
|
||||||
|
<data name="MoveDialog_Target" xml:space="preserve">
|
||||||
|
<value>Target Column</value>
|
||||||
|
</data>
|
||||||
|
<data name="MoveDialog_NoTargets" xml:space="preserve">
|
||||||
|
<value>There is nowhere to move this card.</value>
|
||||||
|
</data>
|
||||||
|
<data name="WidthPreset_Narrow" xml:space="preserve">
|
||||||
|
<value>Narrow</value>
|
||||||
|
</data>
|
||||||
|
<data name="WidthPreset_Standard" xml:space="preserve">
|
||||||
|
<value>Standard</value>
|
||||||
|
</data>
|
||||||
|
<data name="WidthPreset_Wide" xml:space="preserve">
|
||||||
|
<value>Wide</value>
|
||||||
|
</data>
|
||||||
|
<data name="WidthPreset_Custom" xml:space="preserve">
|
||||||
|
<value>Custom</value>
|
||||||
|
</data>
|
||||||
|
<data name="WidthDialog_Pixels" xml:space="preserve">
|
||||||
|
<value>Pixels (160–720)</value>
|
||||||
|
</data>
|
||||||
|
<data name="Confirm_DeleteColumn_Title" xml:space="preserve">
|
||||||
|
<value>Delete Column</value>
|
||||||
|
</data>
|
||||||
|
<data name="Confirm_DeleteColumn_Message" xml:space="preserve">
|
||||||
|
<value>Delete column "{0}" and its {1} card(s)?</value>
|
||||||
|
</data>
|
||||||
|
<data name="Confirm_DeleteCard_Title" xml:space="preserve">
|
||||||
|
<value>Delete Card</value>
|
||||||
|
</data>
|
||||||
|
<data name="Confirm_DeleteCard_Message" xml:space="preserve">
|
||||||
|
<value>Delete card #{0}?</value>
|
||||||
|
</data>
|
||||||
|
<data name="Confirm_Discard_Title" xml:space="preserve">
|
||||||
|
<value>Discard Changes</value>
|
||||||
|
</data>
|
||||||
|
<data name="Confirm_Discard_Message" xml:space="preserve">
|
||||||
|
<value>Discard the unsaved changes?</value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_Argument_Title" xml:space="preserve">
|
||||||
|
<value>Invalid arguments</value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_Argument_Message" xml:space="preserve">
|
||||||
|
<value>YKanBan was started with invalid command-line arguments.</value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_Argument_Usage" xml:space="preserve">
|
||||||
|
<value>Usage: ykanban <path></value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_DirectoryMissing_Title" xml:space="preserve">
|
||||||
|
<value>Folder not found</value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_DirectoryMissing_Message" xml:space="preserve">
|
||||||
|
<value>The folder does not exist: {0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_NotInitialized_Title" xml:space="preserve">
|
||||||
|
<value>No workspace here</value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_NotInitialized_Message" xml:space="preserve">
|
||||||
|
<value>The folder does not contain a .ykanban workspace: {0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_NotInitialized_Initialize" xml:space="preserve">
|
||||||
|
<value>Initialize Workspace</value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_LockConflict_Title" xml:space="preserve">
|
||||||
|
<value>Workspace locked</value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_LockConflict_Message" xml:space="preserve">
|
||||||
|
<value>The workspace is already open in another instance: {0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_Title" xml:space="preserve">
|
||||||
|
<value>Settings</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_Language" xml:space="preserve">
|
||||||
|
<value>Language</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_Language_RestartNotice" xml:space="preserve">
|
||||||
|
<value>Takes effect after restart</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_LanguageEnglish" xml:space="preserve">
|
||||||
|
<value>English</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_LanguageChinese" xml:space="preserve">
|
||||||
|
<value>简体中文</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_Theme" xml:space="preserve">
|
||||||
|
<value>Theme</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_ThemeLight" xml:space="preserve">
|
||||||
|
<value>Light</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_ThemeDark" xml:space="preserve">
|
||||||
|
<value>Dark</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_ThemeFollowSystem" xml:space="preserve">
|
||||||
|
<value>Follow System</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_Confirmations" xml:space="preserve">
|
||||||
|
<value>Confirmations</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_ConfirmDeleteCard" xml:space="preserve">
|
||||||
|
<value>Ask before deleting a card</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_ConfirmDeleteColumn" xml:space="preserve">
|
||||||
|
<value>Ask before deleting a column</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_ConfirmDeleteTag" xml:space="preserve">
|
||||||
|
<value>Ask before deleting a tag</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_ConfirmDiscardEdit" xml:space="preserve">
|
||||||
|
<value>Ask before discarding card edits</value>
|
||||||
|
</data>
|
||||||
|
<data name="About_Title" xml:space="preserve">
|
||||||
|
<value>About</value>
|
||||||
|
</data>
|
||||||
|
<data name="About_Version" xml:space="preserve">
|
||||||
|
<value>Version {0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="About_Repository" xml:space="preserve">
|
||||||
|
<value>Repository</value>
|
||||||
|
</data>
|
||||||
|
<data name="About_License" xml:space="preserve">
|
||||||
|
<value>License</value>
|
||||||
|
</data>
|
||||||
|
<data name="About_LicenseValue" xml:space="preserve">
|
||||||
|
<value>MIT</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetColumn_Todo" xml:space="preserve">
|
||||||
|
<value>To Do</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetColumn_Todo_Description" xml:space="preserve">
|
||||||
|
<value>Tasks that are planned but not started.</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetColumn_InProgress" xml:space="preserve">
|
||||||
|
<value>In Progress</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetColumn_InProgress_Description" xml:space="preserve">
|
||||||
|
<value>Tasks that are currently being worked on.</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetColumn_Done" xml:space="preserve">
|
||||||
|
<value>Done</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetColumn_Done_Description" xml:space="preserve">
|
||||||
|
<value>Tasks that have been completed.</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Bug_Name" xml:space="preserve">
|
||||||
|
<value>bug</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Bug_Description" xml:space="preserve">
|
||||||
|
<value>Something isn't working</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Documentation_Name" xml:space="preserve">
|
||||||
|
<value>documentation</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Documentation_Description" xml:space="preserve">
|
||||||
|
<value>Improvements or additions to documentation</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Duplicate_Name" xml:space="preserve">
|
||||||
|
<value>duplicate</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Duplicate_Description" xml:space="preserve">
|
||||||
|
<value>This issue or pull request already exists</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Enhancement_Name" xml:space="preserve">
|
||||||
|
<value>enhancement</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Enhancement_Description" xml:space="preserve">
|
||||||
|
<value>New feature or request</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_HelpWanted_Name" xml:space="preserve">
|
||||||
|
<value>help-wanted</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_HelpWanted_Description" xml:space="preserve">
|
||||||
|
<value>Extra attention is needed</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Invalid_Name" xml:space="preserve">
|
||||||
|
<value>invalid</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Invalid_Description" xml:space="preserve">
|
||||||
|
<value>This doesn't seem right</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Question_Name" xml:space="preserve">
|
||||||
|
<value>question</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Question_Description" xml:space="preserve">
|
||||||
|
<value>Further information is requested</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Wontfix_Name" xml:space="preserve">
|
||||||
|
<value>wontfix</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Wontfix_Description" xml:space="preserve">
|
||||||
|
<value>This will not be worked on</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_FileNamePattern" xml:space="preserve">
|
||||||
|
<value>{0}-export-{1:yyyyMMdd-HHmmss}.md</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_TimePattern" xml:space="preserve">
|
||||||
|
<value>yyyy-MM-dd HH:mm:ss</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_CardTimePattern" xml:space="preserve">
|
||||||
|
<value>yyyy-MM-dd HH:mm</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_WorkspaceHeading" xml:space="preserve">
|
||||||
|
<value># {0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_ExportedAtLine" xml:space="preserve">
|
||||||
|
<value>> Exported at: {0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_ColumnHeading" xml:space="preserve">
|
||||||
|
<value>## Column: {0} ({1})</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_TagsLine" xml:space="preserve">
|
||||||
|
<value>- Tags: {0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_CreatedModifiedLine" xml:space="preserve">
|
||||||
|
<value>- Created: {0} Modified: {1}</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_TagsSummaryHeading" xml:space="preserve">
|
||||||
|
<value>## Tags</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_TagsTableHeader" xml:space="preserve">
|
||||||
|
<value>| Name | Color | Description | Usage |</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_Done_Title" xml:space="preserve">
|
||||||
|
<value>Export Complete</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_Done_Message" xml:space="preserve">
|
||||||
|
<value>Exported to: {0}</value>
|
||||||
|
</data>
|
||||||
|
</root>
|
||||||
@@ -0,0 +1,448 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Simplified Chinese (zh-Hans) satellite resources.
|
||||||
|
This file is embedded beside the neutral resources; see YKanBan.csproj.
|
||||||
|
-->
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<data name="App_Name" xml:space="preserve">
|
||||||
|
<value>YKanBan</value>
|
||||||
|
</data>
|
||||||
|
<data name="Common_Ok" xml:space="preserve">
|
||||||
|
<value>确定</value>
|
||||||
|
</data>
|
||||||
|
<data name="Common_Cancel" xml:space="preserve">
|
||||||
|
<value>取消</value>
|
||||||
|
</data>
|
||||||
|
<data name="Common_Delete" xml:space="preserve">
|
||||||
|
<value>删除</value>
|
||||||
|
</data>
|
||||||
|
<data name="Common_Edit" xml:space="preserve">
|
||||||
|
<value>编辑</value>
|
||||||
|
</data>
|
||||||
|
<data name="Main_Export" xml:space="preserve">
|
||||||
|
<value>导出</value>
|
||||||
|
</data>
|
||||||
|
<data name="Main_Settings" xml:space="preserve">
|
||||||
|
<value>设置</value>
|
||||||
|
</data>
|
||||||
|
<data name="Main_About" xml:space="preserve">
|
||||||
|
<value>关于</value>
|
||||||
|
</data>
|
||||||
|
<data name="Tab_Tags" xml:space="preserve">
|
||||||
|
<value>标签</value>
|
||||||
|
</data>
|
||||||
|
<data name="Tab_Board" xml:space="preserve">
|
||||||
|
<value>看板</value>
|
||||||
|
</data>
|
||||||
|
<data name="Board_SearchPlaceholder" xml:space="preserve">
|
||||||
|
<value>搜索…</value>
|
||||||
|
</data>
|
||||||
|
<data name="Board_Search" xml:space="preserve">
|
||||||
|
<value>搜索</value>
|
||||||
|
</data>
|
||||||
|
<data name="Board_ClearSearch" xml:space="preserve">
|
||||||
|
<value>清空</value>
|
||||||
|
</data>
|
||||||
|
<data name="Board_AddColumn" xml:space="preserve">
|
||||||
|
<value>新增列</value>
|
||||||
|
</data>
|
||||||
|
<data name="Board_ColumnWidth" xml:space="preserve">
|
||||||
|
<value>列宽</value>
|
||||||
|
</data>
|
||||||
|
<data name="Board_SortCard" xml:space="preserve">
|
||||||
|
<value>卡片排序</value>
|
||||||
|
</data>
|
||||||
|
<data name="Board_SortColumn" xml:space="preserve">
|
||||||
|
<value>列排序</value>
|
||||||
|
</data>
|
||||||
|
<data name="Board_Display" xml:space="preserve">
|
||||||
|
<value>显示</value>
|
||||||
|
</data>
|
||||||
|
<data name="Board_NoColumns" xml:space="preserve">
|
||||||
|
<value>还没有列。</value>
|
||||||
|
</data>
|
||||||
|
<data name="Board_FilterActive" xml:space="preserve">
|
||||||
|
<value>看板处于过滤状态</value>
|
||||||
|
</data>
|
||||||
|
<data name="Board_FilterInactive" xml:space="preserve">
|
||||||
|
<value>看板未处于过滤状态</value>
|
||||||
|
</data>
|
||||||
|
<data name="Search_Error_Title" xml:space="preserve">
|
||||||
|
<value>搜索表达式有误</value>
|
||||||
|
</data>
|
||||||
|
<data name="Search_Error_Message" xml:space="preserve">
|
||||||
|
<value>查询表达式有误,详情:{0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="Sort_IdAsc" xml:space="preserve">
|
||||||
|
<value>ID 正序</value>
|
||||||
|
</data>
|
||||||
|
<data name="Sort_IdDesc" xml:space="preserve">
|
||||||
|
<value>ID 倒序</value>
|
||||||
|
</data>
|
||||||
|
<data name="Sort_CreatedAsc" xml:space="preserve">
|
||||||
|
<value>创建时间正序</value>
|
||||||
|
</data>
|
||||||
|
<data name="Sort_CreatedDesc" xml:space="preserve">
|
||||||
|
<value>创建时间倒序</value>
|
||||||
|
</data>
|
||||||
|
<data name="Sort_UpdatedAsc" xml:space="preserve">
|
||||||
|
<value>修改时间正序</value>
|
||||||
|
</data>
|
||||||
|
<data name="Sort_UpdatedDesc" xml:space="preserve">
|
||||||
|
<value>修改时间倒序</value>
|
||||||
|
</data>
|
||||||
|
<data name="Sort_TitleAsc" xml:space="preserve">
|
||||||
|
<value>标题正序</value>
|
||||||
|
</data>
|
||||||
|
<data name="Sort_TitleDesc" xml:space="preserve">
|
||||||
|
<value>标题倒序</value>
|
||||||
|
</data>
|
||||||
|
<data name="Column_AddCard" xml:space="preserve">
|
||||||
|
<value>新建卡片</value>
|
||||||
|
</data>
|
||||||
|
<data name="Column_Edit" xml:space="preserve">
|
||||||
|
<value>编辑</value>
|
||||||
|
</data>
|
||||||
|
<data name="Column_Delete" xml:space="preserve">
|
||||||
|
<value>删除</value>
|
||||||
|
</data>
|
||||||
|
<data name="Card_Delete" xml:space="preserve">
|
||||||
|
<value>删除</value>
|
||||||
|
</data>
|
||||||
|
<data name="Card_Move" xml:space="preserve">
|
||||||
|
<value>移动到列…</value>
|
||||||
|
</data>
|
||||||
|
<data name="ColumnDialog_AddTitle" xml:space="preserve">
|
||||||
|
<value>新增列</value>
|
||||||
|
</data>
|
||||||
|
<data name="ColumnDialog_EditTitle" xml:space="preserve">
|
||||||
|
<value>编辑列</value>
|
||||||
|
</data>
|
||||||
|
<data name="ColumnDialog_Title" xml:space="preserve">
|
||||||
|
<value>标题</value>
|
||||||
|
</data>
|
||||||
|
<data name="ColumnDialog_Description" xml:space="preserve">
|
||||||
|
<value>描述</value>
|
||||||
|
</data>
|
||||||
|
<data name="ColumnDialog_InvalidTitle" xml:space="preserve">
|
||||||
|
<value>标题为空或已被使用。</value>
|
||||||
|
</data>
|
||||||
|
<data name="CardDialog_AddTitle" xml:space="preserve">
|
||||||
|
<value>新增卡片</value>
|
||||||
|
</data>
|
||||||
|
<data name="CardDialog_EditTitle" xml:space="preserve">
|
||||||
|
<value>编辑卡片</value>
|
||||||
|
</data>
|
||||||
|
<data name="CardDialog_Title" xml:space="preserve">
|
||||||
|
<value>标题</value>
|
||||||
|
</data>
|
||||||
|
<data name="CardDialog_Content" xml:space="preserve">
|
||||||
|
<value>内容</value>
|
||||||
|
</data>
|
||||||
|
<data name="CardDialog_Tags" xml:space="preserve">
|
||||||
|
<value>标签</value>
|
||||||
|
</data>
|
||||||
|
<data name="CardDialog_AddTag" xml:space="preserve">
|
||||||
|
<value>添加标签</value>
|
||||||
|
</data>
|
||||||
|
<data name="CardDialog_Id" xml:space="preserve">
|
||||||
|
<value>编号:{0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="CardDialog_Created" xml:space="preserve">
|
||||||
|
<value>创建:{0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="CardDialog_Modified" xml:space="preserve">
|
||||||
|
<value>修改:{0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="CardDialog_TimePattern" xml:space="preserve">
|
||||||
|
<value>yyyy年M月d日 HH:mm</value>
|
||||||
|
</data>
|
||||||
|
<data name="CardDialog_Error" xml:space="preserve">
|
||||||
|
<value>无法保存卡片。</value>
|
||||||
|
</data>
|
||||||
|
<data name="TagDialog_Title" xml:space="preserve">
|
||||||
|
<value>添加标签</value>
|
||||||
|
</data>
|
||||||
|
<data name="TagDialog_Target" xml:space="preserve">
|
||||||
|
<value>标签</value>
|
||||||
|
</data>
|
||||||
|
<data name="TagDialog_NoTargets" xml:space="preserve">
|
||||||
|
<value>没有可添加的标签。</value>
|
||||||
|
</data>
|
||||||
|
<data name="Tags_AddTag" xml:space="preserve">
|
||||||
|
<value>添加标签</value>
|
||||||
|
</data>
|
||||||
|
<data name="Tags_Empty" xml:space="preserve">
|
||||||
|
<value>还没有标签。</value>
|
||||||
|
</data>
|
||||||
|
<data name="Tags_Usage" xml:space="preserve">
|
||||||
|
<value>{0} 张卡片</value>
|
||||||
|
</data>
|
||||||
|
<data name="TagEditor_AddTitle" xml:space="preserve">
|
||||||
|
<value>新建标签</value>
|
||||||
|
</data>
|
||||||
|
<data name="TagEditor_EditTitle" xml:space="preserve">
|
||||||
|
<value>编辑标签</value>
|
||||||
|
</data>
|
||||||
|
<data name="TagEditor_Name" xml:space="preserve">
|
||||||
|
<value>名称</value>
|
||||||
|
</data>
|
||||||
|
<data name="TagEditor_Color" xml:space="preserve">
|
||||||
|
<value>颜色</value>
|
||||||
|
</data>
|
||||||
|
<data name="TagEditor_Description" xml:space="preserve">
|
||||||
|
<value>描述</value>
|
||||||
|
</data>
|
||||||
|
<data name="TagEditor_InvalidName" xml:space="preserve">
|
||||||
|
<value>名称为空或已被使用。</value>
|
||||||
|
</data>
|
||||||
|
<data name="DeleteTag_Confirm_Title" xml:space="preserve">
|
||||||
|
<value>删除标签</value>
|
||||||
|
</data>
|
||||||
|
<data name="DeleteTag_Confirm_Message" xml:space="preserve">
|
||||||
|
<value>删除标签“{0}”?将从 {1} 张卡片中移除。</value>
|
||||||
|
</data>
|
||||||
|
<data name="MoveDialog_Title" xml:space="preserve">
|
||||||
|
<value>移动卡片</value>
|
||||||
|
</data>
|
||||||
|
<data name="MoveDialog_Target" xml:space="preserve">
|
||||||
|
<value>目标列</value>
|
||||||
|
</data>
|
||||||
|
<data name="MoveDialog_NoTargets" xml:space="preserve">
|
||||||
|
<value>没有可移动到的目标列。</value>
|
||||||
|
</data>
|
||||||
|
<data name="WidthPreset_Narrow" xml:space="preserve">
|
||||||
|
<value>窄</value>
|
||||||
|
</data>
|
||||||
|
<data name="WidthPreset_Standard" xml:space="preserve">
|
||||||
|
<value>标准</value>
|
||||||
|
</data>
|
||||||
|
<data name="WidthPreset_Wide" xml:space="preserve">
|
||||||
|
<value>宽</value>
|
||||||
|
</data>
|
||||||
|
<data name="WidthPreset_Custom" xml:space="preserve">
|
||||||
|
<value>自定义</value>
|
||||||
|
</data>
|
||||||
|
<data name="WidthDialog_Pixels" xml:space="preserve">
|
||||||
|
<value>像素(160–720)</value>
|
||||||
|
</data>
|
||||||
|
<data name="Confirm_DeleteColumn_Title" xml:space="preserve">
|
||||||
|
<value>删除列</value>
|
||||||
|
</data>
|
||||||
|
<data name="Confirm_DeleteColumn_Message" xml:space="preserve">
|
||||||
|
<value>删除列“{0}”及其 {1} 张卡片?</value>
|
||||||
|
</data>
|
||||||
|
<data name="Confirm_DeleteCard_Title" xml:space="preserve">
|
||||||
|
<value>删除卡片</value>
|
||||||
|
</data>
|
||||||
|
<data name="Confirm_DeleteCard_Message" xml:space="preserve">
|
||||||
|
<value>删除卡片 #{0}?</value>
|
||||||
|
</data>
|
||||||
|
<data name="Confirm_Discard_Title" xml:space="preserve">
|
||||||
|
<value>放弃修改</value>
|
||||||
|
</data>
|
||||||
|
<data name="Confirm_Discard_Message" xml:space="preserve">
|
||||||
|
<value>放弃未保存的修改?</value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_Argument_Title" xml:space="preserve">
|
||||||
|
<value>参数错误</value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_Argument_Message" xml:space="preserve">
|
||||||
|
<value>YKanBan 启动参数有误。</value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_Argument_Usage" xml:space="preserve">
|
||||||
|
<value>用法:ykanban <路径></value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_DirectoryMissing_Title" xml:space="preserve">
|
||||||
|
<value>目录不存在</value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_DirectoryMissing_Message" xml:space="preserve">
|
||||||
|
<value>目录不存在:{0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_NotInitialized_Title" xml:space="preserve">
|
||||||
|
<value>尚未初始化</value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_NotInitialized_Message" xml:space="preserve">
|
||||||
|
<value>该目录下没有 .ykanban 工作区:{0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_NotInitialized_Initialize" xml:space="preserve">
|
||||||
|
<value>初始化工作区</value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_LockConflict_Title" xml:space="preserve">
|
||||||
|
<value>工作区已被占用</value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_LockConflict_Message" xml:space="preserve">
|
||||||
|
<value>该工作区已在另一个实例中打开:{0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_Title" xml:space="preserve">
|
||||||
|
<value>设置</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_Language" xml:space="preserve">
|
||||||
|
<value>语言</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_Language_RestartNotice" xml:space="preserve">
|
||||||
|
<value>重启后生效</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_LanguageEnglish" xml:space="preserve">
|
||||||
|
<value>English</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_LanguageChinese" xml:space="preserve">
|
||||||
|
<value>简体中文</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_Theme" xml:space="preserve">
|
||||||
|
<value>主题</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_ThemeLight" xml:space="preserve">
|
||||||
|
<value>亮色</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_ThemeDark" xml:space="preserve">
|
||||||
|
<value>暗色</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_ThemeFollowSystem" xml:space="preserve">
|
||||||
|
<value>跟随系统</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_Confirmations" xml:space="preserve">
|
||||||
|
<value>确认对话框</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_ConfirmDeleteCard" xml:space="preserve">
|
||||||
|
<value>删除卡片前询问</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_ConfirmDeleteColumn" xml:space="preserve">
|
||||||
|
<value>删除列前询问</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_ConfirmDeleteTag" xml:space="preserve">
|
||||||
|
<value>删除标签前询问</value>
|
||||||
|
</data>
|
||||||
|
<data name="Settings_ConfirmDiscardEdit" xml:space="preserve">
|
||||||
|
<value>放弃卡片编辑前询问</value>
|
||||||
|
</data>
|
||||||
|
<data name="About_Title" xml:space="preserve">
|
||||||
|
<value>关于</value>
|
||||||
|
</data>
|
||||||
|
<data name="About_Version" xml:space="preserve">
|
||||||
|
<value>版本 {0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="About_Repository" xml:space="preserve">
|
||||||
|
<value>仓库</value>
|
||||||
|
</data>
|
||||||
|
<data name="About_License" xml:space="preserve">
|
||||||
|
<value>许可证</value>
|
||||||
|
</data>
|
||||||
|
<data name="About_LicenseValue" xml:space="preserve">
|
||||||
|
<value>MIT</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetColumn_Todo" xml:space="preserve">
|
||||||
|
<value>待办</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetColumn_Todo_Description" xml:space="preserve">
|
||||||
|
<value>已计划但尚未开始的任务。</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetColumn_InProgress" xml:space="preserve">
|
||||||
|
<value>进行中</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetColumn_InProgress_Description" xml:space="preserve">
|
||||||
|
<value>正在处理中的任务。</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetColumn_Done" xml:space="preserve">
|
||||||
|
<value>已完成</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetColumn_Done_Description" xml:space="preserve">
|
||||||
|
<value>已完成的任务。</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Bug_Name" xml:space="preserve">
|
||||||
|
<value>缺陷</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Bug_Description" xml:space="preserve">
|
||||||
|
<value>功能没有正常工作</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Documentation_Name" xml:space="preserve">
|
||||||
|
<value>文档</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Documentation_Description" xml:space="preserve">
|
||||||
|
<value>文档的改进或补充</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Duplicate_Name" xml:space="preserve">
|
||||||
|
<value>重复</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Duplicate_Description" xml:space="preserve">
|
||||||
|
<value>该问题或请求已存在</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Enhancement_Name" xml:space="preserve">
|
||||||
|
<value>增强</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Enhancement_Description" xml:space="preserve">
|
||||||
|
<value>新功能或请求</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_HelpWanted_Name" xml:space="preserve">
|
||||||
|
<value>需要帮助</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_HelpWanted_Description" xml:space="preserve">
|
||||||
|
<value>需要额外关注</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Invalid_Name" xml:space="preserve">
|
||||||
|
<value>无效</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Invalid_Description" xml:space="preserve">
|
||||||
|
<value>似乎不正确</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Question_Name" xml:space="preserve">
|
||||||
|
<value>疑问</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Question_Description" xml:space="preserve">
|
||||||
|
<value>需要进一步信息</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Wontfix_Name" xml:space="preserve">
|
||||||
|
<value>不予处理</value>
|
||||||
|
</data>
|
||||||
|
<data name="PresetTag_Wontfix_Description" xml:space="preserve">
|
||||||
|
<value>不会被处理</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_FileNamePattern" xml:space="preserve">
|
||||||
|
<value>{0}-导出-{1:yyyyMMdd-HHmmss}.md</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_TimePattern" xml:space="preserve">
|
||||||
|
<value>yyyy年M月d日 HH:mm</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_CardTimePattern" xml:space="preserve">
|
||||||
|
<value>yyyy年M月d日 HH:mm</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_WorkspaceHeading" xml:space="preserve">
|
||||||
|
<value># {0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_ExportedAtLine" xml:space="preserve">
|
||||||
|
<value>> 导出时间:{0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_ColumnHeading" xml:space="preserve">
|
||||||
|
<value>## 列:{0}({1})</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_TagsLine" xml:space="preserve">
|
||||||
|
<value>- 标签:{0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_CreatedModifiedLine" xml:space="preserve">
|
||||||
|
<value>- 创建:{0} 修改:{1}</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_TagsSummaryHeading" xml:space="preserve">
|
||||||
|
<value>## 标签总表</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_TagsTableHeader" xml:space="preserve">
|
||||||
|
<value>| 名称 | 颜色 | 描述 | 使用数 |</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_Done_Title" xml:space="preserve">
|
||||||
|
<value>导出完成</value>
|
||||||
|
</data>
|
||||||
|
<data name="Export_Done_Message" xml:space="preserve">
|
||||||
|
<value>已导出到:{0}</value>
|
||||||
|
</data>
|
||||||
|
</root>
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
using YKanBan.Models;
|
||||||
|
|
||||||
|
namespace YKanBan.Export;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates the human-readable Markdown snapshot of a whole board. All
|
||||||
|
/// template text and time formats come from the ResX resources in the current
|
||||||
|
/// UI language; the export timestamp uses the per-language pattern, card
|
||||||
|
/// timestamps use the shared minute-precision pattern. The output is meant for
|
||||||
|
/// reading only — there is no re-import.
|
||||||
|
/// </summary>
|
||||||
|
public static class MarkdownExporter {
|
||||||
|
/// <summary>
|
||||||
|
/// Renders the whole board to Markdown.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="workspaceName">Workspace display name (the folder name).</param>
|
||||||
|
/// <param name="columns">All columns, in id order; empty columns are kept.</param>
|
||||||
|
/// <param name="cards">All cards; grouped by column, id order within a column.</param>
|
||||||
|
/// <param name="tags">All tags with usage counts, in id order.</param>
|
||||||
|
/// <param name="exportedAt">Export moment in local time.</param>
|
||||||
|
/// <returns>The Markdown document.</returns>
|
||||||
|
public static string Export(
|
||||||
|
string workspaceName,
|
||||||
|
IReadOnlyList<ColumnModel> columns,
|
||||||
|
IReadOnlyList<CardModel> cards,
|
||||||
|
IReadOnlyList<(TagModel Tag, long UsageCount)> tags,
|
||||||
|
DateTimeOffset exportedAt) {
|
||||||
|
CultureInfo culture = Resources.Culture ?? CultureInfo.CurrentUICulture;
|
||||||
|
|
||||||
|
var builder = new StringBuilder();
|
||||||
|
|
||||||
|
// Header: workspace name and the export timestamp in the UI language's format.
|
||||||
|
builder.AppendLine(string.Format(culture, Resources.Export_WorkspaceHeading, workspaceName));
|
||||||
|
builder.AppendLine(string.Format(
|
||||||
|
culture, Resources.Export_ExportedAtLine, exportedAt.ToString(Resources.Export_TimePattern, culture)));
|
||||||
|
builder.AppendLine();
|
||||||
|
|
||||||
|
// Board body: every column in id order, empty ones included.
|
||||||
|
foreach (ColumnModel column in columns) {
|
||||||
|
IReadOnlyList<CardModel> cardsInColumn = cards.Where(card => card.ColumnId == column.Id).ToArray();
|
||||||
|
builder.AppendLine(string.Format(culture, Resources.Export_ColumnHeading, column.Title, cardsInColumn.Count));
|
||||||
|
if (column.Description.Length > 0) {
|
||||||
|
builder.AppendLine(SingleLine(column.Description));
|
||||||
|
}
|
||||||
|
builder.AppendLine();
|
||||||
|
|
||||||
|
foreach (CardModel card in cardsInColumn) {
|
||||||
|
AppendCard(builder, card, culture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AppendTagTable(builder, tags, culture);
|
||||||
|
return builder.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Builds the default export file name in the UI language, for example
|
||||||
|
/// "MyRepo-export-20260930-142537.md".
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="workspaceName">Workspace display name.</param>
|
||||||
|
/// <param name="exportedAt">Export moment.</param>
|
||||||
|
/// <returns>The file name.</returns>
|
||||||
|
public static string BuildFileName(string workspaceName, DateTimeOffset exportedAt) {
|
||||||
|
CultureInfo culture = Resources.Culture ?? CultureInfo.CurrentUICulture;
|
||||||
|
return string.Format(culture, Resources.Export_FileNamePattern, workspaceName, exportedAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Appends one card block: heading, body, tags line and timestamps line.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="builder">The output builder.</param>
|
||||||
|
/// <param name="card">The card to render.</param>
|
||||||
|
/// <param name="culture">The UI culture.</param>
|
||||||
|
private static void AppendCard(StringBuilder builder, CardModel card, CultureInfo culture) {
|
||||||
|
// Heading: "#id title"; an untitled card shows only the id.
|
||||||
|
builder.AppendLine(card.Title.Length == 0
|
||||||
|
? $"### #{card.Id}"
|
||||||
|
: $"### #{card.Id} {SingleLine(card.Title)}");
|
||||||
|
|
||||||
|
if (card.Content.Length > 0) {
|
||||||
|
builder.AppendLine(card.Content);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (card.Tags.Count > 0) {
|
||||||
|
string names = string.Join(" ", card.Tags.Select(tag => $"`{tag.Name}`"));
|
||||||
|
builder.AppendLine(string.Format(culture, Resources.Export_TagsLine, names));
|
||||||
|
}
|
||||||
|
|
||||||
|
string created = ToLocalTime(card.CreatedAt).ToString(Resources.Export_CardTimePattern, culture);
|
||||||
|
string updated = ToLocalTime(card.UpdatedAt).ToString(Resources.Export_CardTimePattern, culture);
|
||||||
|
builder.AppendLine(string.Format(culture, Resources.Export_CreatedModifiedLine, created, updated));
|
||||||
|
builder.AppendLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Appends the tag summary table with usage counts; tags with zero usage are included.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="builder">The output builder.</param>
|
||||||
|
/// <param name="tags">The tags and their usage counts.</param>
|
||||||
|
/// <param name="culture">The UI culture.</param>
|
||||||
|
private static void AppendTagTable(
|
||||||
|
StringBuilder builder,
|
||||||
|
IReadOnlyList<(TagModel Tag, long UsageCount)> tags,
|
||||||
|
CultureInfo culture) {
|
||||||
|
builder.AppendLine(Resources.Export_TagsSummaryHeading);
|
||||||
|
builder.AppendLine(Resources.Export_TagsTableHeader);
|
||||||
|
builder.AppendLine("|---|---|---|---|");
|
||||||
|
foreach ((TagModel tag, long usage) in tags) {
|
||||||
|
// '|' and line breaks would break the table row; neutralize them.
|
||||||
|
builder.AppendLine($"| {Cell(tag.Name)} | {tag.Color} | {Cell(tag.Description)} | {usage} |");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Formats a table cell: single line with escaped pipe characters.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">The raw cell text.</param>
|
||||||
|
/// <returns>The escaped single-line text.</returns>
|
||||||
|
private static string Cell(string text) => SingleLine(text).Replace("|", "\\|");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Collapses line breaks so the text stays on one Markdown line.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">The raw text.</param>
|
||||||
|
/// <returns>The text without line breaks.</returns>
|
||||||
|
private static string SingleLine(string text) => text.Replace("\r", string.Empty).Replace("\n", " ");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts stored Unix seconds to a local-time <see cref="DateTimeOffset"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="unixSeconds">The stored timestamp.</param>
|
||||||
|
/// <returns>The local time.</returns>
|
||||||
|
private static DateTimeOffset ToLocalTime(long unixSeconds) =>
|
||||||
|
DateTimeOffset.FromUnixTimeSeconds(unixSeconds).ToLocalTime();
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
|
namespace YKanBan.Launching;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Parses raw command-line arguments. The only accepted form is a single,
|
||||||
|
/// non-blank workspace path (<c>ykanban <path></c>); zero arguments,
|
||||||
|
/// more than one argument, or a blank argument is rejected as an argument
|
||||||
|
/// error. The path itself is not checked for existence here.
|
||||||
|
/// </summary>
|
||||||
|
public static class LaunchArguments {
|
||||||
|
/// <summary>
|
||||||
|
/// Tries to parse command-line arguments following the
|
||||||
|
/// <c>ykanban <path></c> contract.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="arguments">The raw arguments, excluding the executable name.</param>
|
||||||
|
/// <param name="folderPath">The parsed workspace path on success, otherwise <see langword="null"/>.</param>
|
||||||
|
/// <returns><see langword="true"/> when exactly one non-blank path was supplied.</returns>
|
||||||
|
public static bool TryParse(IReadOnlyList<string> arguments, [NotNullWhen(true)] out string? folderPath) {
|
||||||
|
if (arguments.Count == 1 && !string.IsNullOrWhiteSpace(arguments[0])) {
|
||||||
|
folderPath = arguments[0];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
folderPath = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
namespace YKanBan.Models;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A card with its assigned tags loaded.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Id">Row id.</param>
|
||||||
|
/// <param name="ColumnId">Owning column.</param>
|
||||||
|
/// <param name="Title">Possibly empty; the empty string is the canonical "no title".</param>
|
||||||
|
/// <param name="Content">Multiline body, possibly empty.</param>
|
||||||
|
/// <param name="CreatedAt">Unix seconds of creation.</param>
|
||||||
|
/// <param name="UpdatedAt">Unix seconds of the last confirmed edit write.</param>
|
||||||
|
/// <param name="Tags">Tags assigned to this card, ordered by tag id.</param>
|
||||||
|
public sealed record CardModel(
|
||||||
|
long Id,
|
||||||
|
long ColumnId,
|
||||||
|
string Title,
|
||||||
|
string Content,
|
||||||
|
long CreatedAt,
|
||||||
|
long UpdatedAt,
|
||||||
|
IReadOnlyList<TagModel> Tags);
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace YKanBan.Models;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A board column as stored in the workspace database.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Id">Row id.</param>
|
||||||
|
/// <param name="Title">Non-empty, table-unique title.</param>
|
||||||
|
/// <param name="Description">Free-form description, possibly empty.</param>
|
||||||
|
/// <param name="CreatedAt">Unix seconds of creation.</param>
|
||||||
|
/// <param name="UpdatedAt">Unix seconds of the last title/description change.</param>
|
||||||
|
public sealed record ColumnModel(long Id, string Title, string Description, long CreatedAt, long UpdatedAt);
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
namespace YKanBan.Models;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An RGB color without an alpha channel, stored as one byte per component —
|
||||||
|
/// mirroring the color structures of WinForms, WPF and Avalonia minus the
|
||||||
|
/// alpha byte. The type is total: every combination of components is valid,
|
||||||
|
/// and all validation happens at the text boundary.
|
||||||
|
///
|
||||||
|
/// It converts to and from the persisted "#RRGGBB" text form; <see cref="ToString"/>
|
||||||
|
/// always produces the canonical lowercase form (for example "#ff0a00"). It is
|
||||||
|
/// not specific to tags and may be reused anywhere a color value is needed.
|
||||||
|
/// </summary>
|
||||||
|
public readonly record struct RgbColor(byte R, byte G, byte B) {
|
||||||
|
/// <summary>
|
||||||
|
/// Parses a "#RRGGBB" text with case-insensitive hex digits.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">The text to parse.</param>
|
||||||
|
/// <returns>The parsed color.</returns>
|
||||||
|
/// <exception cref="FormatException">The text is not in #RRGGBB form.</exception>
|
||||||
|
public static RgbColor Parse(string text) =>
|
||||||
|
TryParse(text, out RgbColor color)
|
||||||
|
? color
|
||||||
|
: throw new FormatException($"Not a valid #RRGGBB color: '{text}'.");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attempts to parse a "#RRGGBB" text. There is no whitespace tolerance.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">The text to parse.</param>
|
||||||
|
/// <param name="color">The parsed color on success, otherwise the default value.</param>
|
||||||
|
/// <returns><see langword="true"/> when the text is exactly #RRGGBB.</returns>
|
||||||
|
public static bool TryParse(string? text, out RgbColor color) {
|
||||||
|
color = default;
|
||||||
|
if (text is not { Length: 7 } || text[0] != '#') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Two hex digits per component: R, G, B.
|
||||||
|
if (TryHexPair(text, 1, out byte r) && TryHexPair(text, 3, out byte g) && TryHexPair(text, 5, out byte b)) {
|
||||||
|
color = new RgbColor(r, g, b);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the canonical lowercase "#RRGGBB" form used by the database and exports.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The lowercase #RRGGBB text.</returns>
|
||||||
|
public override string ToString() => $"#{R:x2}{G:x2}{B:x2}";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Parses exactly two hex digits into a byte value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">The source text.</param>
|
||||||
|
/// <param name="start">Index of the first of the two digits.</param>
|
||||||
|
/// <param name="value">The parsed byte value.</param>
|
||||||
|
/// <returns><see langword="true"/> when both characters are hex digits.</returns>
|
||||||
|
private static bool TryHexPair(string text, int start, out byte value) {
|
||||||
|
value = 0;
|
||||||
|
int high = HexDigit(text[start]);
|
||||||
|
int low = HexDigit(text[start + 1]);
|
||||||
|
if (high < 0 || low < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
value = (byte)((high << 4) | low);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts one hex digit to its value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="character">The character to convert.</param>
|
||||||
|
/// <returns>The digit value, or -1 for any other character.</returns>
|
||||||
|
private static int HexDigit(char character) => character switch {
|
||||||
|
>= '0' and <= '9' => character - '0',
|
||||||
|
>= 'a' and <= 'f' => character - 'a' + 10,
|
||||||
|
>= 'A' and <= 'F' => character - 'A' + 10,
|
||||||
|
_ => -1,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace YKanBan.Models;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A tag assignable to cards. Tags are never garbage-collected: unreferenced
|
||||||
|
/// tags stay until they are deleted explicitly.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Id">Row id.</param>
|
||||||
|
/// <param name="Name">Arbitrary non-empty text; no charset or length rules.</param>
|
||||||
|
/// <param name="Color">The tag color; persisted as #RRGGBB text.</param>
|
||||||
|
/// <param name="Description">Free-form description, possibly empty.</param>
|
||||||
|
public sealed record TagModel(long Id, string Name, RgbColor Color, string Description);
|
||||||
+8
-5
@@ -1,16 +1,19 @@
|
|||||||
using Avalonia;
|
using Avalonia;
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace YKanBan;
|
namespace YKanBan;
|
||||||
|
|
||||||
sealed class Program
|
sealed class Program {
|
||||||
{
|
|
||||||
// Initialization code. Don't use any Avalonia, third-party APIs or any
|
// Initialization code. Don't use any Avalonia, third-party APIs or any
|
||||||
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
||||||
// yet and stuff might break.
|
// yet and stuff might break.
|
||||||
[STAThread]
|
[STAThread]
|
||||||
public static void Main(string[] args) => BuildAvaloniaApp()
|
public static void Main(string[] args) {
|
||||||
.StartWithClassicDesktopLifetime(args);
|
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
|
||||||
|
|
||||||
|
// The lifetime has ended: persist the configuration once, then release services.
|
||||||
|
App.Services?.SaveConfiguration();
|
||||||
|
App.Services?.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
// Avalonia configuration, don't remove; also used by visual designer.
|
// Avalonia configuration, don't remove; also used by visual designer.
|
||||||
public static AppBuilder BuildAvaloniaApp()
|
public static AppBuilder BuildAvaloniaApp()
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
using Pidgin;
|
||||||
|
|
||||||
|
namespace YKanBan.Search;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Lexical tokens of the search syntax.
|
||||||
|
/// </summary>
|
||||||
|
public abstract record SearchToken {
|
||||||
|
/// <summary>
|
||||||
|
/// A bare word; qualifier detection happens later from the text.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Text">The word text.</param>
|
||||||
|
public sealed record Word(string Text) : SearchToken;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A quoted phrase with its escapes already resolved.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Text">The unescaped phrase content.</param>
|
||||||
|
public sealed record Phrase(string Text) : SearchToken;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An opening parenthesis.
|
||||||
|
/// </summary>
|
||||||
|
public sealed record OpenParen : SearchToken;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A closing parenthesis.
|
||||||
|
/// </summary>
|
||||||
|
public sealed record CloseParen : SearchToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Pidgin-based lexer for the search syntax. Splits the input into words,
|
||||||
|
/// quoted phrases and parentheses; whitespace only separates tokens.
|
||||||
|
///
|
||||||
|
/// The lexer is strict: inside a phrase only <c>\"</c> and <c>\\</c> are valid
|
||||||
|
/// escapes, a bare backslash or an unknown escape is rejected, and an
|
||||||
|
/// unterminated phrase is rejected. Any input not covered by the token rules
|
||||||
|
/// is rejected rather than silently ignored.
|
||||||
|
/// </summary>
|
||||||
|
public static class SearchLexer {
|
||||||
|
/// <summary>
|
||||||
|
/// A valid phrase escape sequence: <c>\"</c> or <c>\\</c>.
|
||||||
|
/// </summary>
|
||||||
|
private static readonly Parser<char, char> PhraseEscape =
|
||||||
|
Parser.Try(Parser.String("\\\"").Select(_ => '"'))
|
||||||
|
.Or(Parser.String("\\\\").Select(_ => '\\'));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// One phrase character: an escape or any character except a quote or backslash.
|
||||||
|
/// </summary>
|
||||||
|
private static readonly Parser<char, char> PhraseCharacter =
|
||||||
|
PhraseEscape.Or(Parser<char>.Token(character => character != '"' && character != '\\'));
|
||||||
|
|
||||||
|
private static readonly Parser<char, SearchToken> PhraseParser =
|
||||||
|
from openingQuote in Parser.Char('"')
|
||||||
|
from content in PhraseCharacter.Many()
|
||||||
|
from closingQuote in Parser.Char('"')
|
||||||
|
select (SearchToken)new SearchToken.Phrase(new string(content.ToArray()));
|
||||||
|
|
||||||
|
private static readonly Parser<char, SearchToken> OpenParenParser =
|
||||||
|
Parser.Char('(').Select(_ => (SearchToken)new SearchToken.OpenParen());
|
||||||
|
|
||||||
|
private static readonly Parser<char, SearchToken> CloseParenParser =
|
||||||
|
Parser.Char(')').Select(_ => (SearchToken)new SearchToken.CloseParen());
|
||||||
|
|
||||||
|
private static readonly Parser<char, SearchToken> WordParser =
|
||||||
|
Parser<char>.Token(character =>
|
||||||
|
!char.IsWhiteSpace(character) && character != '(' && character != ')' && character != '"')
|
||||||
|
.AtLeastOnce()
|
||||||
|
.Select(chars => (SearchToken)new SearchToken.Word(new string(chars.ToArray())));
|
||||||
|
|
||||||
|
private static readonly Parser<char, SearchToken> TokenParser =
|
||||||
|
Parser.SkipWhitespaces.Then(
|
||||||
|
PhraseParser
|
||||||
|
.Or(OpenParenParser)
|
||||||
|
.Or(CloseParenParser)
|
||||||
|
.Or(WordParser));
|
||||||
|
|
||||||
|
// Try(...) keeps a failed token non-consuming so Many stops gracefully; End
|
||||||
|
// then rejects any leftover input, which turns dangling quotes or invalid
|
||||||
|
// escapes into hard failures instead of silently dropped text.
|
||||||
|
private static readonly Parser<char, IReadOnlyList<SearchToken>> Lexer =
|
||||||
|
Parser.Try(TokenParser).Many()
|
||||||
|
.Before(Parser.SkipWhitespaces)
|
||||||
|
.Before(Parser<char>.End)
|
||||||
|
.Select(tokens => (IReadOnlyList<SearchToken>)tokens.ToList());
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tokenizes the search text.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">The raw search text.</param>
|
||||||
|
/// <returns>The token stream.</returns>
|
||||||
|
/// <exception cref="SearchSyntaxException">The text contains an invalid escape or an unterminated phrase.</exception>
|
||||||
|
public static IReadOnlyList<SearchToken> Tokenize(string input) {
|
||||||
|
try {
|
||||||
|
return Lexer.ParseOrThrow(input);
|
||||||
|
} catch (ParseException exception) {
|
||||||
|
throw new SearchSyntaxException(exception.Message, exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
// YYC MARK: C# records synthesize equality by running EqualityComparer<T>.Default
|
||||||
|
// on each positional property. For collection properties (IReadOnlyList<>,
|
||||||
|
// ImmutableArray<>, arrays, ...) that comparer falls back to REFERENCE equality,
|
||||||
|
// so the Or/And nodes below deliberately do NOT compare structurally. The only
|
||||||
|
// structural comparison lives in the test helper (SearchNodeComparer); production
|
||||||
|
// code never compares AST nodes.
|
||||||
|
namespace YKanBan.Search;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Root of the search query AST. Search keywords are fixed English grammar
|
||||||
|
/// and are never localized.
|
||||||
|
/// </summary>
|
||||||
|
public abstract record SearchNode {
|
||||||
|
/// <summary>
|
||||||
|
/// Disjunction: matches when any term matches (OR).
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Terms">The alternative terms.</param>
|
||||||
|
public sealed record Or(IReadOnlyList<SearchNode> Terms) : SearchNode;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Conjunction: matches when all terms match (explicit AND or adjacency).
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Terms">The required terms.</param>
|
||||||
|
public sealed record And(IReadOnlyList<SearchNode> Terms) : SearchNode;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A bare word or phrase matched as a substring of the title OR content.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Text">The search text.</param>
|
||||||
|
public sealed record FreeText(string Text) : SearchNode;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A substring match scoped to one card field.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Field">The card field to match against.</param>
|
||||||
|
/// <param name="Text">The search text.</param>
|
||||||
|
public sealed record FieldText(SearchField Field, string Text) : SearchNode;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An exact, case-insensitive tag name match.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Name">The tag name to match.</param>
|
||||||
|
public sealed record TagName(string Name) : SearchNode;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An exact, case-insensitive column title match.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Title">The column title to match.</param>
|
||||||
|
public sealed record ColumnTitle(string Title) : SearchNode;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An exact card id match.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Id">The card id to match.</param>
|
||||||
|
public sealed record CardId(long Id) : SearchNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The card fields a <see cref="SearchNode.FieldText"/> atom can scope to.
|
||||||
|
/// </summary>
|
||||||
|
public enum SearchField {
|
||||||
|
/// <summary>
|
||||||
|
/// The card title.
|
||||||
|
/// </summary>
|
||||||
|
Title,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The card content body.
|
||||||
|
/// </summary>
|
||||||
|
Content,
|
||||||
|
}
|
||||||
@@ -0,0 +1,249 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
using Pidgin;
|
||||||
|
|
||||||
|
namespace YKanBan.Search;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Parses the search grammar with Pidgin, strictly: any malformed input
|
||||||
|
/// (unbalanced parentheses, dangling or consecutive operators, unterminated
|
||||||
|
/// phrases, invalid escapes, qualifier keys without a value or with an
|
||||||
|
/// unknown/non-numeric id value) raises <see cref="SearchSyntaxException"/>.
|
||||||
|
///
|
||||||
|
/// Only uppercase AND/OR are operators (lowercase ones are plain words); AND —
|
||||||
|
/// explicit or by adjacency — binds tighter than OR; parentheses group. Blank
|
||||||
|
/// input returns null and means "show everything". Search keywords and
|
||||||
|
/// qualifier keys are fixed English grammar and are never localized.
|
||||||
|
/// </summary>
|
||||||
|
public static class SearchQueryParser {
|
||||||
|
/// <summary>
|
||||||
|
/// The recognized qualifier keys; add new entries here to extend the grammar.
|
||||||
|
/// </summary>
|
||||||
|
private static readonly (string Key, QualifierKind Kind)[] QualifierTable =
|
||||||
|
[
|
||||||
|
("tag", QualifierKind.Tag),
|
||||||
|
("title", QualifierKind.Title),
|
||||||
|
("content", QualifierKind.Content),
|
||||||
|
("id", QualifierKind.Id),
|
||||||
|
("column", QualifierKind.Column),
|
||||||
|
];
|
||||||
|
|
||||||
|
#region Token primitives
|
||||||
|
|
||||||
|
private static readonly Parser<SearchToken, SearchToken> AndKeyword =
|
||||||
|
Parser<SearchToken>.Token(token => token is SearchToken.Word { Text: "AND" });
|
||||||
|
|
||||||
|
private static readonly Parser<SearchToken, SearchToken> OrKeyword =
|
||||||
|
Parser<SearchToken>.Token(token => token is SearchToken.Word { Text: "OR" });
|
||||||
|
|
||||||
|
private static readonly Parser<SearchToken, SearchToken> OpenParen =
|
||||||
|
Parser<SearchToken>.Token(token => token is SearchToken.OpenParen);
|
||||||
|
|
||||||
|
private static readonly Parser<SearchToken, SearchToken> CloseParen =
|
||||||
|
Parser<SearchToken>.Token(token => token is SearchToken.CloseParen);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The text of a phrase token.
|
||||||
|
/// </summary>
|
||||||
|
private static readonly Parser<SearchToken, string> PhraseText =
|
||||||
|
Parser<SearchToken>.Token(token => token is SearchToken.Phrase)
|
||||||
|
.Select(token => ((SearchToken.Phrase)token).Text);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The text of a word token, operator keywords excluded (they never start an operand).
|
||||||
|
/// </summary>
|
||||||
|
private static readonly Parser<SearchToken, string> NonKeywordWord =
|
||||||
|
Parser<SearchToken>.Token(token => token is SearchToken.Word word && word.Text != "AND" && word.Text != "OR")
|
||||||
|
.Select(token => ((SearchToken.Word)token).Text);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Grammar
|
||||||
|
|
||||||
|
// A bare phrase matched against title or content.
|
||||||
|
private static readonly Parser<SearchToken, SearchNode> FreePhrase =
|
||||||
|
PhraseText.Select(text => (SearchNode)new SearchNode.FreeText(text));
|
||||||
|
|
||||||
|
// A bare word: a "key:value" qualifier when the prefix matches, otherwise free text.
|
||||||
|
private static readonly Parser<SearchToken, SearchNode> WordAtom =
|
||||||
|
NonKeywordWord.Bind(QualifierFrom);
|
||||||
|
|
||||||
|
// '(' orExpr ')' — the deferred method call breaks the
|
||||||
|
// Parenthesized → OrExpr → AndExpr → Operand → Parenthesized recursion cycle.
|
||||||
|
private static readonly Parser<SearchToken, SearchNode> Parenthesized =
|
||||||
|
OpenParen.Then(_ => OrExprDeferred()).Before(CloseParen);
|
||||||
|
|
||||||
|
// operand := '(' orExpr ')' | qualifier-or-word | phrase
|
||||||
|
private static readonly Parser<SearchToken, SearchNode> Operand =
|
||||||
|
Parenthesized.Or(WordAtom).Or(FreePhrase);
|
||||||
|
|
||||||
|
// One andExpr operand together with its optional explicit AND keyword.
|
||||||
|
private static readonly Parser<SearchToken, SearchNode> AndPrefixedOperand =
|
||||||
|
AndKeyword.Optional().Then(Operand);
|
||||||
|
|
||||||
|
// andExpr := operand (AND? operand)*
|
||||||
|
private static readonly Parser<SearchToken, SearchNode> AndExpr =
|
||||||
|
Operand.Bind(first =>
|
||||||
|
AndPrefixedOperand.Many()
|
||||||
|
.Select(rest => FoldAnd(first, rest)));
|
||||||
|
|
||||||
|
// orExpr := andExpr (OR andExpr)+
|
||||||
|
private static readonly Parser<SearchToken, SearchNode> OrExpr =
|
||||||
|
AndExpr.SeparatedAtLeastOnce(OrKeyword)
|
||||||
|
.Select(FoldOr);
|
||||||
|
|
||||||
|
// The full query: orExpr consuming the whole token stream.
|
||||||
|
private static readonly Parser<SearchToken, SearchNode> Query =
|
||||||
|
OrExpr.Before(Parser<SearchToken>.End);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Defers the OrExpr field read to parse time (recursion cycle breaker).
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The OR-expression parser.</returns>
|
||||||
|
private static Parser<SearchToken, SearchNode> OrExprDeferred() => OrExpr;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Parses a search box text.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">The raw search text.</param>
|
||||||
|
/// <returns>The parsed query, or <see langword="null"/> for blank input (meaning: show everything).</returns>
|
||||||
|
/// <exception cref="SearchSyntaxException">The text violates the grammar.</exception>
|
||||||
|
public static SearchNode? Parse(string text) {
|
||||||
|
if (string.IsNullOrWhiteSpace(text)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
List<SearchToken> tokens = SearchLexer.Tokenize(text).ToList();
|
||||||
|
return Query.ParseOrThrow(tokens);
|
||||||
|
} catch (ParseException exception) {
|
||||||
|
throw new SearchSyntaxException(exception.Message, exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Atom construction
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Builds the parser for one word operand: a qualifier atom, an unknown-key
|
||||||
|
/// failure, or free text.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="word">The word token text.</param>
|
||||||
|
/// <returns>The parser producing the operand node.</returns>
|
||||||
|
private static Parser<SearchToken, SearchNode> QualifierFrom(string word) {
|
||||||
|
int colonIndex = word.IndexOf(':');
|
||||||
|
|
||||||
|
// Only a leading run of letters/digits/underscores before ':' can be a qualifier key.
|
||||||
|
if (colonIndex <= 0 || !IsQualifierKeyCandidate(word.AsSpan(0, colonIndex))) {
|
||||||
|
return Parser<SearchToken>.Return<SearchNode>(new SearchNode.FreeText(word));
|
||||||
|
}
|
||||||
|
|
||||||
|
string key = word[..colonIndex];
|
||||||
|
string value = word[(colonIndex + 1)..];
|
||||||
|
|
||||||
|
if (!TryLookupQualifier(key, out QualifierKind kind)) {
|
||||||
|
return Parser<SearchToken>.Fail<SearchNode>($"Unknown qualifier key '{key}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// "key:" without an inline value takes the value from the following phrase, e.g. tag:"a b".
|
||||||
|
return value.Length == 0
|
||||||
|
? PhraseText.Bind(text => AtomParser(kind, text))
|
||||||
|
: AtomParser(kind, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Builds the atom parser for a qualifier value, failing strictly on a non-numeric id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="kind">The qualifier kind.</param>
|
||||||
|
/// <param name="value">The qualifier value.</param>
|
||||||
|
/// <returns>The parser producing the atom node.</returns>
|
||||||
|
private static Parser<SearchToken, SearchNode> AtomParser(QualifierKind kind, string value) =>
|
||||||
|
AtomFrom(kind, value) is { } atom
|
||||||
|
? Parser<SearchToken>.Return(atom)
|
||||||
|
: Parser<SearchToken>.Fail<SearchNode>($"The id qualifier expects an integer, got '{value}'.");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Builds the atom for a qualifier value; null when an id value is not an integer.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="kind">The qualifier kind.</param>
|
||||||
|
/// <param name="value">The qualifier value.</param>
|
||||||
|
/// <returns>The atom node, or <see langword="null"/> for an invalid id value.</returns>
|
||||||
|
private static SearchNode? AtomFrom(QualifierKind kind, string value) => kind switch {
|
||||||
|
QualifierKind.Tag => new SearchNode.TagName(value),
|
||||||
|
QualifierKind.Title => new SearchNode.FieldText(SearchField.Title, value),
|
||||||
|
QualifierKind.Content => new SearchNode.FieldText(SearchField.Content, value),
|
||||||
|
QualifierKind.Column => new SearchNode.ColumnTitle(value),
|
||||||
|
QualifierKind.Id when long.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out long id) =>
|
||||||
|
new SearchNode.CardId(id),
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a qualifier key in the extension table with ordinal (case-sensitive) matching.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">The key text before the colon.</param>
|
||||||
|
/// <param name="kind">The matching qualifier kind.</param>
|
||||||
|
/// <returns><see langword="true"/> when the key is known.</returns>
|
||||||
|
private static bool TryLookupQualifier(string key, out QualifierKind kind) {
|
||||||
|
foreach ((string candidate, QualifierKind candidateKind) in QualifierTable) {
|
||||||
|
if (string.Equals(candidate, key, StringComparison.Ordinal)) {
|
||||||
|
kind = candidateKind;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kind = default;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns whether the text looks like a qualifier key: a non-empty run of
|
||||||
|
/// letters, digits or underscores.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">The candidate key text.</param>
|
||||||
|
/// <returns><see langword="true"/> when every character is a word character.</returns>
|
||||||
|
private static bool IsQualifierKeyCandidate(ReadOnlySpan<char> text) {
|
||||||
|
foreach (char character in text) {
|
||||||
|
if (!(char.IsLetterOrDigit(character) || character == '_')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Collapses an AND chain into a single node.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="first">The first operand.</param>
|
||||||
|
/// <param name="rest">The remaining operands.</param>
|
||||||
|
/// <returns>The single operand, or an <see cref="SearchNode.And"/> node.</returns>
|
||||||
|
private static SearchNode FoldAnd(SearchNode first, IEnumerable<SearchNode> rest) {
|
||||||
|
List<SearchNode> terms = [first, .. rest];
|
||||||
|
return terms.Count == 1 ? terms[0] : new SearchNode.And(terms);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Collapses an OR chain into a single node.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="terms">The operands.</param>
|
||||||
|
/// <returns>The single operand, or a <see cref="SearchNode.Or"/> node.</returns>
|
||||||
|
private static SearchNode FoldOr(IEnumerable<SearchNode> terms) {
|
||||||
|
List<SearchNode> list = terms.ToList();
|
||||||
|
return list.Count == 1 ? list[0] : new SearchNode.Or(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The recognized qualifier kinds.
|
||||||
|
/// </summary>
|
||||||
|
private enum QualifierKind {
|
||||||
|
Tag,
|
||||||
|
Title,
|
||||||
|
Content,
|
||||||
|
Id,
|
||||||
|
Column,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
namespace YKanBan.Search;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A compiled search predicate: a SQL fragment over the "c" (cards) alias plus
|
||||||
|
/// its bound parameters.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Predicate">SQL boolean expression, for <c>SELECT ... FROM cards c WHERE {Predicate}</c>.</param>
|
||||||
|
/// <param name="Parameters">Named parameters referenced by the predicate, in order.</param>
|
||||||
|
public sealed record CompiledSearch(string Predicate, IReadOnlyList<(string Name, object Value)> Parameters);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compiles a parsed search AST into a parameterized SQL predicate. Matching is
|
||||||
|
/// case-insensitive with SQLite's built-in semantics: LIKE's default case
|
||||||
|
/// folding for substring matches plus COLLATE NOCASE for exact matches. LIKE
|
||||||
|
/// wildcards and the escape character in user text are escaped so they match
|
||||||
|
/// literally.
|
||||||
|
/// </summary>
|
||||||
|
public static class SearchSqlCompiler {
|
||||||
|
/// <summary>
|
||||||
|
/// Compiles the query into a SQL predicate.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query">The parsed search AST.</param>
|
||||||
|
/// <returns>The compiled predicate and its parameters.</returns>
|
||||||
|
public static CompiledSearch Compile(SearchNode query) {
|
||||||
|
var parameters = new List<(string Name, object Value)>();
|
||||||
|
string predicate = Build(query, parameters);
|
||||||
|
return new CompiledSearch(predicate, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Recursively builds the SQL expression for one node.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="node">The AST node to compile.</param>
|
||||||
|
/// <param name="parameters">The parameter accumulator.</param>
|
||||||
|
/// <returns>The SQL boolean expression for the node.</returns>
|
||||||
|
private static string Build(SearchNode node, List<(string Name, object Value)> parameters) {
|
||||||
|
switch (node) {
|
||||||
|
case SearchNode.And and:
|
||||||
|
return "(" + string.Join(" AND ", and.Terms.Select(term => Build(term, parameters))) + ")";
|
||||||
|
|
||||||
|
case SearchNode.Or or:
|
||||||
|
return "(" + string.Join(" OR ", or.Terms.Select(term => Build(term, parameters))) + ")";
|
||||||
|
|
||||||
|
case SearchNode.FreeText freeText: {
|
||||||
|
// A bare word matches a substring of the title OR the content.
|
||||||
|
string titleParam = AddParameter(parameters, "%" + EscapeLike(freeText.Text) + "%");
|
||||||
|
string contentParam = AddParameter(parameters, "%" + EscapeLike(freeText.Text) + "%");
|
||||||
|
return $"(c.title LIKE {titleParam} ESCAPE '\\' OR c.content LIKE {contentParam} ESCAPE '\\')";
|
||||||
|
}
|
||||||
|
|
||||||
|
case SearchNode.FieldText field: {
|
||||||
|
string column = field.Field == SearchField.Title ? "c.title" : "c.content";
|
||||||
|
string param = AddParameter(parameters, "%" + EscapeLike(field.Text) + "%");
|
||||||
|
return $"{column} LIKE {param} ESCAPE '\\'";
|
||||||
|
}
|
||||||
|
|
||||||
|
case SearchNode.TagName tag: {
|
||||||
|
string param = AddParameter(parameters, tag.Name);
|
||||||
|
return "EXISTS (SELECT 1 FROM card_tags ct JOIN tags t ON t.id = ct.tag_id " +
|
||||||
|
$"WHERE ct.card_id = c.id AND t.name COLLATE NOCASE = {param})";
|
||||||
|
}
|
||||||
|
|
||||||
|
case SearchNode.ColumnTitle column: {
|
||||||
|
string param = AddParameter(parameters, column.Title);
|
||||||
|
return $"c.column_id IN (SELECT id FROM columns WHERE title COLLATE NOCASE = {param})";
|
||||||
|
}
|
||||||
|
|
||||||
|
case SearchNode.CardId id: {
|
||||||
|
string param = AddParameter(parameters, id.Id);
|
||||||
|
return $"c.id = {param}";
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new InvalidOperationException($"Unsupported search node: {node.GetType().Name}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Binds a value under a fresh name and returns the SQL placeholder.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parameters">The parameter accumulator.</param>
|
||||||
|
/// <param name="value">The value to bind.</param>
|
||||||
|
/// <returns>The placeholder text.</returns>
|
||||||
|
private static string AddParameter(List<(string Name, object Value)> parameters, object value) {
|
||||||
|
string name = "$p" + parameters.Count.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||||
|
parameters.Add((name, value));
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Escapes LIKE wildcards and the escape character inside user text.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">The raw user text.</param>
|
||||||
|
/// <returns>The text with <c>\</c>, <c>%</c> and <c>_</c> escaped.</returns>
|
||||||
|
private static string EscapeLike(string text) =>
|
||||||
|
text.Replace("\\", "\\\\").Replace("%", "\\%").Replace("_", "\\_");
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
namespace YKanBan.Search;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Thrown when the search text violates the search grammar. Carries the
|
||||||
|
/// underlying parser's descriptive English message; the UI surfaces it as a
|
||||||
|
/// search error instead of coupling to Pidgin types. The message is never
|
||||||
|
/// localized.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class SearchSyntaxException : Exception {
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the exception with a descriptive English message.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">The English diagnostic message.</param>
|
||||||
|
/// <param name="innerException">The underlying parse failure.</param>
|
||||||
|
public SearchSyntaxException(string message, Exception innerException)
|
||||||
|
: base(message, innerException) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
using YKanBan.Storage.AppData;
|
||||||
|
using YKanBan.Storage.Workspace;
|
||||||
|
|
||||||
|
namespace YKanBan.Services;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Composition root for the whole process: owns the loaded configuration and
|
||||||
|
/// the single open workspace session. The configuration is persisted once at
|
||||||
|
/// shutdown; the session (lock plus connection) lives until disposal.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class AppServices : IDisposable {
|
||||||
|
/// <summary>
|
||||||
|
/// Loads the configuration and prepares the service graph.
|
||||||
|
/// </summary>
|
||||||
|
public AppServices() {
|
||||||
|
ConfigStore = new AppConfigStore(AppDataPaths.AppConfigJsonPath);
|
||||||
|
Config = ConfigStore.Load();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the mutable application configuration, persisted at shutdown.
|
||||||
|
/// </summary>
|
||||||
|
public AppConfig Config { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the store backing app.json.
|
||||||
|
/// </summary>
|
||||||
|
public AppConfigStore ConfigStore { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the open workspace session, or <see langword="null"/> while no
|
||||||
|
/// workspace is open (for example on an error page).
|
||||||
|
/// </summary>
|
||||||
|
public WorkspaceSession? Session { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens a workspace, acquiring its exclusive lock and connection.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The workspace folder to open.</param>
|
||||||
|
/// <returns>The open session.</returns>
|
||||||
|
/// <exception cref="YKanBan.Storage.WorkspaceNotInitializedException">The folder has no .ykanban structure.</exception>
|
||||||
|
/// <exception cref="YKanBan.Storage.WorkspaceLockException">Another instance already holds the lock.</exception>
|
||||||
|
public WorkspaceSession OpenWorkspace(string folderPath) {
|
||||||
|
Session = WorkspaceSession.Open(folderPath);
|
||||||
|
return Session;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Persists the configuration; called once at shutdown.
|
||||||
|
/// </summary>
|
||||||
|
public void SaveConfiguration() => ConfigStore.Save(Config);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Releases the workspace session, if any.
|
||||||
|
/// </summary>
|
||||||
|
public void Dispose() => Session?.Dispose();
|
||||||
|
}
|
||||||
@@ -0,0 +1,230 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace YKanBan.Storage.AppData;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Display ordering options, used for both cards and columns. Except for the id
|
||||||
|
/// order, every option falls back to id ascending as the final tie-breaker.
|
||||||
|
/// </summary>
|
||||||
|
public enum SortOption {
|
||||||
|
/// <summary>
|
||||||
|
/// Primary key ascending.
|
||||||
|
/// </summary>
|
||||||
|
[EnumMember(Value = "id-asc")]
|
||||||
|
IdAscending,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Primary key descending.
|
||||||
|
/// </summary>
|
||||||
|
[EnumMember(Value = "id-desc")]
|
||||||
|
IdDescending,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creation time ascending.
|
||||||
|
/// </summary>
|
||||||
|
[EnumMember(Value = "created-asc")]
|
||||||
|
CreatedAscending,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creation time descending.
|
||||||
|
/// </summary>
|
||||||
|
[EnumMember(Value = "created-desc")]
|
||||||
|
CreatedDescending,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Last modification time ascending.
|
||||||
|
/// </summary>
|
||||||
|
[EnumMember(Value = "updated-asc")]
|
||||||
|
UpdatedAscending,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Last modification time descending.
|
||||||
|
/// </summary>
|
||||||
|
[EnumMember(Value = "updated-desc")]
|
||||||
|
UpdatedDescending,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Title by code points (BINARY collation) ascending.
|
||||||
|
/// </summary>
|
||||||
|
[EnumMember(Value = "title-asc")]
|
||||||
|
TitleAscending,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Title by code points (BINARY collation) descending.
|
||||||
|
/// </summary>
|
||||||
|
[EnumMember(Value = "title-desc")]
|
||||||
|
TitleDescending,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Column width presets. <see cref="Custom"/> uses a user-defined pixel width.
|
||||||
|
/// </summary>
|
||||||
|
public enum ColumnWidthPreset {
|
||||||
|
/// <summary>
|
||||||
|
/// Narrow preset.
|
||||||
|
/// </summary>
|
||||||
|
[EnumMember(Value = "narrow")]
|
||||||
|
Narrow,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Standard preset (320 px, the default).
|
||||||
|
/// </summary>
|
||||||
|
[EnumMember(Value = "standard")]
|
||||||
|
Standard,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Wide preset.
|
||||||
|
/// </summary>
|
||||||
|
[EnumMember(Value = "wide")]
|
||||||
|
Wide,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// User-defined pixel width (160–720).
|
||||||
|
/// </summary>
|
||||||
|
[EnumMember(Value = "custom")]
|
||||||
|
Custom,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// UI theme selection.
|
||||||
|
/// </summary>
|
||||||
|
public enum ThemeOption {
|
||||||
|
/// <summary>
|
||||||
|
/// Always light.
|
||||||
|
/// </summary>
|
||||||
|
[EnumMember(Value = "light")]
|
||||||
|
Light,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Always dark.
|
||||||
|
/// </summary>
|
||||||
|
[EnumMember(Value = "dark")]
|
||||||
|
Dark,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Follow the operating system setting (default).
|
||||||
|
/// </summary>
|
||||||
|
[EnumMember(Value = "follow-system")]
|
||||||
|
FollowSystem,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Board column width settings, applied globally.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class ColumnWidthSettings {
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the active width preset.
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("preset")]
|
||||||
|
public ColumnWidthPreset Preset { get; set; } = ColumnWidthPreset.Standard;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the manual width in pixels, used when <see cref="Preset"/>
|
||||||
|
/// is <see cref="ColumnWidthPreset.Custom"/> (range 160–720).
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("custom-pixels")]
|
||||||
|
public int CustomPixels { get; set; } = 320;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Everything that controls how the board is displayed: the column width and
|
||||||
|
/// the card and column ordering.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class DisplaySettings {
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the board column width settings.
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("column-width")]
|
||||||
|
public ColumnWidthSettings ColumnWidth { get; set; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the order of cards within their column.
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("card-sort")]
|
||||||
|
public SortOption CardSort { get; set; } = SortOption.IdAscending;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the left-to-right order of the columns.
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("column-sort")]
|
||||||
|
public SortOption ColumnSort { get; set; } = SortOption.IdAscending;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Confirmation-dialog toggles for the destructive actions.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class ConfirmationSettings {
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets whether deleting a card asks for confirmation.
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("delete-card")]
|
||||||
|
public bool DeleteCard { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets whether deleting a column asks for confirmation.
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("delete-column")]
|
||||||
|
public bool DeleteColumn { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets whether deleting a tag asks for confirmation.
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("delete-tag")]
|
||||||
|
public bool DeleteTag { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets whether discarding card edits asks for confirmation.
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("discard-edit")]
|
||||||
|
public bool DiscardEdit { get; set; } = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Root object of app.json, the whole-file key/value configuration store.
|
||||||
|
/// Keys and enum values are serialized in kebab-case (declared explicitly via
|
||||||
|
/// <see cref="JsonPropertyAttribute"/> and <see cref="EnumMemberAttribute"/>).
|
||||||
|
/// The <c>version</c> field is the migration hook for future format changes.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class AppConfig {
|
||||||
|
/// <summary>
|
||||||
|
/// Current configuration format version.
|
||||||
|
/// </summary>
|
||||||
|
public const int CurrentFormatVersion = 1;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Default UI language code.
|
||||||
|
/// </summary>
|
||||||
|
public const string DefaultLanguage = "en";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the configuration format version of this file.
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("version")]
|
||||||
|
public int Version { get; set; } = CurrentFormatVersion;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the UI language code ("en" default or "zh-Hans").
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("language")]
|
||||||
|
public string Language { get; set; } = DefaultLanguage;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the UI theme selection (default: follow the system).
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("theme")]
|
||||||
|
public ThemeOption Theme { get; set; } = ThemeOption.FollowSystem;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the board display settings (width and ordering).
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("display")]
|
||||||
|
public DisplaySettings Display { get; set; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the confirmation-dialog settings.
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("confirmations")]
|
||||||
|
public ConfirmationSettings Confirmations { get; set; } = new();
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Converters;
|
||||||
|
|
||||||
|
namespace YKanBan.Storage.AppData;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads and saves app.json with graceful degradation: a missing file yields
|
||||||
|
/// defaults; a corrupt file is backed up to app.json.bak and then defaults are
|
||||||
|
/// used. Saving writes the file directly (no atomic replace) — losing the last
|
||||||
|
/// session's settings to a crash is an accepted trade-off.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class AppConfigStore {
|
||||||
|
private static readonly JsonSerializerSettings SerializerSettings = new() {
|
||||||
|
Formatting = Formatting.Indented,
|
||||||
|
NullValueHandling = NullValueHandling.Ignore,
|
||||||
|
|
||||||
|
// Enums round-trip through the kebab-case strings declared via [EnumMember].
|
||||||
|
Converters = { new StringEnumConverter() },
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a store bound to a specific app.json path.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filePath">Full path of the app.json file to manage.</param>
|
||||||
|
public AppConfigStore(string filePath) => FilePath = filePath;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the full path of the managed app.json file.
|
||||||
|
/// </summary>
|
||||||
|
public string FilePath { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads the configuration. A missing file yields defaults; a corrupt file
|
||||||
|
/// is backed up to app.json.bak and then defaults are used.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The loaded configuration, or defaults when none could be read.</returns>
|
||||||
|
/// <exception cref="IOException">The file exists but cannot be read.</exception>
|
||||||
|
public AppConfig Load() {
|
||||||
|
// Missing file is a normal first-run state: run with defaults.
|
||||||
|
if (!File.Exists(FilePath)) {
|
||||||
|
return new AppConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
string json = File.ReadAllText(FilePath);
|
||||||
|
try {
|
||||||
|
// A JSON null literal deserializes to null; treat it like defaults.
|
||||||
|
AppConfig? config = JsonConvert.DeserializeObject<AppConfig>(json, SerializerSettings);
|
||||||
|
if (config is null) {
|
||||||
|
return new AppConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Older or hand-edited files may miss whole sections; each falls back to its defaults.
|
||||||
|
config.Display ??= new DisplaySettings();
|
||||||
|
config.Confirmations ??= new ConfirmationSettings();
|
||||||
|
return config;
|
||||||
|
} catch (JsonException) {
|
||||||
|
// Corrupt: keep a copy for inspection, then continue with defaults.
|
||||||
|
File.Copy(FilePath, FilePath + ".bak", overwrite: true);
|
||||||
|
return new AppConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes the configuration directly to disk (no atomic replace).
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="config">The configuration to serialize.</param>
|
||||||
|
public void Save(AppConfig config) {
|
||||||
|
// Create the parent folder on demand; normally it already exists.
|
||||||
|
string? directory = Path.GetDirectoryName(FilePath);
|
||||||
|
if (!string.IsNullOrEmpty(directory)) {
|
||||||
|
Directory.CreateDirectory(directory);
|
||||||
|
}
|
||||||
|
|
||||||
|
File.WriteAllText(FilePath, JsonConvert.SerializeObject(config, SerializerSettings));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
namespace YKanBan.Storage.AppData;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Well-known locations under the per-user application data folder
|
||||||
|
/// (%APPDATA%/YKanBan on Windows and the equivalent directory on other
|
||||||
|
/// platforms).
|
||||||
|
/// </summary>
|
||||||
|
public static class AppDataPaths {
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the per-user YKanBan application data folder.
|
||||||
|
/// </summary>
|
||||||
|
public static string Directory =>
|
||||||
|
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "YKanBan");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the full path of app.json.
|
||||||
|
/// </summary>
|
||||||
|
public static string AppConfigJsonPath => Path.Combine(Directory, "app.json");
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace YKanBan.Storage;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A single incremental schema step. Migrations form a contiguous list
|
||||||
|
/// starting at version 1; each step is applied when the stored
|
||||||
|
/// <c>user_version</c> is exactly one below <see cref="Version"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Version">Target <c>user_version</c> after this migration is applied.</param>
|
||||||
|
/// <param name="Name">Short human-readable identifier used for diagnostics.</param>
|
||||||
|
/// <param name="Sql">SQL script executed atomically together with the version bump.</param>
|
||||||
|
public sealed record SchemaMigration(int Version, string Name, string Sql);
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
|
||||||
|
namespace YKanBan.Storage;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shared SQLite plumbing for workspace databases: opens a connection with
|
||||||
|
/// the mandated PRAGMA configuration (WAL journal, NORMAL synchronous mode,
|
||||||
|
/// foreign keys on) and applies incremental <c>user_version</c> migrations.
|
||||||
|
/// </summary>
|
||||||
|
public static class SqliteDatabase {
|
||||||
|
/// <summary>
|
||||||
|
/// Opens (creating if needed) a database file, applies the mandatory
|
||||||
|
/// PRAGMAs and runs any pending migrations.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="databasePath">Path of the SQLite database file.</param>
|
||||||
|
/// <param name="migrations">Contiguous migration list ordered by version, starting at 1.</param>
|
||||||
|
/// <returns>An open connection with all PRAGMAs applied and the schema migrated.</returns>
|
||||||
|
public static SqliteConnection Open(string databasePath, IReadOnlyList<SchemaMigration> migrations) {
|
||||||
|
var connection = new SqliteConnection(new SqliteConnectionStringBuilder {
|
||||||
|
DataSource = databasePath,
|
||||||
|
Mode = SqliteOpenMode.ReadWriteCreate,
|
||||||
|
|
||||||
|
// Each process holds its own single connection; a pool would only add noise.
|
||||||
|
Pooling = false,
|
||||||
|
}.ToString());
|
||||||
|
|
||||||
|
connection.Open();
|
||||||
|
try {
|
||||||
|
ApplyPragmas(connection);
|
||||||
|
ApplyMigrations(connection, migrations);
|
||||||
|
return connection;
|
||||||
|
} catch {
|
||||||
|
connection.Dispose();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads the stored <c>PRAGMA user_version</c> value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connection">An open database connection.</param>
|
||||||
|
/// <returns>The stored schema version.</returns>
|
||||||
|
public static long ReadUserVersion(SqliteConnection connection) {
|
||||||
|
using var command = connection.CreateCommand();
|
||||||
|
command.CommandText = "PRAGMA user_version;";
|
||||||
|
return (long)command.ExecuteScalar()!;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Applies the per-connection PRAGMAs. WAL is a persistent database
|
||||||
|
/// property, but the statement is harmless to repeat; foreign keys must be
|
||||||
|
/// enabled on every connection or the DDL cascades never fire.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connection">An open database connection.</param>
|
||||||
|
internal static void ApplyPragmas(SqliteConnection connection) {
|
||||||
|
// WAL plus NORMAL synchronous is the chosen durability/performance trade-off.
|
||||||
|
Execute(connection, "PRAGMA journal_mode=WAL;");
|
||||||
|
Execute(connection, "PRAGMA synchronous=NORMAL;");
|
||||||
|
Execute(connection, "PRAGMA foreign_keys=ON;");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Runs every migration newer than the stored <c>user_version</c>, each in
|
||||||
|
/// its own transaction together with its version bump.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connection">An open database connection.</param>
|
||||||
|
/// <param name="migrations">Contiguous migration list ordered by version, starting at 1.</param>
|
||||||
|
/// <exception cref="ArgumentException">The migration list is not contiguous from version 1.</exception>
|
||||||
|
/// <exception cref="SchemaVersionException">The database was written by a newer build.</exception>
|
||||||
|
internal static void ApplyMigrations(SqliteConnection connection, IReadOnlyList<SchemaMigration> migrations) {
|
||||||
|
// Contract check: the list must be ordered, contiguous and start at version 1.
|
||||||
|
for (int index = 0; index < migrations.Count; index++) {
|
||||||
|
if (migrations[index].Version != index + 1) {
|
||||||
|
throw new ArgumentException("Migrations must be contiguous and start at version 1.", nameof(migrations));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
long current = ReadUserVersion(connection);
|
||||||
|
int latest = migrations.Count;
|
||||||
|
|
||||||
|
// A database written by a newer build cannot be managed by this one; refuse loudly.
|
||||||
|
if (current > latest) {
|
||||||
|
throw new SchemaVersionException(current, latest);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply each pending migration atomically so a crash never leaves a half-migrated database.
|
||||||
|
foreach (SchemaMigration migration in migrations) {
|
||||||
|
if (migration.Version <= current) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var transaction = connection.BeginTransaction();
|
||||||
|
Execute(connection, migration.Sql, transaction);
|
||||||
|
Execute(connection, $"PRAGMA user_version={migration.Version};", transaction);
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Executes a non-query SQL script, optionally inside an explicit transaction.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connection">An open database connection.</param>
|
||||||
|
/// <param name="commandText">The SQL script to execute.</param>
|
||||||
|
/// <param name="transaction">The transaction to enlist in, when any.</param>
|
||||||
|
private static void Execute(SqliteConnection connection, string commandText, SqliteTransaction? transaction = null) {
|
||||||
|
using var command = connection.CreateCommand();
|
||||||
|
command.Transaction = transaction;
|
||||||
|
command.CommandText = commandText;
|
||||||
|
command.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
namespace YKanBan.Storage;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Base class for the typed exceptions raised by the storage layer.
|
||||||
|
/// Exception messages are always English and never localized; the UI maps the
|
||||||
|
/// exception type to a localized resource key instead.
|
||||||
|
/// </summary>
|
||||||
|
public abstract class YKanBanException : Exception {
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the exception with an English diagnostic message.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">The English diagnostic message.</param>
|
||||||
|
/// <param name="innerException">The underlying cause, when any.</param>
|
||||||
|
protected YKanBanException(string message, Exception? innerException = null)
|
||||||
|
: base(message, innerException) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Signals that the folder passed on the command line does not exist on disk.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class WorkspaceDirectoryMissingException : YKanBanException {
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the folder path that was expected to exist.
|
||||||
|
/// </summary>
|
||||||
|
public string FolderPath { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the exception for a folder that is absent on disk.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The missing folder path.</param>
|
||||||
|
public WorkspaceDirectoryMissingException(string folderPath)
|
||||||
|
: base($"The folder does not exist: {folderPath}") {
|
||||||
|
FolderPath = folderPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Signals that a folder exists but has no .ykanban structure, so it is not
|
||||||
|
/// (yet) a workspace.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class WorkspaceNotInitializedException : YKanBanException {
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the folder path that lacks the .ykanban structure.
|
||||||
|
/// </summary>
|
||||||
|
public string FolderPath { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the exception for a folder without a .ykanban structure.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The uninitialized folder path.</param>
|
||||||
|
public WorkspaceNotInitializedException(string folderPath)
|
||||||
|
: base($"The folder is not a YKanBan workspace (missing .ykanban): {folderPath}") {
|
||||||
|
FolderPath = folderPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Signals that another instance already holds the workspace lock, so this
|
||||||
|
/// process must not touch the workspace.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class WorkspaceLockException : YKanBanException {
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the lock file that could not be acquired.
|
||||||
|
/// </summary>
|
||||||
|
public string LockFilePath { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the exception for a failed lock acquisition.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="lockFilePath">The lock file that is already held.</param>
|
||||||
|
/// <param name="innerException">The underlying I/O error.</param>
|
||||||
|
public WorkspaceLockException(string lockFilePath, Exception innerException)
|
||||||
|
: base($"The workspace is locked by another instance: {lockFilePath}", innerException) {
|
||||||
|
LockFilePath = lockFilePath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Signals that the database was written by a newer build than the one
|
||||||
|
/// currently running, so its schema cannot be safely managed.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class SchemaVersionException : YKanBanException {
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the user_version value found in the database.
|
||||||
|
/// </summary>
|
||||||
|
public long StoredVersion { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the newest schema version this build understands.
|
||||||
|
/// </summary>
|
||||||
|
public int SupportedVersion { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the exception for an unmanageable schema version.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="storedVersion">The user_version read from the database.</param>
|
||||||
|
/// <param name="supportedVersion">The newest schema version this build supports.</param>
|
||||||
|
public SchemaVersionException(long storedVersion, int supportedVersion)
|
||||||
|
: base($"Database schema version {storedVersion} is newer than the latest supported version {supportedVersion}.") {
|
||||||
|
StoredVersion = storedVersion;
|
||||||
|
SupportedVersion = supportedVersion;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
namespace YKanBan.Storage;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Supplies the current Unix timestamp. Every timestamp persisted by YKanBan
|
||||||
|
/// is an INTEGER count of Unix seconds.
|
||||||
|
/// </summary>
|
||||||
|
public static class UnixTime {
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the current UTC time expressed as Unix seconds.
|
||||||
|
/// </summary>
|
||||||
|
public static long Now => DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
|
||||||
|
namespace YKanBan.Storage.Workspace;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates the .ykanban structure for a folder: the folder itself and an
|
||||||
|
/// empty, fully migrated database. Adding preset content is deliberately a
|
||||||
|
/// separate concern handled by <see cref="WorkspacePreset"/>, so the
|
||||||
|
/// database can be created without any rows.
|
||||||
|
/// </summary>
|
||||||
|
public static class WorkspaceInitializer {
|
||||||
|
/// <summary>
|
||||||
|
/// Returns whether the folder contains a .ykanban structure. Only the
|
||||||
|
/// passed folder is checked; parent folders are never searched.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The folder to inspect.</param>
|
||||||
|
/// <returns><see langword="true"/> when .ykanban exists in the folder.</returns>
|
||||||
|
public static bool IsWorkspace(string folderPath) => Directory.Exists(WorkspacePaths.Root(folderPath));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a fresh workspace: creates .ykanban and an empty migrated
|
||||||
|
/// database, without adding any preset content.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The existing folder to initialize.</param>
|
||||||
|
/// <exception cref="WorkspaceDirectoryMissingException">The folder does not exist on disk.</exception>
|
||||||
|
/// <exception cref="InvalidOperationException">The workspace database already exists.</exception>
|
||||||
|
public static void Initialize(string folderPath) {
|
||||||
|
if (!Directory.Exists(folderPath)) {
|
||||||
|
throw new WorkspaceDirectoryMissingException(folderPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
string databasePath = WorkspacePaths.Database(folderPath);
|
||||||
|
if (File.Exists(databasePath)) {
|
||||||
|
throw new InvalidOperationException($"The workspace database already exists: {databasePath}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the .ykanban folder, then the migrated but still empty database.
|
||||||
|
Directory.CreateDirectory(WorkspacePaths.Root(folderPath));
|
||||||
|
using SqliteConnection connection = SqliteDatabase.Open(databasePath, WorkspaceSchema.Migrations);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
namespace YKanBan.Storage.Workspace;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Exclusive, OS-enforced lock over a workspace's ykanban.lock. The handle is
|
||||||
|
/// held until disposal, so crashes and power loss release it automatically. The
|
||||||
|
/// lock file is kept empty; only its exclusive OS handle carries meaning.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class WorkspaceLock : IDisposable {
|
||||||
|
private readonly FileStream _stream;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the lock around an already-acquired handle.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="stream">The exclusively opened lock file stream.</param>
|
||||||
|
/// <param name="lockFilePath">Path of the lock file being held.</param>
|
||||||
|
private WorkspaceLock(FileStream stream, string lockFilePath) {
|
||||||
|
_stream = stream;
|
||||||
|
LockFilePath = lockFilePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the path of the lock file being held.
|
||||||
|
/// </summary>
|
||||||
|
public string LockFilePath { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Acquires the workspace lock, leaving the lock file empty.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The workspace folder to lock.</param>
|
||||||
|
/// <returns>The held lock; dispose it to release.</returns>
|
||||||
|
/// <exception cref="WorkspaceNotInitializedException">The folder has no .ykanban structure.</exception>
|
||||||
|
/// <exception cref="WorkspaceLockException">Another instance already holds the lock.</exception>
|
||||||
|
public static WorkspaceLock Acquire(string folderPath) {
|
||||||
|
string lockFilePath = WorkspacePaths.LockFile(folderPath);
|
||||||
|
FileStream stream;
|
||||||
|
try {
|
||||||
|
// FileShare.None gives the exclusive semantics; FileMode.Create empties any stale file.
|
||||||
|
// SAFETY: FileMode.Create truncates a pre-existing file, but the lock
|
||||||
|
// file is empty by design and the path always comes from
|
||||||
|
// WorkspacePaths.LockFile, so no user data is ever affected.
|
||||||
|
stream = new FileStream(lockFilePath, FileMode.Create, FileAccess.Write, FileShare.None);
|
||||||
|
} catch (DirectoryNotFoundException) {
|
||||||
|
throw new WorkspaceNotInitializedException(folderPath);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new WorkspaceLockException(lockFilePath, ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new WorkspaceLock(stream, lockFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Releases the exclusive handle. The lock file itself is intentionally
|
||||||
|
/// left on disk; the OS releases the handle even on a crash.
|
||||||
|
/// </summary>
|
||||||
|
public void Dispose() => _stream.Dispose();
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
namespace YKanBan.Storage.Workspace;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Well-known file and folder names inside a workspace's .ykanban structure,
|
||||||
|
/// plus helpers that combine them with a workspace folder path.
|
||||||
|
/// </summary>
|
||||||
|
public static class WorkspacePaths {
|
||||||
|
/// <summary>
|
||||||
|
/// Name of the workspace root folder created inside a managed project.
|
||||||
|
/// </summary>
|
||||||
|
public const string RootFolderName = ".ykanban";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Name of the SQLite database inside .ykanban.
|
||||||
|
/// </summary>
|
||||||
|
public const string DatabaseFileName = "ykanban.db";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Name of the exclusive lock file inside .ykanban.
|
||||||
|
/// </summary>
|
||||||
|
public const string LockFileName = "ykanban.lock";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the .ykanban root path for a workspace folder.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The workspace folder path.</param>
|
||||||
|
/// <returns>The path of the .ykanban folder.</returns>
|
||||||
|
public static string Root(string folderPath) => Path.Combine(folderPath, RootFolderName);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the workspace database path for a workspace folder.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The workspace folder path.</param>
|
||||||
|
/// <returns>The path of ykanban.db.</returns>
|
||||||
|
public static string Database(string folderPath) => Path.Combine(Root(folderPath), DatabaseFileName);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the workspace lock file path for a workspace folder.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The workspace folder path.</param>
|
||||||
|
/// <returns>The path of ykanban.lock.</returns>
|
||||||
|
public static string LockFile(string folderPath) => Path.Combine(Root(folderPath), LockFileName);
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
|
||||||
|
namespace YKanBan.Storage.Workspace;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds the initial workspace content. The preset column titles/descriptions and
|
||||||
|
/// tag names/descriptions are read straight from the ResX resources in the UI
|
||||||
|
/// language active when they are added; they then become ordinary data that no
|
||||||
|
/// longer follows language switches.
|
||||||
|
/// </summary>
|
||||||
|
public static class WorkspacePreset {
|
||||||
|
/// <summary>
|
||||||
|
/// Inserts the three preset columns (the current language's equivalents of
|
||||||
|
/// To Do / In Progress / Done) with their descriptions in a single transaction.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The initialized workspace folder.</param>
|
||||||
|
/// <exception cref="SqliteException">The workspace database does not exist or a title collides with an existing column.</exception>
|
||||||
|
public static void AddPresetColumns(string folderPath) {
|
||||||
|
using SqliteConnection connection = SqliteDatabase.Open(
|
||||||
|
WorkspacePaths.Database(folderPath), WorkspaceSchema.Migrations);
|
||||||
|
|
||||||
|
long now = UnixTime.Now;
|
||||||
|
|
||||||
|
// Preset titles and descriptions are data at creation time: whatever the current language says gets stored.
|
||||||
|
(string Title, string Description)[] columns =
|
||||||
|
[
|
||||||
|
(Resources.PresetColumn_Todo, Resources.PresetColumn_Todo_Description),
|
||||||
|
(Resources.PresetColumn_InProgress, Resources.PresetColumn_InProgress_Description),
|
||||||
|
(Resources.PresetColumn_Done, Resources.PresetColumn_Done_Description),
|
||||||
|
];
|
||||||
|
|
||||||
|
// Insert all three atomically so a partially populated workspace can never exist.
|
||||||
|
using var transaction = connection.BeginTransaction();
|
||||||
|
foreach ((string title, string description) in columns) {
|
||||||
|
using var command = connection.CreateCommand();
|
||||||
|
command.Transaction = transaction;
|
||||||
|
command.CommandText = """
|
||||||
|
INSERT INTO columns (title, description, created_at, updated_at)
|
||||||
|
VALUES ($title, $description, $now, $now);
|
||||||
|
""";
|
||||||
|
command.Parameters.AddWithValue("$title", title);
|
||||||
|
command.Parameters.AddWithValue("$description", description);
|
||||||
|
command.Parameters.AddWithValue("$now", now);
|
||||||
|
command.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Inserts the preset tag set (names, colors and descriptions in the current
|
||||||
|
/// language) in a single transaction.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The initialized workspace folder.</param>
|
||||||
|
/// <exception cref="SqliteException">The workspace database does not exist or a tag name collides.</exception>
|
||||||
|
public static void AddPresetTags(string folderPath) {
|
||||||
|
using SqliteConnection connection = SqliteDatabase.Open(
|
||||||
|
WorkspacePaths.Database(folderPath), WorkspaceSchema.Migrations);
|
||||||
|
|
||||||
|
// Colors are stored in the canonical lowercase #rrggbb form.
|
||||||
|
(string Name, string Color, string Description)[] tags =
|
||||||
|
[
|
||||||
|
(Resources.PresetTag_Bug_Name, "#d73a4a", Resources.PresetTag_Bug_Description),
|
||||||
|
(Resources.PresetTag_Documentation_Name, "#0075ca", Resources.PresetTag_Documentation_Description),
|
||||||
|
(Resources.PresetTag_Duplicate_Name, "#cfd3d7", Resources.PresetTag_Duplicate_Description),
|
||||||
|
(Resources.PresetTag_Enhancement_Name, "#a2eeef", Resources.PresetTag_Enhancement_Description),
|
||||||
|
(Resources.PresetTag_HelpWanted_Name, "#008672", Resources.PresetTag_HelpWanted_Description),
|
||||||
|
(Resources.PresetTag_Invalid_Name, "#e4e669", Resources.PresetTag_Invalid_Description),
|
||||||
|
(Resources.PresetTag_Question_Name, "#d876e3", Resources.PresetTag_Question_Description),
|
||||||
|
(Resources.PresetTag_Wontfix_Name, "#ffffff", Resources.PresetTag_Wontfix_Description),
|
||||||
|
];
|
||||||
|
|
||||||
|
using var transaction = connection.BeginTransaction();
|
||||||
|
foreach ((string name, string color, string description) in tags) {
|
||||||
|
using var command = connection.CreateCommand();
|
||||||
|
command.Transaction = transaction;
|
||||||
|
command.CommandText = """
|
||||||
|
INSERT INTO tags (name, color, description)
|
||||||
|
VALUES ($name, $color, $description);
|
||||||
|
""";
|
||||||
|
command.Parameters.AddWithValue("$name", name);
|
||||||
|
command.Parameters.AddWithValue("$color", color);
|
||||||
|
command.Parameters.AddWithValue("$description", description);
|
||||||
|
command.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,519 @@
|
|||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
|
||||||
|
using YKanBan.Models;
|
||||||
|
using YKanBan.Search;
|
||||||
|
|
||||||
|
namespace YKanBan.Storage.Workspace;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Data access for one open workspace database: CRUD for columns, cards and
|
||||||
|
/// tags, card moves and tag assignment. Cascading deletes are left to the DDL.
|
||||||
|
///
|
||||||
|
/// Timestamp rules:
|
||||||
|
/// - cards.updated_at refreshes only when a card edit is confirmed with
|
||||||
|
/// changes; moving a card to another column never refreshes it;
|
||||||
|
/// - columns.updated_at refreshes only when title or description changes;
|
||||||
|
/// - a confirmation with no effective change performs no write at all.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class WorkspaceRepository : IDisposable {
|
||||||
|
private readonly SqliteConnection _connection;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens the repository over an initialized workspace database.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The workspace folder.</param>
|
||||||
|
public WorkspaceRepository(string folderPath) {
|
||||||
|
_connection = SqliteDatabase.Open(WorkspacePaths.Database(folderPath), WorkspaceSchema.Migrations);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Closes the underlying connection.
|
||||||
|
/// </summary>
|
||||||
|
public void Dispose() => _connection.Dispose();
|
||||||
|
|
||||||
|
#region Columns
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns all columns ordered by id ascending.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>All columns in id order.</returns>
|
||||||
|
public IReadOnlyList<ColumnModel> GetColumns() {
|
||||||
|
using var command = CreateCommand(
|
||||||
|
"SELECT id, title, description, created_at, updated_at FROM columns ORDER BY id ASC;");
|
||||||
|
using var reader = command.ExecuteReader();
|
||||||
|
|
||||||
|
var columns = new List<ColumnModel>();
|
||||||
|
while (reader.Read()) {
|
||||||
|
columns.Add(ReadColumn(reader));
|
||||||
|
}
|
||||||
|
return columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the column with the given id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="columnId">The column id.</param>
|
||||||
|
/// <returns>The column, or <see langword="null"/> when it does not exist.</returns>
|
||||||
|
public ColumnModel? GetColumn(long columnId) {
|
||||||
|
using var command = CreateCommand(
|
||||||
|
"SELECT id, title, description, created_at, updated_at FROM columns WHERE id = $id;");
|
||||||
|
command.Parameters.AddWithValue("$id", columnId);
|
||||||
|
using var reader = command.ExecuteReader();
|
||||||
|
return reader.Read() ? ReadColumn(reader) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a column with created_at equal to updated_at.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="title">The non-empty, table-unique title.</param>
|
||||||
|
/// <param name="description">The optional description.</param>
|
||||||
|
/// <returns>The created column.</returns>
|
||||||
|
/// <exception cref="SqliteException">The title is empty or not unique.</exception>
|
||||||
|
public ColumnModel AddColumn(string title, string description) {
|
||||||
|
long now = UnixTime.Now;
|
||||||
|
using var transaction = _connection.BeginTransaction();
|
||||||
|
long id = ExecuteInsert(transaction,
|
||||||
|
"INSERT INTO columns (title, description, created_at, updated_at) VALUES ($title, $description, $now, $now);",
|
||||||
|
("$title", title), ("$description", description), ("$now", now));
|
||||||
|
transaction.Commit();
|
||||||
|
|
||||||
|
return new ColumnModel(id, title, description, now, now);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Rewrites the title and description. A call with no effective change
|
||||||
|
/// writes nothing and leaves the timestamp alone.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="columnId">The column to update.</param>
|
||||||
|
/// <param name="title">The new non-empty, table-unique title.</param>
|
||||||
|
/// <param name="description">The new description.</param>
|
||||||
|
/// <returns>The updated column, or the unchanged one for a no-op.</returns>
|
||||||
|
/// <exception cref="InvalidOperationException">The column does not exist.</exception>
|
||||||
|
/// <exception cref="SqliteException">The new title is empty or not unique.</exception>
|
||||||
|
public ColumnModel UpdateColumn(long columnId, string title, string description) {
|
||||||
|
ColumnModel existing = GetColumn(columnId)
|
||||||
|
?? throw new InvalidOperationException($"Column {columnId} does not exist.");
|
||||||
|
|
||||||
|
// Unchanged title and description: no write, no timestamp refresh.
|
||||||
|
if (existing.Title == title && existing.Description == description) {
|
||||||
|
return existing;
|
||||||
|
}
|
||||||
|
|
||||||
|
long now = UnixTime.Now;
|
||||||
|
using var command = CreateCommand(
|
||||||
|
"UPDATE columns SET title = $title, description = $description, updated_at = $now WHERE id = $id;");
|
||||||
|
command.Parameters.AddWithValue("$title", title);
|
||||||
|
command.Parameters.AddWithValue("$description", description);
|
||||||
|
command.Parameters.AddWithValue("$now", now);
|
||||||
|
command.Parameters.AddWithValue("$id", columnId);
|
||||||
|
command.ExecuteNonQuery();
|
||||||
|
|
||||||
|
return new ColumnModel(columnId, title, description, existing.CreatedAt, now);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes a column; the DDL cascade removes its cards and their tag links.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="columnId">The column to delete.</param>
|
||||||
|
/// <returns><see langword="true"/> when a row was deleted.</returns>
|
||||||
|
public bool DeleteColumn(long columnId) => ExecuteDelete("DELETE FROM columns WHERE id = $id;", columnId);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Cards
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns all cards with their assigned tags loaded, ordered by id ascending.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>All cards in id order.</returns>
|
||||||
|
public IReadOnlyList<CardModel> GetCards() {
|
||||||
|
using var command = CreateCommand("""
|
||||||
|
SELECT c.id, c.column_id, c.title, c.content, c.created_at, c.updated_at,
|
||||||
|
t.id, t.name, t.color, t.description
|
||||||
|
FROM cards c
|
||||||
|
LEFT JOIN card_tags ct ON ct.card_id = c.id
|
||||||
|
LEFT JOIN tags t ON t.id = ct.tag_id
|
||||||
|
ORDER BY c.id ASC;
|
||||||
|
""");
|
||||||
|
using var reader = command.ExecuteReader();
|
||||||
|
|
||||||
|
// Single grouped pass: one output card per distinct card id, with its tags accumulated alongside.
|
||||||
|
var cards = new List<CardModel>();
|
||||||
|
var tagsByCard = new Dictionary<long, List<TagModel>>();
|
||||||
|
while (reader.Read()) {
|
||||||
|
long cardId = reader.GetInt64(0);
|
||||||
|
if (!tagsByCard.TryGetValue(cardId, out List<TagModel>? tags)) {
|
||||||
|
tags = new List<TagModel>();
|
||||||
|
tagsByCard[cardId] = tags;
|
||||||
|
cards.Add(new CardModel(
|
||||||
|
cardId,
|
||||||
|
reader.GetInt64(1),
|
||||||
|
reader.GetString(2),
|
||||||
|
reader.GetString(3),
|
||||||
|
reader.GetInt64(4),
|
||||||
|
reader.GetInt64(5),
|
||||||
|
tags));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reader.IsDBNull(6)) {
|
||||||
|
tags.Add(ReadTag(reader, 6));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cards;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the ids of the cards matching a compiled search predicate.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="search">The compiled search predicate and its parameters.</param>
|
||||||
|
/// <returns>The matching card ids.</returns>
|
||||||
|
public IReadOnlyCollection<long> GetCardIdsMatching(CompiledSearch search) {
|
||||||
|
using var command = CreateCommand($"SELECT c.id FROM cards c WHERE {search.Predicate};");
|
||||||
|
foreach ((string name, object value) in search.Parameters) {
|
||||||
|
command.Parameters.AddWithValue(name, value);
|
||||||
|
}
|
||||||
|
using var reader = command.ExecuteReader();
|
||||||
|
|
||||||
|
var ids = new HashSet<long>();
|
||||||
|
while (reader.Read()) {
|
||||||
|
ids.Add(reader.GetInt64(0));
|
||||||
|
}
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the card with the given id, with its tags loaded.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cardId">The card id.</param>
|
||||||
|
/// <returns>The card, or <see langword="null"/> when it does not exist.</returns>
|
||||||
|
public CardModel? GetCard(long cardId) {
|
||||||
|
using var command = CreateCommand("""
|
||||||
|
SELECT c.id, c.column_id, c.title, c.content, c.created_at, c.updated_at,
|
||||||
|
t.id, t.name, t.color, t.description
|
||||||
|
FROM cards c
|
||||||
|
LEFT JOIN card_tags ct ON ct.card_id = c.id
|
||||||
|
LEFT JOIN tags t ON t.id = ct.tag_id
|
||||||
|
WHERE c.id = $id
|
||||||
|
ORDER BY c.id ASC;
|
||||||
|
""");
|
||||||
|
command.Parameters.AddWithValue("$id", cardId);
|
||||||
|
using var reader = command.ExecuteReader();
|
||||||
|
|
||||||
|
// The LEFT JOIN may repeat the card row once per tag; build it on the first row only.
|
||||||
|
CardModel? card = null;
|
||||||
|
var tags = new List<TagModel>();
|
||||||
|
while (reader.Read()) {
|
||||||
|
card ??= new CardModel(
|
||||||
|
reader.GetInt64(0),
|
||||||
|
reader.GetInt64(1),
|
||||||
|
reader.GetString(2),
|
||||||
|
reader.GetString(3),
|
||||||
|
reader.GetInt64(4),
|
||||||
|
reader.GetInt64(5),
|
||||||
|
tags);
|
||||||
|
|
||||||
|
if (!reader.IsDBNull(6)) {
|
||||||
|
tags.Add(ReadTag(reader, 6));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return card;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a card with its initial tag assignment and created_at equal to updated_at.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="columnId">The owning column.</param>
|
||||||
|
/// <param name="title">The card title, possibly empty.</param>
|
||||||
|
/// <param name="content">The card content, possibly empty.</param>
|
||||||
|
/// <param name="tagIds">The tags to assign initially.</param>
|
||||||
|
/// <returns>The created card with tags loaded.</returns>
|
||||||
|
/// <exception cref="SqliteException">The column or a tag id does not exist.</exception>
|
||||||
|
public CardModel AddCard(long columnId, string title, string content, IReadOnlyCollection<long> tagIds) {
|
||||||
|
long now = UnixTime.Now;
|
||||||
|
using var transaction = _connection.BeginTransaction();
|
||||||
|
long id = ExecuteInsert(transaction,
|
||||||
|
"INSERT INTO cards (column_id, title, content, created_at, updated_at) VALUES ($columnId, $title, $content, $now, $now);",
|
||||||
|
("$columnId", columnId), ("$title", title), ("$content", content), ("$now", now));
|
||||||
|
foreach (long tagId in tagIds.Distinct()) {
|
||||||
|
ExecuteNonQuery(transaction,
|
||||||
|
"INSERT INTO card_tags (card_id, tag_id) VALUES ($cardId, $tagId);",
|
||||||
|
("$cardId", id), ("$tagId", tagId));
|
||||||
|
}
|
||||||
|
transaction.Commit();
|
||||||
|
|
||||||
|
return new CardModel(id, columnId, title, content, now, now, LoadTags(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Applies one card edit confirmation as a single atomic unit: the card row
|
||||||
|
/// (title, content, refreshed updated_at) plus the complete tag assignment.
|
||||||
|
/// A confirmation with no effective change writes nothing; a failure
|
||||||
|
/// mid-way rolls the whole edit back.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cardId">The card to update.</param>
|
||||||
|
/// <param name="title">The new title.</param>
|
||||||
|
/// <param name="content">The new content.</param>
|
||||||
|
/// <param name="tagIds">The complete set of tags to assign.</param>
|
||||||
|
/// <returns>The updated card with tags loaded, or the unchanged one for a no-op.</returns>
|
||||||
|
/// <exception cref="InvalidOperationException">The card does not exist.</exception>
|
||||||
|
/// <exception cref="SqliteException">A tag id does not exist; nothing is written.</exception>
|
||||||
|
public CardModel UpdateCard(long cardId, string title, string content, IReadOnlyCollection<long> tagIds) {
|
||||||
|
CardModel existing = GetCard(cardId)
|
||||||
|
?? throw new InvalidOperationException($"Card {cardId} does not exist.");
|
||||||
|
|
||||||
|
// No effective change in title, content or tag set: no write, no timestamp refresh.
|
||||||
|
bool tagsChanged = !tagIds.Distinct().ToHashSet().SetEquals(existing.Tags.Select(tag => tag.Id));
|
||||||
|
if (existing.Title == title && existing.Content == content && !tagsChanged) {
|
||||||
|
return existing;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The confirmed write refreshes updated_at even when only the tag set changed.
|
||||||
|
long now = UnixTime.Now;
|
||||||
|
using var transaction = _connection.BeginTransaction();
|
||||||
|
ExecuteNonQuery(transaction,
|
||||||
|
"UPDATE cards SET title = $title, content = $content, updated_at = $now WHERE id = $id;",
|
||||||
|
("$title", title), ("$content", content), ("$now", now), ("$id", cardId));
|
||||||
|
|
||||||
|
// Tag assignment is rewritten wholesale; card_tags carries nothing beyond the pair.
|
||||||
|
ExecuteNonQuery(transaction, "DELETE FROM card_tags WHERE card_id = $id;", ("$id", cardId));
|
||||||
|
foreach (long tagId in tagIds.Distinct()) {
|
||||||
|
ExecuteNonQuery(transaction,
|
||||||
|
"INSERT INTO card_tags (card_id, tag_id) VALUES ($cardId, $tagId);",
|
||||||
|
("$cardId", cardId), ("$tagId", tagId));
|
||||||
|
}
|
||||||
|
transaction.Commit();
|
||||||
|
|
||||||
|
return new CardModel(cardId, existing.ColumnId, title, content, existing.CreatedAt, now, LoadTags(cardId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Moves a card to another column. This writes to the database but
|
||||||
|
/// deliberately does NOT refresh the card's updated_at; moving to the
|
||||||
|
/// current column is a no-op.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cardId">The card to move.</param>
|
||||||
|
/// <param name="targetColumnId">The destination column.</param>
|
||||||
|
/// <returns><see langword="true"/> when the card actually moved.</returns>
|
||||||
|
public bool MoveCard(long cardId, long targetColumnId) {
|
||||||
|
using var command = CreateCommand(
|
||||||
|
"UPDATE cards SET column_id = $columnId WHERE id = $id AND column_id <> $columnId;");
|
||||||
|
command.Parameters.AddWithValue("$columnId", targetColumnId);
|
||||||
|
command.Parameters.AddWithValue("$id", cardId);
|
||||||
|
return command.ExecuteNonQuery() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes a card; the DDL cascade removes its tag links.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cardId">The card to delete.</param>
|
||||||
|
/// <returns><see langword="true"/> when a row was deleted.</returns>
|
||||||
|
public bool DeleteCard(long cardId) => ExecuteDelete("DELETE FROM cards WHERE id = $id;", cardId);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Tags
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns all tags ordered by id ascending; unreferenced tags are included.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>All tags in id order.</returns>
|
||||||
|
public IReadOnlyList<TagModel> GetTags() {
|
||||||
|
using var command = CreateCommand(
|
||||||
|
"SELECT id, name, color, description FROM tags ORDER BY id ASC;");
|
||||||
|
using var reader = command.ExecuteReader();
|
||||||
|
|
||||||
|
var tags = new List<TagModel>();
|
||||||
|
while (reader.Read()) {
|
||||||
|
tags.Add(ReadTag(reader, 0));
|
||||||
|
}
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns every tag together with the number of cards using it, ordered by tag id.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The tag/usage pairs in tag id order.</returns>
|
||||||
|
public IReadOnlyList<(TagModel Tag, long UsageCount)> GetTagsWithUsage() {
|
||||||
|
using var command = CreateCommand("""
|
||||||
|
SELECT t.id, t.name, t.color, t.description, COUNT(ct.card_id)
|
||||||
|
FROM tags t
|
||||||
|
LEFT JOIN card_tags ct ON ct.tag_id = t.id
|
||||||
|
GROUP BY t.id, t.name, t.color, t.description
|
||||||
|
ORDER BY t.id ASC;
|
||||||
|
""");
|
||||||
|
using var reader = command.ExecuteReader();
|
||||||
|
|
||||||
|
var tags = new List<(TagModel Tag, long UsageCount)>();
|
||||||
|
while (reader.Read()) {
|
||||||
|
tags.Add((ReadTag(reader, 0), reader.GetInt64(4)));
|
||||||
|
}
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a tag.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The non-empty, table-unique name.</param>
|
||||||
|
/// <param name="color">The tag color.</param>
|
||||||
|
/// <param name="description">The optional description.</param>
|
||||||
|
/// <returns>The created tag.</returns>
|
||||||
|
/// <exception cref="SqliteException">The name is empty or not unique.</exception>
|
||||||
|
public TagModel AddTag(string name, RgbColor color, string description) {
|
||||||
|
using var transaction = _connection.BeginTransaction();
|
||||||
|
long id = ExecuteInsert(transaction,
|
||||||
|
"INSERT INTO tags (name, color, description) VALUES ($name, $color, $description);",
|
||||||
|
("$name", name), ("$color", color.ToString()), ("$description", description));
|
||||||
|
transaction.Commit();
|
||||||
|
|
||||||
|
return new TagModel(id, name, color, description);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Rewrites name, color and description. A call with no effective change writes nothing.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tagId">The tag to update.</param>
|
||||||
|
/// <param name="name">The new non-empty, table-unique name.</param>
|
||||||
|
/// <param name="color">The new color.</param>
|
||||||
|
/// <param name="description">The new description.</param>
|
||||||
|
/// <returns>The updated tag, or the unchanged one for a no-op.</returns>
|
||||||
|
/// <exception cref="InvalidOperationException">The tag does not exist.</exception>
|
||||||
|
/// <exception cref="SqliteException">The new name is empty or not unique.</exception>
|
||||||
|
public TagModel UpdateTag(long tagId, string name, RgbColor color, string description) {
|
||||||
|
TagModel existing = GetTag(tagId)
|
||||||
|
?? throw new InvalidOperationException($"Tag {tagId} does not exist.");
|
||||||
|
|
||||||
|
// Unchanged name, color and description: no write.
|
||||||
|
if (existing.Name == name && existing.Color == color && existing.Description == description) {
|
||||||
|
return existing;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var command = CreateCommand(
|
||||||
|
"UPDATE tags SET name = $name, color = $color, description = $description WHERE id = $id;");
|
||||||
|
command.Parameters.AddWithValue("$name", name);
|
||||||
|
command.Parameters.AddWithValue("$color", color.ToString());
|
||||||
|
command.Parameters.AddWithValue("$description", description);
|
||||||
|
command.Parameters.AddWithValue("$id", tagId);
|
||||||
|
command.ExecuteNonQuery();
|
||||||
|
|
||||||
|
return new TagModel(tagId, name, color, description);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes a tag; the DDL cascade removes its card links while the cards survive.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tagId">The tag to delete.</param>
|
||||||
|
/// <returns><see langword="true"/> when a row was deleted.</returns>
|
||||||
|
public bool DeleteTag(long tagId) => ExecuteDelete("DELETE FROM tags WHERE id = $id;", tagId);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Helpers
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the tag with the given id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tagId">The tag id.</param>
|
||||||
|
/// <returns>The tag, or <see langword="null"/> when it does not exist.</returns>
|
||||||
|
private TagModel? GetTag(long tagId) {
|
||||||
|
using var command = CreateCommand(
|
||||||
|
"SELECT id, name, color, description FROM tags WHERE id = $id;");
|
||||||
|
command.Parameters.AddWithValue("$id", tagId);
|
||||||
|
using var reader = command.ExecuteReader();
|
||||||
|
return reader.Read() ? ReadTag(reader, 0) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the tags currently assigned to a card, ordered by tag id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cardId">The card id.</param>
|
||||||
|
/// <returns>The assigned tags in id order.</returns>
|
||||||
|
private IReadOnlyList<TagModel> LoadTags(long cardId) {
|
||||||
|
using var command = CreateCommand("""
|
||||||
|
SELECT t.id, t.name, t.color, t.description
|
||||||
|
FROM tags t
|
||||||
|
JOIN card_tags ct ON ct.tag_id = t.id
|
||||||
|
WHERE ct.card_id = $cardId
|
||||||
|
ORDER BY t.id ASC;
|
||||||
|
""");
|
||||||
|
command.Parameters.AddWithValue("$cardId", cardId);
|
||||||
|
using var reader = command.ExecuteReader();
|
||||||
|
|
||||||
|
var tags = new List<TagModel>();
|
||||||
|
while (reader.Read()) {
|
||||||
|
tags.Add(ReadTag(reader, 0));
|
||||||
|
}
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads a columns row from the reader cursor.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="reader">The reader positioned on a columns row.</param>
|
||||||
|
/// <returns>The column model.</returns>
|
||||||
|
private static ColumnModel ReadColumn(SqliteDataReader reader) =>
|
||||||
|
new(reader.GetInt64(0), reader.GetString(1), reader.GetString(2), reader.GetInt64(3), reader.GetInt64(4));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads a tags row from the reader cursor, starting at the given column
|
||||||
|
/// offset; the color text is converted to its components.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="reader">The reader positioned on a row containing a tag.</param>
|
||||||
|
/// <param name="offset">Index of the tag's id column.</param>
|
||||||
|
/// <returns>The tag model.</returns>
|
||||||
|
private static TagModel ReadTag(SqliteDataReader reader, int offset) =>
|
||||||
|
new(reader.GetInt64(offset), reader.GetString(offset + 1), RgbColor.Parse(reader.GetString(offset + 2)), reader.GetString(offset + 3));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a command bound to this connection.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sql">The command text.</param>
|
||||||
|
/// <param name="transaction">The transaction to enlist in, when any.</param>
|
||||||
|
/// <returns>The prepared command.</returns>
|
||||||
|
private SqliteCommand CreateCommand(string sql, SqliteTransaction? transaction = null) {
|
||||||
|
SqliteCommand command = _connection.CreateCommand();
|
||||||
|
command.Transaction = transaction;
|
||||||
|
command.CommandText = sql;
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Executes a parameterized non-query statement inside a transaction.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="transaction">The transaction to enlist in.</param>
|
||||||
|
/// <param name="sql">The statement to execute.</param>
|
||||||
|
/// <param name="parameters">Name/value pairs bound as SQL parameters.</param>
|
||||||
|
private void ExecuteNonQuery(SqliteTransaction transaction, string sql, params (string Name, object? Value)[] parameters) {
|
||||||
|
using SqliteCommand command = CreateCommand(sql, transaction);
|
||||||
|
foreach ((string name, object? value) in parameters) {
|
||||||
|
command.Parameters.AddWithValue(name, value);
|
||||||
|
}
|
||||||
|
command.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Inserts a row inside a transaction and returns the generated rowid.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="transaction">The transaction to enlist in.</param>
|
||||||
|
/// <param name="sql">The INSERT statement.</param>
|
||||||
|
/// <param name="parameters">Name/value pairs bound as SQL parameters.</param>
|
||||||
|
/// <returns>The rowid assigned to the inserted row.</returns>
|
||||||
|
private long ExecuteInsert(SqliteTransaction transaction, string sql, params (string Name, object? Value)[] parameters) {
|
||||||
|
ExecuteNonQuery(transaction, sql, parameters);
|
||||||
|
using SqliteCommand rowId = CreateCommand("SELECT last_insert_rowid();", transaction);
|
||||||
|
return (long)rowId.ExecuteScalar()!;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes a row by id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sql">The DELETE statement with an <c>$id</c> parameter.</param>
|
||||||
|
/// <param name="id">The id to delete.</param>
|
||||||
|
/// <returns><see langword="true"/> when a row was deleted.</returns>
|
||||||
|
private bool ExecuteDelete(string sql, long id) {
|
||||||
|
using SqliteCommand command = CreateCommand(sql);
|
||||||
|
command.Parameters.AddWithValue("$id", id);
|
||||||
|
return command.ExecuteNonQuery() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
namespace YKanBan.Storage.Workspace;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Schema definitions for the per-workspace database. A workspace holds a
|
||||||
|
/// single board with a columns → cards hierarchy plus tags and their
|
||||||
|
/// assignments. Data validity is expressed in DDL (CHECK / UNIQUE / FOREIGN
|
||||||
|
/// KEY) so every stored row is valid by construction, and cascading deletes
|
||||||
|
/// are covered by the same DDL.
|
||||||
|
/// </summary>
|
||||||
|
public static class WorkspaceSchema {
|
||||||
|
/// <summary>
|
||||||
|
/// Newest workspace schema version this build understands.
|
||||||
|
/// </summary>
|
||||||
|
public const int CurrentVersion = 1;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ordered, contiguous migration list for the workspace database.
|
||||||
|
/// </summary>
|
||||||
|
public static readonly IReadOnlyList<SchemaMigration> Migrations =
|
||||||
|
[
|
||||||
|
new SchemaMigration(CurrentVersion, "initial schema", """
|
||||||
|
CREATE TABLE columns (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
title TEXT NOT NULL UNIQUE CHECK (length(title) > 0),
|
||||||
|
description TEXT NOT NULL DEFAULT '',
|
||||||
|
created_at INTEGER NOT NULL,
|
||||||
|
updated_at INTEGER NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE cards (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
column_id INTEGER NOT NULL REFERENCES columns (id) ON DELETE CASCADE,
|
||||||
|
title TEXT NOT NULL DEFAULT '',
|
||||||
|
content TEXT NOT NULL DEFAULT '',
|
||||||
|
created_at INTEGER NOT NULL,
|
||||||
|
updated_at INTEGER NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE tags (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
name TEXT NOT NULL UNIQUE CHECK (length(name) > 0),
|
||||||
|
color TEXT NOT NULL CHECK (color GLOB '#[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]'),
|
||||||
|
description TEXT NOT NULL DEFAULT ''
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE card_tags (
|
||||||
|
card_id INTEGER NOT NULL REFERENCES cards (id) ON DELETE CASCADE,
|
||||||
|
tag_id INTEGER NOT NULL REFERENCES tags (id) ON DELETE CASCADE,
|
||||||
|
PRIMARY KEY (card_id, tag_id)
|
||||||
|
);
|
||||||
|
"""),
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
namespace YKanBan.Storage.Workspace;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// One open workspace for the process lifetime: the exclusive lock plus the
|
||||||
|
/// single repository connection. Opening acquires the lock first, so a folder
|
||||||
|
/// without .ykanban, or one already locked by another instance, fails before
|
||||||
|
/// any database work happens. Disposing releases the repository and then the
|
||||||
|
/// lock.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class WorkspaceSession : IDisposable {
|
||||||
|
private readonly WorkspaceLock _workspaceLock;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the session around an acquired lock and an open repository.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The canonical workspace folder path.</param>
|
||||||
|
/// <param name="workspaceLock">The exclusive lock held while this session is open.</param>
|
||||||
|
/// <param name="repository">The data access object for this workspace.</param>
|
||||||
|
private WorkspaceSession(string folderPath, WorkspaceLock workspaceLock, WorkspaceRepository repository) {
|
||||||
|
FolderPath = folderPath;
|
||||||
|
_workspaceLock = workspaceLock;
|
||||||
|
Repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the canonical workspace folder path.
|
||||||
|
/// </summary>
|
||||||
|
public string FolderPath { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the data access object for this workspace.
|
||||||
|
/// </summary>
|
||||||
|
public WorkspaceRepository Repository { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens a workspace: acquires its exclusive lock and opens its repository.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The workspace folder to open.</param>
|
||||||
|
/// <returns>The opened session; dispose it to release the lock and connection.</returns>
|
||||||
|
/// <exception cref="WorkspaceNotInitializedException">The folder has no .ykanban structure.</exception>
|
||||||
|
/// <exception cref="WorkspaceLockException">Another instance already holds the lock.</exception>
|
||||||
|
public static WorkspaceSession Open(string folderPath) {
|
||||||
|
WorkspaceLock workspaceLock = WorkspaceLock.Acquire(folderPath);
|
||||||
|
try {
|
||||||
|
var repository = new WorkspaceRepository(folderPath);
|
||||||
|
return new WorkspaceSession(folderPath, workspaceLock, repository);
|
||||||
|
} catch {
|
||||||
|
workspaceLock.Dispose();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Releases the repository connection, then the exclusive lock.
|
||||||
|
/// </summary>
|
||||||
|
public void Dispose() {
|
||||||
|
Repository.Dispose();
|
||||||
|
_workspaceLock.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
-10
@@ -1,31 +1,29 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.Templates;
|
using Avalonia.Controls.Templates;
|
||||||
|
|
||||||
using YKanBan.ViewModels;
|
using YKanBan.ViewModels;
|
||||||
|
|
||||||
namespace YKanBan;
|
namespace YKanBan;
|
||||||
|
|
||||||
public class ViewLocator : IDataTemplate
|
public class ViewLocator : IDataTemplate {
|
||||||
{
|
|
||||||
|
|
||||||
public Control? Build(object? param)
|
public Control? Build(object? param) {
|
||||||
{
|
|
||||||
if (param is null)
|
if (param is null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal);
|
var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal);
|
||||||
var type = Type.GetType(name);
|
var type = Type.GetType(name);
|
||||||
|
|
||||||
if (type != null)
|
if (type != null) {
|
||||||
{
|
|
||||||
return (Control)Activator.CreateInstance(type)!;
|
return (Control)Activator.CreateInstance(type)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TextBlock { Text = "Not Found: " + name };
|
return new TextBlock { Text = "Not Found: " + name };
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Match(object? data)
|
public bool Match(object? data) {
|
||||||
{
|
|
||||||
return data is ViewModelBase;
|
return data is ViewModelBase;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,343 @@
|
|||||||
|
using System.Collections.ObjectModel;
|
||||||
|
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
|
||||||
|
using YKanBan.Models;
|
||||||
|
using YKanBan.Search;
|
||||||
|
using YKanBan.Services;
|
||||||
|
using YKanBan.Storage.AppData;
|
||||||
|
using YKanBan.Storage.Workspace;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels.Board;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The board tab: a toolbar (search box, add-column and the Display button)
|
||||||
|
/// over horizontally arranged columns of vertically stacked cards. All
|
||||||
|
/// persistence goes through the workspace repository; the board reloads from it
|
||||||
|
/// after each change.
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class BoardViewModel : ViewModelBase {
|
||||||
|
private readonly AppServices _services;
|
||||||
|
private readonly WorkspaceRepository _repository;
|
||||||
|
|
||||||
|
// The active search result filter, or null when the whole board is shown.
|
||||||
|
private IReadOnlyCollection<long>? _matchedCardIds;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the board, loading its current content.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="services">The process composition root (configuration access).</param>
|
||||||
|
/// <param name="session">The open workspace session.</param>
|
||||||
|
public BoardViewModel(AppServices services, WorkspaceSession session) {
|
||||||
|
_services = services;
|
||||||
|
_repository = session.Repository;
|
||||||
|
Display = new DisplaySettingsViewModel(_services.Config, Reload);
|
||||||
|
|
||||||
|
Reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the workspace repository used for all board data access.
|
||||||
|
/// </summary>
|
||||||
|
public WorkspaceRepository Repository => _repository;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the live application configuration.
|
||||||
|
/// </summary>
|
||||||
|
public AppConfig Config => _services.Config;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the display options (column width, card sort, column sort).
|
||||||
|
/// </summary>
|
||||||
|
public DisplaySettingsViewModel Display { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the columns shown by the board, in display order.
|
||||||
|
/// </summary>
|
||||||
|
public ObservableCollection<ColumnViewModel> Columns { get; } = [];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the search box text. The board does not filter on change;
|
||||||
|
/// the search runs only when the search button is used.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private string searchText = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the rendered column width in pixels, applied globally.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private double columnWidth;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether a search filter is currently applied.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsFiltering => _matchedCardIds is not null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the localized filter status text shown as the status icon tooltip.
|
||||||
|
/// </summary>
|
||||||
|
public string FilterStatusText => IsFiltering ? Resources.Board_FilterActive : Resources.Board_FilterInactive;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the status icon opacity: full while filtering, dimmed otherwise.
|
||||||
|
/// </summary>
|
||||||
|
public double FilterIconOpacity => IsFiltering ? 1.0 : 0.4;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the board has any columns.
|
||||||
|
/// </summary>
|
||||||
|
public bool HasColumns => Columns.Count > 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the board is empty.
|
||||||
|
/// </summary>
|
||||||
|
public bool HasNoColumns => Columns.Count == 0;
|
||||||
|
|
||||||
|
#region Interactions
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the interaction that opens the new-column editor.
|
||||||
|
/// </summary>
|
||||||
|
public Interaction<Unit> AddColumn { get; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the interaction that opens the column editor.
|
||||||
|
/// </summary>
|
||||||
|
public Interaction<ColumnViewModel> EditColumn { get; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the interaction that confirms and deletes a column.
|
||||||
|
/// </summary>
|
||||||
|
public Interaction<ColumnViewModel> DeleteColumn { get; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the interaction that opens the new-card editor.
|
||||||
|
/// </summary>
|
||||||
|
public Interaction<ColumnViewModel> AddCard { get; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the interaction that opens the card editor.
|
||||||
|
/// </summary>
|
||||||
|
public Interaction<CardViewModel> EditCard { get; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the interaction that confirms and deletes a card.
|
||||||
|
/// </summary>
|
||||||
|
public Interaction<CardViewModel> DeleteCard { get; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the interaction that opens the move-card dialog.
|
||||||
|
/// </summary>
|
||||||
|
public Interaction<CardViewModel> MoveCard { get; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the interaction that shows the search error dialog, carrying the English parser detail.
|
||||||
|
/// </summary>
|
||||||
|
public Interaction<string> ShowSearchError { get; } = new();
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Commands
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens the new-column editor.
|
||||||
|
/// </summary>
|
||||||
|
[RelayCommand]
|
||||||
|
private Task AddNewColumnAsync() => AddColumn.Handle(Unit.Value);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Runs the current search. A blank query shows everything; an invalid
|
||||||
|
/// expression opens the error dialog and keeps the previous results and text.
|
||||||
|
/// </summary>
|
||||||
|
[RelayCommand]
|
||||||
|
private async Task SearchAsync() {
|
||||||
|
if (string.IsNullOrWhiteSpace(SearchText)) {
|
||||||
|
ApplyFilter(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
SearchNode? query = SearchQueryParser.Parse(SearchText);
|
||||||
|
if (query is null) {
|
||||||
|
ApplyFilter(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CompiledSearch compiled = SearchSqlCompiler.Compile(query);
|
||||||
|
ApplyFilter(_repository.GetCardIdsMatching(compiled));
|
||||||
|
} catch (SearchSyntaxException exception) {
|
||||||
|
// The error dialog carries the parser's non-localized English detail.
|
||||||
|
await ShowSearchError.Handle(exception.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clears the search box and restores the unfiltered board.
|
||||||
|
/// </summary>
|
||||||
|
[RelayCommand]
|
||||||
|
private void ClearSearch() {
|
||||||
|
SearchText = string.Empty;
|
||||||
|
ApplyFilter(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Applies a new result filter (null clears it) and rebuilds the board when it changed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="matchedIds">The new filter, or <see langword="null"/> for no filter.</param>
|
||||||
|
private void ApplyFilter(IReadOnlyCollection<long>? matchedIds) {
|
||||||
|
if (_matchedCardIds is null && matchedIds is null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_matchedCardIds = matchedIds;
|
||||||
|
OnPropertyChanged(nameof(IsFiltering));
|
||||||
|
OnPropertyChanged(nameof(FilterStatusText));
|
||||||
|
OnPropertyChanged(nameof(FilterIconOpacity));
|
||||||
|
Reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Requests from columns and cards
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Requests the new-card editor for the given column.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="column">The target column.</param>
|
||||||
|
/// <returns>A task completing after the editor closes.</returns>
|
||||||
|
public Task RequestAddCardAsync(ColumnViewModel column) => AddCard.Handle(column);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Requests the editor for the given card.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="card">The card to edit.</param>
|
||||||
|
/// <returns>A task completing after the editor closes.</returns>
|
||||||
|
public Task RequestEditCardAsync(CardViewModel card) => EditCard.Handle(card);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Requests deletion of the given card.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="card">The card to delete.</param>
|
||||||
|
/// <returns>A task completing after confirmation.</returns>
|
||||||
|
public Task RequestDeleteCardAsync(CardViewModel card) => DeleteCard.Handle(card);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Requests moving the given card to another column.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="card">The card to move.</param>
|
||||||
|
/// <returns>A task completing after the move.</returns>
|
||||||
|
public Task RequestMoveCardAsync(CardViewModel card) => MoveCard.Handle(card);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Requests the editor for the given column.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="column">The column to edit.</param>
|
||||||
|
/// <returns>A task completing after the editor closes.</returns>
|
||||||
|
public Task RequestEditColumnAsync(ColumnViewModel column) => EditColumn.Handle(column);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Requests deletion of the given column.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="column">The column to delete.</param>
|
||||||
|
/// <returns>A task completing after confirmation.</returns>
|
||||||
|
public Task RequestDeleteColumnAsync(ColumnViewModel column) => DeleteColumn.Handle(column);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Loading and ordering
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reloads all columns and cards from the repository and rebuilds the board.
|
||||||
|
/// </summary>
|
||||||
|
public void Reload() {
|
||||||
|
IReadOnlyList<ColumnModel> columns = _repository.GetColumns();
|
||||||
|
IReadOnlyList<CardModel> cards = _repository.GetCards();
|
||||||
|
|
||||||
|
// An active search hides non-matching cards while every column stays visible.
|
||||||
|
if (_matchedCardIds is not null) {
|
||||||
|
cards = cards.Where(card => _matchedCardIds.Contains(card.Id)).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Group cards by column once so each column can be built independently.
|
||||||
|
Dictionary<long, List<CardModel>> cardsByColumn = cards
|
||||||
|
.GroupBy(card => card.ColumnId)
|
||||||
|
.ToDictionary(group => group.Key, group => group.ToList());
|
||||||
|
|
||||||
|
IEnumerable<ColumnModel> orderedColumns = SortColumns(columns, _services.Config.Display.ColumnSort);
|
||||||
|
|
||||||
|
Columns.Clear();
|
||||||
|
foreach (ColumnModel column in orderedColumns) {
|
||||||
|
// Cards are sorted within their column by the selected card order.
|
||||||
|
IEnumerable<CardModel> columnCards = cardsByColumn.TryGetValue(column.Id, out List<CardModel>? list)
|
||||||
|
? SortCards(list, _services.Config.Display.CardSort)
|
||||||
|
: [];
|
||||||
|
Columns.Add(new ColumnViewModel(this, column, columnCards.Select(card => new CardViewModel(this, card))));
|
||||||
|
}
|
||||||
|
|
||||||
|
ApplyColumnWidth();
|
||||||
|
OnPropertyChanged(nameof(HasColumns));
|
||||||
|
OnPropertyChanged(nameof(HasNoColumns));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Recomputes the global column width and pushes it to every column.
|
||||||
|
/// </summary>
|
||||||
|
public void ApplyColumnWidth() {
|
||||||
|
ColumnWidth = ColumnWidthPixels(_services.Config.Display.ColumnWidth);
|
||||||
|
foreach (ColumnViewModel column in Columns) {
|
||||||
|
column.Width = ColumnWidth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Resolves a column width setting to its pixel value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="settings">The configured column width.</param>
|
||||||
|
/// <returns>The width in pixels.</returns>
|
||||||
|
public static double ColumnWidthPixels(ColumnWidthSettings settings) => settings.Preset switch {
|
||||||
|
ColumnWidthPreset.Narrow => 240,
|
||||||
|
ColumnWidthPreset.Wide => 480,
|
||||||
|
ColumnWidthPreset.Custom => settings.CustomPixels,
|
||||||
|
_ => 320,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Orders cards by the selected option, tie-breaking by id ascending.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cards">The cards to order.</param>
|
||||||
|
/// <param name="option">The selected order.</param>
|
||||||
|
/// <returns>The ordered cards.</returns>
|
||||||
|
private static IEnumerable<CardModel> SortCards(IEnumerable<CardModel> cards, SortOption option) => option switch {
|
||||||
|
SortOption.IdAscending => cards.OrderBy(card => card.Id),
|
||||||
|
SortOption.IdDescending => cards.OrderByDescending(card => card.Id),
|
||||||
|
SortOption.CreatedAscending => cards.OrderBy(card => card.CreatedAt).ThenBy(card => card.Id),
|
||||||
|
SortOption.CreatedDescending => cards.OrderByDescending(card => card.CreatedAt).ThenBy(card => card.Id),
|
||||||
|
SortOption.UpdatedAscending => cards.OrderBy(card => card.UpdatedAt).ThenBy(card => card.Id),
|
||||||
|
SortOption.UpdatedDescending => cards.OrderByDescending(card => card.UpdatedAt).ThenBy(card => card.Id),
|
||||||
|
SortOption.TitleAscending => cards.OrderBy(card => card.Title, StringComparer.Ordinal).ThenBy(card => card.Id),
|
||||||
|
SortOption.TitleDescending => cards.OrderByDescending(card => card.Title, StringComparer.Ordinal).ThenBy(card => card.Id),
|
||||||
|
_ => cards.OrderBy(card => card.Id),
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Orders columns by the selected option, tie-breaking by id ascending.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="columns">The columns to order.</param>
|
||||||
|
/// <param name="option">The selected order.</param>
|
||||||
|
/// <returns>The ordered columns.</returns>
|
||||||
|
private static IEnumerable<ColumnModel> SortColumns(IEnumerable<ColumnModel> columns, SortOption option) => option switch {
|
||||||
|
SortOption.IdAscending => columns.OrderBy(column => column.Id),
|
||||||
|
SortOption.IdDescending => columns.OrderByDescending(column => column.Id),
|
||||||
|
SortOption.CreatedAscending => columns.OrderBy(column => column.CreatedAt).ThenBy(column => column.Id),
|
||||||
|
SortOption.CreatedDescending => columns.OrderByDescending(column => column.CreatedAt).ThenBy(column => column.Id),
|
||||||
|
SortOption.UpdatedAscending => columns.OrderBy(column => column.UpdatedAt).ThenBy(column => column.Id),
|
||||||
|
SortOption.UpdatedDescending => columns.OrderByDescending(column => column.UpdatedAt).ThenBy(column => column.Id),
|
||||||
|
SortOption.TitleAscending => columns.OrderBy(column => column.Title, StringComparer.Ordinal).ThenBy(column => column.Id),
|
||||||
|
SortOption.TitleDescending => columns.OrderByDescending(column => column.Title, StringComparer.Ordinal).ThenBy(column => column.Id),
|
||||||
|
_ => columns.OrderBy(column => column.Id),
|
||||||
|
};
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
|
||||||
|
using YKanBan.Models;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels.Board;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// One card on the board. Clicking the card body opens the editor; the corner
|
||||||
|
/// menu offers delete and move. The shown text is the "#id title" heading, a
|
||||||
|
/// truncated content preview and the colored tag badges; timestamps are not
|
||||||
|
/// shown on the board.
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class CardViewModel : ViewModelBase {
|
||||||
|
/// <summary>
|
||||||
|
/// Maximum number of content characters shown in the card preview.
|
||||||
|
/// </summary>
|
||||||
|
private const int PreviewLength = 200;
|
||||||
|
|
||||||
|
private readonly BoardViewModel _board;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the card view from its model.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="board">The owning board view model.</param>
|
||||||
|
/// <param name="card">The card model to display.</param>
|
||||||
|
public CardViewModel(BoardViewModel board, CardModel card) {
|
||||||
|
_board = board;
|
||||||
|
Model = card;
|
||||||
|
TagBadges = card.Tags.Select(tag => new TagBadgeViewModel(tag)).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the underlying card model.
|
||||||
|
/// </summary>
|
||||||
|
public CardModel Model { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the card id.
|
||||||
|
/// </summary>
|
||||||
|
public long Id => Model.Id;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the owning column id.
|
||||||
|
/// </summary>
|
||||||
|
public long ColumnId => Model.ColumnId;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the tag badges shown under the content.
|
||||||
|
/// </summary>
|
||||||
|
public IReadOnlyList<TagBadgeViewModel> TagBadges { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the bold id marker, for example "#61".
|
||||||
|
/// </summary>
|
||||||
|
public string IdText => $"#{Model.Id}";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the card title, empty when the card has no title.
|
||||||
|
/// </summary>
|
||||||
|
public string TitleText => Model.Title;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the card has a title to show.
|
||||||
|
/// </summary>
|
||||||
|
public bool HasTitle => Model.Title.Length > 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the card has content to preview.
|
||||||
|
/// </summary>
|
||||||
|
public bool HasContent => Model.Content.Length > 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the content preview, collapsed to one line and truncated.
|
||||||
|
/// </summary>
|
||||||
|
public string PreviewContent {
|
||||||
|
get {
|
||||||
|
string singleLine = Model.Content.Replace("\r", " ").Replace("\n", " ");
|
||||||
|
return singleLine.Length <= PreviewLength ? singleLine : singleLine[..PreviewLength] + "…";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the card has any tags.
|
||||||
|
/// </summary>
|
||||||
|
public bool HasTags => TagBadges.Count > 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens the card editor.
|
||||||
|
/// </summary>
|
||||||
|
[RelayCommand]
|
||||||
|
private void Edit() => _ = _board.RequestEditCardAsync(this);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Asks the board to delete this card.
|
||||||
|
/// </summary>
|
||||||
|
[RelayCommand]
|
||||||
|
private void Delete() => _ = _board.RequestDeleteCardAsync(this);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Asks the board to move this card to another column.
|
||||||
|
/// </summary>
|
||||||
|
[RelayCommand]
|
||||||
|
private void Move() => _ = _board.RequestMoveCardAsync(this);
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
using System.Collections.ObjectModel;
|
||||||
|
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
|
||||||
|
using YKanBan.Models;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels.Board;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// One board column: a header with its title, card count and actions, plus the
|
||||||
|
/// vertically stacked cards.
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class ColumnViewModel : ViewModelBase {
|
||||||
|
private readonly BoardViewModel _board;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the column view from its model and cards.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="board">The owning board view model.</param>
|
||||||
|
/// <param name="column">The column model.</param>
|
||||||
|
/// <param name="cards">The already sorted cards belonging to this column.</param>
|
||||||
|
public ColumnViewModel(BoardViewModel board, ColumnModel column, IEnumerable<CardViewModel> cards) {
|
||||||
|
_board = board;
|
||||||
|
Model = column;
|
||||||
|
Cards = new ObservableCollection<CardViewModel>(cards);
|
||||||
|
width = board.ColumnWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the underlying column model.
|
||||||
|
/// </summary>
|
||||||
|
public ColumnModel Model { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the column id.
|
||||||
|
/// </summary>
|
||||||
|
public long Id => Model.Id;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the column title.
|
||||||
|
/// </summary>
|
||||||
|
public string Title => Model.Title;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the column description.
|
||||||
|
/// </summary>
|
||||||
|
public string Description => Model.Description;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the cards in this column, already in display order.
|
||||||
|
/// </summary>
|
||||||
|
public ObservableCollection<CardViewModel> Cards { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the number of cards in this column.
|
||||||
|
/// </summary>
|
||||||
|
public int CardCount => Cards.Count;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the tooltip text: the column description when present, otherwise
|
||||||
|
/// <see langword="null"/> so no tooltip is shown.
|
||||||
|
/// </summary>
|
||||||
|
public string? ToolTipText => Model.Description.Length > 0 ? Model.Description : null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the rendered column width in pixels, applied globally.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private double width;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens the editor for a new card in this column.
|
||||||
|
/// </summary>
|
||||||
|
[RelayCommand]
|
||||||
|
private void AddCard() => _ = _board.RequestAddCardAsync(this);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens the editor for this column.
|
||||||
|
/// </summary>
|
||||||
|
[RelayCommand]
|
||||||
|
private void Edit() => _ = _board.RequestEditColumnAsync(this);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Asks the board to delete this column.
|
||||||
|
/// </summary>
|
||||||
|
[RelayCommand]
|
||||||
|
private void Delete() => _ = _board.RequestDeleteColumnAsync(this);
|
||||||
|
}
|
||||||
@@ -0,0 +1,164 @@
|
|||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
|
using YKanBan.Storage.AppData;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels.Board;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The board display options shown in the Display flyout: the global column
|
||||||
|
/// width and the separate card and column orderings. Every change writes to
|
||||||
|
/// the configuration and asks the board to refresh immediately.
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class DisplaySettingsViewModel : ViewModelBase {
|
||||||
|
/// <summary>
|
||||||
|
/// Smallest accepted manual width.
|
||||||
|
/// </summary>
|
||||||
|
public const int MinimumPixels = 160;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Largest accepted manual width.
|
||||||
|
/// </summary>
|
||||||
|
public const int MaximumPixels = 720;
|
||||||
|
|
||||||
|
private readonly AppConfig _config;
|
||||||
|
private readonly Action _refresh;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the display options from the configuration.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="config">The live application configuration.</param>
|
||||||
|
/// <param name="refresh">Invoked after every change to refresh the board.</param>
|
||||||
|
public DisplaySettingsViewModel(AppConfig config, Action refresh) {
|
||||||
|
_config = config;
|
||||||
|
_refresh = refresh;
|
||||||
|
|
||||||
|
Presets =
|
||||||
|
[
|
||||||
|
new OptionItem(ColumnWidthPreset.Narrow, Resources.WidthPreset_Narrow),
|
||||||
|
new OptionItem(ColumnWidthPreset.Standard, Resources.WidthPreset_Standard),
|
||||||
|
new OptionItem(ColumnWidthPreset.Wide, Resources.WidthPreset_Wide),
|
||||||
|
new OptionItem(ColumnWidthPreset.Custom, Resources.WidthPreset_Custom),
|
||||||
|
];
|
||||||
|
SortOptions = BuildSortOptions();
|
||||||
|
|
||||||
|
selectedPreset = Presets.FirstOrDefault(option => (ColumnWidthPreset)option.Value == config.Display.ColumnWidth.Preset)
|
||||||
|
?? Presets[1];
|
||||||
|
customPixels = config.Display.ColumnWidth.CustomPixels;
|
||||||
|
selectedCardSort = FindSort(SortOptions, config.Display.CardSort);
|
||||||
|
selectedColumnSort = FindSort(SortOptions, config.Display.ColumnSort);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the width preset choices.
|
||||||
|
/// </summary>
|
||||||
|
public IReadOnlyList<OptionItem> Presets { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the ordering choices (shared by cards and columns).
|
||||||
|
/// </summary>
|
||||||
|
public IReadOnlyList<OptionItem> SortOptions { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the selected width preset.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private OptionItem? selectedPreset;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the manual pixel width used by the custom preset.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private decimal? customPixels;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the selected card order.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private OptionItem? selectedCardSort;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the selected column order.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private OptionItem? selectedColumnSort;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the custom preset is selected.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsCustom => SelectedPreset is not null && (ColumnWidthPreset)SelectedPreset.Value == ColumnWidthPreset.Custom;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stores the width preset and refreshes the board.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">The new selection.</param>
|
||||||
|
partial void OnSelectedPresetChanged(OptionItem? value) {
|
||||||
|
OnPropertyChanged(nameof(IsCustom));
|
||||||
|
if (value is not null) {
|
||||||
|
_config.Display.ColumnWidth.Preset = (ColumnWidthPreset)value.Value;
|
||||||
|
_refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stores the manual width and refreshes the board when the custom preset is active.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">The new pixel count.</param>
|
||||||
|
partial void OnCustomPixelsChanged(decimal? value) {
|
||||||
|
if (value is null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pixels = (int)value.Value;
|
||||||
|
_config.Display.ColumnWidth.CustomPixels = pixels;
|
||||||
|
if (IsCustom) {
|
||||||
|
_refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stores the card order and refreshes the board.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">The new selection.</param>
|
||||||
|
partial void OnSelectedCardSortChanged(OptionItem? value) {
|
||||||
|
if (value is not null) {
|
||||||
|
_config.Display.CardSort = (SortOption)value.Value;
|
||||||
|
_refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stores the column order and refreshes the board.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">The new selection.</param>
|
||||||
|
partial void OnSelectedColumnSortChanged(OptionItem? value) {
|
||||||
|
if (value is not null) {
|
||||||
|
_config.Display.ColumnSort = (SortOption)value.Value;
|
||||||
|
_refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Builds the localized eight-way ordering option list.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The ordering options.</returns>
|
||||||
|
private static IReadOnlyList<OptionItem> BuildSortOptions() =>
|
||||||
|
[
|
||||||
|
new OptionItem(SortOption.IdAscending, Resources.Sort_IdAsc),
|
||||||
|
new OptionItem(SortOption.IdDescending, Resources.Sort_IdDesc),
|
||||||
|
new OptionItem(SortOption.CreatedAscending, Resources.Sort_CreatedAsc),
|
||||||
|
new OptionItem(SortOption.CreatedDescending, Resources.Sort_CreatedDesc),
|
||||||
|
new OptionItem(SortOption.UpdatedAscending, Resources.Sort_UpdatedAsc),
|
||||||
|
new OptionItem(SortOption.UpdatedDescending, Resources.Sort_UpdatedDesc),
|
||||||
|
new OptionItem(SortOption.TitleAscending, Resources.Sort_TitleAsc),
|
||||||
|
new OptionItem(SortOption.TitleDescending, Resources.Sort_TitleDesc),
|
||||||
|
];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Finds the option matching a stored sort value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="options">The option list.</param>
|
||||||
|
/// <param name="value">The stored value.</param>
|
||||||
|
/// <returns>The matching option, or the first option.</returns>
|
||||||
|
private static OptionItem FindSort(IReadOnlyList<OptionItem> options, SortOption value) =>
|
||||||
|
options.FirstOrDefault(option => (SortOption)option.Value == value) ?? options[0];
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
using Avalonia.Media;
|
||||||
|
|
||||||
|
using YKanBan.Models;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels.Board;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A read-only colored tag badge shown on a card: the tag name over a
|
||||||
|
/// background taken directly from the tag color (user data, never themed) and
|
||||||
|
/// an automatically contrasting text color.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class TagBadgeViewModel {
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a badge from a tag.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tag">The tag to render.</param>
|
||||||
|
public TagBadgeViewModel(TagModel tag) {
|
||||||
|
Tag = tag;
|
||||||
|
Name = tag.Name;
|
||||||
|
Color background = Color.FromRgb(tag.Color.R, tag.Color.G, tag.Color.B);
|
||||||
|
Background = new SolidColorBrush(background);
|
||||||
|
Foreground = new SolidColorBrush(ContrastingTextColor(background));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the underlying tag model.
|
||||||
|
/// </summary>
|
||||||
|
public TagModel Tag { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the tag name.
|
||||||
|
/// </summary>
|
||||||
|
public string Name { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the tooltip text: the tag description when present, otherwise
|
||||||
|
/// <see langword="null"/> so no tooltip is shown.
|
||||||
|
/// </summary>
|
||||||
|
public string? ToolTipText => Tag.Description.Length > 0 ? Tag.Description : null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the badge background brush.
|
||||||
|
/// </summary>
|
||||||
|
public IBrush Background { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the badge text brush.
|
||||||
|
/// </summary>
|
||||||
|
public IBrush Foreground { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Picks black or white text for readability against the given background.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="background">The badge background color.</param>
|
||||||
|
/// <returns>The contrasting text color.</returns>
|
||||||
|
private static Color ContrastingTextColor(Color background) {
|
||||||
|
double luminance = (0.299 * background.R + 0.587 * background.G + 0.114 * background.B) / 255.0;
|
||||||
|
return luminance > 0.6 ? Colors.Black : Colors.White;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels.Dialogs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The about dialog: application name, version, repository link and license.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class AboutDialogViewModel : ViewModelBase {
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the view model, reading the version from the assembly.
|
||||||
|
/// </summary>
|
||||||
|
public AboutDialogViewModel() {
|
||||||
|
string version = typeof(AboutDialogViewModel).Assembly.GetName().Version?.ToString(3) ?? "0.0.0";
|
||||||
|
Version = string.Format(
|
||||||
|
Resources.Culture ?? CultureInfo.CurrentCulture, Resources.About_Version, version);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the application name.
|
||||||
|
/// </summary>
|
||||||
|
public string AppName => Resources.App_Name;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the localized version line.
|
||||||
|
/// </summary>
|
||||||
|
public string Version { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the repository URL.
|
||||||
|
/// </summary>
|
||||||
|
public string RepositoryUrl => "https://github.com/yyc12345/YKanBan";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the license name.
|
||||||
|
/// </summary>
|
||||||
|
public string License => Resources.About_LicenseValue;
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
using Avalonia.Media;
|
||||||
|
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
|
||||||
|
using YKanBan.Models;
|
||||||
|
using YKanBan.ViewModels.Board;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels.Dialogs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// One tag assigned to the card being edited, shown with a colored badge and a
|
||||||
|
/// remove action that only changes the in-memory assignment (the actual write
|
||||||
|
/// happens on confirm).
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class AssignedTagViewModel {
|
||||||
|
private readonly CardEditorViewModel _editor;
|
||||||
|
private readonly TagBadgeViewModel _badge;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the assigned-tag row.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="editor">The owning card editor.</param>
|
||||||
|
/// <param name="tag">The assigned tag.</param>
|
||||||
|
public AssignedTagViewModel(CardEditorViewModel editor, TagModel tag) {
|
||||||
|
_editor = editor;
|
||||||
|
Tag = tag;
|
||||||
|
_badge = new TagBadgeViewModel(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the assigned tag model.
|
||||||
|
/// </summary>
|
||||||
|
public TagModel Tag { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the tag name.
|
||||||
|
/// </summary>
|
||||||
|
public string Name => _badge.Name;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the badge background brush.
|
||||||
|
/// </summary>
|
||||||
|
public IBrush Background => _badge.Background;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the badge text brush.
|
||||||
|
/// </summary>
|
||||||
|
public IBrush Foreground => _badge.Foreground;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes this tag from the in-memory assignment.
|
||||||
|
/// </summary>
|
||||||
|
[RelayCommand]
|
||||||
|
private void Remove() => _editor.RemoveTag(Tag);
|
||||||
|
}
|
||||||
@@ -0,0 +1,181 @@
|
|||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
|
||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
|
||||||
|
using YKanBan.Models;
|
||||||
|
using YKanBan.Storage.Workspace;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels.Dialogs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The add/edit card dialog: title, content and the assigned-tag area, plus
|
||||||
|
/// read-only id and timestamps for an existing card. The confirm writes the
|
||||||
|
/// card and its tag assignment as one unit; a confirm with no effective change
|
||||||
|
/// writes nothing; cancelling never writes.
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class CardEditorViewModel : ViewModelBase {
|
||||||
|
private readonly WorkspaceRepository _repository;
|
||||||
|
private readonly long _columnId;
|
||||||
|
private readonly CardModel? _existing;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the dialog for a new or existing card.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="repository">The workspace repository.</param>
|
||||||
|
/// <param name="columnId">The owning column (used when adding).</param>
|
||||||
|
/// <param name="existing">The card to edit, or <see langword="null"/> to add one.</param>
|
||||||
|
public CardEditorViewModel(WorkspaceRepository repository, long columnId, CardModel? existing) {
|
||||||
|
_repository = repository;
|
||||||
|
_columnId = columnId;
|
||||||
|
_existing = existing;
|
||||||
|
title = existing?.Title ?? string.Empty;
|
||||||
|
content = existing?.Content ?? string.Empty;
|
||||||
|
AssignedTags = new ObservableCollection<AssignedTagViewModel>(
|
||||||
|
(existing?.Tags ?? []).Select(tag => new AssignedTagViewModel(this, tag)));
|
||||||
|
|
||||||
|
if (existing is not null) {
|
||||||
|
IdLine = string.Format(Culture, Resources.CardDialog_Id, $"#{existing.Id}");
|
||||||
|
CreatedLine = string.Format(Culture, Resources.CardDialog_Created, FormatTime(existing.CreatedAt));
|
||||||
|
ModifiedLine = string.Format(Culture, Resources.CardDialog_Modified, FormatTime(existing.UpdatedAt));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the interaction that opens the nested tag picker.
|
||||||
|
/// </summary>
|
||||||
|
public Interaction<Unit, TagModel?> ShowTagPicker { get; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the workspace repository (used by the tag picker).
|
||||||
|
/// </summary>
|
||||||
|
public WorkspaceRepository Repository => _repository;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether this dialog creates a new card.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsNew => _existing is null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the localized window title.
|
||||||
|
/// </summary>
|
||||||
|
public string WindowTitle => IsNew ? Resources.CardDialog_AddTitle : Resources.CardDialog_EditTitle;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the read-only id line, empty for a new card.
|
||||||
|
/// </summary>
|
||||||
|
public string IdLine { get; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the read-only created line, empty for a new card.
|
||||||
|
/// </summary>
|
||||||
|
public string CreatedLine { get; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the read-only modified line, empty for a new card.
|
||||||
|
/// </summary>
|
||||||
|
public string ModifiedLine { get; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the tags currently assigned to the card (in memory until confirmed).
|
||||||
|
/// </summary>
|
||||||
|
public ObservableCollection<AssignedTagViewModel> AssignedTags { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the card title.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private string title;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the card content.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private string content;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the inline error shown when the write fails.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private string? errorMessage;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether there are unsaved effective changes.
|
||||||
|
/// </summary>
|
||||||
|
public bool HasChanges {
|
||||||
|
get {
|
||||||
|
if (_existing is null) {
|
||||||
|
return Title.Length > 0 || Content.Length > 0 || AssignedTags.Count > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool tagsChanged = !AssignedTags.Select(row => row.Tag.Id).ToHashSet()
|
||||||
|
.SetEquals(_existing.Tags.Select(tag => tag.Id));
|
||||||
|
return _existing.Title != Title || _existing.Content != Content || tagsChanged;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens the nested tag picker and adds the chosen tag when it is new to the card.
|
||||||
|
/// </summary>
|
||||||
|
[RelayCommand]
|
||||||
|
private async Task AddTagAsync() {
|
||||||
|
TagModel? tag = await ShowTagPicker.Handle(Unit.Value);
|
||||||
|
if (tag is not null && AssignedTags.All(row => row.Tag.Id != tag.Id)) {
|
||||||
|
AssignedTags.Add(new AssignedTagViewModel(this, tag));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes a tag from the in-memory assignment.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tag">The tag to remove.</param>
|
||||||
|
public void RemoveTag(TagModel tag) {
|
||||||
|
AssignedTagViewModel? row = AssignedTags.FirstOrDefault(item => item.Tag.Id == tag.Id);
|
||||||
|
if (row is not null) {
|
||||||
|
AssignedTags.Remove(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes the card and its tags when there is an effective change.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns><see langword="true"/> when the dialog may close.</returns>
|
||||||
|
public bool TryAccept() {
|
||||||
|
ErrorMessage = null;
|
||||||
|
|
||||||
|
// A confirm with no effective change writes nothing and just closes.
|
||||||
|
if (!HasChanges) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
IReadOnlyCollection<long> tagIds = AssignedTags.Select(row => row.Tag.Id).ToList();
|
||||||
|
if (_existing is null) {
|
||||||
|
_repository.AddCard(_columnId, Title, Content, tagIds);
|
||||||
|
} else {
|
||||||
|
_repository.UpdateCard(_existing.Id, Title, Content, tagIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (SqliteException) {
|
||||||
|
ErrorMessage = Resources.CardDialog_Error;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the culture used for formatted read-only lines.
|
||||||
|
/// </summary>
|
||||||
|
private static CultureInfo Culture => Resources.Culture ?? CultureInfo.CurrentCulture;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Formats a stored timestamp as a local time using the UI language pattern.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="unixSeconds">The stored timestamp.</param>
|
||||||
|
/// <returns>The formatted local time.</returns>
|
||||||
|
private static string FormatTime(long unixSeconds) =>
|
||||||
|
DateTimeOffset.FromUnixTimeSeconds(unixSeconds).ToLocalTime().ToString(Resources.CardDialog_TimePattern, Culture);
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
|
||||||
|
using YKanBan.Models;
|
||||||
|
using YKanBan.Storage.Workspace;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels.Dialogs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The add/edit column dialog: a required title and an optional description.
|
||||||
|
/// The write happens when the dialog is accepted; a duplicate or empty title
|
||||||
|
/// keeps the dialog open with an inline error.
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class ColumnEditorViewModel : ViewModelBase {
|
||||||
|
private readonly WorkspaceRepository _repository;
|
||||||
|
private readonly ColumnModel? _existing;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the dialog for a new or existing column.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="repository">The workspace repository.</param>
|
||||||
|
/// <param name="existing">The column to edit, or <see langword="null"/> to add one.</param>
|
||||||
|
public ColumnEditorViewModel(WorkspaceRepository repository, ColumnModel? existing) {
|
||||||
|
_repository = repository;
|
||||||
|
_existing = existing;
|
||||||
|
title = existing?.Title ?? string.Empty;
|
||||||
|
description = existing?.Description ?? string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether this dialog creates a new column.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsNew => _existing is null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the localized window title.
|
||||||
|
/// </summary>
|
||||||
|
public string WindowTitle => IsNew ? Resources.ColumnDialog_AddTitle : Resources.ColumnDialog_EditTitle;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the column title.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private string title;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the column description.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private string description;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the inline error shown when the title is rejected.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private string? errorMessage;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes the column when accepted.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns><see langword="true"/> when the dialog may close.</returns>
|
||||||
|
public bool TryAccept() {
|
||||||
|
ErrorMessage = null;
|
||||||
|
try {
|
||||||
|
if (_existing is null) {
|
||||||
|
_repository.AddColumn(Title, Description);
|
||||||
|
} else {
|
||||||
|
_repository.UpdateColumn(_existing.Id, Title, Description);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (SqliteException) {
|
||||||
|
ErrorMessage = Resources.ColumnDialog_InvalidTitle;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels.Dialogs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The confirmation shown before deleting a card, naming the card id.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class DeleteCardConfirmViewModel : ViewModelBase {
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the confirmation.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cardId">The id of the card to delete.</param>
|
||||||
|
public DeleteCardConfirmViewModel(long cardId) {
|
||||||
|
Message = string.Format(
|
||||||
|
Resources.Culture ?? CultureInfo.CurrentCulture,
|
||||||
|
Resources.Confirm_DeleteCard_Message,
|
||||||
|
cardId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the localized confirmation message.
|
||||||
|
/// </summary>
|
||||||
|
public string Message { get; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels.Dialogs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The confirmation shown before deleting a column, naming the column and how
|
||||||
|
/// many cards it will cascade-delete.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class DeleteColumnConfirmViewModel : ViewModelBase {
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the confirmation.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="columnTitle">The title of the column to delete.</param>
|
||||||
|
/// <param name="cardCount">The number of cards in the column.</param>
|
||||||
|
public DeleteColumnConfirmViewModel(string columnTitle, int cardCount) {
|
||||||
|
Message = string.Format(
|
||||||
|
Resources.Culture ?? CultureInfo.CurrentCulture,
|
||||||
|
Resources.Confirm_DeleteColumn_Message,
|
||||||
|
columnTitle,
|
||||||
|
cardCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the localized confirmation message.
|
||||||
|
/// </summary>
|
||||||
|
public string Message { get; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels.Dialogs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The confirmation shown before deleting a tag, naming the tag and how many
|
||||||
|
/// cards it will be removed from.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class DeleteTagConfirmViewModel : ViewModelBase {
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the confirmation.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tagName">The name of the tag to delete.</param>
|
||||||
|
/// <param name="usageCount">The number of cards using the tag.</param>
|
||||||
|
public DeleteTagConfirmViewModel(string tagName, long usageCount) {
|
||||||
|
Message = string.Format(
|
||||||
|
Resources.Culture ?? CultureInfo.CurrentCulture,
|
||||||
|
Resources.DeleteTag_Confirm_Message,
|
||||||
|
tagName,
|
||||||
|
usageCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the localized confirmation message.
|
||||||
|
/// </summary>
|
||||||
|
public string Message { get; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace YKanBan.ViewModels.Dialogs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The confirmation shown before closing an editor with unsaved changes.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class DiscardEditConfirmViewModel : ViewModelBase {
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the localized confirmation message.
|
||||||
|
/// </summary>
|
||||||
|
public string Message => Resources.Confirm_Discard_Message;
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels.Dialogs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The confirmation dialog shown after a successful Markdown export, naming the
|
||||||
|
/// written file.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class ExportDoneViewModel : ViewModelBase {
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the dialog with the exported file path.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filePath">The path the export was written to.</param>
|
||||||
|
public ExportDoneViewModel(string filePath) {
|
||||||
|
Message = string.Format(
|
||||||
|
Resources.Culture ?? CultureInfo.CurrentCulture, Resources.Export_Done_Message, filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the localized confirmation message.
|
||||||
|
/// </summary>
|
||||||
|
public string Message { get; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
|
using YKanBan.Models;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels.Dialogs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The move-card dialog: choose one of the other columns as the destination.
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class MoveCardViewModel : ViewModelBase {
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the dialog with the candidate destination columns.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="columns">All columns; the card's current column is excluded.</param>
|
||||||
|
/// <param name="currentColumnId">The card's current column id.</param>
|
||||||
|
public MoveCardViewModel(IReadOnlyList<ColumnModel> columns, long currentColumnId) {
|
||||||
|
Targets = columns
|
||||||
|
.Where(column => column.Id != currentColumnId)
|
||||||
|
.Select(column => new OptionItem(column.Id, column.Title))
|
||||||
|
.ToList();
|
||||||
|
selectedTarget = Targets.FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the candidate destination columns.
|
||||||
|
/// </summary>
|
||||||
|
public IReadOnlyList<OptionItem> Targets { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the selected destination column.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private OptionItem? selectedTarget;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether there is anywhere to move the card.
|
||||||
|
/// </summary>
|
||||||
|
public bool CanMove => Targets.Count > 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels.Dialogs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The pure-information dialog shown when the search expression is invalid. It
|
||||||
|
/// wraps the parser's non-localized English detail in the localized message.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class SearchErrorViewModel : ViewModelBase {
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the dialog with the parser's English detail.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="detail">The non-localized parser error description.</param>
|
||||||
|
public SearchErrorViewModel(string detail) {
|
||||||
|
Message = string.Format(
|
||||||
|
Resources.Culture ?? CultureInfo.CurrentCulture,
|
||||||
|
Resources.Search_Error_Message,
|
||||||
|
detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the localized error message.
|
||||||
|
/// </summary>
|
||||||
|
public string Message { get; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
|
using YKanBan.Storage.AppData;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels.Dialogs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The settings dialog: language (restart to apply), theme and the four
|
||||||
|
/// confirmation-dialog toggles. Nothing is applied until the user accepts;
|
||||||
|
/// cancelling or closing the window discards the changes.
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class SettingsDialogViewModel : ViewModelBase {
|
||||||
|
private readonly AppConfig _config;
|
||||||
|
private readonly string _startupLanguage;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the dialog from the live configuration.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="config">The live application configuration.</param>
|
||||||
|
/// <param name="startupLanguage">The language applied at startup, for the restart notice.</param>
|
||||||
|
public SettingsDialogViewModel(AppConfig config, string startupLanguage) {
|
||||||
|
_config = config;
|
||||||
|
_startupLanguage = startupLanguage;
|
||||||
|
|
||||||
|
Languages =
|
||||||
|
[
|
||||||
|
new OptionItem(AppConfig.DefaultLanguage, Resources.Settings_LanguageEnglish),
|
||||||
|
new OptionItem("zh-Hans", Resources.Settings_LanguageChinese),
|
||||||
|
];
|
||||||
|
selectedLanguage = Languages.FirstOrDefault(option => (string)option.Value == _config.Language)
|
||||||
|
?? Languages[0];
|
||||||
|
|
||||||
|
Themes =
|
||||||
|
[
|
||||||
|
new OptionItem(ThemeOption.Light, Resources.Settings_ThemeLight),
|
||||||
|
new OptionItem(ThemeOption.Dark, Resources.Settings_ThemeDark),
|
||||||
|
new OptionItem(ThemeOption.FollowSystem, Resources.Settings_ThemeFollowSystem),
|
||||||
|
];
|
||||||
|
selectedTheme = Themes.FirstOrDefault(option => option.Value.Equals(_config.Theme)) ?? Themes[^1];
|
||||||
|
|
||||||
|
confirmDeleteCard = _config.Confirmations.DeleteCard;
|
||||||
|
confirmDeleteColumn = _config.Confirmations.DeleteColumn;
|
||||||
|
confirmDeleteTag = _config.Confirmations.DeleteTag;
|
||||||
|
confirmDiscardEdit = _config.Confirmations.DiscardEdit;
|
||||||
|
RefreshRestartNotice();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the available languages.
|
||||||
|
/// </summary>
|
||||||
|
public IReadOnlyList<OptionItem> Languages { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the available themes.
|
||||||
|
/// </summary>
|
||||||
|
public IReadOnlyList<OptionItem> Themes { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the selected language; takes effect after a restart.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private OptionItem? selectedLanguage;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the selected theme; applied when the dialog is accepted.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private OptionItem? selectedTheme;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets whether deleting a card asks for confirmation.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private bool confirmDeleteCard;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets whether deleting a column asks for confirmation.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private bool confirmDeleteColumn;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets whether deleting a tag asks for confirmation.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private bool confirmDeleteTag;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets whether discarding card edits asks for confirmation.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private bool confirmDiscardEdit;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets whether the working language differs from the one applied at startup.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private bool restartNoticeVisible;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Commits the working values into the live configuration.
|
||||||
|
/// </summary>
|
||||||
|
public void Accept() {
|
||||||
|
if (SelectedLanguage is not null) {
|
||||||
|
_config.Language = (string)SelectedLanguage.Value;
|
||||||
|
}
|
||||||
|
if (SelectedTheme is not null) {
|
||||||
|
_config.Theme = (ThemeOption)SelectedTheme.Value;
|
||||||
|
App.ApplyTheme(_config.Theme);
|
||||||
|
}
|
||||||
|
|
||||||
|
_config.Confirmations.DeleteCard = ConfirmDeleteCard;
|
||||||
|
_config.Confirmations.DeleteColumn = ConfirmDeleteColumn;
|
||||||
|
_config.Confirmations.DeleteTag = ConfirmDeleteTag;
|
||||||
|
_config.Confirmations.DiscardEdit = ConfirmDiscardEdit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Refreshes the restart notice after a language selection change.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">The new selection.</param>
|
||||||
|
partial void OnSelectedLanguageChanged(OptionItem? value) => RefreshRestartNotice();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Recomputes whether the restart notice must be shown.
|
||||||
|
/// </summary>
|
||||||
|
private void RefreshRestartNotice() =>
|
||||||
|
RestartNoticeVisible = SelectedLanguage is not null && (string)SelectedLanguage.Value != _startupLanguage;
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
using Avalonia.Media;
|
||||||
|
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
|
||||||
|
using YKanBan.Models;
|
||||||
|
using YKanBan.Storage.Workspace;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels.Dialogs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The add/edit tag dialog: a name, a color chosen with a color picker and an
|
||||||
|
/// optional description. The write happens when the dialog is accepted; a
|
||||||
|
/// duplicate or empty name keeps the dialog open with an inline error.
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class TagEditorViewModel : ViewModelBase {
|
||||||
|
private readonly WorkspaceRepository _repository;
|
||||||
|
private readonly TagModel? _existing;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the dialog for a new or existing tag.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="repository">The workspace repository.</param>
|
||||||
|
/// <param name="existing">The tag to edit, or <see langword="null"/> to add one.</param>
|
||||||
|
public TagEditorViewModel(WorkspaceRepository repository, TagModel? existing) {
|
||||||
|
_repository = repository;
|
||||||
|
_existing = existing;
|
||||||
|
name = existing?.Name ?? string.Empty;
|
||||||
|
description = existing?.Description ?? string.Empty;
|
||||||
|
color = existing is not null
|
||||||
|
? Color.FromRgb(existing.Color.R, existing.Color.G, existing.Color.B)
|
||||||
|
: Colors.Gray;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether this dialog creates a new tag.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsNew => _existing is null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the localized window title.
|
||||||
|
/// </summary>
|
||||||
|
public string WindowTitle => IsNew ? Resources.TagEditor_AddTitle : Resources.TagEditor_EditTitle;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the tag name.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private string name;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the tag color.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private Color color;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the tag description.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private string description;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the inline error shown when the name is rejected.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private string? errorMessage;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes the tag when accepted.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns><see langword="true"/> when the dialog may close.</returns>
|
||||||
|
public bool TryAccept() {
|
||||||
|
ErrorMessage = null;
|
||||||
|
var rgb = new RgbColor(Color.R, Color.G, Color.B);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (_existing is null) {
|
||||||
|
_repository.AddTag(Name, rgb, Description);
|
||||||
|
} else {
|
||||||
|
_repository.UpdateTag(_existing.Id, Name, rgb, Description);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (SqliteException) {
|
||||||
|
ErrorMessage = Resources.TagEditor_InvalidName;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
|
using YKanBan.Storage.Workspace;
|
||||||
|
using YKanBan.ViewModels.Board;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels.Dialogs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The nested tag picker opened from the card editor: choose one tag that is
|
||||||
|
/// not already assigned to the card. When no candidate remains the picker
|
||||||
|
/// shows a message and cannot be confirmed.
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class TagPickerViewModel : ViewModelBase {
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the picker with the tags not yet assigned to the card.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="repository">The workspace repository.</param>
|
||||||
|
/// <param name="assignedTagIds">The tag ids already assigned to the card.</param>
|
||||||
|
public TagPickerViewModel(WorkspaceRepository repository, IReadOnlyCollection<long> assignedTagIds) {
|
||||||
|
Targets = repository.GetTags()
|
||||||
|
.Where(tag => !assignedTagIds.Contains(tag.Id))
|
||||||
|
.Select(tag => new TagBadgeViewModel(tag))
|
||||||
|
.ToList();
|
||||||
|
selectedTarget = Targets.FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the assignable tags.
|
||||||
|
/// </summary>
|
||||||
|
public IReadOnlyList<TagBadgeViewModel> Targets { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the selected tag.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private TagBadgeViewModel? selectedTarget;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether there is a tag to add.
|
||||||
|
/// </summary>
|
||||||
|
public bool CanAdd => Targets.Count > 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace YKanBan.ViewModels.ErrorPages;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The full-window page shown when YKanBan is started without arguments or with
|
||||||
|
/// invalid arguments. It has no operations.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class ArgumentErrorPageViewModel : ViewModelBase {
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels.ErrorPages;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The full-window page shown when the folder passed on the command line does
|
||||||
|
/// not exist. It has no operations.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class DirectoryMissingPageViewModel : ViewModelBase {
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the page for a missing folder.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The folder path that does not exist.</param>
|
||||||
|
public DirectoryMissingPageViewModel(string folderPath) {
|
||||||
|
FolderPath = folderPath;
|
||||||
|
Message = string.Format(
|
||||||
|
Resources.Culture ?? CultureInfo.CurrentCulture, Resources.Error_DirectoryMissing_Message, folderPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the folder path that does not exist.
|
||||||
|
/// </summary>
|
||||||
|
public string FolderPath { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the localized explanatory message.
|
||||||
|
/// </summary>
|
||||||
|
public string Message { get; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels.ErrorPages;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The full-window page shown when the workspace is already locked by another
|
||||||
|
/// instance. It has no operations.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class LockConflictPageViewModel : ViewModelBase {
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the page for a locked workspace.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The locked workspace folder.</param>
|
||||||
|
public LockConflictPageViewModel(string folderPath) {
|
||||||
|
FolderPath = folderPath;
|
||||||
|
Message = string.Format(
|
||||||
|
Resources.Culture ?? CultureInfo.CurrentCulture, Resources.Error_LockConflict_Message, folderPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the locked workspace folder.
|
||||||
|
/// </summary>
|
||||||
|
public string FolderPath { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the localized explanatory message.
|
||||||
|
/// </summary>
|
||||||
|
public string Message { get; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels.ErrorPages;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The full-window page shown when the folder exists but has no .ykanban
|
||||||
|
/// structure. It is the only error page with an operation: initializing the
|
||||||
|
/// workspace.
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class NotInitializedPageViewModel : ViewModelBase {
|
||||||
|
private readonly Interaction<Unit> _initializeWorkspace;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the page for a folder without a workspace.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The uninitialized folder path.</param>
|
||||||
|
/// <param name="initializeWorkspace">The interaction that performs initialization.</param>
|
||||||
|
public NotInitializedPageViewModel(string folderPath, Interaction<Unit> initializeWorkspace) {
|
||||||
|
FolderPath = folderPath;
|
||||||
|
_initializeWorkspace = initializeWorkspace;
|
||||||
|
Message = string.Format(
|
||||||
|
Resources.Culture ?? CultureInfo.CurrentCulture, Resources.Error_NotInitialized_Message, folderPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the uninitialized folder path.
|
||||||
|
/// </summary>
|
||||||
|
public string FolderPath { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the localized explanatory message.
|
||||||
|
/// </summary>
|
||||||
|
public string Message { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Asks the owning view model to initialize this folder as a workspace.
|
||||||
|
/// </summary>
|
||||||
|
[RelayCommand]
|
||||||
|
private async Task InitializeAsync() => await _initializeWorkspace.Handle(Unit.Value);
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
namespace YKanBan.ViewModels;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Input placeholder for interactions that carry no meaningful payload.
|
||||||
|
/// </summary>
|
||||||
|
public readonly record struct Unit {
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the single unit value.
|
||||||
|
/// </summary>
|
||||||
|
public static Unit Value => default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A view-model side request with no result that the owning view fulfils
|
||||||
|
/// through a registered handler (opening a dialog, for example) — the classic
|
||||||
|
/// MVVM interaction pattern, implemented locally without extra dependencies.
|
||||||
|
/// The view model never holds a reference to a view.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TInput">The request payload.</typeparam>
|
||||||
|
public sealed class Interaction<TInput> {
|
||||||
|
private Func<TInput, Task>? _handler;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Registers the single handler; the view calls this once.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="handler">The handler that fulfils the request.</param>
|
||||||
|
public void RegisterHandler(Func<TInput, Task> handler) => _handler = handler;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invokes the registered handler.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">The request payload.</param>
|
||||||
|
/// <returns>A task that completes when the handler completes.</returns>
|
||||||
|
/// <exception cref="InvalidOperationException">No handler has been registered.</exception>
|
||||||
|
public Task Handle(TInput input) =>
|
||||||
|
_handler is null
|
||||||
|
? throw new InvalidOperationException("No handler registered for this interaction.")
|
||||||
|
: _handler(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A view-model side request that produces a result, fulfilled through a
|
||||||
|
/// registered handler.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TInput">The request payload.</typeparam>
|
||||||
|
/// <typeparam name="TOutput">The handler's answer.</typeparam>
|
||||||
|
public sealed class Interaction<TInput, TOutput> {
|
||||||
|
private Func<TInput, Task<TOutput>>? _handler;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Registers the single handler; the view calls this once.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="handler">The handler that fulfils the request.</param>
|
||||||
|
public void RegisterHandler(Func<TInput, Task<TOutput>> handler) => _handler = handler;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invokes the registered handler.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">The request payload.</param>
|
||||||
|
/// <returns>The handler's answer.</returns>
|
||||||
|
/// <exception cref="InvalidOperationException">No handler has been registered.</exception>
|
||||||
|
public Task<TOutput> Handle(TInput input) =>
|
||||||
|
_handler is null
|
||||||
|
? throw new InvalidOperationException("No handler registered for this interaction.")
|
||||||
|
: _handler(input);
|
||||||
|
}
|
||||||
@@ -1,6 +1,118 @@
|
|||||||
namespace YKanBan.ViewModels;
|
using System.Diagnostics;
|
||||||
|
|
||||||
public partial class MainWindowViewModel : ViewModelBase
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
{
|
|
||||||
public string Greeting { get; } = "Welcome to Avalonia!";
|
using YKanBan.Launching;
|
||||||
|
using YKanBan.Services;
|
||||||
|
using YKanBan.Storage;
|
||||||
|
using YKanBan.Storage.Workspace;
|
||||||
|
using YKanBan.ViewModels.ErrorPages;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The main window view model. It resolves the launch arguments into either the
|
||||||
|
/// normal workspace view or one of the full-window error pages, and owns the
|
||||||
|
/// interactions that the view fulfils by opening dialogs.
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class MainWindowViewModel : ViewModelBase {
|
||||||
|
private readonly AppServices _services;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the view model and resolves the workspace state.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="services">The process composition root.</param>
|
||||||
|
/// <param name="arguments">The command-line arguments (excluding the executable).</param>
|
||||||
|
public MainWindowViewModel(AppServices services, IReadOnlyList<string> arguments) {
|
||||||
|
_services = services;
|
||||||
|
ShowSettings = new Interaction<Unit>();
|
||||||
|
ShowAbout = new Interaction<Unit>();
|
||||||
|
InitializeWorkspace = new Interaction<Unit>();
|
||||||
|
InitializeWorkspace.RegisterHandler(_ => InitializeCurrentWorkspaceAsync());
|
||||||
|
Resolve(arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the interaction that opens the settings dialog.
|
||||||
|
/// </summary>
|
||||||
|
public Interaction<Unit> ShowSettings { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the interaction that opens the about dialog.
|
||||||
|
/// </summary>
|
||||||
|
public Interaction<Unit> ShowAbout { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the interaction that initializes the not-initialized workspace.
|
||||||
|
/// </summary>
|
||||||
|
public Interaction<Unit> InitializeWorkspace { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the window title.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private string title = Resources.App_Name;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the current content: the workspace view or an error page.
|
||||||
|
/// </summary>
|
||||||
|
[ObservableProperty]
|
||||||
|
private ViewModelBase? content;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Resolves the launch arguments into a content view model.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="arguments">The command-line arguments.</param>
|
||||||
|
private void Resolve(IReadOnlyList<string> arguments) {
|
||||||
|
if (!LaunchArguments.TryParse(arguments, out string? folderPath)) {
|
||||||
|
Content = new ArgumentErrorPageViewModel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Directory.Exists(folderPath)) {
|
||||||
|
Content = new DirectoryMissingPageViewModel(folderPath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
OpenWorkspace(folderPath);
|
||||||
|
} catch (WorkspaceNotInitializedException) {
|
||||||
|
Content = new NotInitializedPageViewModel(folderPath, InitializeWorkspace);
|
||||||
|
} catch (WorkspaceLockException) {
|
||||||
|
Content = new LockConflictPageViewModel(folderPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens the workspace and switches the content to the normal view.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderPath">The workspace folder to open.</param>
|
||||||
|
private void OpenWorkspace(string folderPath) {
|
||||||
|
WorkspaceSession session = _services.OpenWorkspace(folderPath);
|
||||||
|
Content = new WorkspaceViewModel(_services, session, ShowSettings, ShowAbout);
|
||||||
|
Title = $"{new DirectoryInfo(folderPath).Name} - {Resources.App_Name}";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the folder shown by the not-initialized page, adds the preset
|
||||||
|
/// columns and opens the resulting workspace.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A completed task once initialization has been attempted.</returns>
|
||||||
|
private Task InitializeCurrentWorkspaceAsync() {
|
||||||
|
if (Content is not NotInitializedPageViewModel page) {
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
WorkspaceInitializer.Initialize(page.FolderPath);
|
||||||
|
WorkspacePreset.AddPresetColumns(page.FolderPath);
|
||||||
|
WorkspacePreset.AddPresetTags(page.FolderPath);
|
||||||
|
OpenWorkspace(page.FolderPath);
|
||||||
|
} catch (Exception exception) when (exception is YKanBanException or IOException or UnauthorizedAccessException) {
|
||||||
|
// Initialization failed; the page remains so the user can retry.
|
||||||
|
Debug.WriteLine(exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace YKanBan.ViewModels;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A selectable option for combo boxes: a backing value plus its localized
|
||||||
|
/// display label.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Value">The backing value (an enum value or a language code).</param>
|
||||||
|
/// <param name="Label">The localized display label.</param>
|
||||||
|
public sealed record OptionItem(object Value, string Label);
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
|
||||||
|
using YKanBan.Models;
|
||||||
|
using YKanBan.ViewModels.Board;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels.Tags;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// One row of the tag manager: a color swatch, the name, the description and the
|
||||||
|
/// usage count, plus edit and delete actions.
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class TagItemViewModel {
|
||||||
|
private readonly TagsViewModel _owner;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the row.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="owner">The owning tag manager.</param>
|
||||||
|
/// <param name="tag">The tag model.</param>
|
||||||
|
/// <param name="usageCount">The number of cards using the tag.</param>
|
||||||
|
public TagItemViewModel(TagsViewModel owner, TagModel tag, long usageCount) {
|
||||||
|
_owner = owner;
|
||||||
|
Tag = tag;
|
||||||
|
Badge = new TagBadgeViewModel(tag);
|
||||||
|
UsageCount = usageCount;
|
||||||
|
UsageText = string.Format(
|
||||||
|
Resources.Culture ?? CultureInfo.CurrentCulture, Resources.Tags_Usage, usageCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the underlying tag model.
|
||||||
|
/// </summary>
|
||||||
|
public TagModel Tag { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the colored badge for the swatch and name.
|
||||||
|
/// </summary>
|
||||||
|
public TagBadgeViewModel Badge { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the tag name.
|
||||||
|
/// </summary>
|
||||||
|
public string Name => Tag.Name;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the tag description.
|
||||||
|
/// </summary>
|
||||||
|
public string Description => Tag.Description;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the tag has a description.
|
||||||
|
/// </summary>
|
||||||
|
public bool HasDescription => Tag.Description.Length > 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the number of cards using the tag.
|
||||||
|
/// </summary>
|
||||||
|
public long UsageCount { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the localized usage count.
|
||||||
|
/// </summary>
|
||||||
|
public string UsageText { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Asks the manager to edit this tag.
|
||||||
|
/// </summary>
|
||||||
|
[RelayCommand]
|
||||||
|
private void Edit() => _ = _owner.RequestEditAsync(this);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Asks the manager to delete this tag.
|
||||||
|
/// </summary>
|
||||||
|
[RelayCommand]
|
||||||
|
private void Delete() => _ = _owner.RequestDeleteAsync(this);
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
using System.Collections.ObjectModel;
|
||||||
|
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
|
||||||
|
using YKanBan.Models;
|
||||||
|
using YKanBan.Storage.Workspace;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels.Tags;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The tags tab: a manager for the workspace's tags (create, rename, recolor,
|
||||||
|
/// re-describe and delete), showing each tag's color, name, description and
|
||||||
|
/// usage count. Tag changes also refresh the board.
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class TagsViewModel : ViewModelBase {
|
||||||
|
private readonly WorkspaceRepository _repository;
|
||||||
|
private readonly Action _boardChanged;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the manager, loading the current tags.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="repository">The workspace repository.</param>
|
||||||
|
/// <param name="boardChanged">Invoked after a tag change so the board refreshes.</param>
|
||||||
|
public TagsViewModel(WorkspaceRepository repository, Action boardChanged) {
|
||||||
|
_repository = repository;
|
||||||
|
_boardChanged = boardChanged;
|
||||||
|
Reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the workspace repository used for tag access.
|
||||||
|
/// </summary>
|
||||||
|
public WorkspaceRepository Repository => _repository;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the tags in id order.
|
||||||
|
/// </summary>
|
||||||
|
public ObservableCollection<TagItemViewModel> Tags { get; } = [];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the workspace has any tags.
|
||||||
|
/// </summary>
|
||||||
|
public bool HasTags => Tags.Count > 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the workspace has no tags.
|
||||||
|
/// </summary>
|
||||||
|
public bool HasNoTags => Tags.Count == 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the interaction that opens the new-tag editor.
|
||||||
|
/// </summary>
|
||||||
|
public Interaction<Unit> AddTag { get; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the interaction that opens the tag editor.
|
||||||
|
/// </summary>
|
||||||
|
public Interaction<TagItemViewModel> EditTag { get; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the interaction that confirms and deletes a tag.
|
||||||
|
/// </summary>
|
||||||
|
public Interaction<TagItemViewModel> DeleteTag { get; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens the new-tag editor.
|
||||||
|
/// </summary>
|
||||||
|
[RelayCommand]
|
||||||
|
private Task AddNewTagAsync() => AddTag.Handle(Unit.Value);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Requests the editor for a tag.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item">The tag to edit.</param>
|
||||||
|
/// <returns>A task completing after the editor closes.</returns>
|
||||||
|
public Task RequestEditAsync(TagItemViewModel item) => EditTag.Handle(item);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Requests deletion of a tag.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item">The tag to delete.</param>
|
||||||
|
/// <returns>A task completing after confirmation.</returns>
|
||||||
|
public Task RequestDeleteAsync(TagItemViewModel item) => DeleteTag.Handle(item);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reloads the tag list from the repository.
|
||||||
|
/// </summary>
|
||||||
|
public void Reload() {
|
||||||
|
Tags.Clear();
|
||||||
|
foreach ((TagModel tag, long usage) in _repository.GetTagsWithUsage()) {
|
||||||
|
Tags.Add(new TagItemViewModel(this, tag, usage));
|
||||||
|
}
|
||||||
|
|
||||||
|
OnPropertyChanged(nameof(HasTags));
|
||||||
|
OnPropertyChanged(nameof(HasNoTags));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reloads the tags and refreshes the board after a tag change.
|
||||||
|
/// </summary>
|
||||||
|
public void RefreshAfterChange() {
|
||||||
|
Reload();
|
||||||
|
_boardChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,5 @@
|
|||||||
|
|
||||||
namespace YKanBan.ViewModels;
|
namespace YKanBan.ViewModels;
|
||||||
|
|
||||||
public class ViewModelBase : ObservableObject
|
public class ViewModelBase : ObservableObject {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
|
||||||
|
using YKanBan.Services;
|
||||||
|
using YKanBan.Storage.Workspace;
|
||||||
|
using YKanBan.ViewModels.Board;
|
||||||
|
using YKanBan.ViewModels.Tags;
|
||||||
|
|
||||||
|
namespace YKanBan.ViewModels;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The normal workspace view: the top display area (name, path and the export,
|
||||||
|
/// settings and about buttons) plus the board and tags tabs.
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class WorkspaceViewModel : ViewModelBase {
|
||||||
|
private readonly Interaction<Unit> _showSettings;
|
||||||
|
private readonly Interaction<Unit> _showAbout;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the view for an open workspace.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="services">The process composition root.</param>
|
||||||
|
/// <param name="session">The open workspace session.</param>
|
||||||
|
/// <param name="showSettings">The interaction that opens the settings dialog.</param>
|
||||||
|
/// <param name="showAbout">The interaction that opens the about dialog.</param>
|
||||||
|
public WorkspaceViewModel(
|
||||||
|
AppServices services,
|
||||||
|
WorkspaceSession session,
|
||||||
|
Interaction<Unit> showSettings,
|
||||||
|
Interaction<Unit> showAbout) {
|
||||||
|
Session = session;
|
||||||
|
WorkspaceName = new DirectoryInfo(session.FolderPath).Name;
|
||||||
|
WorkspacePath = session.FolderPath;
|
||||||
|
_showSettings = showSettings;
|
||||||
|
_showAbout = showAbout;
|
||||||
|
|
||||||
|
// Both tabs share the same repository; tag changes refresh the board.
|
||||||
|
Board = new BoardViewModel(services, session);
|
||||||
|
Tags = new TagsViewModel(session.Repository, Board.Reload);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the open workspace session (lock plus repository).
|
||||||
|
/// </summary>
|
||||||
|
public WorkspaceSession Session { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the workspace display name (the folder name).
|
||||||
|
/// </summary>
|
||||||
|
public string WorkspaceName { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the full workspace folder path.
|
||||||
|
/// </summary>
|
||||||
|
public string WorkspacePath { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the board tab view model.
|
||||||
|
/// </summary>
|
||||||
|
public BoardViewModel Board { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the tags tab view model.
|
||||||
|
/// </summary>
|
||||||
|
public TagsViewModel Tags { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the interaction that runs the export flow.
|
||||||
|
/// </summary>
|
||||||
|
public Interaction<Unit> Export { get; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens the settings dialog through the registered interaction.
|
||||||
|
/// </summary>
|
||||||
|
[RelayCommand]
|
||||||
|
private async Task OpenSettingsAsync() => await _showSettings.Handle(Unit.Value);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens the about dialog through the registered interaction.
|
||||||
|
/// </summary>
|
||||||
|
[RelayCommand]
|
||||||
|
private async Task OpenAboutAsync() => await _showAbout.Handle(Unit.Value);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Runs the export flow through the registered interaction.
|
||||||
|
/// </summary>
|
||||||
|
[RelayCommand]
|
||||||
|
private async Task RunExportAsync() => await Export.Handle(Unit.Value);
|
||||||
|
}
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
<UserControl xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:vm="using:YKanBan.ViewModels.Board"
|
||||||
|
xmlns:vmBase="using:YKanBan.ViewModels"
|
||||||
|
xmlns:lang="using:YKanBan"
|
||||||
|
xmlns:icons="using:IconPacks.Avalonia.Lucide"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="600"
|
||||||
|
x:Class="YKanBan.Views.Board.BoardView"
|
||||||
|
x:DataType="vm:BoardViewModel">
|
||||||
|
|
||||||
|
<Grid RowDefinitions="Auto,*">
|
||||||
|
|
||||||
|
<!-- Toolbar: search, add column and the combined display options. -->
|
||||||
|
<Grid Grid.Row="0" Margin="8" ColumnDefinitions="Auto,*,Auto,Auto,Auto,Auto">
|
||||||
|
<!-- Wrapped in a transparent-border hit area so the tooltip triggers across the whole 16x16 box. -->
|
||||||
|
<Border Grid.Column="0" Background="Transparent" Padding="2" Margin="0,0,6,0"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
ToolTip.Tip="{Binding FilterStatusText}">
|
||||||
|
<icons:PackIconLucide Kind="ListFilter" Width="16" Height="16"
|
||||||
|
Opacity="{Binding FilterIconOpacity}"/>
|
||||||
|
</Border>
|
||||||
|
|
||||||
|
<TextBox Grid.Column="1" Text="{Binding SearchText}" VerticalAlignment="Center"
|
||||||
|
Watermark="{x:Static lang:Resources.Board_SearchPlaceholder}">
|
||||||
|
<TextBox.KeyBindings>
|
||||||
|
<KeyBinding Gesture="Enter" Command="{Binding SearchCommand}"/>
|
||||||
|
</TextBox.KeyBindings>
|
||||||
|
</TextBox>
|
||||||
|
|
||||||
|
<Button Grid.Column="2" Margin="4,0,0,0" Command="{Binding ClearSearchCommand}"
|
||||||
|
ToolTip.Tip="{x:Static lang:Resources.Board_ClearSearch}">
|
||||||
|
<icons:PackIconLucide Kind="X" Width="16" Height="16"/>
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button Grid.Column="3" Margin="4,0,0,0" Command="{Binding SearchCommand}"
|
||||||
|
ToolTip.Tip="{x:Static lang:Resources.Board_Search}">
|
||||||
|
<icons:PackIconLucide Kind="Search" Width="16" Height="16"/>
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button Grid.Column="4" Margin="12,0,0,0" Command="{Binding AddNewColumnCommand}">
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="6">
|
||||||
|
<icons:PackIconLucide Kind="Plus" Width="16" Height="16"/>
|
||||||
|
<TextBlock Text="{x:Static lang:Resources.Board_AddColumn}"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button Grid.Column="5" Margin="4,0,0,0">
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="6">
|
||||||
|
<icons:PackIconLucide Kind="SlidersHorizontal" Width="16" Height="16"/>
|
||||||
|
<TextBlock Text="{x:Static lang:Resources.Board_Display}"/>
|
||||||
|
</StackPanel>
|
||||||
|
<Button.Flyout>
|
||||||
|
<Flyout Placement="BottomEdgeAlignedRight">
|
||||||
|
<StackPanel Width="280" Spacing="12" Margin="4">
|
||||||
|
|
||||||
|
<StackPanel Spacing="4">
|
||||||
|
<TextBlock Text="{x:Static lang:Resources.Board_ColumnWidth}"/>
|
||||||
|
<ComboBox ItemsSource="{Binding Display.Presets}"
|
||||||
|
SelectedItem="{Binding Display.SelectedPreset}"
|
||||||
|
HorizontalAlignment="Stretch">
|
||||||
|
<ComboBox.ItemTemplate>
|
||||||
|
<DataTemplate x:DataType="vmBase:OptionItem">
|
||||||
|
<TextBlock Text="{Binding Label}"/>
|
||||||
|
</DataTemplate>
|
||||||
|
</ComboBox.ItemTemplate>
|
||||||
|
</ComboBox>
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="8"
|
||||||
|
IsVisible="{Binding Display.IsCustom}">
|
||||||
|
<TextBlock Text="{x:Static lang:Resources.WidthDialog_Pixels}"
|
||||||
|
VerticalAlignment="Center"/>
|
||||||
|
<NumericUpDown Value="{Binding Display.CustomPixels}"
|
||||||
|
Minimum="160" Maximum="720" Width="120"/>
|
||||||
|
</StackPanel>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<StackPanel Spacing="4">
|
||||||
|
<TextBlock Text="{x:Static lang:Resources.Board_SortCard}"/>
|
||||||
|
<ComboBox ItemsSource="{Binding Display.SortOptions}"
|
||||||
|
SelectedItem="{Binding Display.SelectedCardSort}"
|
||||||
|
HorizontalAlignment="Stretch">
|
||||||
|
<ComboBox.ItemTemplate>
|
||||||
|
<DataTemplate x:DataType="vmBase:OptionItem">
|
||||||
|
<TextBlock Text="{Binding Label}"/>
|
||||||
|
</DataTemplate>
|
||||||
|
</ComboBox.ItemTemplate>
|
||||||
|
</ComboBox>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<StackPanel Spacing="4">
|
||||||
|
<TextBlock Text="{x:Static lang:Resources.Board_SortColumn}"/>
|
||||||
|
<ComboBox ItemsSource="{Binding Display.SortOptions}"
|
||||||
|
SelectedItem="{Binding Display.SelectedColumnSort}"
|
||||||
|
HorizontalAlignment="Stretch">
|
||||||
|
<ComboBox.ItemTemplate>
|
||||||
|
<DataTemplate x:DataType="vmBase:OptionItem">
|
||||||
|
<TextBlock Text="{Binding Label}"/>
|
||||||
|
</DataTemplate>
|
||||||
|
</ComboBox.ItemTemplate>
|
||||||
|
</ComboBox>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
</StackPanel>
|
||||||
|
</Flyout>
|
||||||
|
</Button.Flyout>
|
||||||
|
</Button>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<!-- Board surface: columns horizontally, each scrolling its cards vertically. -->
|
||||||
|
<ScrollViewer Grid.Row="1" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
|
||||||
|
<ItemsControl ItemsSource="{Binding Columns}" Margin="8">
|
||||||
|
<ItemsControl.ItemsPanel>
|
||||||
|
<ItemsPanelTemplate>
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="12"/>
|
||||||
|
</ItemsPanelTemplate>
|
||||||
|
</ItemsControl.ItemsPanel>
|
||||||
|
</ItemsControl>
|
||||||
|
</ScrollViewer>
|
||||||
|
|
||||||
|
<TextBlock Grid.Row="1" Text="{x:Static lang:Resources.Board_NoColumns}"
|
||||||
|
IsVisible="{Binding HasNoColumns}"
|
||||||
|
HorizontalAlignment="Center" VerticalAlignment="Center" Opacity="0.6"/>
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
</UserControl>
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
using Avalonia.Controls;
|
||||||
|
|
||||||
|
using YKanBan.ViewModels.Board;
|
||||||
|
using YKanBan.ViewModels.Dialogs;
|
||||||
|
using YKanBan.Views.Dialogs;
|
||||||
|
|
||||||
|
namespace YKanBan.Views.Board;
|
||||||
|
|
||||||
|
public partial class BoardView : UserControl {
|
||||||
|
private bool _registered;
|
||||||
|
|
||||||
|
public BoardView() {
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnDataContextChanged(EventArgs e) {
|
||||||
|
base.OnDataContextChanged(e);
|
||||||
|
if (DataContext is BoardViewModel board && !_registered) {
|
||||||
|
_registered = true;
|
||||||
|
board.AddColumn.RegisterHandler(_ => EditColumnAsync(board, null));
|
||||||
|
board.EditColumn.RegisterHandler(column => EditColumnAsync(board, column));
|
||||||
|
board.DeleteColumn.RegisterHandler(column => DeleteColumnAsync(board, column));
|
||||||
|
board.AddCard.RegisterHandler(column => EditCardAsync(board, column, null));
|
||||||
|
board.EditCard.RegisterHandler(card => EditCardAsync(board, null, card));
|
||||||
|
board.DeleteCard.RegisterHandler(card => DeleteCardAsync(board, card));
|
||||||
|
board.MoveCard.RegisterHandler(card => MoveCardAsync(board, card));
|
||||||
|
board.ShowSearchError.RegisterHandler(ShowSearchErrorAsync);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the window that owns this board, used as the dialog owner.
|
||||||
|
/// </summary>
|
||||||
|
private Window? OwningWindow => TopLevel.GetTopLevel(this) as Window;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shows the add/edit column dialog and reloads on success.
|
||||||
|
/// </summary>
|
||||||
|
private async Task EditColumnAsync(BoardViewModel board, ColumnViewModel? column) {
|
||||||
|
if (OwningWindow is not Window owner) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var dialog = new ColumnEditorDialog {
|
||||||
|
DataContext = new ColumnEditorViewModel(board.Repository, column?.Model),
|
||||||
|
};
|
||||||
|
if (await dialog.ShowDialog<bool>(owner)) {
|
||||||
|
board.Reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Confirms and deletes a column, then reloads.
|
||||||
|
/// </summary>
|
||||||
|
private async Task DeleteColumnAsync(BoardViewModel board, ColumnViewModel column) {
|
||||||
|
if (OwningWindow is not Window owner) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool confirmed = true;
|
||||||
|
if (board.Config.Confirmations.DeleteColumn) {
|
||||||
|
var dialog = new DeleteColumnConfirmDialog {
|
||||||
|
DataContext = new DeleteColumnConfirmViewModel(column.Title, column.CardCount),
|
||||||
|
};
|
||||||
|
confirmed = await dialog.ShowDialog<bool>(owner);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!confirmed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
board.Repository.DeleteColumn(column.Id);
|
||||||
|
board.Reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shows the add/edit card dialog and reloads on success.
|
||||||
|
/// </summary>
|
||||||
|
private async Task EditCardAsync(BoardViewModel board, ColumnViewModel? column, CardViewModel? card) {
|
||||||
|
if (OwningWindow is not Window owner) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
long columnId = card?.ColumnId ?? column!.Id;
|
||||||
|
var dialog = new CardEditorDialog {
|
||||||
|
DataContext = new CardEditorViewModel(board.Repository, columnId, card?.Model),
|
||||||
|
};
|
||||||
|
if (await dialog.ShowDialog<bool>(owner)) {
|
||||||
|
board.Reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Confirms and deletes a card, then reloads.
|
||||||
|
/// </summary>
|
||||||
|
private async Task DeleteCardAsync(BoardViewModel board, CardViewModel card) {
|
||||||
|
if (OwningWindow is not Window owner) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool confirmed = true;
|
||||||
|
if (board.Config.Confirmations.DeleteCard) {
|
||||||
|
var dialog = new DeleteCardConfirmDialog {
|
||||||
|
DataContext = new DeleteCardConfirmViewModel(card.Id),
|
||||||
|
};
|
||||||
|
confirmed = await dialog.ShowDialog<bool>(owner);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!confirmed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
board.Repository.DeleteCard(card.Id);
|
||||||
|
board.Reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shows the move-card dialog and reloads when a destination is chosen.
|
||||||
|
/// </summary>
|
||||||
|
private async Task MoveCardAsync(BoardViewModel board, CardViewModel card) {
|
||||||
|
if (OwningWindow is not Window owner) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var dialog = new MoveCardDialog {
|
||||||
|
DataContext = new MoveCardViewModel(board.Repository.GetColumns(), card.ColumnId),
|
||||||
|
};
|
||||||
|
if (await dialog.ShowDialog<long?>(owner) is long targetColumnId) {
|
||||||
|
board.Repository.MoveCard(card.Id, targetColumnId);
|
||||||
|
board.Reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shows the search syntax error dialog.
|
||||||
|
/// </summary>
|
||||||
|
private async Task ShowSearchErrorAsync(string detail) {
|
||||||
|
if (OwningWindow is not Window owner) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var dialog = new SearchErrorDialog {
|
||||||
|
DataContext = new SearchErrorViewModel(detail),
|
||||||
|
};
|
||||||
|
await dialog.ShowDialog(owner);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
<UserControl xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:vm="using:YKanBan.ViewModels.Board"
|
||||||
|
xmlns:lang="using:YKanBan"
|
||||||
|
xmlns:icons="using:IconPacks.Avalonia.Lucide"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="320" d:DesignHeight="120"
|
||||||
|
x:Class="YKanBan.Views.Board.CardView"
|
||||||
|
x:DataType="vm:CardViewModel">
|
||||||
|
|
||||||
|
<Border Background="{DynamicResource CardBackgroundBrush}"
|
||||||
|
BorderBrush="{DynamicResource CardBorderBrush}"
|
||||||
|
BorderThickness="1" CornerRadius="6" Padding="8"
|
||||||
|
Cursor="Hand" Tapped="OnCardTapped">
|
||||||
|
|
||||||
|
<Grid RowDefinitions="Auto,Auto,Auto">
|
||||||
|
|
||||||
|
<!-- Row 1: id, title and the corner menu. -->
|
||||||
|
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto">
|
||||||
|
<TextBlock Grid.Column="0" Text="{Binding IdText}" FontWeight="Bold" VerticalAlignment="Center"/>
|
||||||
|
<TextBlock Grid.Column="1" Text="{Binding TitleText}" IsVisible="{Binding HasTitle}"
|
||||||
|
VerticalAlignment="Center" Margin="4,0"
|
||||||
|
TextWrapping="NoWrap" TextTrimming="CharacterEllipsis"
|
||||||
|
ToolTip.Tip="{Binding TitleText}"/>
|
||||||
|
<Button Grid.Column="2" Padding="4,2" VerticalAlignment="Center"
|
||||||
|
Tapped="OnMenuButtonTapped">
|
||||||
|
<icons:PackIconLucide Kind="EllipsisVertical" Width="16" Height="16"/>
|
||||||
|
<Button.Flyout>
|
||||||
|
<MenuFlyout>
|
||||||
|
<MenuItem Header="{x:Static lang:Resources.Card_Move}" Command="{Binding MoveCommand}"/>
|
||||||
|
<MenuItem Header="{x:Static lang:Resources.Card_Delete}" Command="{Binding DeleteCommand}"/>
|
||||||
|
</MenuFlyout>
|
||||||
|
</Button.Flyout>
|
||||||
|
</Button>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<!-- Row 2: content preview. -->
|
||||||
|
<TextBlock Grid.Row="1" Text="{Binding PreviewContent}" IsVisible="{Binding HasContent}"
|
||||||
|
TextWrapping="Wrap" FontSize="12" Opacity="0.85" Margin="0,4,0,0"/>
|
||||||
|
|
||||||
|
<!-- Row 3: tag badges. -->
|
||||||
|
<ItemsControl Grid.Row="2" ItemsSource="{Binding TagBadges}" IsVisible="{Binding HasTags}"
|
||||||
|
Margin="0,4,0,0">
|
||||||
|
<ItemsControl.ItemsPanel>
|
||||||
|
<ItemsPanelTemplate>
|
||||||
|
<WrapPanel/>
|
||||||
|
</ItemsPanelTemplate>
|
||||||
|
</ItemsControl.ItemsPanel>
|
||||||
|
<ItemsControl.ItemTemplate>
|
||||||
|
<DataTemplate x:DataType="vm:TagBadgeViewModel">
|
||||||
|
<Border Background="{Binding Background}" CornerRadius="8"
|
||||||
|
Padding="6,2" Margin="0,0,4,4"
|
||||||
|
ToolTip.Tip="{Binding ToolTipText}">
|
||||||
|
<TextBlock Text="{Binding Name}" Foreground="{Binding Foreground}" FontSize="11"/>
|
||||||
|
</Border>
|
||||||
|
</DataTemplate>
|
||||||
|
</ItemsControl.ItemTemplate>
|
||||||
|
</ItemsControl>
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
</Border>
|
||||||
|
</UserControl>
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Input;
|
||||||
|
|
||||||
|
using YKanBan.ViewModels.Board;
|
||||||
|
|
||||||
|
namespace YKanBan.Views.Board;
|
||||||
|
|
||||||
|
public partial class CardView : UserControl {
|
||||||
|
public CardView() {
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clicking the card body opens the card editor.
|
||||||
|
/// </summary>
|
||||||
|
private void OnCardTapped(object? sender, TappedEventArgs e) {
|
||||||
|
if (DataContext is CardViewModel card) {
|
||||||
|
card.EditCommand.Execute(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stops the corner menu button's tap from bubbling to the card body.
|
||||||
|
/// </summary>
|
||||||
|
private void OnMenuButtonTapped(object? sender, TappedEventArgs e) => e.Handled = true;
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
<UserControl xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:vm="using:YKanBan.ViewModels.Board"
|
||||||
|
xmlns:lang="using:YKanBan"
|
||||||
|
xmlns:icons="using:IconPacks.Avalonia.Lucide"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="320" d:DesignHeight="600"
|
||||||
|
x:Class="YKanBan.Views.Board.ColumnView"
|
||||||
|
x:DataType="vm:ColumnViewModel">
|
||||||
|
|
||||||
|
<Border Width="{Binding Width}" MinWidth="160" MaxWidth="720"
|
||||||
|
Background="{DynamicResource BoardColumnBackgroundBrush}"
|
||||||
|
BorderBrush="{DynamicResource BoardColumnBorderBrush}"
|
||||||
|
BorderThickness="1" CornerRadius="8" VerticalAlignment="Stretch">
|
||||||
|
|
||||||
|
<Grid RowDefinitions="Auto,*" Margin="10">
|
||||||
|
|
||||||
|
<Grid Grid.Row="0" ColumnDefinitions="*,Auto,Auto">
|
||||||
|
<StackPanel Grid.Column="0" Orientation="Horizontal" Spacing="6" VerticalAlignment="Center">
|
||||||
|
<TextBlock Text="{Binding Title}" FontWeight="SemiBold"
|
||||||
|
TextTrimming="CharacterEllipsis" ToolTip.Tip="{Binding ToolTipText}"/>
|
||||||
|
<TextBlock Text="{Binding CardCount}" Opacity="0.6" VerticalAlignment="Center"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<Button Grid.Column="1" Margin="4,0,0,0" Padding="4,2"
|
||||||
|
Command="{Binding AddCardCommand}"
|
||||||
|
ToolTip.Tip="{x:Static lang:Resources.Column_AddCard}">
|
||||||
|
<icons:PackIconLucide Kind="Plus" Width="16" Height="16"/>
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button Grid.Column="2" Margin="2,0,0,0" Padding="4,2">
|
||||||
|
<icons:PackIconLucide Kind="EllipsisVertical" Width="16" Height="16"/>
|
||||||
|
<Button.Flyout>
|
||||||
|
<MenuFlyout>
|
||||||
|
<MenuItem Header="{x:Static lang:Resources.Column_Edit}" Command="{Binding EditCommand}"/>
|
||||||
|
<MenuItem Header="{x:Static lang:Resources.Column_Delete}" Command="{Binding DeleteCommand}"/>
|
||||||
|
</MenuFlyout>
|
||||||
|
</Button.Flyout>
|
||||||
|
</Button>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" Margin="0,8,0,0">
|
||||||
|
<ItemsControl ItemsSource="{Binding Cards}">
|
||||||
|
<ItemsControl.ItemsPanel>
|
||||||
|
<ItemsPanelTemplate>
|
||||||
|
<StackPanel Spacing="8"/>
|
||||||
|
</ItemsPanelTemplate>
|
||||||
|
</ItemsControl.ItemsPanel>
|
||||||
|
</ItemsControl>
|
||||||
|
</ScrollViewer>
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
</Border>
|
||||||
|
</UserControl>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using Avalonia.Controls;
|
||||||
|
|
||||||
|
namespace YKanBan.Views.Board;
|
||||||
|
|
||||||
|
public partial class ColumnView : UserControl {
|
||||||
|
public ColumnView() {
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<Window xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:vm="using:YKanBan.ViewModels.Dialogs"
|
||||||
|
xmlns:lang="using:YKanBan"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="460" d:DesignHeight="320"
|
||||||
|
x:Class="YKanBan.Views.Dialogs.AboutDialog"
|
||||||
|
x:DataType="vm:AboutDialogViewModel"
|
||||||
|
Title="{x:Static lang:Resources.About_Title}"
|
||||||
|
Width="460" Height="320" MinWidth="460" MinHeight="320" CanResize="True"
|
||||||
|
WindowStartupLocation="CenterOwner"
|
||||||
|
ShowInTaskbar="False">
|
||||||
|
|
||||||
|
<Grid RowDefinitions="*,Auto" Margin="20">
|
||||||
|
|
||||||
|
<StackPanel Grid.Row="0" Spacing="10">
|
||||||
|
<TextBlock Text="{Binding AppName}" FontSize="20" FontWeight="SemiBold"/>
|
||||||
|
<TextBlock Text="{Binding Version}"/>
|
||||||
|
|
||||||
|
<StackPanel Spacing="4">
|
||||||
|
<TextBlock Text="{x:Static lang:Resources.About_Repository}" FontWeight="SemiBold"/>
|
||||||
|
<HyperlinkButton Content="{Binding RepositoryUrl}" NavigateUri="{Binding RepositoryUrl}"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<StackPanel Spacing="4">
|
||||||
|
<TextBlock Text="{x:Static lang:Resources.About_License}" FontWeight="SemiBold"/>
|
||||||
|
<TextBlock Text="{Binding License}"/>
|
||||||
|
</StackPanel>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<Button Grid.Row="1" Content="{x:Static lang:Resources.Common_Ok}"
|
||||||
|
Click="OnCloseClick" HorizontalAlignment="Right" MinWidth="90"
|
||||||
|
IsDefault="True" IsCancel="True"/>
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
|
|
||||||
|
namespace YKanBan.Views.Dialogs;
|
||||||
|
|
||||||
|
public partial class AboutDialog : Window {
|
||||||
|
public AboutDialog() {
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Closes the dialog.
|
||||||
|
/// </summary>
|
||||||
|
private void OnCloseClick(object? sender, RoutedEventArgs e) => Close();
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
<Window xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:vm="using:YKanBan.ViewModels.Dialogs"
|
||||||
|
xmlns:lang="using:YKanBan"
|
||||||
|
xmlns:icons="using:IconPacks.Avalonia.Lucide"
|
||||||
|
xmlns:conv="using:Avalonia.Data.Converters"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="520" d:DesignHeight="560"
|
||||||
|
x:Class="YKanBan.Views.Dialogs.CardEditorDialog"
|
||||||
|
x:DataType="vm:CardEditorViewModel"
|
||||||
|
Title="{Binding WindowTitle}"
|
||||||
|
Width="520" Height="560" MinWidth="520" MinHeight="560" CanResize="True"
|
||||||
|
WindowStartupLocation="CenterOwner"
|
||||||
|
ShowInTaskbar="False">
|
||||||
|
|
||||||
|
<Grid RowDefinitions="*,Auto" Margin="20">
|
||||||
|
<ScrollViewer Grid.Row="0" VerticalScrollBarVisibility="Auto">
|
||||||
|
<StackPanel Spacing="6">
|
||||||
|
|
||||||
|
<TextBlock Text="{x:Static lang:Resources.CardDialog_Title}"/>
|
||||||
|
<TextBox Text="{Binding Title}"/>
|
||||||
|
|
||||||
|
<TextBlock Text="{x:Static lang:Resources.CardDialog_Content}" Margin="0,6,0,0"/>
|
||||||
|
<TextBox Text="{Binding Content}" AcceptsReturn="True" TextWrapping="Wrap"
|
||||||
|
VerticalContentAlignment="Top" Height="160"/>
|
||||||
|
|
||||||
|
<TextBlock Text="{x:Static lang:Resources.CardDialog_Tags}" Margin="0,6,0,0"/>
|
||||||
|
<ItemsControl ItemsSource="{Binding AssignedTags}">
|
||||||
|
<ItemsControl.ItemsPanel>
|
||||||
|
<ItemsPanelTemplate>
|
||||||
|
<WrapPanel/>
|
||||||
|
</ItemsPanelTemplate>
|
||||||
|
</ItemsControl.ItemsPanel>
|
||||||
|
<ItemsControl.ItemTemplate>
|
||||||
|
<DataTemplate x:DataType="vm:AssignedTagViewModel">
|
||||||
|
<Border Background="{Binding Background}" CornerRadius="8"
|
||||||
|
Padding="6,2" Margin="0,0,4,4">
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="4">
|
||||||
|
<TextBlock Text="{Binding Name}" Foreground="{Binding Foreground}"
|
||||||
|
FontSize="11" VerticalAlignment="Center"/>
|
||||||
|
<Button Command="{Binding RemoveCommand}" Padding="0"
|
||||||
|
Background="Transparent" BorderThickness="0">
|
||||||
|
<icons:PackIconLucide Kind="X" Width="10" Height="10"
|
||||||
|
Foreground="{Binding Foreground}"/>
|
||||||
|
</Button>
|
||||||
|
</StackPanel>
|
||||||
|
</Border>
|
||||||
|
</DataTemplate>
|
||||||
|
</ItemsControl.ItemTemplate>
|
||||||
|
</ItemsControl>
|
||||||
|
<Button Content="{x:Static lang:Resources.CardDialog_AddTag}"
|
||||||
|
Command="{Binding AddTagCommand}" HorizontalAlignment="Left"/>
|
||||||
|
|
||||||
|
<StackPanel Spacing="2" IsVisible="{Binding !IsNew}" Opacity="0.7" Margin="0,8,0,0">
|
||||||
|
<TextBlock Text="{Binding IdLine}"/>
|
||||||
|
<TextBlock Text="{Binding CreatedLine}"/>
|
||||||
|
<TextBlock Text="{Binding ModifiedLine}"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<TextBlock Text="{Binding ErrorMessage}"
|
||||||
|
IsVisible="{Binding ErrorMessage, Converter={x:Static conv:ObjectConverters.IsNotNull}}"
|
||||||
|
Foreground="{DynamicResource ErrorTextBrush}" TextWrapping="Wrap" Margin="0,4,0,0"/>
|
||||||
|
</StackPanel>
|
||||||
|
</ScrollViewer>
|
||||||
|
|
||||||
|
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right"
|
||||||
|
Spacing="8" Margin="0,16,0,0">
|
||||||
|
<Button Content="{x:Static lang:Resources.Common_Ok}" Click="OnOkClick" MinWidth="90" IsDefault="True"/>
|
||||||
|
<Button Content="{x:Static lang:Resources.Common_Cancel}" Click="OnCancelClick" MinWidth="90"
|
||||||
|
IsCancel="True"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
|
using Avalonia.Threading;
|
||||||
|
|
||||||
|
using YKanBan.Models;
|
||||||
|
using YKanBan.ViewModels;
|
||||||
|
using YKanBan.ViewModels.Dialogs;
|
||||||
|
|
||||||
|
namespace YKanBan.Views.Dialogs;
|
||||||
|
|
||||||
|
public partial class CardEditorDialog : Window {
|
||||||
|
private bool _allowClose;
|
||||||
|
|
||||||
|
public CardEditorDialog() {
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnDataContextChanged(EventArgs e) {
|
||||||
|
base.OnDataContextChanged(e);
|
||||||
|
if (DataContext is CardEditorViewModel viewModel) {
|
||||||
|
viewModel.ShowTagPicker.RegisterHandler(ShowTagPickerAsync);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shows the nested tag picker, owned by this dialog.
|
||||||
|
/// </summary>
|
||||||
|
private async Task<TagModel?> ShowTagPickerAsync(Unit input) {
|
||||||
|
if (DataContext is not CardEditorViewModel viewModel) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var dialog = new TagPickerDialog {
|
||||||
|
DataContext = new TagPickerViewModel(
|
||||||
|
viewModel.Repository,
|
||||||
|
viewModel.AssignedTags.Select(row => row.Tag.Id).ToList()),
|
||||||
|
};
|
||||||
|
return await dialog.ShowDialog<TagModel?>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes the card and closes when accepted.
|
||||||
|
/// </summary>
|
||||||
|
private void OnOkClick(object? sender, RoutedEventArgs e) {
|
||||||
|
if (DataContext is CardEditorViewModel viewModel && viewModel.TryAccept()) {
|
||||||
|
_allowClose = true;
|
||||||
|
Close(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Requests a close, confirming the discard first when needed.
|
||||||
|
/// </summary>
|
||||||
|
private void OnCancelClick(object? sender, RoutedEventArgs e) => _ = RequestCloseAsync();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Intercepts the window close button to run the discard confirmation.
|
||||||
|
/// </summary>
|
||||||
|
protected override void OnClosing(WindowClosingEventArgs e) {
|
||||||
|
base.OnClosing(e);
|
||||||
|
if (_allowClose) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (HasUnsavedChanges && DiscardConfirmEnabled) {
|
||||||
|
e.Cancel = true;
|
||||||
|
Dispatcher.UIThread.Post(() => _ = RequestCloseAsync());
|
||||||
|
} else {
|
||||||
|
_allowClose = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Confirms the discard and closes, or stays open when declined.
|
||||||
|
/// </summary>
|
||||||
|
private async Task RequestCloseAsync() {
|
||||||
|
if (HasUnsavedChanges && DiscardConfirmEnabled) {
|
||||||
|
var dialog = new DiscardEditConfirmDialog { DataContext = new DiscardEditConfirmViewModel() };
|
||||||
|
if (!await dialog.ShowDialog<bool>(this)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_allowClose = true;
|
||||||
|
Close(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets whether the editor has unsaved changes.
|
||||||
|
/// </summary>
|
||||||
|
private bool HasUnsavedChanges => DataContext is CardEditorViewModel viewModel && viewModel.HasChanges;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets whether the discard confirmation setting is enabled.
|
||||||
|
/// </summary>
|
||||||
|
private static bool DiscardConfirmEnabled => App.Services?.Config.Confirmations.DiscardEdit == true;
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<Window xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:vm="using:YKanBan.ViewModels.Dialogs"
|
||||||
|
xmlns:lang="using:YKanBan"
|
||||||
|
xmlns:conv="using:Avalonia.Data.Converters"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="420" d:DesignHeight="300"
|
||||||
|
x:Class="YKanBan.Views.Dialogs.ColumnEditorDialog"
|
||||||
|
x:DataType="vm:ColumnEditorViewModel"
|
||||||
|
Title="{Binding WindowTitle}"
|
||||||
|
Width="420" Height="300" MinWidth="420" MinHeight="300" CanResize="True"
|
||||||
|
WindowStartupLocation="CenterOwner"
|
||||||
|
ShowInTaskbar="False">
|
||||||
|
|
||||||
|
<Grid RowDefinitions="*,Auto" Margin="20">
|
||||||
|
<StackPanel Grid.Row="0" Spacing="6">
|
||||||
|
<TextBlock Text="{x:Static lang:Resources.ColumnDialog_Title}"/>
|
||||||
|
<TextBox Text="{Binding Title}"/>
|
||||||
|
|
||||||
|
<TextBlock Text="{x:Static lang:Resources.ColumnDialog_Description}" Margin="0,6,0,0"/>
|
||||||
|
<TextBox Text="{Binding Description}" AcceptsReturn="True" TextWrapping="Wrap"
|
||||||
|
VerticalContentAlignment="Top" Height="80"/>
|
||||||
|
|
||||||
|
<TextBlock Text="{Binding ErrorMessage}"
|
||||||
|
IsVisible="{Binding ErrorMessage, Converter={x:Static conv:ObjectConverters.IsNotNull}}"
|
||||||
|
Foreground="{DynamicResource ErrorTextBrush}" TextWrapping="Wrap" Margin="0,4,0,0"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right"
|
||||||
|
Spacing="8" Margin="0,16,0,0">
|
||||||
|
<Button Content="{x:Static lang:Resources.Common_Ok}" Click="OnOkClick" MinWidth="90" IsDefault="True"/>
|
||||||
|
<Button Content="{x:Static lang:Resources.Common_Cancel}" Click="OnCancelClick" MinWidth="90" IsCancel="True"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
|
|
||||||
|
using YKanBan.ViewModels.Dialogs;
|
||||||
|
|
||||||
|
namespace YKanBan.Views.Dialogs;
|
||||||
|
|
||||||
|
public partial class ColumnEditorDialog : Window {
|
||||||
|
public ColumnEditorDialog() {
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes the column and closes when accepted.
|
||||||
|
/// </summary>
|
||||||
|
private void OnOkClick(object? sender, RoutedEventArgs e) {
|
||||||
|
if (DataContext is ColumnEditorViewModel viewModel && viewModel.TryAccept()) {
|
||||||
|
Close(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Closes without writing.
|
||||||
|
/// </summary>
|
||||||
|
private void OnCancelClick(object? sender, RoutedEventArgs e) => Close(false);
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<Window xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:vm="using:YKanBan.ViewModels.Dialogs"
|
||||||
|
xmlns:lang="using:YKanBan"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="420" d:DesignHeight="200"
|
||||||
|
x:Class="YKanBan.Views.Dialogs.DeleteCardConfirmDialog"
|
||||||
|
x:DataType="vm:DeleteCardConfirmViewModel"
|
||||||
|
Title="{x:Static lang:Resources.Confirm_DeleteCard_Title}"
|
||||||
|
Width="420" Height="200" MinWidth="420" MinHeight="200" CanResize="True"
|
||||||
|
WindowStartupLocation="CenterOwner"
|
||||||
|
ShowInTaskbar="False">
|
||||||
|
|
||||||
|
<Grid RowDefinitions="*,Auto" Margin="20">
|
||||||
|
<TextBlock Grid.Row="0" Text="{Binding Message}" TextWrapping="Wrap" VerticalAlignment="Top"/>
|
||||||
|
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right" Spacing="8">
|
||||||
|
<Button Content="{x:Static lang:Resources.Common_Delete}" Click="OnConfirmClick"
|
||||||
|
MinWidth="90" IsDefault="True"/>
|
||||||
|
<Button Content="{x:Static lang:Resources.Common_Cancel}" Click="OnCancelClick"
|
||||||
|
MinWidth="90" IsCancel="True"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
|
|
||||||
|
namespace YKanBan.Views.Dialogs;
|
||||||
|
|
||||||
|
public partial class DeleteCardConfirmDialog : Window {
|
||||||
|
public DeleteCardConfirmDialog() {
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Confirms the deletion.
|
||||||
|
/// </summary>
|
||||||
|
private void OnConfirmClick(object? sender, RoutedEventArgs e) => Close(true);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cancels the deletion.
|
||||||
|
/// </summary>
|
||||||
|
private void OnCancelClick(object? sender, RoutedEventArgs e) => Close(false);
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<Window xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:vm="using:YKanBan.ViewModels.Dialogs"
|
||||||
|
xmlns:lang="using:YKanBan"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="420" d:DesignHeight="200"
|
||||||
|
x:Class="YKanBan.Views.Dialogs.DeleteColumnConfirmDialog"
|
||||||
|
x:DataType="vm:DeleteColumnConfirmViewModel"
|
||||||
|
Title="{x:Static lang:Resources.Confirm_DeleteColumn_Title}"
|
||||||
|
Width="420" Height="200" MinWidth="420" MinHeight="200" CanResize="True"
|
||||||
|
WindowStartupLocation="CenterOwner"
|
||||||
|
ShowInTaskbar="False">
|
||||||
|
|
||||||
|
<Grid RowDefinitions="*,Auto" Margin="20">
|
||||||
|
<TextBlock Grid.Row="0" Text="{Binding Message}" TextWrapping="Wrap" VerticalAlignment="Top"/>
|
||||||
|
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right" Spacing="8">
|
||||||
|
<Button Content="{x:Static lang:Resources.Common_Delete}" Click="OnConfirmClick"
|
||||||
|
MinWidth="90" IsDefault="True"/>
|
||||||
|
<Button Content="{x:Static lang:Resources.Common_Cancel}" Click="OnCancelClick"
|
||||||
|
MinWidth="90" IsCancel="True"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
Loaded 100 of 134 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user