From 179fdec77852ebb803392594ca1a26e352279168 Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Thu, 11 Jul 2024 21:39:25 -0600 Subject: [PATCH] add open in flex button to fw lite (#948) * add open with flex button to project page * change default morph type to stem --- .../Api/FwDataMiniLcmApi.cs | 4 +-- backend/FwLite/LocalWebApp/Program.cs | 1 + .../LocalWebApp/Routes/FwIntegrationRoutes.cs | 32 +++++++++++++++++++ frontend/viewer/src/FwDataProjectView.svelte | 3 +- frontend/viewer/src/ProjectView.svelte | 25 +++++++++++++++ .../viewer/src/lib/services/lexbox-api.ts | 3 +- 6 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 backend/FwLite/LocalWebApp/Routes/FwIntegrationRoutes.cs diff --git a/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs b/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs index b8a2ddd39..beb449c27 100644 --- a/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs +++ b/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs @@ -301,11 +301,11 @@ public async Task CreateEntry(Entry entry) Cache.ServiceLocator.ActionHandler, () => { - var rootMorphType = MorphTypeRepository.GetObject(MoMorphTypeTags.kguidMorphRoot); + var stemMorphType = MorphTypeRepository.GetObject(MoMorphTypeTags.kguidMorphStem); var firstSense = entry.Senses.FirstOrDefault(); var lexEntry = LexEntryFactory.Create(new LexEntryComponents { - MorphType = rootMorphType, + MorphType = stemMorphType, LexemeFormAlternatives = MultiStringToTsStrings(entry.LexemeForm), GlossAlternatives = MultiStringToTsStrings(firstSense?.Gloss), GlossFeatures = [], diff --git a/backend/FwLite/LocalWebApp/Program.cs b/backend/FwLite/LocalWebApp/Program.cs index ab3d04eb1..b02430623 100644 --- a/backend/FwLite/LocalWebApp/Program.cs +++ b/backend/FwLite/LocalWebApp/Program.cs @@ -71,6 +71,7 @@ app.MapHistoryRoutes(); app.MapActivities(); app.MapProjectRoutes(); +app.MapFwIntegrationRoutes(); app.MapTest(); app.MapImport(); app.MapAuthRoutes(); diff --git a/backend/FwLite/LocalWebApp/Routes/FwIntegrationRoutes.cs b/backend/FwLite/LocalWebApp/Routes/FwIntegrationRoutes.cs new file mode 100644 index 000000000..22270afc9 --- /dev/null +++ b/backend/FwLite/LocalWebApp/Routes/FwIntegrationRoutes.cs @@ -0,0 +1,32 @@ +using FwDataMiniLcmBridge; +using LocalWebApp.Hubs; +using Microsoft.AspNetCore.SignalR; +using Microsoft.OpenApi.Models; + +namespace LocalWebApp.Routes; + +public static class FwIntegrationRoutes +{ + public static IEndpointConventionBuilder MapFwIntegrationRoutes(this WebApplication app) + { + var group = app.MapGroup($"/api/fw/{{{FwDataMiniLcmHub.ProjectRouteKey}}}").WithOpenApi( + operation => + { + operation.Parameters.Add(new OpenApiParameter() + { + Name = FwDataMiniLcmHub.ProjectRouteKey, In = ParameterLocation.Path, Required = true + }); + return operation; + }); + group.MapGet("/open/entry/{id}", + async (FwDataProjectContext context, IHubContext hubContext, FwDataFactory factory, Guid id) => + { + if (context.Project is null) return Results.BadRequest("No project is set in the context"); + await hubContext.Clients.Group(context.Project.Name).OnProjectClosed(CloseReason.Locked); + factory.CloseCurrentProject(); + //need to use redirect as a way to not trigger flex until after we have closed the project + return Results.Redirect($"silfw://localhost/link?database={context.Project.Name}&tool=lexiconEdit&guid={id}"); + }); + return group; + } +} diff --git a/frontend/viewer/src/FwDataProjectView.svelte b/frontend/viewer/src/FwDataProjectView.svelte index 9c64d4205..0f779a4d6 100644 --- a/frontend/viewer/src/FwDataProjectView.svelte +++ b/frontend/viewer/src/FwDataProjectView.svelte @@ -33,13 +33,14 @@ SetupSignalR(connection, { history: false, write: true, + openWithFlex: true, }, { OnEntryUpdated: async (entry: Entry) => { console.log('OnEntryUpdated', entry); }, async OnProjectClosed(reason: CloseReason): Promise { - connected = false; + // connected = false; switch (reason) { case CloseReason.User: navigate('/'); diff --git a/frontend/viewer/src/ProjectView.svelte b/frontend/viewer/src/ProjectView.svelte index cf0f7fd4b..28968f5f1 100644 --- a/frontend/viewer/src/ProjectView.svelte +++ b/frontend/viewer/src/ProjectView.svelte @@ -24,6 +24,8 @@ import { ViewerSearchParam, getSearchParam, updateSearchParam } from './lib/utils/search-params'; import SaveStatus from './lib/status/SaveStatus.svelte'; import { saveEventDispatcher, saveHandler } from './lib/services/save-event-service'; + import {AppNotification} from './lib/notifications/notifications'; + import flexLogo from './lib/assets/flex-logo.png'; export let loading = false; @@ -215,6 +217,13 @@ unsubSelectedEntry(); }; }); + + async function openInFlex() { + AppNotification.displayAction('The project is open in FieldWorks. Please close it to reopen.', 'warning', { + label: 'Open', + callback: () => window.location.reload() + }); + } @@ -311,6 +320,22 @@ {/if} + {#if $features.openWithFlex && $selectedEntry} +
+ + +
+ {/if}
diff --git a/frontend/viewer/src/lib/services/lexbox-api.ts b/frontend/viewer/src/lib/services/lexbox-api.ts index c465b3dae..8a6416a1c 100644 --- a/frontend/viewer/src/lib/services/lexbox-api.ts +++ b/frontend/viewer/src/lib/services/lexbox-api.ts @@ -14,7 +14,8 @@ export enum WritingSystemType { export interface LexboxApiFeatures { history?: boolean; write?: boolean; -}; + openWithFlex?: boolean; +} export interface LexboxApi { GetWritingSystems(): Promise;