保存配方时自动记录修订日期
This commit is contained in:
parent
c2307717f0
commit
e8a0e0f769
@ -1,4 +1,4 @@
|
||||
// 配方编辑节点:把可序列化配方转换为可绑定、可增删排序的区域和步骤树,保存时转换回配置。
|
||||
// 配方编辑节点:把可序列化配方转换为可绑定、可增删排序的区域和步骤树,保存时转换回配置。
|
||||
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Input;
|
||||
@ -152,8 +152,10 @@ public class RecipeNode : EditorNode
|
||||
get { return IsNew; }
|
||||
}
|
||||
|
||||
internal void MarkSaved(string fileName)
|
||||
/// <summary>写盘成功后同步文件名和修订日期,使后续编辑快照与已保存配置一致。</summary>
|
||||
internal void MarkSaved(string fileName, string? revisionDate)
|
||||
{
|
||||
RevisionDate = revisionDate;
|
||||
FileName = fileName;
|
||||
IsNew = false;
|
||||
}
|
||||
@ -177,6 +179,9 @@ public class RecipeNode : EditorNode
|
||||
set { SetProperty(ref _version, value); }
|
||||
}
|
||||
|
||||
/// <summary>上次保存的修订日期,随配置载入和写出。</summary>
|
||||
private string? RevisionDate { get; set; }
|
||||
|
||||
/// <summary>说明(sop.description)</summary>
|
||||
public string Description
|
||||
{
|
||||
@ -376,6 +381,7 @@ public class RecipeNode : EditorNode
|
||||
IsNew = isNew,
|
||||
Name = isNew ? config.Sop.Name : fileName,
|
||||
Version = config.Sop.Version,
|
||||
RevisionDate = config.Sop.RevisionDate,
|
||||
Description = config.Sop.Description,
|
||||
};
|
||||
|
||||
@ -444,6 +450,7 @@ public class RecipeNode : EditorNode
|
||||
|
||||
config.Sop.Name = Name;
|
||||
config.Sop.Version = Version;
|
||||
config.Sop.RevisionDate = RevisionDate;
|
||||
config.Sop.Description = Description;
|
||||
config.Sop.Parts = LegacyParts?.ToList();
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using Avalonia.Media;
|
||||
@ -346,6 +347,8 @@ public partial class RecipeEditorViewModel : BindableBase, IDialogAware
|
||||
if (_isNew && File.Exists(path)) throw new IOException("同名配方已存在,请使用其他配方名");
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
||||
var config = Recipe.ToConfig();
|
||||
// 日期先写入待保存的配置,回读成功后再同步到编辑节点。
|
||||
config.Sop.RevisionDate = DateTime.Today.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
|
||||
var baselineYaml = SopConfigLoader.ToYaml(config);
|
||||
var saved = SopConfigLoader.Save(config, path);
|
||||
// 只有落盘并回读成功才更新基准,保存失败时仍保留关闭确认。
|
||||
@ -353,7 +356,7 @@ public partial class RecipeEditorViewModel : BindableBase, IDialogAware
|
||||
|
||||
_path = path;
|
||||
_isNew = false;
|
||||
Recipe.MarkSaved(Path.GetFileNameWithoutExtension(path));
|
||||
Recipe.MarkSaved(Path.GetFileNameWithoutExtension(path), saved.Sop.RevisionDate);
|
||||
InitializeRecipeTools();
|
||||
RaisePropertyChanged(nameof(FileNameText));
|
||||
RaisePropertyChanged(nameof(Title));
|
||||
|
||||
@ -28,6 +28,10 @@ public class SopBody
|
||||
/// <summary>版本</summary>
|
||||
public string Version { get; set; } = "1.0";
|
||||
|
||||
/// <summary>最近一次在编辑器保存的本地日期(yyyy-MM-dd);旧配方可省略。</summary>
|
||||
[YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitNull)]
|
||||
public string? RevisionDate { get; set; }
|
||||
|
||||
/// <summary>说明</summary>
|
||||
public string Description { get; set; } = "";
|
||||
|
||||
|
||||
@ -1547,11 +1547,17 @@ internal static class Smoke
|
||||
{"onSaved",new Action<string>(_=>callbacks++)}},_=>{});
|
||||
await Task.Delay(80);
|
||||
var modal=lifetime.Windows.OfType<RecipeDialogWindow>().Single();
|
||||
// 先修改配方,触发有未保存改动时的关闭确认。
|
||||
((RecipeEditorViewModel)modal.DataContext!).Recipe.AddStepCommand.Execute();
|
||||
((RecipeEditorViewModel)modal.DataContext!).CloseCommand.Execute();
|
||||
await ChooseRecipeClose(modal,"SaveRecipeAndCloseButton");
|
||||
for(var i=0;i<100&&lifetime.Windows.Contains(modal);i++)await Task.Delay(20);
|
||||
Check(!lifetime.Windows.Contains(modal)&&File.Exists(store.ConfigPath(config.Sop.Name))&&callbacks==1,
|
||||
"Prism关闭按钮确认后保存一次并正常关闭");
|
||||
// 从磁盘回读,确认关闭时保存也会自动记录本地修订日期。
|
||||
var saved = SopHelper.Engine.Sop.SopConfigLoader.Load(store.ConfigPath(config.Sop.Name));
|
||||
Check(saved.Sop.RevisionDate == DateTime.Today.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture),
|
||||
"保存配方后写入本地修订日期");
|
||||
dialogs.ShowDialog("RecipeEditorDialog",new DialogParameters{{"directory",store.RecipesDirectory},{"new",false},{"config",config},
|
||||
{"path",store.ConfigPath(config.Sop.Name)}},_=>{});
|
||||
await Task.Delay(80);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user