mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-05 10:39:26 -05:00
feat(data): store a nest's job number apart from the customer
Job numbers were going into Customer ("GM / 4980-88R"), which breaks
sorting, searching and grouping by customer. A nest now has its own
Job # field: one or several jobs separated by commas, normalized to
"a, b". It is saved in nest.json and the server (schema v21), edited
beside Customer in Edit Nest (WinForms and Avalonia), shown as a
sortable, searchable column in the Open list, and printed on the nest
report and in MCP output.
Deploy the server before the desktop: the open overlay takes the
server's job number, and an older server has none.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
857b88a2c7
commit
bfdfefeb9e
40 files changed
+304
-44
No files matched your search
@@ -154,10 +154,10 @@ public sealed partial class NestDatabase : IDisposable
|
||||
command.Transaction = transaction;
|
||||
command.CommandText = """
|
||||
INSERT INTO nests (id, name, customer, dateCreated, dateModified, material,
|
||||
materialGrade, thickness, thicknessName, units, status, plateCount, partCount, comments, madeBy,
|
||||
materialGrade, thickness, thicknessName, jobNumber, units, status, plateCount, partCount, comments, madeBy,
|
||||
fileSize, savedAt, file)
|
||||
VALUES ($id, $name, $customer, $dateCreated, $dateModified, $material,
|
||||
$materialGrade, $thickness, $thicknessName, $units, $status, $plateCount, $partCount, $comments,
|
||||
$materialGrade, $thickness, $thicknessName, $jobNumber, $units, $status, $plateCount, $partCount, $comments,
|
||||
$madeBy, $fileSize, $savedAt, $file)
|
||||
""";
|
||||
AddRecordParameters(command, id, record, file, updateFile: true);
|
||||
@@ -212,7 +212,7 @@ public sealed partial class NestDatabase : IDisposable
|
||||
UPDATE nests SET
|
||||
name = $name, customer = $customer, dateCreated = $dateCreated,
|
||||
dateModified = $dateModified, material = $material,
|
||||
materialGrade = $materialGrade, thickness = $thickness, thicknessName = $thicknessName, units = $units, status = $status, plateCount = $plateCount,
|
||||
materialGrade = $materialGrade, thickness = $thickness, thicknessName = $thicknessName, jobNumber = $jobNumber, units = $units, status = $status, plateCount = $plateCount,
|
||||
partCount = $partCount, comments = $comments, madeBy = $madeBy,
|
||||
savedAt = $savedAt, revision = $revision, restoredFromRevision=$source{fileClause}
|
||||
WHERE id = $id
|
||||
@@ -317,7 +317,7 @@ public sealed partial class NestDatabase : IDisposable
|
||||
}
|
||||
|
||||
private static bool SameMetadata(NestRecord a, NestRecord b) =>
|
||||
a.Name == b.Name && a.Customer == b.Customer && a.DateCreated == b.DateCreated &&
|
||||
a.Name == b.Name && a.Customer == b.Customer && a.JobNumber == b.JobNumber && a.DateCreated == b.DateCreated &&
|
||||
a.DateModified == b.DateModified && a.Material == b.Material && a.MaterialGrade == b.MaterialGrade &&
|
||||
a.Thickness == b.Thickness && a.ThicknessName == b.ThicknessName && a.Units == b.Units && a.Status == b.Status && a.PlateCount == b.PlateCount && a.PartCount == b.PartCount &&
|
||||
a.Comments == b.Comments && a.MadeBy == b.MadeBy;
|
||||
@@ -352,7 +352,7 @@ public sealed partial class NestDatabase : IDisposable
|
||||
command.Transaction = transaction;
|
||||
command.CommandText = "PRAGMA user_version";
|
||||
var version = (long)command.ExecuteScalar()!;
|
||||
if (version > 20) throw new InvalidOperationException("Database schema is newer than this server.");
|
||||
if (version > 21) throw new InvalidOperationException("Database schema is newer than this server.");
|
||||
if (version == 0)
|
||||
{
|
||||
command.CommandText = """
|
||||
@@ -485,6 +485,22 @@ public sealed partial class NestDatabase : IDisposable
|
||||
command.CommandText = "PRAGMA user_version=20";
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
if (version < 21)
|
||||
{
|
||||
// Job numbers, kept apart from the customer; existing records stay blank until
|
||||
// their nest is edited and saved again.
|
||||
foreach (var table in new[] { "nests", "nest_revisions" })
|
||||
{
|
||||
command.CommandText = $"SELECT COUNT(*) FROM pragma_table_info('{table}') WHERE name='jobNumber'";
|
||||
if ((long)command.ExecuteScalar()! == 0)
|
||||
{
|
||||
command.CommandText = $"ALTER TABLE {table} ADD COLUMN jobNumber TEXT NOT NULL DEFAULT ''";
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
command.CommandText = "PRAGMA user_version=21";
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
}
|
||||
@@ -558,7 +574,7 @@ public sealed partial class NestDatabase : IDisposable
|
||||
private const string RecordColumns = """
|
||||
id, name, customer, dateCreated, dateModified, material, thickness,
|
||||
status, plateCount, partCount, comments, madeBy, fileSize, savedAt, revision, deleted, restoredFromRevision,
|
||||
materialGrade, units, thicknessName
|
||||
materialGrade, units, thicknessName, jobNumber
|
||||
""";
|
||||
|
||||
// Case-insensitive (ASCII) substring over the text columns and the status's stored
|
||||
@@ -566,6 +582,7 @@ public sealed partial class NestDatabase : IDisposable
|
||||
private const string SearchPredicate = """
|
||||
name LIKE $pattern ESCAPE '\'
|
||||
OR customer LIKE $pattern ESCAPE '\'
|
||||
OR jobNumber LIKE $pattern ESCAPE '\'
|
||||
OR material LIKE $pattern ESCAPE '\'
|
||||
OR materialGrade LIKE $pattern ESCAPE '\'
|
||||
OR thicknessName LIKE $pattern ESCAPE '\'
|
||||
@@ -593,6 +610,7 @@ public sealed partial class NestDatabase : IDisposable
|
||||
NestSortField.Comments => "comments COLLATE NOCASE",
|
||||
NestSortField.FileSize => "fileSize",
|
||||
NestSortField.MaterialGrade => "materialGrade COLLATE NOCASE",
|
||||
NestSortField.JobNumber => "jobNumber COLLATE NOCASE",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(field), field, "Unsupported sort column."),
|
||||
};
|
||||
|
||||
@@ -668,6 +686,7 @@ public sealed partial class NestDatabase : IDisposable
|
||||
command.Parameters.AddWithValue("$materialGrade", record.MaterialGrade);
|
||||
command.Parameters.AddWithValue("$thickness", record.Thickness);
|
||||
command.Parameters.AddWithValue("$thicknessName", record.ThicknessName ?? "");
|
||||
command.Parameters.AddWithValue("$jobNumber", Nest.NormalizeJobNumbers(record.JobNumber));
|
||||
command.Parameters.AddWithValue("$units", record.Units.ToString());
|
||||
command.Parameters.AddWithValue("$status", record.Status.ToString());
|
||||
command.Parameters.AddWithValue("$plateCount", record.PlateCount);
|
||||
@@ -708,6 +727,7 @@ public sealed partial class NestDatabase : IDisposable
|
||||
MaterialGrade = reader.GetString(first + 17),
|
||||
Units = Enum.TryParse<Units>(reader.GetString(first + 18), true, out var units) ? units : Units.Inches,
|
||||
ThicknessName = reader.GetString(first + 19),
|
||||
JobNumber = reader.GetString(first + 20),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ internal static class NestMetadata
|
||||
{
|
||||
if (record.Name is null) return "name must be a string.";
|
||||
if (record.Customer is null) return "customer must be a string.";
|
||||
if (record.JobNumber is null) return "jobNumber must be a string.";
|
||||
if (record.Material is null) return "material must be a string.";
|
||||
if (record.MaterialGrade is null) return "materialGrade must be a string.";
|
||||
if (record.ThicknessName is null) return "thicknessName must be a string.";
|
||||
|
||||
Reference in new issue
Block a user