Skip to content

Commit

Permalink
Get FLEx model version from repo and store in metadata (#1082)
Browse files Browse the repository at this point in the history
Project page now shows the version number of FieldWorks that was used to
create the project, based on the model version appearing at the tip of
the hg repo. (A tooltip also shows the raw model number, e.g. 7000072,
when hovered over). This is NOT automatically updated on hg push, as we
expect this to rarely ever change.
  • Loading branch information
rmunn authored Oct 15, 2024
1 parent cc3ea41 commit e7d5aec
Show file tree
Hide file tree
Showing 14 changed files with 1,577 additions and 1 deletion.
17 changes: 17 additions & 0 deletions backend/LexBoxApi/GraphQL/ProjectMutations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,23 @@ public async Task<IQueryable<Project>> UpdateLangProjectId(string code,
return dbContext.Projects.Where(p => p.Id == projectId);
}

[Error<NotFoundException>]
[Error<DbError>]
[Error<UnauthorizedAccessException>]
[UseMutationConvention]
[UseFirstOrDefault]
[UseProjection]
public async Task<IQueryable<Project>> UpdateFLExModelVersion(string code,
IPermissionService permissionService,
[Service] ProjectService projectService,
LexBoxDbContext dbContext)
{
var projectId = await projectService.LookupProjectId(code);
await permissionService.AssertCanManageProject(projectId);
await projectService.UpdateFLExModelVersion(projectId);
return dbContext.Projects.Where(p => p.Id == projectId);
}

[Error<NotFoundException>]
[Error<LastMemberCantLeaveException>]
[UseMutationConvention]
Expand Down
8 changes: 8 additions & 0 deletions backend/LexBoxApi/Services/HgService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,14 @@ private string[] GetWsList(System.Xml.XmlElement root, string tagName)
return null;
}

public async Task<int?> GetModelVersionOfFlexProject(ProjectCode code, CancellationToken token = default)
{
var result = await ExecuteHgCommandServerCommand(code, "flexmodelversion", token);
var text = await result.ReadAsStringAsync(token);
var json = JsonDocument.Parse(text);
return json.RootElement.GetProperty("modelversion").GetInt32();
}

public Task RevertRepo(ProjectCode code, string revHash)
{
throw new NotImplementedException();
Expand Down
12 changes: 12 additions & 0 deletions backend/LexBoxApi/Services/ProjectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ public async Task UpdateProjectLangProjectId(Guid projectId)
await dbContext.SaveChangesAsync();
}

public async Task UpdateFLExModelVersion(Guid projectId)
{
var project = await dbContext.Projects.FindAsync(projectId);
if (project is null || project.Type != ProjectType.FLEx) return;
await dbContext.Entry(project).Reference(p => p.FlexProjectMetadata).LoadAsync();
var modelVersion = await hgService.GetModelVersionOfFlexProject(project.Code);
if (modelVersion is null) return;
project.FlexProjectMetadata ??= new FlexProjectMetadata();
project.FlexProjectMetadata.FlexModelVersion = modelVersion;
await dbContext.SaveChangesAsync();
}

public async Task<Guid> CreateDraftProject(CreateProjectInput input)
{
// No need for a transaction if we're just saving a single item
Expand Down
1 change: 1 addition & 0 deletions backend/LexCore/Entities/FlexProjectMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class FlexProjectMetadata
/// </summary>
public Guid? LangProjectId { get; set; }
public ProjectWritingSystems? WritingSystems { get; set; }
public int? FlexModelVersion { get; set; }
}

public class ProjectWritingSystems
Expand Down
1 change: 1 addition & 0 deletions backend/LexCore/ServiceInterfaces/IHgService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public interface IHgService
Task SoftDeleteRepo(ProjectCode code, string deletedRepoSuffix);
Task<ProjectWritingSystems?> GetProjectWritingSystems(ProjectCode code, CancellationToken token = default);
Task<Guid?> GetProjectIdOfFlexProject(ProjectCode code, CancellationToken token = default);
Task<int?> GetModelVersionOfFlexProject(ProjectCode code, CancellationToken token = default);
BackupExecutor? BackupRepo(ProjectCode code);
Task ResetRepo(ProjectCode code);
Task FinishReset(ProjectCode code, Stream zipFile);
Expand Down
Loading

0 comments on commit e7d5aec

Please sign in to comment.