diff --git a/backend/LexBoxApi/GraphQL/CustomTypes/IsLanguageForgeProjectDataLoader.cs b/backend/LexBoxApi/GraphQL/CustomTypes/IsLanguageForgeProjectDataLoader.cs new file mode 100644 index 000000000..74037310b --- /dev/null +++ b/backend/LexBoxApi/GraphQL/CustomTypes/IsLanguageForgeProjectDataLoader.cs @@ -0,0 +1,30 @@ +using LexCore.ServiceInterfaces; +using LfClassicData; +using MongoDB.Driver; +using MongoDB.Driver.Linq; + +namespace LexBoxApi.GraphQL.CustomTypes; + +public class IsLanguageForgeProjectDataLoader : BatchDataLoader, IIsLanguageForgeProjectDataLoader +{ + private readonly SystemDbContext _systemDbContext; + + public IsLanguageForgeProjectDataLoader( + SystemDbContext systemDbContext, + IBatchScheduler batchScheduler, + DataLoaderOptions? options = null) + : base(batchScheduler, options) + { + _systemDbContext = systemDbContext; + } + + protected override async Task> LoadBatchAsync( + IReadOnlyList projectCodes, + CancellationToken cancellationToken) + { + return await MongoExtensions.ToAsyncEnumerable(_systemDbContext.Projects.AsQueryable() + .Select(p => p.ProjectCode) + .Where(projectCode => projectCodes.Contains(projectCode))) + .ToDictionaryAsync(projectCode => projectCode, _ => true, cancellationToken); + } +} diff --git a/backend/LexBoxApi/GraphQL/GraphQlSetupKernel.cs b/backend/LexBoxApi/GraphQL/GraphQlSetupKernel.cs index fd0457973..252da0584 100644 --- a/backend/LexBoxApi/GraphQL/GraphQlSetupKernel.cs +++ b/backend/LexBoxApi/GraphQL/GraphQlSetupKernel.cs @@ -20,6 +20,7 @@ public static void AddLexGraphQL(this IServiceCollection services, IHostEnvironm .InitializeOnStartup() .RegisterDbContext() .RegisterService() + .RegisterService() .RegisterService() .RegisterService() .RegisterService() diff --git a/backend/LexBoxApi/LexBoxKernel.cs b/backend/LexBoxApi/LexBoxKernel.cs index 899f21444..4281d81b6 100644 --- a/backend/LexBoxApi/LexBoxKernel.cs +++ b/backend/LexBoxApi/LexBoxKernel.cs @@ -1,6 +1,7 @@ using LexBoxApi.Auth; using LexBoxApi.Config; using LexBoxApi.GraphQL; +using LexBoxApi.GraphQL.CustomTypes; using LexBoxApi.Services; using LexCore.Config; using LexCore.ServiceInterfaces; @@ -52,6 +53,7 @@ public static void AddLexBoxApi(this IServiceCollection services, services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddSingleton(); services.AddSingleton(); diff --git a/backend/LexCore/Entities/Project.cs b/backend/LexCore/Entities/Project.cs index 5758c0d29..37f2e9b32 100644 --- a/backend/LexCore/Entities/Project.cs +++ b/backend/LexCore/Entities/Project.cs @@ -50,6 +50,15 @@ public bool GetHasAbandonedTransactions(IHgService hgService) { return hgService.HasAbandonedTransactions(Code); } + + public Task GetIsLanguageForgeProject(IIsLanguageForgeProjectDataLoader loader) + { + if (Type is ProjectType.Unknown or ProjectType.FLEx) + { + return loader.LoadAsync(Code); + } + return Task.FromResult(false); + } } public enum ProjectMigrationStatus diff --git a/backend/LexCore/ServiceInterfaces/IIsLanguageForgeProjectDataLoader.cs b/backend/LexCore/ServiceInterfaces/IIsLanguageForgeProjectDataLoader.cs new file mode 100644 index 000000000..6482581b2 --- /dev/null +++ b/backend/LexCore/ServiceInterfaces/IIsLanguageForgeProjectDataLoader.cs @@ -0,0 +1,6 @@ +namespace LexCore.ServiceInterfaces; + +public interface IIsLanguageForgeProjectDataLoader +{ + public Task LoadAsync(string projectCode, CancellationToken cancellationToken = default); +} diff --git a/frontend/schema.graphql b/frontend/schema.graphql index 93b8a9056..dddbfd48d 100644 --- a/frontend/schema.graphql +++ b/frontend/schema.graphql @@ -214,6 +214,7 @@ type Project { users: [ProjectUsers!]! changesets: [Changeset!]! hasAbandonedTransactions: Boolean! + isLanguageForgeProject: Boolean! parentId: UUID name: String! description: String diff --git a/frontend/src/routes/(authenticated)/project/[project_code]/+page.svelte b/frontend/src/routes/(authenticated)/project/[project_code]/+page.svelte index d470585ce..6e9b6df43 100644 --- a/frontend/src/routes/(authenticated)/project/[project_code]/+page.svelte +++ b/frontend/src/routes/(authenticated)/project/[project_code]/+page.svelte @@ -234,12 +234,14 @@ {#if project.type === ProjectType.FlEx && $isDev} + {#if project.isLanguageForgeProject} {$t('project_page.open_with_viewer')} - - + {/if} + + {:else}