Skip to content

Commit

Permalink
Merge pull request #684 from bcgov/659-fertigation-validation
Browse files Browse the repository at this point in the history
[FEAT][NMP-659] Added validation for fertigation modal
  • Loading branch information
acatchpole authored Aug 29, 2024
2 parents ca860af + 43ff471 commit a309f08
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 28 deletions.
23 changes: 19 additions & 4 deletions app/Server/src/SERVERAPI/Controllers/NutrientsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,21 @@ public IActionResult FertigationDetails(FertigationDetailsViewModel fgvm)

try
{
if (fgvm.buttonPressed == "Calculate")
{
if (!ModelState.IsValid)
{
FertigationDetailsSetup(ref fgvm);
return PartialView(fgvm);
}

// Calculation logic will be implemented here by Adam and the t
// As of now, clear the model state until that ticket is implemented
ModelState.Clear();
fgvm.btnText = "Add to Field";
FertigationDetailsSetup(ref fgvm); // go back to the setup, somewhat recursive
return PartialView(fgvm);
}
if (fgvm.buttonPressed == "ResetDensity")
{
ModelState.Clear();
Expand Down Expand Up @@ -639,7 +654,7 @@ public IActionResult FertigationDetails(FertigationDetailsViewModel fgvm)
{
if (!ft.Custom)
{
if (fgvm.density != _sd.GetLiquidFertilizerDensity(fgvm.selFertOption, fgvm.selDensityUnitOption).Value.ToString("#.##"))
if (fgvm.density != _sd.GetLiquidFertilizerDensity(fgvm.selFertOption ?? 0, fgvm.selDensityUnitOption ?? 0).Value.ToString("#.##"))
{
fgvm.stdDensity = false;
}
Expand All @@ -650,7 +665,7 @@ public IActionResult FertigationDetails(FertigationDetailsViewModel fgvm)
}
}

var fertilizerNutrients = _calculateFertilizerNutrients.GetFertilizerNutrients(fgvm.selFertOption,
var fertilizerNutrients = _calculateFertilizerNutrients.GetFertilizerNutrients(fgvm.selFertOption ?? 0,
fgvm.fertilizerType,
Convert.ToDecimal(fgvm.productRate),
Convert.ToInt32(fgvm.selProductRateUnitOption),
Expand Down Expand Up @@ -743,7 +758,7 @@ private int FertigationInsert(FertigationDetailsViewModel fgvm)
NutrientFertilizer nf = new NutrientFertilizer()
{
fertilizerTypeId = Convert.ToInt32(fgvm.selTypOption),
fertilizerId = fgvm.selFertOption,
fertilizerId = fgvm.selFertOption ?? 0,
applUnitId = Convert.ToInt32(fgvm.selProductRateUnitOption),
applRate = Convert.ToDecimal(fgvm.productRate),
applDate = string.IsNullOrEmpty(fgvm.applDate) ? (DateTime?)null : Convert.ToDateTime(fgvm.applDate),
Expand All @@ -764,7 +779,7 @@ private void FertigationUpdate(FertigationDetailsViewModel fgvm)
{
NutrientFertilizer nf = _ud.GetFieldNutrientsFertilizer(fgvm.fieldName, fgvm.id.Value);
nf.fertilizerTypeId = Convert.ToInt32(fgvm.selTypOption);
nf.fertilizerId = fgvm.selFertOption;
nf.fertilizerId = fgvm.selFertOption ?? 0;
nf.applUnitId = Convert.ToInt32(fgvm.selProductRateUnitOption);
nf.applRate = Convert.ToDecimal(fgvm.productRate);
nf.applDate = string.IsNullOrEmpty(fgvm.applDate) ? (DateTime?)null : Convert.ToDateTime(fgvm.applDate);
Expand Down
31 changes: 29 additions & 2 deletions app/Server/src/SERVERAPI/ViewModels/FertigationDetailsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,71 @@ public class FertigationDetailsViewModel
public string cropName { get; set; }
public string buttonPressed { get; set; }
public string fieldArea { get; set; }

//fetilizer type
[Required(ErrorMessage = "Required")]
[Range(1, 9999, ErrorMessage = "Required")]
public string selTypOption { get; set; } // the selected fertilizer type
public int selFertOption { get; set; } // the selected
[Required(ErrorMessage = "Required")]
public int? selFertOption { get; set; } // the selected
public string fertilizerType { get; set; }
public string currUnit { get; set; }
public List<SelectListItem> typOptions { get; set; }
public List<SelectListItem> fertilizers { get; set; }

//fertilizer
public List<SelectListItem> FertigationList { get; set; }
[Required(ErrorMessage = "Required")]
[Range(1, 9999, ErrorMessage = "Required")]
public List<SelectListItem> fertOptions { get; set; }

//product rate
[Required(ErrorMessage = "Required")]
[Range(1, 9999, ErrorMessage = "Required")]
public string selProductRateUnitOption { get; set; }
public string selProductRateUnitOptionText { get; set; }
public List<SelectListItem> productRateUnitOptions { get; set; }
[Required(ErrorMessage = "Required")]
[Range(1, 9999, ErrorMessage = "Required")]
public string productRate { get; set; }

//density
//density unit
public int selDensityUnitOption { get; set; }
[Required(ErrorMessage = "Required")]
[Range(1, 9999, ErrorMessage = "Required")]
public int? selDensityUnitOption { get; set; }
public List<SelectListItem> densityUnitOptions { get; set; }
[Required(ErrorMessage = "Required")]
[Range(1, 9999, ErrorMessage = "Required")]
public string density { get; set; }
public bool stdDensity { get; set; }

//injection rate
//injection unit
[Required(ErrorMessage = "Required")]
[Range(1, 9999, ErrorMessage = "Required")]
public string injectionRate { get; set; }
[Required(ErrorMessage = "Required")]
public string selInjectionRateUnitOption { get; set; }
[Required(ErrorMessage = "Required")]
public string selInjectionRateUnitOptionText { get; set; }
public List<SelectListItem> injectionRateUnitOptions { get; set; }

//#of fertigations per season
[Required(ErrorMessage = "Required")]
[Range(1, 9999, ErrorMessage = "Required")]
public int eventsPerSeason { get; set; }

//fertigation scheduling
[Required(ErrorMessage = "Required")]
public string selFertSchedOption { get; set; }
[Required(ErrorMessage = "Required")]
[Range(1, 9999, ErrorMessage = "Required")]
public int selApplPeriod { get; set; }
public List<SelectListItem> applPeriod { get; set; }

//start date
[Required(ErrorMessage = "Required")]
public string applDate { get; set; }
public bool manualEntry { get; set; }
//calculated
Expand Down
50 changes: 28 additions & 22 deletions app/Server/src/SERVERAPI/Views/Nutrients/FertigationDetails.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,23 @@
<h4 class="title" style="margin-bottom: 15px;">Provide Product Details</h4>
<div class="form-group col-sm-3" style="width:150px;">
<label for="ddlTyp">Fertilizer Type</label>
<select class="form-control" asp-for="selTypOption" asp-items="@(new SelectList(Model.typOptions,"Id","Value"))" id="ddlTyp">
<option>select</option>
</select>
<span asp-validation-for="selTypOption" class="text-danger"></span>
<select class="form-control" asp-for="selTypOption" asp-items="@(new SelectList(Model.typOptions,"Id","Value"))" id="ddlTyp">
<option value="">select</option>
</select>
<span asp-validation-for="selTypOption" class="text-danger"></span>
</div>
<div class="form-group col-sm-3" style="width:150px;">
<label for="ddlFert">Fertilizer</label>
<select class="form-control" asp-for="selFertOption" asp-items="@(new SelectList(Model.fertOptions,"Id","Value"))" id="ddlFert">
<option>select</option>
</select>
<select class="form-control" asp-for="selFertOption" asp-items="@(new SelectList(Model.fertOptions,"Id","Value"))" id="ddlFert">
<option value="">select</option>
</select>
<span asp-validation-for="selFertOption" class="text-danger"></span>
</div>
<div class="form-group col-sm-2" style="margin-right:0px; padding-right:0px; width:100px">
<label for="rate">Product Rate</label>
<div>
<input class="form-control" asp-for="productRate" id="rate" type="text" />
<span asp-validation-for="productRate" class="text-danger"></span>
</div>
</div>
<div class="form-group col-sm-2" style="margin-left:0px;padding-left:0px">
Expand All @@ -42,25 +43,26 @@
<select class="form-control" asp-for="selProductRateUnitOption" asp-items="@(new SelectList(Model.productRateUnitOptions,"Id","Value"))" id="ddlProdRate">
<option>select</option>
</select>
<span asp-validation-for="selProductRateUnitOption" class="text-danger"></span>
</div>
<div style="display:table-row"></div>
</div>
</div>
<div class="form-group col-sm-2" style="margin-right:0px; padding-right:0px; width:100px">
<label for="rate">Density</label>
<label for="density">Density</label>
<div>
<input class="form-control" asp-for="density" id="rate" type="text" />
<input class="form-control" asp-for="density" id="density" type="text" />
<span asp-validation-for="density" class="text-danger"></span>
</div>
</div>
<div class="form-group col-sm-2" style="margin-left:0px;padding-left:0px; width:100px">
<div style="display:table; width:100%">
<div style="display:table-row">
<label for="ddlDensity" style="text-align: center; display: block;">Units</label>
<select class="form-control" asp-for="selDensityUnitOption" asp-items="@(new SelectList(Model.densityUnitOptions,"Id","Value"))" id="ddlDensity">
<option>select</option>
<option value="">select</option>
</select>
<span asp-validation-for="selDensityUnitOption" class="text-danger"></span>
</div>
<div style="display:table-row"></div>
</div>
</div>
</div>
Expand All @@ -72,30 +74,34 @@
<div class="form-group">
<h4 class="title" style="margin-bottom: 15px;">Provide Application Details</h4>
<div class="form-group col-sm-2" style="margin-right:0px; padding-right:0px; width:100px">
<label for="rate">Injection Rate</label>
<label for="injectionRate">Injection Rate</label>
<div>
<input class="form-control" asp-for="injectionRate" id="rate" type="text" />
<input class="form-control" asp-for="injectionRate" id="injectionRate" type="text" />
<span asp-validation-for="injectionRate" class="text-danger"></span>
</div>
</div>
<div class="form-group col-sm-2" style="margin-left:0px; padding-left:0px">
<div style="display:table; width:100%">
<label for="ddlInjRate" style="text-align: center; display: block;">Units</label>
<select class="form-control" asp-for="selInjectionRateUnitOption" asp-items="@(new SelectList(Model.injectionRateUnitOptions,"Id","Value"))" id="ddlInjRate">
<option>select</option>
</select>
<label for="ddlInjRate" style="text-align: center; display: block;">Units</label>
<select class="form-control" asp-for="selInjectionRateUnitOption" asp-items="@(new SelectList(Model.injectionRateUnitOptions,"Id","Value"))" id="ddlInjRate">
<option value="">select</option>
</select>
<span asp-validation-for="selInjectionRateUnitOption" class="text-danger"></span>
</div>
</div>
<div class="form-group col-sm-4">
<label for="rate">Proposed Number of Fertigation Per Season</label>
<label for="eventsPerSeason">Proposed Number of Fertigation Per Season</label>
<div>
<input class="form-control" id="eventsPerSeason" type="text" asp-for="eventsPerSeason" style="width:100px" />
<span asp-validation-for="eventsPerSeason" class="text-danger"></span>
</div>
</div>
<div class="form-group col-sm-3">
<label for="ddlMan">Fertigation Scheduling</label>
<select class="form-control" id="ddlMan" style="width:100%">
<option>select</option>
<select class="form-control" id="ddlMan" style="width:100%" asp-for="selFertSchedOption">
<option value="">select</option>
</select>
<span asp-validation-for="selFertSchedOption" class="text-danger"></span>
<div class="mt-2">
<div class="input-group">
<input class="form-control" asp-for="applDate" id="applDate" type="date" style="width:100%" />
Expand All @@ -108,7 +114,7 @@
<div style="clear:both"></div>
<div class="row" style="padding-bottom: 15px; text-align: right">
<button class="btn" type="button" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary" id="calc_button" style="margin-left: 5px">Calculate</button>
<button type="submit" class="btn btn-primary" id="calc_button" name="buttonPressed" value="Calculate" style="margin-left: 5px">Calculate</button>
</div>


Expand Down

0 comments on commit a309f08

Please sign in to comment.