-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Documents tab on participant dashboard, it lists all the docume…
…nts assciated with the case. From the list, user can open and view each documents
- Loading branch information
1 parent
24a47c3
commit d45099b
Showing
5 changed files
with
241 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/Application/Features/Documents/Queries/GetByParticipantId.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
102
src/Server.UI/Pages/Participants/Components/CaseDocuments.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
src/Server.UI/Pages/Participants/Components/ViewDocumentDialog.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters