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 });
}
[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);

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 VehicleId { get; set; }
public int ReminderRecordId { get; set; }
public DateTime DateCreated { get; set; }
public DateTime DateModified { get; set; }
public string Description { get; set; }

View File

@@ -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
}; }
/// <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 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)
{
<i class="bi bi-card-checklist"></i>
@@ -30,7 +36,7 @@
<i class="bi bi-exclamation-octagon"></i>
}
</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)
{
<i class="bi bi-fire"></i>

View File

@@ -101,7 +101,10 @@
</button>
<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="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>
</div>
}
@@ -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()
}
}
</script>

View File

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

View File

@@ -90,6 +90,10 @@
<div class="modal-footer">
@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-secondary" onclick="hideAddReminderRecordModal()">@translator.Translate(userLanguage, "Cancel")</button>

View File

@@ -94,3 +94,9 @@
</table>
</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>

View File

@@ -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.

View File

@@ -218,3 +218,25 @@ function getAndValidateReminderRecordValues() {
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");
});
}