Skip to content

Commit

Permalink
Added Documents tab on participant dashboard, it lists all the docume…
Browse files Browse the repository at this point in the history
…nts assciated with the case. From the list, user can open and view each documents
  • Loading branch information
vks333 authored and carlsixsmith-moj committed Sep 3, 2024
1 parent 24a47c3 commit d45099b
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Application/Features/Documents/DTOs/DocumentDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Cfo.Cats.Application.Features.Documents.DTOs;
[Description("Documents")]
public class DocumentDto
{
[Description("Id")] public int Id { get; set; }
[Description("Id")] public Guid? Id { get; set; }

[Description("Title")] public string? Title { get; set; }

Expand All @@ -23,6 +23,8 @@ public class DocumentDto
[Description("Tenant Name")] public string? TenantName { get; set; }

[Description("Content")] public string? Content { get; set; }
[Description("Created By")] public string CreatedBy { get; set; } = string.Empty;
[Description("Created Date")] public DateTime Created { get; set; }

[Description("Owner")] public ApplicationUserDto? Owner { get; set; }

Expand Down
47 changes: 47 additions & 0 deletions src/Application/Features/Documents/Queries/GetByParticipantId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Cfo.Cats.Application.Common.Security;
using Cfo.Cats.Application.Common.Validators;
using Cfo.Cats.Application.Features.Documents.DTOs;
using Cfo.Cats.Application.Features.Participants.DTOs;
using Cfo.Cats.Application.SecurityConstants;
using DocumentFormat.OpenXml.InkML;
using System.Threading.Tasks;

namespace Cfo.Cats.Application.Features.Documents.Queries;
public static class GetByParticipantId
{
[RequestAuthorize(Policy = SecurityPolicies.AuthorizedUser)]

public class Query : IRequest<Result<DocumentDto[]>>
{
public required string ParticipantId { get; set; }
}

public class Handler(IUnitOfWork unitOfWork, IMapper mapper) : IRequestHandler<Query, Result<DocumentDto[]>>
{
public async Task<Result<DocumentDto[]>> Handle(Query request, CancellationToken cancellationToken)
{
string likeCriteria = string.Format(@"Files/{0}%", request.ParticipantId);
var query = unitOfWork.DbContext.Documents
.Where(d => EF.Functions.Like(d.URL, likeCriteria));

var documents = await query.ProjectTo<DocumentDto>(mapper.ConfigurationProvider)
.ToArrayAsync(cancellationToken) ?? [];

return Result<DocumentDto[]>.Success(documents);
}
}
public class Validator : AbstractValidator<Query>
{
public Validator()
{
RuleFor(x => x.ParticipantId.ToString())
.NotEmpty()
.MinimumLength(9)
.MaximumLength(9)
.Matches(ValidationConstants.AlphaNumeric)
.WithMessage(string.Format(ValidationConstants.AlphaNumericMessage, "Participant Id"));

}
}
}

102 changes: 102 additions & 0 deletions src/Server.UI/Pages/Participants/Components/CaseDocuments.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
@using Cfo.Cats.Application.Common.Interfaces.Identity
@using Cfo.Cats.Server.UI.Pages.Participants.Components
@using Cfo.Cats.Application.Features.Participants.DTOs
@using Cfo.Cats.Application.Features.Documents.DTOs
@using Cfo.Cats.Application.Features.Participants.Queries
@using Cfo.Cats.Application.Features.Documents.Queries
@using Cfo.Cats.Application.SecurityConstants
@using System.Net.Http.Json

@inherits CatsComponentBase

@inject IUserService UserService
@inject IStringLocalizer<CaseDocuments> L


@attribute [Authorize(Policy = SecurityPolicies.AuthorizedUser)]

<style>
.mud-table-toolbar {
height: 120px !important;
}
</style>
<MudLoading Loading="_loading" />
@if (_notFound)
{
<MudAlert>
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined" Square="true" Class="my-2">No documents yet.</MudAlert>
</MudAlert>
}
else
{
<MudDataGrid T="DocumentDto" FixedHeader="true"
FixedFooter="true"
Virtualize="true"
Height="calc(100vh - 330px)"
Items="@_documents"
Hover="true">

<Columns>
<PropertyColumn Property="x => x.Title" Title="@L[_currentDto.GetMemberDescription(x => x.Title)]" />
<PropertyColumn Property="x => x.Description" Title="@L[_currentDto.GetMemberDescription(x => x.Description)]" />
<PropertyColumn Property="x => x.Created" Title="@L[_currentDto.GetMemberDescription(x => x.Created)]" />
<PropertyColumn Property="x => UserService.DataSource.First(u => u.Id == x.CreatedBy).DisplayName" Title="@L[_currentDto.GetMemberDescription(x => x.CreatedBy)]" />
<TemplateColumn>
<CellTemplate>
<MudButton Size="@Size.Small" StartIcon="@Icons.Material.Outlined.ViewColumn" OnClick="@(() => OpenDocumentDialog(context.Item))">Open</MudButton>
</CellTemplate>
</TemplateColumn>
</Columns>
</MudDataGrid>
}

@code {
bool _loading = true;
bool _notFound = false;
private DocumentDto[] _documents = [];
private DocumentDto _currentDto = new() { Id = Guid.Empty };

[Parameter]
[EditorRequired]
public string ParticipantId { get; set; } = default!;

[CascadingParameter]
public UserProfile? UserProfile { get; set; } = null!;

protected Guid SelectedDocument { get; set; } = Guid.Empty;


protected override async Task OnInitializedAsync()
{
try
{
if (String.IsNullOrWhiteSpace(ParticipantId) == false)
{
_documents = await GetNewMediator().Send(new GetByParticipantId.Query()
{
ParticipantId = ParticipantId
});
_notFound = _documents.Count() == 0;
}
}finally{
_loading = false;
}
}

public async Task OpenDocumentDialog(DocumentDto item)
{
await DialogService.ShowAsync<ViewDocumentDialog>(
"View Document Dialog",
new DialogParameters<ViewDocumentDialog>()
{
{ x => x.Model, item }
},
new DialogOptions
{
MaxWidth = MaxWidth.ExtraExtraLarge,
Position=DialogPosition.Center,
FullWidth = true,
CloseButton = true
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
@using Cfo.Cats.Application.Common.Interfaces.Identity
@using Cfo.Cats.Server.UI.Pages.Participants.Components
@using Cfo.Cats.Application.Features.Participants.DTOs
@using Cfo.Cats.Application.Features.Documents.DTOs
@using Cfo.Cats.Application.Features.Participants.Queries
@using Cfo.Cats.Application.Features.Documents.Queries
@using Cfo.Cats.Application.SecurityConstants
@inherits CatsComponentBase

@inject IValidationService Validator

<style>
.full-size-object {
width: 100%;
height: 100%;
}
</style>

<MudDialog Style="height: 100%">
<DialogContent>
@if (Model is not null)
{
@if (fileBase64 != null && extension!.Equals("pdf", StringComparison.CurrentCultureIgnoreCase))
{
<object data="data:application/pdf;base64,@fileBase64" type="application/pdf" class="full-size-object">
<p>PDF cannot be displayed.</p>
</object>
}
else if (IsFileRejected)
{
<MudText Typo="Typo.caption">
File cannot be displayed. Please contact support.
</MudText>
}
else
{
<MudLoading Loading="true" />
}
}
</DialogContent>
<DialogActions>
<MudButton OnClick="Cancel">@ConstantString.Close</MudButton>
</DialogActions>
</MudDialog>

@code {
[CascadingParameter] private MudDialogInstance MudDialog { get; set; } = default!;

[Parameter, EditorRequired]
public required DocumentDto Model { get; set; }
private bool IsFileRejected { get; set; }
private string? fileBase64;
private string? extension;
private void Cancel()
{
MudDialog.Cancel();
}
protected override async Task OnInitializedAsync()
{
Guid documentId = Model.Id!.Value;
if (documentId != Guid.Empty)
{
var query = new GetDocumentById.Query()
{
Id = documentId
};

var result = await GetNewMediator().Send(query);
if (result.Succeeded)
{
IsFileRejected = false;
using (var memoryStream = new MemoryStream())
{
await result.Data!.FileStream.CopyToAsync(memoryStream);
var bytes = memoryStream.ToArray();
fileBase64 = Convert.ToBase64String(bytes);
}
extension = result.Data!.FileExtension;
}
else
{
IsFileRejected = true;
}
}
}
}
3 changes: 3 additions & 0 deletions src/Server.UI/Pages/Participants/Participant.razor
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@
<MudTabPanel Text="Bio">
<CaseBio ParticipantId="@Id" />
</MudTabPanel>
<MudTabPanel Text="Documents">
<CaseDocuments ParticipantId="@Id" />
</MudTabPanel>
<MudTabPanel Text="Pathway Plan">
<CasePathwayPlan ParticipantId="@Id" OnUpdate="Refresh" />
</MudTabPanel>
Expand Down

0 comments on commit d45099b

Please sign in to comment.