Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C2T UI #207

Merged
merged 43 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
f710c0e
Creating C2T form
Oddvocado Oct 7, 2024
f35aacb
Typo fix
Oddvocado Oct 8, 2024
5767b75
Adds section 10
Oddvocado Oct 8, 2024
06debc9
Adds remaining questions
Oddvocado Oct 8, 2024
c000d9e
Validation for section 10
Oddvocado Oct 8, 2024
10dfc52
radio button and validation update
Oddvocado Oct 9, 2024
95f8252
Adds turbo
Oddvocado Oct 9, 2024
d292eb6
Add dropdowns to beginning of form
Oddvocado Oct 9, 2024
36c4adb
Add dynamic change on modality
Oddvocado Oct 11, 2024
2206402
progress commit
Oddvocado Oct 16, 2024
4d15178
displays unobtrusive validation on dynamic form change
Oddvocado Oct 17, 2024
3ea4849
Add turbo stream to display validation errors
Oddvocado Oct 21, 2024
a3e831e
Remove turbo cdn from layout
Oddvocado Oct 22, 2024
2598138
Remove Mode and RMMode inputs on partial
Oddvocado Oct 22, 2024
5a15b07
Adjusts data annotations
Oddvocado Oct 22, 2024
8389fab
Adds javascript file and updates stimulus
Oddvocado Oct 23, 2024
b3f26c2
Fix for small js bug
Oddvocado Oct 23, 2024
85febf1
Merge branch 'main' into C2T-UI
Oddvocado Oct 23, 2024
c2064ed
Update views and js
Oddvocado Oct 24, 2024
204d2c2
Making the linter happy?
Oddvocado Oct 24, 2024
a9e0f3b
Linter round 2
Oddvocado Oct 24, 2024
c3f1ca3
remove script tags in partials
Oddvocado Oct 24, 2024
f161e50
correct enum dropdown
Oddvocado Oct 28, 2024
9fc8a22
add custom jquery validation to partials
Oddvocado Oct 29, 2024
c03d14e
Add data annotation for telephone/in-person
Oddvocado Oct 29, 2024
328e43b
Update validation
Oddvocado Oct 29, 2024
0b8a2df
Merge branch 'main' into C2T-UI
Oddvocado Oct 29, 2024
104750a
remove rmmode label on C2
Oddvocado Oct 30, 2024
c34eedb
Add/maps missing properties
Oddvocado Oct 30, 2024
f0855e8
Using rowCSS variable in views
Oddvocado Oct 31, 2024
9a682f7
fix typo
Oddvocado Oct 31, 2024
ffe2415
cleaning things up
Oddvocado Oct 31, 2024
bda5631
adds tailwind border around section headers
Oddvocado Oct 31, 2024
304daa4
additional tailwind styling
Oddvocado Oct 31, 2024
e0adf07
Add info alert to top of page
Oddvocado Oct 31, 2024
2663e59
Additional validation
Oddvocado Oct 31, 2024
e696d4e
Merge branch 'main' into C2T-UI
ashleybot Nov 6, 2024
eb371c9
Merge branch 'main' into C2T-UI
ashleybot Nov 6, 2024
2cf161c
Turn off Turbo for participation create
ashleybot Nov 6, 2024
15fccfb
Formatted instructions
ashleybot Nov 6, 2024
ca27c11
Fixes MOCATOS validation
ashleybot Nov 6, 2024
c519a06
Update dependencies
Oddvocado Nov 7, 2024
ea222ef
Bump version number
Oddvocado Nov 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UDS.Net.Forms.Models;
using UDS.Net.Services.Enums;

namespace UDS.Net.Forms.DataAnnotations
{
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class RequiredIfInPersonVisitAttribute : ValidationAttribute, IClientModelValidator
{
private string _watchedField = "";
private string _watchedFieldValue = "";

public RequiredIfInPersonVisitAttribute(string watchedField, string value) : base()
{
_watchedField = watchedField;
_watchedFieldValue = value;
}
protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
{
// does the form have a status and is it attempting to be finalized?
if (validationContext.ObjectType.IsSubclassOf(typeof(FormModel)))
{
var form = (FormModel)validationContext.ObjectInstance;

// only validate if the form is attempting to be completed
if (form.Status == FormStatus.Finalized)

if (form.MODE == FormMode.InPerson || form.RMMODE == RemoteModality.Video)
{
// get the watched property and compare
var type = validationContext.ObjectType;

if (type != null)
{
var watchedProperty = type.GetProperty(_watchedField);

if (watchedProperty != null)
{
var currentValue = watchedProperty.GetValue(validationContext.ObjectInstance, null);
if (currentValue != null)
{
if (currentValue.ToString() == _watchedFieldValue)
{
// if the watched field's value matches what we're looking for then this field requires a value
if (value == null)
return new ValidationResult(this.ErrorMessage);
}
}
}
}
}
}


return ValidationResult.Success;
}

public void AddValidation(ClientModelValidationContext context)
{
MergeAttribute(context.Attributes, "data-val", "true");
MergeAttribute(context.Attributes, "data-val-requiredif", this.ErrorMessage);
string watched = _watchedField;
var containerName = context.ModelMetadata.ContainerType.Name;
if (!String.IsNullOrEmpty(containerName))
{
watched = containerName + "." + _watchedField;
}
MergeAttribute(context.Attributes, "data-val-requiredif-watchedfield", watched);
MergeAttribute(context.Attributes, "data-val-requiredif-watchedfieldvalue", _watchedFieldValue);
}

/// <summary>
/// See https://learn.microsoft.com/en-us/aspnet/core/mvc/models/validation?view=aspnetcore-7.0#iclientmodelvalidator-for-client-side-validation
/// </summary>
private static bool MergeAttribute(IDictionary<string, string> attributes, string key, string value)
{
if (attributes.ContainsKey(key))
{
return false;
}

attributes.Add(key, value);
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UDS.Net.Forms.Models;
using UDS.Net.Services.Enums;

namespace UDS.Net.Forms.DataAnnotations
{
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class RequiredIfTelephoneVisitAttribute : ValidationAttribute, IClientModelValidator
{
private string _watchedField = "";
private string _watchedFieldValue = "";

public RequiredIfTelephoneVisitAttribute(string watchedField, string value) : base()
{
_watchedField = watchedField;
_watchedFieldValue = value;
}
protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
{
// does the form have a status and is it attempting to be finalized?
if (validationContext.ObjectType.IsSubclassOf(typeof(FormModel)))
{
var form = (FormModel)validationContext.ObjectInstance;

// only validate if the form is attempting to be completed
if (form.Status == FormStatus.Finalized && form.RMMODE == RemoteModality.Telephone)
{
// get the watched property and compare
var type = validationContext.ObjectType;

if (type != null)
{
var watchedProperty = type.GetProperty(_watchedField);

if (watchedProperty != null)
{
var currentValue = watchedProperty.GetValue(validationContext.ObjectInstance, null);
if (currentValue != null)
{
if (currentValue.ToString() == _watchedFieldValue)
{
// if the watched field's value matches what we're looking for then this field requires a value
if (value == null)
return new ValidationResult(this.ErrorMessage);
}
}
}
}
}
}


return ValidationResult.Success;
}

public void AddValidation(ClientModelValidationContext context)
{
MergeAttribute(context.Attributes, "data-val", "true");
MergeAttribute(context.Attributes, "data-val-requiredif", this.ErrorMessage);
string watched = _watchedField;
var containerName = context.ModelMetadata.ContainerType.Name;
if (!String.IsNullOrEmpty(containerName))
{
watched = containerName + "." + _watchedField;
}
MergeAttribute(context.Attributes, "data-val-requiredif-watchedfield", watched);
MergeAttribute(context.Attributes, "data-val-requiredif-watchedfieldvalue", _watchedFieldValue);
}

/// <summary>
/// See https://learn.microsoft.com/en-us/aspnet/core/mvc/models/validation?view=aspnetcore-7.0#iclientmodelvalidator-for-client-side-validation
/// </summary>
private static bool MergeAttribute(IDictionary<string, string> attributes, string key, string value)
{
if (attributes.ContainsKey(key))
{
return false;
}

attributes.Add(key, value);
return true;
}
}
}
7 changes: 7 additions & 0 deletions src/UDS.Net.Forms/Extensions/DomainToViewModelMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,7 @@ public static C2 ToVM(this C2FormFields fields, int formId)
MOCAVIS = fields.MOCAVIS,
MOCAHEAR = fields.MOCAHEAR,
MOCATOTS = fields.MOCATOTS,
MOCBTOTS = fields.MOCBTOTS,
MOCATRAI = fields.MOCATRAI,
MOCACUBE = fields.MOCACUBE,
MOCACLOC = fields.MOCACLOC,
Expand Down Expand Up @@ -1354,6 +1355,12 @@ public static C2 ToVM(this C2FormFields fields, int formId)
CERADJ6INT = fields.CERADJ6INT,
CERADJ7YES = fields.CERADJ7YES,
CERADJ7NO = fields.CERADJ7NO,
OTRAILA = fields.OTRAILA,
OTRLARR = fields.OTRLARR,
OTRLALI = fields.OTRLALI,
OTRAILB = fields.OTRAILB,
OTRLBRR = fields.OTRLBRR,
OTRLBLI = fields.OTRLBLI,
VNTTOTW = fields.VNTTOTW,
VNTPCNC = fields.VNTPCNC,
RESPVAL = fields.RESPVAL,
Expand Down
7 changes: 7 additions & 0 deletions src/UDS.Net.Forms/Extensions/ViewModelToDomainMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@ public static IFormFields GetFormFields(this C2 vm)
MOCAVIS = vm.MOCAVIS,
MOCAHEAR = vm.MOCAHEAR,
MOCATOTS = vm.MOCATOTS,
MOCBTOTS = vm.MOCBTOTS,
MOCATRAI = vm.MOCATRAI,
MOCACUBE = vm.MOCACUBE,
MOCACLOC = vm.MOCACLOC,
Expand Down Expand Up @@ -1039,6 +1040,12 @@ public static IFormFields GetFormFields(this C2 vm)
CERADJ6INT = vm.CERADJ6INT,
CERADJ7YES = vm.CERADJ7YES,
CERADJ7NO = vm.CERADJ7NO,
OTRAILA = vm.OTRAILA,
OTRLARR = vm.OTRLARR,
OTRLALI = vm.OTRLALI,
OTRAILB = vm.OTRAILB,
OTRLBRR = vm.OTRLBRR,
OTRLBLI = vm.OTRLBLI,
VNTTOTW = vm.VNTTOTW,
VNTPCNC = vm.VNTPCNC,
RESPVAL = vm.RESPVAL,
Expand Down
20 changes: 20 additions & 0 deletions src/UDS.Net.Forms/Models/PageModels/FormPageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,26 @@ protected async Task<IActionResult> OnPostAsync(int id)

Visit = visit.ToVM();

if (BaseForm.Kind == "C2")
{
if (BaseForm != null)
{
var C2 = new C2Model(_visitService);

C2.Visit = Visit;
C2.BaseForm = BaseForm;
C2.C2 = (C2)BaseForm;

var form = visit.Forms.Where(f => f.Kind == _formKind).FirstOrDefault();

if (!ModelState.IsValid)
{
Response.ContentType = "text/vnd.turbo-stream.html";
return Partial("_C2Validation", C2);
}
};
}

return Page();
}

Expand Down
Loading