diff --git a/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs b/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs index 80eebd829..42af56c24 100644 --- a/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs +++ b/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs @@ -19,7 +19,7 @@ namespace FwDataMiniLcmBridge.Api; -public class FwDataMiniLcmApi(Lazy cacheLazy, bool onCloseSave, ILogger logger, FwDataProject project, MiniLcmValidators validators) : IMiniLcmApi, IDisposable +public class FwDataMiniLcmApi(Lazy cacheLazy, bool onCloseSave, ILogger logger, FwDataProject project, MiniLcmValidators validators) : IMiniLcmApi, IMiniLcmSaveApi { internal LcmCache Cache => cacheLazy.Value; public FwDataProject Project { get; } = project; diff --git a/backend/FwLite/FwLiteShared/Services/MiniLcmJsInvokable.cs b/backend/FwLite/FwLiteShared/Services/MiniLcmJsInvokable.cs index 6e89e6ecc..d24f7a3c4 100644 --- a/backend/FwLite/FwLiteShared/Services/MiniLcmJsInvokable.cs +++ b/backend/FwLite/FwLiteShared/Services/MiniLcmJsInvokable.cs @@ -22,8 +22,12 @@ public MiniLcmFeatures SupportedFeatures() return new(History: isCrdtProject, Write: true, OpenWithFlex: isFwDataProject, Feedback: true, Sync: SupportsSync); } - private void TriggerSync() + private void OnDataChanged() { + if (api is IMiniLcmSaveApi saveApi) + { + saveApi.Save(); + } if (SupportsSync) { backgroundSyncService.TriggerSync(project); @@ -109,69 +113,88 @@ public Task CreateWritingSystem(WritingSystemType type, WritingSy } [JSInvokable] - public Task UpdateWritingSystem(WritingSystem before, WritingSystem after) + public async Task UpdateWritingSystem(WritingSystem before, WritingSystem after) { - return api.UpdateWritingSystem(before, after); + var updatedWritingSystem = await api.UpdateWritingSystem(before, after); + OnDataChanged(); + return updatedWritingSystem; } [JSInvokable] - public Task CreatePartOfSpeech(PartOfSpeech partOfSpeech) + public async Task CreatePartOfSpeech(PartOfSpeech partOfSpeech) { - return api.CreatePartOfSpeech(partOfSpeech); + var createdPartOfSpeech = await api.CreatePartOfSpeech(partOfSpeech); + OnDataChanged(); + return createdPartOfSpeech; } [JSInvokable] - public Task UpdatePartOfSpeech(PartOfSpeech before, PartOfSpeech after) + public async Task UpdatePartOfSpeech(PartOfSpeech before, PartOfSpeech after) { - return api.UpdatePartOfSpeech(before, after); + var updatedPartOfSpeech = await api.UpdatePartOfSpeech(before, after); + OnDataChanged(); + return updatedPartOfSpeech; } [JSInvokable] - public Task DeletePartOfSpeech(Guid id) + public async Task DeletePartOfSpeech(Guid id) { - return api.DeletePartOfSpeech(id); + await api.DeletePartOfSpeech(id); + OnDataChanged(); } [JSInvokable] - public Task CreateSemanticDomain(SemanticDomain semanticDomain) + public async Task CreateSemanticDomain(SemanticDomain semanticDomain) { - return api.CreateSemanticDomain(semanticDomain); + var createdSemanticDomain = await api.CreateSemanticDomain(semanticDomain); + OnDataChanged(); + return createdSemanticDomain; } [JSInvokable] - public Task UpdateSemanticDomain(SemanticDomain before, SemanticDomain after) + public async Task UpdateSemanticDomain(SemanticDomain before, SemanticDomain after) { - return api.UpdateSemanticDomain(before, after); + var updatedSemanticDomain = await api.UpdateSemanticDomain(before, after); + OnDataChanged(); + return updatedSemanticDomain; } [JSInvokable] - public Task DeleteSemanticDomain(Guid id) + public async Task DeleteSemanticDomain(Guid id) { - return api.DeleteSemanticDomain(id); + await api.DeleteSemanticDomain(id); + OnDataChanged(); } [JSInvokable] - public Task CreateComplexFormType(ComplexFormType complexFormType) + public async Task CreateComplexFormType(ComplexFormType complexFormType) { - return api.CreateComplexFormType(complexFormType); + var createdComplexFormType = await api.CreateComplexFormType(complexFormType); + OnDataChanged(); + return createdComplexFormType; } [JSInvokable] - public Task UpdateComplexFormType(ComplexFormType before, ComplexFormType after) + public async Task UpdateComplexFormType(ComplexFormType before, ComplexFormType after) { - return api.UpdateComplexFormType(before, after); + var updatedComplexFormType = await api.UpdateComplexFormType(before, after); + OnDataChanged(); + return updatedComplexFormType; } [JSInvokable] - public Task DeleteComplexFormType(Guid id) + public async Task DeleteComplexFormType(Guid id) { - return api.DeleteComplexFormType(id); + await api.DeleteComplexFormType(id); + OnDataChanged(); } [JSInvokable] - public Task CreateEntry(Entry entry) + public async Task CreateEntry(Entry entry) { - return api.CreateEntry(entry); + var createdEntry = await api.CreateEntry(entry); + OnDataChanged(); + return createdEntry; } [JSInvokable] @@ -179,86 +202,104 @@ public async Task UpdateEntry(Entry before, Entry after) { //todo trigger sync on the test var result = await api.UpdateEntry(before, after); - TriggerSync(); + OnDataChanged(); return result; } [JSInvokable] - public Task DeleteEntry(Guid id) + public async Task DeleteEntry(Guid id) { - return api.DeleteEntry(id); + await api.DeleteEntry(id); + OnDataChanged(); } [JSInvokable] - public Task CreateComplexFormComponent(ComplexFormComponent complexFormComponent) + public async Task CreateComplexFormComponent(ComplexFormComponent complexFormComponent) { - return api.CreateComplexFormComponent(complexFormComponent); + var createdComplexFormComponent = await api.CreateComplexFormComponent(complexFormComponent); + OnDataChanged(); + return createdComplexFormComponent; } [JSInvokable] - public Task DeleteComplexFormComponent(ComplexFormComponent complexFormComponent) + public async Task DeleteComplexFormComponent(ComplexFormComponent complexFormComponent) { - return api.DeleteComplexFormComponent(complexFormComponent); + await api.DeleteComplexFormComponent(complexFormComponent); + OnDataChanged(); } [JSInvokable] - public Task AddComplexFormType(Guid entryId, Guid complexFormTypeId) + public async Task AddComplexFormType(Guid entryId, Guid complexFormTypeId) { - return api.AddComplexFormType(entryId, complexFormTypeId); + await api.AddComplexFormType(entryId, complexFormTypeId); + OnDataChanged(); } [JSInvokable] - public Task RemoveComplexFormType(Guid entryId, Guid complexFormTypeId) + public async Task RemoveComplexFormType(Guid entryId, Guid complexFormTypeId) { - return api.RemoveComplexFormType(entryId, complexFormTypeId); + await api.RemoveComplexFormType(entryId, complexFormTypeId); + OnDataChanged(); } [JSInvokable] - public Task CreateSense(Guid entryId, Sense sense) + public async Task CreateSense(Guid entryId, Sense sense) { - return api.CreateSense(entryId, sense); + var createdSense = await api.CreateSense(entryId, sense); + OnDataChanged(); + return createdSense; } [JSInvokable] - public Task UpdateSense(Guid entryId, Sense before, Sense after) + public async Task UpdateSense(Guid entryId, Sense before, Sense after) { - return api.UpdateSense(entryId, before, after); + var updatedSense = await api.UpdateSense(entryId, before, after); + OnDataChanged(); + return updatedSense; } [JSInvokable] - public Task DeleteSense(Guid entryId, Guid senseId) + public async Task DeleteSense(Guid entryId, Guid senseId) { - return api.DeleteSense(entryId, senseId); + await api.DeleteSense(entryId, senseId); + OnDataChanged(); } [JSInvokable] - public Task AddSemanticDomainToSense(Guid senseId, SemanticDomain semanticDomain) + public async Task AddSemanticDomainToSense(Guid senseId, SemanticDomain semanticDomain) { - return api.AddSemanticDomainToSense(senseId, semanticDomain); + await api.AddSemanticDomainToSense(senseId, semanticDomain); + OnDataChanged(); } [JSInvokable] - public Task RemoveSemanticDomainFromSense(Guid senseId, Guid semanticDomainId) + public async Task RemoveSemanticDomainFromSense(Guid senseId, Guid semanticDomainId) { - return api.RemoveSemanticDomainFromSense(senseId, semanticDomainId); + await api.RemoveSemanticDomainFromSense(senseId, semanticDomainId); + OnDataChanged(); } [JSInvokable] - public Task CreateExampleSentence(Guid entryId, Guid senseId, ExampleSentence exampleSentence) + public async Task CreateExampleSentence(Guid entryId, Guid senseId, ExampleSentence exampleSentence) { - return api.CreateExampleSentence(entryId, senseId, exampleSentence); + var createdExampleSentence = await api.CreateExampleSentence(entryId, senseId, exampleSentence); + OnDataChanged(); + return createdExampleSentence; } [JSInvokable] - public Task UpdateExampleSentence(Guid entryId, Guid senseId, ExampleSentence before, ExampleSentence after) + public async Task UpdateExampleSentence(Guid entryId, Guid senseId, ExampleSentence before, ExampleSentence after) { - return api.UpdateExampleSentence(entryId, senseId, before, after); + var updatedExampleSentence = await api.UpdateExampleSentence(entryId, senseId, before, after); + OnDataChanged(); + return updatedExampleSentence; } [JSInvokable] - public Task DeleteExampleSentence(Guid entryId, Guid senseId, Guid exampleSentenceId) + public async Task DeleteExampleSentence(Guid entryId, Guid senseId, Guid exampleSentenceId) { - return api.DeleteExampleSentence(entryId, senseId, exampleSentenceId); + await api.DeleteExampleSentence(entryId, senseId, exampleSentenceId); + OnDataChanged(); } public void Dispose() diff --git a/backend/FwLite/MiniLcm/IMiniLcmWriteApi.cs b/backend/FwLite/MiniLcm/IMiniLcmWriteApi.cs index c9e74442b..1dfe7c287 100644 --- a/backend/FwLite/MiniLcm/IMiniLcmWriteApi.cs +++ b/backend/FwLite/MiniLcm/IMiniLcmWriteApi.cs @@ -71,6 +71,14 @@ Task UpdateExampleSentence(Guid entryId, #endregion } +/// +/// API for saving the project, really only used by FwData +/// +public interface IMiniLcmSaveApi +{ + void Save(); +} + /// /// wrapper around JsonPatchDocument that allows for fluent updates ///