Skip to content

Commit

Permalink
add open in flex button to fw lite (#948)
Browse files Browse the repository at this point in the history
* add open with flex button to project page

* change default morph type to stem
  • Loading branch information
hahn-kev authored Jul 12, 2024
1 parent 614c0b6 commit 179fdec
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 4 deletions.
4 changes: 2 additions & 2 deletions backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@ public async Task<Entry> 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 = [],
Expand Down
1 change: 1 addition & 0 deletions backend/FwLite/LocalWebApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
app.MapHistoryRoutes();
app.MapActivities();
app.MapProjectRoutes();
app.MapFwIntegrationRoutes();
app.MapTest();
app.MapImport();
app.MapAuthRoutes();
Expand Down
32 changes: 32 additions & 0 deletions backend/FwLite/LocalWebApp/Routes/FwIntegrationRoutes.cs
Original file line number Diff line number Diff line change
@@ -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<FwDataMiniLcmHub, ILexboxHubClient> 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;
}
}
3 changes: 2 additions & 1 deletion frontend/viewer/src/FwDataProjectView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
connected = false;
// connected = false;
switch (reason) {
case CloseReason.User:
navigate('/');
Expand Down
25 changes: 25 additions & 0 deletions frontend/viewer/src/ProjectView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
});
}
</script>

<svelte:head>
Expand Down Expand Up @@ -311,6 +320,22 @@

</div>
{/if}
{#if $features.openWithFlex && $selectedEntry}
<div class="contents">
<!-- button must be a link otherwise it won't follow the redirect to a protocol handler-->
<Button
href={`/api/fw/${projectName}/open/entry/${$selectedEntry.id}`}
on:click={openInFlex}
variant="fill-light"
color="info"
size="sm">
<img src={flexLogo} alt="FieldWorks logo" class="h-6"/>
<div class="hidden" class:sm:contents={!$entryActionsPortal.collapsed}>
Open in FieldWorks
</div>
</Button>
</div>
{/if}
<div class="contents max-sm:hidden" class:hidden={collapseActionBar}>
<Toc entry={$selectedEntry} />
</div>
Expand Down
3 changes: 2 additions & 1 deletion frontend/viewer/src/lib/services/lexbox-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export enum WritingSystemType {
export interface LexboxApiFeatures {
history?: boolean;
write?: boolean;
};
openWithFlex?: boolean;
}

export interface LexboxApi {
GetWritingSystems(): Promise<WritingSystems>;
Expand Down

0 comments on commit 179fdec

Please sign in to comment.