202 lines
7.7 KiB
Plaintext
202 lines
7.7 KiB
Plaintext
@inject MesaFabApprovalAuthStateProvider authStateProvider
|
|
@inject NavigationManager navigationManager
|
|
@inject IPCRBService pcrbService
|
|
@inject IUserService userService
|
|
@inject ISnackbar snackbar
|
|
|
|
<MudDialog>
|
|
<DialogContent>
|
|
<MudPaper Class="m-2 p-2">
|
|
<MudForm @bind-Errors="@errors">
|
|
<MudTextField T="string"
|
|
Label="Action"
|
|
Required
|
|
RequiredError="Enter action item"
|
|
@bind-Value="@name"
|
|
@bind-Text="@name"
|
|
Immediate
|
|
Clearable
|
|
AutoGrow
|
|
AutoFocus />
|
|
<MudCheckBox Label="Gating"
|
|
Color="Color.Tertiary"
|
|
@bind-Value=gating
|
|
LabelPosition="LabelPosition.Start" />
|
|
<MudCheckBox Label="Closed"
|
|
Color="Color.Tertiary"
|
|
@bind-Value="@closedStatus"
|
|
LabelPosition="LabelPosition.Start" />
|
|
@if (closedStatus) {
|
|
<MudDatePicker Label="Closed Date"
|
|
Color="Color.Tertiary"
|
|
@bind-Date="@closedDate"
|
|
Clearable
|
|
MinDate="@DateTimeUtilities.MIN_DT"
|
|
MaxDate="@DateTimeUtilities.MAX_DT"
|
|
Placeholder="Select a closed date" />
|
|
}
|
|
<MudSelect T="User"
|
|
Label="Responsible Person"
|
|
Variant="Variant.Outlined"
|
|
Required
|
|
RequiredError="You must select a responsible person"
|
|
Clearable
|
|
AnchorOrigin="Origin.BottomCenter"
|
|
ToStringFunc="@UserToNameConverter"
|
|
@bind-Value=@responsiblePerson>
|
|
@foreach (User user in allActiveUsers.OrderBy(u => u.FirstName)) {
|
|
<MudSelectItem T="User" Value="@(user)" />
|
|
}
|
|
</MudSelect>
|
|
</MudForm>
|
|
</MudPaper>
|
|
</DialogContent>
|
|
<DialogActions>
|
|
<MudButton Variant="Variant.Filled"
|
|
Color="Color.Tertiary"
|
|
Class="m1-auto"
|
|
OnClick=Save>
|
|
@if (saveActionItemInProcess) {
|
|
<MudProgressCircular Class="m-1" Size="Size.Small" Indeterminate="true" />
|
|
<MudText>Processing</MudText>
|
|
} else {
|
|
<MudText>Submit</MudText>
|
|
}
|
|
</MudButton>
|
|
<MudButton Variant="Variant.Filled"
|
|
Class="grey text-black m1-auto"
|
|
OnClick=Cancel>
|
|
Cancel
|
|
</MudButton>
|
|
</DialogActions>
|
|
</MudDialog>
|
|
|
|
@code {
|
|
[CascadingParameter]
|
|
MudDialogInstance MudDialog { get; set; }
|
|
|
|
[Parameter]
|
|
public int planNumber { get; set; } = 0;
|
|
|
|
[Parameter]
|
|
public int step { get; set; } = 0;
|
|
|
|
[Parameter]
|
|
public PCRBActionItem? actionItem { get; set; } = null;
|
|
|
|
[Parameter]
|
|
public IEnumerable<User> allActiveUsers { get; set; }
|
|
|
|
private string[] errors = { };
|
|
|
|
private string name = "";
|
|
private bool gating = false;
|
|
private DateTime? closedDate = DateTimeUtilities.MAX_DT;
|
|
private bool closedStatus = false;
|
|
private User? responsiblePerson = null;
|
|
|
|
private bool saveActionItemInProcess = false;
|
|
|
|
protected override async Task OnParametersSetAsync() {
|
|
if (authStateProvider.CurrentUser is null) {
|
|
await authStateProvider.Logout();
|
|
navigationManager.NavigateTo("login");
|
|
}
|
|
|
|
if (planNumber <= 0) {
|
|
snackbar.Add($"{planNumber} is not a valid PCRB plan#", Severity.Error);
|
|
MudDialog.Close(DialogResult.Cancel());
|
|
}
|
|
|
|
if (allActiveUsers is null || allActiveUsers.Count() <= 0)
|
|
allActiveUsers = await userService.GetAllActiveUsers();
|
|
|
|
if (actionItem is not null) {
|
|
name = actionItem.Name;
|
|
gating = actionItem.Gating;
|
|
closedStatus = actionItem.ClosedStatus;
|
|
closedDate = actionItem.ClosedDate;
|
|
if (closedDate.Equals(DateTimeUtilities.MAX_DT)) {
|
|
closedDate = DateTime.Now;
|
|
}
|
|
if (actionItem.ResponsiblePersonID > 0) {
|
|
if (actionItem.ResponsiblePerson is not null) responsiblePerson = actionItem.ResponsiblePerson;
|
|
else responsiblePerson = await userService.GetUserByUserId(actionItem.ResponsiblePersonID);
|
|
actionItem.ResponsiblePerson = responsiblePerson;
|
|
}
|
|
} else {
|
|
name = "";
|
|
gating = false;
|
|
closedStatus = false;
|
|
closedDate = DateTime.Now;
|
|
responsiblePerson = null;
|
|
}
|
|
}
|
|
|
|
private async Task Save() {
|
|
saveActionItemInProcess = true;
|
|
try {
|
|
if (authStateProvider.CurrentUser is null) {
|
|
await authStateProvider.Logout();
|
|
navigationManager.NavigateTo("login");
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(name)) throw new Exception("name missing");
|
|
|
|
if (actionItem is null) {
|
|
actionItem = new() {
|
|
Name = name,
|
|
UploadedBy = authStateProvider.CurrentUser,
|
|
UploadedByID = authStateProvider.CurrentUser.UserID,
|
|
PlanNumber = planNumber,
|
|
Step = step,
|
|
Gating = gating,
|
|
ClosedStatus = closedStatus,
|
|
ResponsiblePerson = responsiblePerson,
|
|
ResponsiblePersonID = responsiblePerson.UserID,
|
|
ClosedDate = closedDate,
|
|
ClosedBy = closedDate is null || closedDate >= DateTimeUtilities.MAX_DT ? null : authStateProvider.CurrentUser,
|
|
ClosedByID = closedStatus ? authStateProvider.CurrentUser.UserID : 0
|
|
};
|
|
|
|
if (actionItem.ClosedStatus == false) {
|
|
actionItem.ClosedDate = DateTimeUtilities.MAX_DT;
|
|
}
|
|
|
|
await pcrbService.CreateNewActionItem(actionItem);
|
|
} else {
|
|
actionItem.Name = name;
|
|
actionItem.Gating = gating;
|
|
actionItem.ClosedStatus = closedStatus;
|
|
actionItem.ClosedDate = closedDate;
|
|
if (closedStatus) {
|
|
actionItem.ClosedBy = authStateProvider.CurrentUser;
|
|
actionItem.ClosedByID = authStateProvider.CurrentUser.UserID;
|
|
} else {
|
|
actionItem.ClosedDate = DateTimeUtilities.MAX_DT;
|
|
}
|
|
actionItem.ResponsiblePerson = responsiblePerson;
|
|
if (responsiblePerson is not null)
|
|
actionItem.ResponsiblePersonID = responsiblePerson.UserID;
|
|
|
|
await pcrbService.UpdateActionItem(actionItem);
|
|
}
|
|
|
|
saveActionItemInProcess = false;
|
|
|
|
MudDialog.Close(DialogResult.Ok(actionItem));
|
|
} catch (Exception ex) {
|
|
saveActionItemInProcess = false;
|
|
snackbar.Add($"Unable to save action item, because {ex.Message}", Severity.Error);
|
|
}
|
|
}
|
|
|
|
private void Cancel() {
|
|
MudDialog.Close(DialogResult.Cancel());
|
|
}
|
|
|
|
private Func<User, string> UserToNameConverter = u => u is null ? string.Empty : u.GetFullName();
|
|
|
|
private Func<PCRBAttachment, string> AttachmentToFileNameConverter = a => a is null ? "" : a.FileName;
|
|
}
|