feat(adminui): create-new-script from the inline virtual-tag panel

This commit is contained in:
Joseph Doherty
2026-06-16 16:44:14 -04:00
parent 526eebb3bb
commit c98625fd9f
4 changed files with 192 additions and 1 deletions
@@ -1011,6 +1011,30 @@ public sealed class UnsTreeService(IDbContextFactory<OtOpcUaConfigDbContext> dbF
.ToList();
}
/// <inheritdoc />
public async Task<UnsMutationResult> CreateScriptAsync(string name, CancellationToken ct = default)
{
await using var db = await dbFactory.CreateDbContextAsync(ct);
// System-generated id, mirroring the Script-edit page's "SC-{12 hex}" convention.
var scriptId = $"SC-{Guid.NewGuid().ToString("N")[..12]}";
var resolvedName = string.IsNullOrWhiteSpace(name) ? "New script" : name.Trim();
// Blank source; SourceHash is the SHA-256 of that blank body so it stays consistent with the
// inline save (UpdateScriptSourceAsync recomputes it the same way).
db.Scripts.Add(new Script
{
ScriptId = scriptId,
Name = resolvedName,
Language = "CSharp",
SourceCode = "",
SourceHash = HashSource(""),
});
await db.SaveChangesAsync(ct);
return new UnsMutationResult(true, null, scriptId);
}
/// <summary>
/// When the bound script uses the reserved <c>{{equip}}</c> token, the owning equipment must have
/// a derivable tag base (≥1 driver tag, all sharing one object prefix). Returns a rejection result