diff --git a/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs b/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs index 788bad33b..a701101bb 100644 --- a/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs +++ b/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs @@ -136,9 +136,15 @@ private WritingSystem FromLcmWritingSystem(CoreWritingSystemDefinition ws, int i }; } - public Task GetWritingSystem(WritingSystemId id, WritingSystemType type) + public async Task GetWritingSystem(WritingSystemId id, WritingSystemType type) { - throw new NotImplementedException(); + var writingSystems = await GetWritingSystems(); + return type switch + { + WritingSystemType.Vernacular => writingSystems.Vernacular.FirstOrDefault(ws => ws.WsId == id), + WritingSystemType.Analysis => writingSystems.Analysis.FirstOrDefault(ws => ws.WsId == id), + _ => throw new ArgumentOutOfRangeException(nameof(type), type, null) + } ?? throw new NullReferenceException($"unable to find writing system with id {id}"); } internal void CompleteExemplars(WritingSystems writingSystems) @@ -208,13 +214,12 @@ await Cache.DoUsingNewOrCurrentUOW("Update WritingSystem", "Revert WritingSystem", async () => { - var updateProxy = new UpdateWritingSystemProxy(lcmWritingSystem, this) + var updateProxy = new UpdateWritingSystemProxy(lcmWritingSystem) { Id = Guid.Empty, Type = type, }; update.Apply(updateProxy); - updateProxy.CommitUpdate(Cache); }); return await GetWritingSystem(id, type); } diff --git a/backend/FwLite/FwDataMiniLcmBridge/Api/UpdateProxy/UpdateWritingSystemProxy.cs b/backend/FwLite/FwDataMiniLcmBridge/Api/UpdateProxy/UpdateWritingSystemProxy.cs index eaf849fcb..3baf370de 100644 --- a/backend/FwLite/FwDataMiniLcmBridge/Api/UpdateProxy/UpdateWritingSystemProxy.cs +++ b/backend/FwLite/FwDataMiniLcmBridge/Api/UpdateProxy/UpdateWritingSystemProxy.cs @@ -9,60 +9,43 @@ namespace FwDataMiniLcmBridge.Api.UpdateProxy; public record UpdateWritingSystemProxy : WritingSystem { - private readonly CoreWritingSystemDefinition _origLcmWritingSystem; - private readonly CoreWritingSystemDefinition _workingLcmWritingSystem; - private readonly FwDataMiniLcmApi _lexboxLcmApi; + private readonly CoreWritingSystemDefinition _lcmWritingSystem; [SetsRequiredMembers] - public UpdateWritingSystemProxy(CoreWritingSystemDefinition lcmWritingSystem, FwDataMiniLcmApi lexboxLcmApi) + public UpdateWritingSystemProxy(CoreWritingSystemDefinition lcmWritingSystem) { - _origLcmWritingSystem = lcmWritingSystem; - _workingLcmWritingSystem = new CoreWritingSystemDefinition(lcmWritingSystem, cloneId: true); - base.Abbreviation = Abbreviation = _origLcmWritingSystem.Abbreviation ?? ""; - base.Name = Name = _origLcmWritingSystem.LanguageName ?? ""; - base.Font = Font = _origLcmWritingSystem.DefaultFontName ?? ""; - _lexboxLcmApi = lexboxLcmApi; - } - - public void CommitUpdate(LcmCache cache) - { - if (_workingLcmWritingSystem.Id == _origLcmWritingSystem.Id) - { - cache.ServiceLocator.WritingSystemManager.Set(_workingLcmWritingSystem); - } - else - { - // Changing the ID of a writing system requires LCM to do a lot of work, so only go through that process if absolutely required - WritingSystemServices.MergeWritingSystems(cache, _workingLcmWritingSystem, _origLcmWritingSystem); - } + _lcmWritingSystem = lcmWritingSystem; + base.Abbreviation = Abbreviation = _lcmWritingSystem.Abbreviation ?? ""; + base.Name = Name = _lcmWritingSystem.LanguageName ?? ""; + base.Font = Font = _lcmWritingSystem.DefaultFontName ?? ""; } public override required WritingSystemId WsId { - get => _workingLcmWritingSystem.Id; - set => _workingLcmWritingSystem.Id = value; + get => _lcmWritingSystem.Id; + set => throw new NotSupportedException("Changing the ID of a writing system is not supported"); } public override required string Name { - get => _workingLcmWritingSystem.LanguageName; + get => _lcmWritingSystem.LanguageName; set { } // Silently do nothing; name should be derived from WsId at all times, so if the name should change then so should the WsId } public override required string Abbreviation { - get => _workingLcmWritingSystem.Abbreviation; - set => _workingLcmWritingSystem.Abbreviation = value; + get => _lcmWritingSystem.Abbreviation; + set => _lcmWritingSystem.Abbreviation = value; } public override required string Font { - get => _workingLcmWritingSystem.DefaultFontName; + get => _lcmWritingSystem.DefaultFontName; set { - if (value != _workingLcmWritingSystem.DefaultFontName) + if (value != _lcmWritingSystem.DefaultFontName) { - _workingLcmWritingSystem.DefaultFont = new FontDefinition(value); + _lcmWritingSystem.DefaultFont = new FontDefinition(value); } } } diff --git a/backend/FwLite/FwLiteShared/TypeGen/ReinforcedFwLiteTypingConfig.cs b/backend/FwLite/FwLiteShared/TypeGen/ReinforcedFwLiteTypingConfig.cs index 7aad43cdb..b0d9e1fd0 100644 --- a/backend/FwLite/FwLiteShared/TypeGen/ReinforcedFwLiteTypingConfig.cs +++ b/backend/FwLite/FwLiteShared/TypeGen/ReinforcedFwLiteTypingConfig.cs @@ -74,7 +74,7 @@ private static void ConfigureMiniLcmTypes(ConfigurationBuilder builder) exportBuilder.Ignore(); } })); - builder.ExportAsEnum().UseString(); + builder.ExportAsEnum(); builder.ExportAsInterface() .FlattenHierarchy() .WithPublicProperties() diff --git a/backend/FwLite/LcmCrdt/CrdtProjectsService.cs b/backend/FwLite/LcmCrdt/CrdtProjectsService.cs index 0533e66f2..e2b1c3c89 100644 --- a/backend/FwLite/LcmCrdt/CrdtProjectsService.cs +++ b/backend/FwLite/LcmCrdt/CrdtProjectsService.cs @@ -150,6 +150,18 @@ await lexboxApi.CreateEntry(new() ] }); + await lexboxApi.CreateWritingSystem(WritingSystemType.Vernacular, + new() + { + Id = Guid.NewGuid(), + Type = WritingSystemType.Vernacular, + WsId = "de", + Name = "German", + Abbreviation = "de", + Font = "Arial", + Exemplars = WritingSystem.LatinExemplars + }); + await lexboxApi.CreateWritingSystem(WritingSystemType.Vernacular, new() { @@ -173,5 +185,16 @@ await lexboxApi.CreateWritingSystem(WritingSystemType.Analysis, Font = "Arial", Exemplars = WritingSystem.LatinExemplars }); + await lexboxApi.CreateWritingSystem(WritingSystemType.Analysis, + new() + { + Id = Guid.NewGuid(), + Type = WritingSystemType.Analysis, + WsId = "fr", + Name = "French", + Abbreviation = "fr", + Font = "Arial", + Exemplars = WritingSystem.LatinExemplars + }); } } diff --git a/backend/FwLite/MiniLcm.Tests/WritingSystemTestsBase.cs b/backend/FwLite/MiniLcm.Tests/WritingSystemTestsBase.cs index 3d740d65a..99534c47f 100644 --- a/backend/FwLite/MiniLcm.Tests/WritingSystemTestsBase.cs +++ b/backend/FwLite/MiniLcm.Tests/WritingSystemTestsBase.cs @@ -64,4 +64,15 @@ await Api.CreateWritingSystem(WritingSystemType.Vernacular, }); await action.Should().ThrowAsync(); } + + [Fact] + public async Task UpdateExistingWritingSystem_Works() + { + var writingSystems = await Api.GetWritingSystems(); + var writingSystem = writingSystems.Vernacular.First(); + var original = writingSystem.Copy(); + writingSystem.Abbreviation = "New Abbreviation"; + var updatedWritingSystem = await Api.UpdateWritingSystem(original, writingSystem); + updatedWritingSystem.Abbreviation.Should().Be("New Abbreviation"); + } } diff --git a/backend/FwLite/MiniLcm/Models/WritingSystem.cs b/backend/FwLite/MiniLcm/Models/WritingSystem.cs index e23627cd7..6b5b26b37 100644 --- a/backend/FwLite/MiniLcm/Models/WritingSystem.cs +++ b/backend/FwLite/MiniLcm/Models/WritingSystem.cs @@ -1,6 +1,8 @@ -namespace MiniLcm.Models; +using System.Text.Json.Serialization; -public record WritingSystem: IObjectWithId +namespace MiniLcm.Models; + +public record WritingSystem: IObjectWithId { public required Guid Id { get; set; } public virtual required WritingSystemId WsId { get; set; } @@ -26,7 +28,7 @@ public void RemoveReference(Guid id, DateTimeOffset time) { } - public IObjectWithId Copy() + public WritingSystem Copy() { return new WritingSystem { diff --git a/frontend/viewer/src/lib/dotnet-types/generated-types/MiniLcm/Models/WritingSystemType.ts b/frontend/viewer/src/lib/dotnet-types/generated-types/MiniLcm/Models/WritingSystemType.ts index 20921cddf..a19962b02 100644 --- a/frontend/viewer/src/lib/dotnet-types/generated-types/MiniLcm/Models/WritingSystemType.ts +++ b/frontend/viewer/src/lib/dotnet-types/generated-types/MiniLcm/Models/WritingSystemType.ts @@ -4,7 +4,7 @@ // the code is regenerated. export enum WritingSystemType { - Vernacular = "Vernacular", - Analysis = "Analysis" + Vernacular = 0, + Analysis = 1 } /* eslint-enable */ diff --git a/frontend/viewer/src/lib/entry-data.ts b/frontend/viewer/src/lib/entry-data.ts index 31880a53c..e182c5532 100644 --- a/frontend/viewer/src/lib/entry-data.ts +++ b/frontend/viewer/src/lib/entry-data.ts @@ -49,7 +49,7 @@ export const writingSystems: IWritingSystems = { 'abbreviation': 'Por', 'font': '???', 'exemplars': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'], - 'type': WritingSystemType.Vernacular, + 'type': WritingSystemType.Analysis, 'order': 1 } ], diff --git a/frontend/viewer/src/lib/layout/AppBarMenu.svelte b/frontend/viewer/src/lib/layout/AppBarMenu.svelte index ec9315e23..12dd4040e 100644 --- a/frontend/viewer/src/lib/layout/AppBarMenu.svelte +++ b/frontend/viewer/src/lib/layout/AppBarMenu.svelte @@ -2,11 +2,13 @@ import AboutDialog from '$lib/about/AboutDialog.svelte'; import ActivityView from '$lib/activity/ActivityView.svelte'; import {useFeatures} from '$lib/services/feature-service'; - import {mdiDotsVertical, mdiEyeSettingsOutline, mdiHistory, mdiInformationVariantCircle} from '@mdi/js'; + import {mdiDotsVertical, mdiEyeSettingsOutline, mdiHistory, mdiInformationVariantCircle, mdiNoteEdit} from '@mdi/js'; import {createEventDispatcher} from 'svelte'; import {Button, MenuItem, ResponsiveMenu, Toggle} from 'svelte-ux'; import {asScottyPortal} from './Scotty.svelte'; import {useProjectViewState} from '$lib/services/project-view-state-service'; + import WritingSystemDialog from '$lib/writing-system/WritingSystemDialog.svelte'; + import DevContent from '$lib/layout/DevContent.svelte'; const dispatch = createEventDispatcher<{ showOptionsDialog: void; @@ -20,6 +22,7 @@ let activityViewOpen = false; let aboutDialogOpen = false; + let wsEditDialogOpen = false; @@ -41,6 +44,11 @@ aboutDialogOpen = true}>About {/if} + + wsEditDialogOpen = true}> + Edit WS + + @@ -50,11 +58,12 @@ {#if $features.history} {/if} - {#if about} {/if} + +