added ability to create plans from reminders.

This commit is contained in:
DESKTOP-GENO133\IvanPlex
2024-02-18 14:20:20 -07:00
parent 275b60aa14
commit 8dfee0fd12
11 changed files with 100 additions and 20 deletions

View File

@@ -1757,6 +1757,16 @@ namespace CarCareTracker.Controllers
return PartialView("_PlanRecordModal", new PlanRecordInput() { ExtraFields = _extraFieldDataAccess.GetExtraFieldsById((int)ImportMode.PlanRecord).ExtraFields }); return PartialView("_PlanRecordModal", new PlanRecordInput() { ExtraFields = _extraFieldDataAccess.GetExtraFieldsById((int)ImportMode.PlanRecord).ExtraFields });
} }
[HttpPost] [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) public IActionResult UpdatePlanRecordProgress(int planRecordId, PlanProgress planProgress, int odometer = 0)
{ {
var existingRecord = _planRecordDataAccess.GetPlanRecordById(planRecordId); var existingRecord = _planRecordDataAccess.GetPlanRecordById(planRecordId);
@@ -1825,6 +1835,24 @@ namespace CarCareTracker.Controllers
}; };
_upgradeRecordDataAccess.SaveUpgradeRecordToVehicle(newRecord); _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); return Json(result);
} }
@@ -1847,6 +1875,7 @@ namespace CarCareTracker.Controllers
VehicleId = result.VehicleId, VehicleId = result.VehicleId,
Files = result.Files, Files = result.Files,
RequisitionHistory = result.RequisitionHistory, RequisitionHistory = result.RequisitionHistory,
ReminderRecordId = result.ReminderRecordId,
ExtraFields = StaticHelper.AddExtraFields(result.ExtraFields, _extraFieldDataAccess.GetExtraFieldsById((int)ImportMode.PlanRecord).ExtraFields) ExtraFields = StaticHelper.AddExtraFields(result.ExtraFields, _extraFieldDataAccess.GetExtraFieldsById((int)ImportMode.PlanRecord).ExtraFields)
}; };
return PartialView("_PlanRecordModal", convertedResult); return PartialView("_PlanRecordModal", convertedResult);

View File

@@ -1,8 +0,0 @@
namespace CarCareTracker.Models
{
public class PlanCostItem
{
public string CostName { get; set; }
public decimal CostAmount { get; set; }
}
}

View File

@@ -4,6 +4,7 @@
{ {
public int Id { get; set; } public int Id { get; set; }
public int VehicleId { get; set; } public int VehicleId { get; set; }
public int ReminderRecordId { get; set; }
public DateTime DateCreated { get; set; } public DateTime DateCreated { get; set; }
public DateTime DateModified { get; set; } public DateTime DateModified { get; set; }
public string Description { get; set; } public string Description { get; set; }

View File

@@ -4,6 +4,7 @@
{ {
public int Id { get; set; } public int Id { get; set; }
public int VehicleId { get; set; } public int VehicleId { get; set; }
public int ReminderRecordId { get; set; }
public string DateCreated { get; set; } = DateTime.Now.ToShortDateString(); public string DateCreated { get; set; } = DateTime.Now.ToShortDateString();
public string DateModified { get; set; } = DateTime.Now.ToShortDateString(); public string DateModified { get; set; } = DateTime.Now.ToShortDateString();
public string Description { get; set; } public string Description { get; set; }
@@ -19,6 +20,7 @@
public PlanRecord ToPlanRecord() { return new PlanRecord { public PlanRecord ToPlanRecord() { return new PlanRecord {
Id = Id, Id = Id,
VehicleId = VehicleId, VehicleId = VehicleId,
ReminderRecordId = ReminderRecordId,
DateCreated = DateTime.Parse(DateCreated), DateCreated = DateTime.Parse(DateCreated),
DateModified = DateTime.Parse(DateModified), DateModified = DateTime.Parse(DateModified),
Description = Description, Description = Description,
@@ -31,5 +33,9 @@
ExtraFields = ExtraFields, ExtraFields = ExtraFields,
RequisitionHistory = RequisitionHistory RequisitionHistory = RequisitionHistory
}; } }; }
/// <summary>
/// only used to hide view template button on plan create modal.
/// </summary>
public bool CreatedFromReminder { get; set; }
} }
} }

View File

@@ -16,7 +16,13 @@
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-6 col-md-1"> @if (Model.ReminderRecordId != default)
{
<div class="col-4 col-md-1">
<i class="bi bi-bell"></i>
</div>
}
<div class="@(Model.ReminderRecordId != default ? "col-4" : "col-6") col-md-1">
@if (Model.ImportMode == ImportMode.ServiceRecord) @if (Model.ImportMode == ImportMode.ServiceRecord)
{ {
<i class="bi bi-card-checklist"></i> <i class="bi bi-card-checklist"></i>
@@ -30,7 +36,7 @@
<i class="bi bi-exclamation-octagon"></i> <i class="bi bi-exclamation-octagon"></i>
} }
</div> </div>
<div class="col-6 col-md-1"> <div class="@(Model.ReminderRecordId != default ? "col-4" : "col-6") col-md-1">
@if (Model.Priority == PlanPriority.Critical) @if (Model.Priority == PlanPriority.Critical)
{ {
<i class="bi bi-fire"></i> <i class="bi bi-fire"></i>

View File

@@ -101,7 +101,10 @@
</button> </button>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a class="dropdown-item" href="#" onclick="savePlanRecordTemplate()">@translator.Translate(userLanguage, "Save as Template")</a></li> <li><a class="dropdown-item" href="#" onclick="savePlanRecordTemplate()">@translator.Translate(userLanguage, "Save as Template")</a></li>
<li><a class="dropdown-item" href="#" onclick="showPlanRecordTemplatesModal()">@translator.Translate(userLanguage, "View Templates")</a></li> @if (!Model.CreatedFromReminder)
{
<li><a class="dropdown-item" href="#" onclick="showPlanRecordTemplatesModal()">@translator.Translate(userLanguage, "View Templates")</a></li>
}
</ul> </ul>
</div> </div>
} }
@@ -124,7 +127,9 @@
function getPlanRecordModelData() { function getPlanRecordModelData() {
return { return {
id: @Model.Id, id: @Model.Id,
dateCreated: decodeHTMLEntities('@(Model.DateCreated)') dateCreated: decodeHTMLEntities('@(Model.DateCreated)'),
reminderRecordId: decodeHTMLEntities('@Model.ReminderRecordId'),
createdFromReminder: @Model.CreatedFromReminder.ToString().ToLower()
} }
} }
</script> </script>

View File

@@ -29,6 +29,10 @@
<tr class="d-flex" id="supplyRows"> <tr class="d-flex" id="supplyRows">
<td class="col-8 text-truncate"> <td class="col-8 text-truncate">
@StaticHelper.TruncateStrings(planRecordTemplate.Description) @StaticHelper.TruncateStrings(planRecordTemplate.Description)
@if(planRecordTemplate.ReminderRecordId != default)
{
<i class="bi bi-bell ms-2"></i>
}
@if (planRecordTemplate.Files.Any()) @if (planRecordTemplate.Files.Any())
{ {
<i class="bi bi-paperclip ms-2"></i> <i class="bi bi-paperclip ms-2"></i>

View File

@@ -90,6 +90,10 @@
<div class="modal-footer"> <div class="modal-footer">
@if (!isNew) @if (!isNew)
{ {
@if (Model.IsRecurring)
{
<button type="button" class="btn btn-warning" onclick="createPlanRecordFromReminder(@Model.Id)">@translator.Translate(userLanguage, "Plan")</button>
}
<button type="button" class="btn btn-danger" onclick="deleteReminderRecord(@Model.Id)" style="margin-right:auto;">@translator.Translate(userLanguage, "Delete")</button> <button type="button" class="btn btn-danger" onclick="deleteReminderRecord(@Model.Id)" style="margin-right:auto;">@translator.Translate(userLanguage, "Delete")</button>
} }
<button type="button" class="btn btn-secondary" onclick="hideAddReminderRecordModal()">@translator.Translate(userLanguage, "Cancel")</button> <button type="button" class="btn btn-secondary" onclick="hideAddReminderRecordModal()">@translator.Translate(userLanguage, "Cancel")</button>

View File

@@ -93,4 +93,10 @@
</tbody> </tbody>
</table> </table>
</div> </div>
</div>
<div class="modal fade" data-bs-focus="false" id="planRecordModal" tabindex="-1" role="dialog" aria-hidden="true" data-bs-backdrop="static" data-bs-keyboard="false">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content" id="planRecordModalContent">
</div>
</div>
</div> </div>

View File

@@ -25,6 +25,10 @@ function showEditPlanRecordModal(planRecordId) {
} }
function hideAddPlanRecordModal() { function hideAddPlanRecordModal() {
$('#planRecordModal').modal('hide'); $('#planRecordModal').modal('hide');
if (getPlanRecordModelData().createdFromReminder) {
//show reminder Modal
$("#reminderRecordModal").modal("show");
}
} }
function deletePlanRecord(planRecordId) { function deletePlanRecord(planRecordId) {
$("#workAroundInput").show(); $("#workAroundInput").show();
@@ -64,10 +68,12 @@ function savePlanRecordToVehicle(isEdit) {
if (data) { if (data) {
successToast(isEdit ? "Plan Record Updated" : "Plan Record Added."); successToast(isEdit ? "Plan Record Updated" : "Plan Record Added.");
hideAddPlanRecordModal(); hideAddPlanRecordModal();
saveScrollPosition(); if (!getPlanRecordModelData().createdFromReminder) {
getVehiclePlanRecords(formValues.vehicleId); saveScrollPosition();
if (formValues.addReminderRecord) { getVehiclePlanRecords(formValues.vehicleId);
setTimeout(function () { showAddReminderModal(formValues); }, 500); if (formValues.addReminderRecord) {
setTimeout(function () { showAddReminderModal(formValues); }, 500);
}
} }
} else { } else {
errorToast(genericErrorMessage()); errorToast(genericErrorMessage());
@@ -139,9 +145,6 @@ function savePlanRecordTemplate() {
$.post('/Vehicle/SavePlanRecordTemplateToVehicleId', { planRecord: formValues }, function (data) { $.post('/Vehicle/SavePlanRecordTemplateToVehicleId', { planRecord: formValues }, function (data) {
if (data.success) { if (data.success) {
successToast(data.message); successToast(data.message);
hideAddPlanRecordModal();
saveScrollPosition();
getVehiclePlanRecords(formValues.vehicleId);
} else { } else {
errorToast(data.message); errorToast(data.message);
} }
@@ -157,6 +160,7 @@ function getAndValidatePlanRecordValues() {
var planDateCreated = getPlanRecordModelData().dateCreated; var planDateCreated = getPlanRecordModelData().dateCreated;
var vehicleId = GetVehicleId().vehicleId; var vehicleId = GetVehicleId().vehicleId;
var planRecordId = getPlanRecordModelData().id; var planRecordId = getPlanRecordModelData().id;
var reminderRecordId = getPlanRecordModelData().reminderRecordId;
//validation //validation
var hasError = false; var hasError = false;
var extraFields = getAndValidateExtraFields(); var extraFields = getAndValidateExtraFields();
@@ -189,7 +193,8 @@ function getAndValidatePlanRecordValues() {
progress: planProgress, progress: planProgress,
importMode: planType, importMode: planType,
extraFields: extraFields.extraFields, extraFields: extraFields.extraFields,
requisitionHistory: supplyUsageHistory requisitionHistory: supplyUsageHistory,
reminderRecordId: reminderRecordId
} }
} }
//drag and drop stuff. //drag and drop stuff.

View File

@@ -217,4 +217,26 @@ function getAndValidateReminderRecordValues() {
customMileageInterval: customMileageInterval, customMileageInterval: customMileageInterval,
customMonthInterval: customMonthInterval 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");
});
} }