From 8dfee0fd12a9f147e7bb951a4dcb73cacb233e72 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GENO133\\IvanPlex" Date: Sun, 18 Feb 2024 14:20:20 -0700 Subject: [PATCH] added ability to create plans from reminders. --- Controllers/VehicleController.cs | 29 +++++++++++++++++++ Models/PlanRecord/PlanCostItem.cs | 8 ----- Models/PlanRecord/PlanRecord.cs | 1 + Models/PlanRecord/PlanRecordInput.cs | 6 ++++ Views/Vehicle/_PlanRecordItem.cshtml | 10 +++++-- Views/Vehicle/_PlanRecordModal.cshtml | 9 ++++-- Views/Vehicle/_PlanRecordTemplateModal.cshtml | 4 +++ Views/Vehicle/_ReminderRecordModal.cshtml | 4 +++ Views/Vehicle/_ReminderRecords.cshtml | 6 ++++ wwwroot/js/planrecord.js | 21 +++++++++----- wwwroot/js/reminderrecord.js | 22 ++++++++++++++ 11 files changed, 100 insertions(+), 20 deletions(-) delete mode 100644 Models/PlanRecord/PlanCostItem.cs diff --git a/Controllers/VehicleController.cs b/Controllers/VehicleController.cs index 193d5cc..1e80098 100644 --- a/Controllers/VehicleController.cs +++ b/Controllers/VehicleController.cs @@ -1757,6 +1757,16 @@ namespace CarCareTracker.Controllers return PartialView("_PlanRecordModal", new PlanRecordInput() { ExtraFields = _extraFieldDataAccess.GetExtraFieldsById((int)ImportMode.PlanRecord).ExtraFields }); } [HttpPost] + public IActionResult GetAddPlanRecordPartialView(PlanRecordInput? planModel) + { + if (planModel is not null) + { + planModel.ExtraFields = _extraFieldDataAccess.GetExtraFieldsById((int)ImportMode.PlanRecord).ExtraFields; + return PartialView("_PlanRecordModal", planModel); + } + return PartialView("_PlanRecordModal", new PlanRecordInput() { ExtraFields = _extraFieldDataAccess.GetExtraFieldsById((int)ImportMode.PlanRecord).ExtraFields }); + } + [HttpPost] public IActionResult UpdatePlanRecordProgress(int planRecordId, PlanProgress planProgress, int odometer = 0) { var existingRecord = _planRecordDataAccess.GetPlanRecordById(planRecordId); @@ -1825,6 +1835,24 @@ namespace CarCareTracker.Controllers }; _upgradeRecordDataAccess.SaveUpgradeRecordToVehicle(newRecord); } + //push back any reminders + if (existingRecord.ReminderRecordId != default) + { + var existingReminder = _reminderRecordDataAccess.GetReminderRecordById(existingRecord.ReminderRecordId); + if (existingReminder is not null && existingReminder.Id != default) + { + existingReminder = _reminderHelper.GetUpdatedRecurringReminderRecord(existingReminder); + //save to db. + var reminderUpdateResult = _reminderRecordDataAccess.SaveReminderRecordToVehicle(existingReminder); + if (!reminderUpdateResult) + { + _logger.LogError("Unable to update reminder"); + } + } else + { + _logger.LogError("Unable to update reminder because it no longer exists."); + } + } } return Json(result); } @@ -1847,6 +1875,7 @@ namespace CarCareTracker.Controllers VehicleId = result.VehicleId, Files = result.Files, RequisitionHistory = result.RequisitionHistory, + ReminderRecordId = result.ReminderRecordId, ExtraFields = StaticHelper.AddExtraFields(result.ExtraFields, _extraFieldDataAccess.GetExtraFieldsById((int)ImportMode.PlanRecord).ExtraFields) }; return PartialView("_PlanRecordModal", convertedResult); diff --git a/Models/PlanRecord/PlanCostItem.cs b/Models/PlanRecord/PlanCostItem.cs deleted file mode 100644 index 37bafa7..0000000 --- a/Models/PlanRecord/PlanCostItem.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace CarCareTracker.Models -{ - public class PlanCostItem - { - public string CostName { get; set; } - public decimal CostAmount { get; set; } - } -} diff --git a/Models/PlanRecord/PlanRecord.cs b/Models/PlanRecord/PlanRecord.cs index a5a72a5..83bad98 100644 --- a/Models/PlanRecord/PlanRecord.cs +++ b/Models/PlanRecord/PlanRecord.cs @@ -4,6 +4,7 @@ { public int Id { get; set; } public int VehicleId { get; set; } + public int ReminderRecordId { get; set; } public DateTime DateCreated { get; set; } public DateTime DateModified { get; set; } public string Description { get; set; } diff --git a/Models/PlanRecord/PlanRecordInput.cs b/Models/PlanRecord/PlanRecordInput.cs index d18a707..801bd6f 100644 --- a/Models/PlanRecord/PlanRecordInput.cs +++ b/Models/PlanRecord/PlanRecordInput.cs @@ -4,6 +4,7 @@ { public int Id { get; set; } public int VehicleId { get; set; } + public int ReminderRecordId { get; set; } public string DateCreated { get; set; } = DateTime.Now.ToShortDateString(); public string DateModified { get; set; } = DateTime.Now.ToShortDateString(); public string Description { get; set; } @@ -19,6 +20,7 @@ public PlanRecord ToPlanRecord() { return new PlanRecord { Id = Id, VehicleId = VehicleId, + ReminderRecordId = ReminderRecordId, DateCreated = DateTime.Parse(DateCreated), DateModified = DateTime.Parse(DateModified), Description = Description, @@ -31,5 +33,9 @@ ExtraFields = ExtraFields, RequisitionHistory = RequisitionHistory }; } + /// + /// only used to hide view template button on plan create modal. + /// + public bool CreatedFromReminder { get; set; } } } diff --git a/Views/Vehicle/_PlanRecordItem.cshtml b/Views/Vehicle/_PlanRecordItem.cshtml index 2e11902..21cff13 100644 --- a/Views/Vehicle/_PlanRecordItem.cshtml +++ b/Views/Vehicle/_PlanRecordItem.cshtml @@ -16,7 +16,13 @@
-
+ @if (Model.ReminderRecordId != default) + { +
+ +
+ } +
@if (Model.ImportMode == ImportMode.ServiceRecord) { @@ -30,7 +36,7 @@ }
-
+
@if (Model.Priority == PlanPriority.Critical) { diff --git a/Views/Vehicle/_PlanRecordModal.cshtml b/Views/Vehicle/_PlanRecordModal.cshtml index 83d93c8..ff84f38 100644 --- a/Views/Vehicle/_PlanRecordModal.cshtml +++ b/Views/Vehicle/_PlanRecordModal.cshtml @@ -101,7 +101,10 @@
} @@ -124,7 +127,9 @@ function getPlanRecordModelData() { return { id: @Model.Id, - dateCreated: decodeHTMLEntities('@(Model.DateCreated)') + dateCreated: decodeHTMLEntities('@(Model.DateCreated)'), + reminderRecordId: decodeHTMLEntities('@Model.ReminderRecordId'), + createdFromReminder: @Model.CreatedFromReminder.ToString().ToLower() } } \ No newline at end of file diff --git a/Views/Vehicle/_PlanRecordTemplateModal.cshtml b/Views/Vehicle/_PlanRecordTemplateModal.cshtml index 198e17d..600639f 100644 --- a/Views/Vehicle/_PlanRecordTemplateModal.cshtml +++ b/Views/Vehicle/_PlanRecordTemplateModal.cshtml @@ -29,6 +29,10 @@ @StaticHelper.TruncateStrings(planRecordTemplate.Description) + @if(planRecordTemplate.ReminderRecordId != default) + { + + } @if (planRecordTemplate.Files.Any()) { diff --git a/Views/Vehicle/_ReminderRecordModal.cshtml b/Views/Vehicle/_ReminderRecordModal.cshtml index 053e3b1..c55b2ca 100644 --- a/Views/Vehicle/_ReminderRecordModal.cshtml +++ b/Views/Vehicle/_ReminderRecordModal.cshtml @@ -90,6 +90,10 @@ +
+ \ No newline at end of file diff --git a/wwwroot/js/planrecord.js b/wwwroot/js/planrecord.js index 555e821..838ab75 100644 --- a/wwwroot/js/planrecord.js +++ b/wwwroot/js/planrecord.js @@ -25,6 +25,10 @@ function showEditPlanRecordModal(planRecordId) { } function hideAddPlanRecordModal() { $('#planRecordModal').modal('hide'); + if (getPlanRecordModelData().createdFromReminder) { + //show reminder Modal + $("#reminderRecordModal").modal("show"); + } } function deletePlanRecord(planRecordId) { $("#workAroundInput").show(); @@ -64,10 +68,12 @@ function savePlanRecordToVehicle(isEdit) { if (data) { successToast(isEdit ? "Plan Record Updated" : "Plan Record Added."); hideAddPlanRecordModal(); - saveScrollPosition(); - getVehiclePlanRecords(formValues.vehicleId); - if (formValues.addReminderRecord) { - setTimeout(function () { showAddReminderModal(formValues); }, 500); + if (!getPlanRecordModelData().createdFromReminder) { + saveScrollPosition(); + getVehiclePlanRecords(formValues.vehicleId); + if (formValues.addReminderRecord) { + setTimeout(function () { showAddReminderModal(formValues); }, 500); + } } } else { errorToast(genericErrorMessage()); @@ -139,9 +145,6 @@ function savePlanRecordTemplate() { $.post('/Vehicle/SavePlanRecordTemplateToVehicleId', { planRecord: formValues }, function (data) { if (data.success) { successToast(data.message); - hideAddPlanRecordModal(); - saveScrollPosition(); - getVehiclePlanRecords(formValues.vehicleId); } else { errorToast(data.message); } @@ -157,6 +160,7 @@ function getAndValidatePlanRecordValues() { var planDateCreated = getPlanRecordModelData().dateCreated; var vehicleId = GetVehicleId().vehicleId; var planRecordId = getPlanRecordModelData().id; + var reminderRecordId = getPlanRecordModelData().reminderRecordId; //validation var hasError = false; var extraFields = getAndValidateExtraFields(); @@ -189,7 +193,8 @@ function getAndValidatePlanRecordValues() { progress: planProgress, importMode: planType, extraFields: extraFields.extraFields, - requisitionHistory: supplyUsageHistory + requisitionHistory: supplyUsageHistory, + reminderRecordId: reminderRecordId } } //drag and drop stuff. diff --git a/wwwroot/js/reminderrecord.js b/wwwroot/js/reminderrecord.js index f6edf6a..5159b39 100644 --- a/wwwroot/js/reminderrecord.js +++ b/wwwroot/js/reminderrecord.js @@ -217,4 +217,26 @@ function getAndValidateReminderRecordValues() { customMileageInterval: customMileageInterval, customMonthInterval: customMonthInterval } +} +function createPlanRecordFromReminder(reminderRecordId) { + //get values + var formValues = getAndValidateReminderRecordValues(); + //validate + if (formValues.hasError) { + errorToast("Please check the form data"); + return; + } + var planModelInput = { + id: 0, + createdFromReminder: true, + vehicleId: formValues.vehicleId, + reminderRecordId: reminderRecordId, + description: formValues.description, + notes: formValues.notes + }; + $.post('/Vehicle/GetAddPlanRecordPartialView', { planModel: planModelInput }, function (data) { + $("#reminderRecordModal").modal("hide"); + $("#planRecordModalContent").html(data); + $("#planRecordModal").modal("show"); + }); } \ No newline at end of file