From f2b9dea2b6179bbf401cedcaa074454217c7ce16 Mon Sep 17 00:00:00 2001 From: "DESKTOP-T0O5CDB\\DESK-555BD" Date: Sun, 24 Nov 2024 13:47:01 -0700 Subject: [PATCH] Added context menu to plan records. --- Controllers/Vehicle/PlanController.cs | 4 + Controllers/VehicleController.cs | 31 +++++++- Views/Vehicle/_PlanRecordItem.cshtml | 2 +- Views/Vehicle/_PlanRecords.cshtml | 14 +++- wwwroot/js/planrecord.js | 105 ++++++++++++++++++++++++++ wwwroot/js/shared.js | 8 ++ wwwroot/js/vehicle.js | 1 + 7 files changed, 162 insertions(+), 3 deletions(-) diff --git a/Controllers/Vehicle/PlanController.cs b/Controllers/Vehicle/PlanController.cs index 9800da5..020ef8f 100644 --- a/Controllers/Vehicle/PlanController.cs +++ b/Controllers/Vehicle/PlanController.cs @@ -151,6 +151,10 @@ namespace CarCareTracker.Controllers [HttpPost] public IActionResult UpdatePlanRecordProgress(int planRecordId, PlanProgress planProgress, int odometer = 0) { + if (planRecordId == default) + { + return Json(false); + } var existingRecord = _planRecordDataAccess.GetPlanRecordById(planRecordId); existingRecord.Progress = planProgress; existingRecord.DateModified = DateTime.Now; diff --git a/Controllers/VehicleController.cs b/Controllers/VehicleController.cs index ef9fbeb..0230b53 100644 --- a/Controllers/VehicleController.cs +++ b/Controllers/VehicleController.cs @@ -506,6 +506,7 @@ namespace CarCareTracker.Controllers { var existingRecord = _serviceRecordDataAccess.GetServiceRecordById(recordId); existingRecord.Id = default; + existingRecord.RequisitionHistory = new List(); result = _serviceRecordDataAccess.SaveServiceRecordToVehicle(existingRecord); } break; @@ -513,6 +514,7 @@ namespace CarCareTracker.Controllers { var existingRecord = _collisionRecordDataAccess.GetCollisionRecordById(recordId); existingRecord.Id = default; + existingRecord.RequisitionHistory = new List(); result = _collisionRecordDataAccess.SaveCollisionRecordToVehicle(existingRecord); } break; @@ -520,6 +522,7 @@ namespace CarCareTracker.Controllers { var existingRecord = _upgradeRecordDataAccess.GetUpgradeRecordById(recordId); existingRecord.Id = default; + existingRecord.RequisitionHistory = new List(); result = _upgradeRecordDataAccess.SaveUpgradeRecordToVehicle(existingRecord); } break; @@ -541,6 +544,7 @@ namespace CarCareTracker.Controllers { var existingRecord = _supplyRecordDataAccess.GetSupplyRecordById(recordId); existingRecord.Id = default; + existingRecord.RequisitionHistory = new List(); result = _supplyRecordDataAccess.SaveSupplyRecordToVehicle(existingRecord); } break; @@ -565,6 +569,15 @@ namespace CarCareTracker.Controllers result = _reminderRecordDataAccess.SaveReminderRecordToVehicle(existingRecord); } break; + case ImportMode.PlanRecord: + { + var existingRecord = _planRecordDataAccess.GetPlanRecordById(recordId); + existingRecord.Id = default; + existingRecord.ReminderRecordId = default; + existingRecord.RequisitionHistory = new List(); + result = _planRecordDataAccess.SavePlanRecordToVehicle(existingRecord); + } + break; } } if (result) @@ -589,7 +602,8 @@ namespace CarCareTracker.Controllers { var existingRecord = _serviceRecordDataAccess.GetServiceRecordById(recordId); existingRecord.Id = default; - foreach(int vehicleId in vehicleIds) + existingRecord.RequisitionHistory = new List(); + foreach (int vehicleId in vehicleIds) { existingRecord.VehicleId = vehicleId; result = _serviceRecordDataAccess.SaveServiceRecordToVehicle(existingRecord); @@ -600,6 +614,7 @@ namespace CarCareTracker.Controllers { var existingRecord = _collisionRecordDataAccess.GetCollisionRecordById(recordId); existingRecord.Id = default; + existingRecord.RequisitionHistory = new List(); foreach (int vehicleId in vehicleIds) { existingRecord.VehicleId = vehicleId; @@ -611,6 +626,7 @@ namespace CarCareTracker.Controllers { var existingRecord = _upgradeRecordDataAccess.GetUpgradeRecordById(recordId); existingRecord.Id = default; + existingRecord.RequisitionHistory = new List(); foreach (int vehicleId in vehicleIds) { existingRecord.VehicleId = vehicleId; @@ -684,6 +700,19 @@ namespace CarCareTracker.Controllers } } break; + case ImportMode.PlanRecord: + { + var existingRecord = _planRecordDataAccess.GetPlanRecordById(recordId); + existingRecord.Id = default; + existingRecord.ReminderRecordId = default; + existingRecord.RequisitionHistory = new List(); + foreach (int vehicleId in vehicleIds) + { + existingRecord.VehicleId = vehicleId; + result = _planRecordDataAccess.SavePlanRecordToVehicle(existingRecord); + } + } + break; } } if (result) diff --git a/Views/Vehicle/_PlanRecordItem.cshtml b/Views/Vehicle/_PlanRecordItem.cshtml index 891cd47..5d11ade 100644 --- a/Views/Vehicle/_PlanRecordItem.cshtml +++ b/Views/Vehicle/_PlanRecordItem.cshtml @@ -1,5 +1,5 @@ @model PlanRecord -
+
diff --git a/Views/Vehicle/_PlanRecords.cshtml b/Views/Vehicle/_PlanRecords.cshtml index 14714ec..336fbcd 100644 --- a/Views/Vehicle/_PlanRecords.cshtml +++ b/Views/Vehicle/_PlanRecords.cshtml @@ -116,4 +116,16 @@
-
\ No newline at end of file +
+ + \ No newline at end of file diff --git a/wwwroot/js/planrecord.js b/wwwroot/js/planrecord.js index 1515e60..caec9d7 100644 --- a/wwwroot/js/planrecord.js +++ b/wwwroot/js/planrecord.js @@ -269,6 +269,10 @@ function dragStart(event, planRecordId) { } function dragOver(event) { event.preventDefault(); + if (planTouchTimer) { + clearTimeout(planTouchTimer); + planTouchTimer = null; + } } function dropBox(event, newProgress) { var targetSwimLane = $(event.target).hasClass("swimlane") ? event.target : $(event.target).parents(".swimlane")[0]; @@ -349,4 +353,105 @@ function orderPlanSupplies(planRecordTemplateId, closeSwal) { function hideOrderSupplyModal() { $("#planRecordTemplateSupplyOrderModal").modal('hide'); showPlanRecordTemplatesModal(); +} +function configurePlanTableContextMenu(planRecordId, currentSwimLane) { + //clear any bound actions + $(".context-menu-move").off('click'); + //bind context menu actions + $(".context-menu-delete").on('click', () => { + deletePlanRecord(planRecordId, true); + }); + let planRecordIdArray = [planRecordId]; + $(".context-menu-duplicate").on('click', () => { + duplicateRecords(planRecordIdArray, 'PlanRecord'); + }); + $(".context-menu-duplicate-vehicle").on('click', () => { + duplicateRecordsToOtherVehicles(planRecordIdArray, 'PlanRecord'); + }); + $(".context-menu-move.move-planned").on('click', () => { + draggedId = planRecordId; + updatePlanRecordProgress('Backlog'); + draggedId = 0; + }); + $(".context-menu-move.move-doing").on('click', () => { + draggedId = planRecordId; + updatePlanRecordProgress('InProgress'); + }); + $(".context-menu-move.move-testing").on('click', () => { + draggedId = planRecordId; + updatePlanRecordProgress('Testing'); + }); + $(".context-menu-move.move-done").on('click', () => { + draggedId = planRecordId; + updatePlanRecordProgress('Done'); + }); + //hide all move buttons + $(".context-menu-move").hide(); + $(".context-menu-delete").show(); //delete is always visible. + switch (currentSwimLane) { + case 'Backlog': + $(".context-menu-move.move-header").show(); + $(".context-menu-move.move-doing").show(); + $(".context-menu-move.move-testing").show(); + $(".context-menu-move.move-done").show(); + break; + case 'InProgress': + $(".context-menu-move.move-header").show(); + $(".context-menu-move.move-planned").show(); + $(".context-menu-move.move-testing").show(); + $(".context-menu-move.move-done").show(); + break; + case 'Testing': + $(".context-menu-move.move-header").show(); + $(".context-menu-move.move-planned").show(); + $(".context-menu-move.move-doing").show(); + $(".context-menu-move.move-done").show(); + break; + case 'Done': + break; + } +} +function showPlanTableContextMenu(e, planRecordId, currentSwimLane) { + if (event != undefined) { + event.preventDefault(); + } + if (getDeviceIsTouchOnly()) { + return; + } + if (planRecordId == 0) { + return; + } + $(".table-context-menu").fadeIn("fast"); + $(".table-context-menu").css({ + left: getMenuPosition(event.clientX, 'width', 'scrollLeft'), + top: getMenuPosition(event.clientY, 'height', 'scrollTop') + }); + configurePlanTableContextMenu(planRecordId, currentSwimLane); +} +function showPlanTableContextMenuForMobile(e, xPosition, yPosition, planRecordId, currentSwimLane) { + $(".table-context-menu").fadeIn("fast"); + $(".table-context-menu").css({ + left: getMenuPosition(xPosition, 'width', 'scrollLeft'), + top: getMenuPosition(yPosition, 'height', 'scrollTop') + }); + configurePlanTableContextMenu(planRecordId, currentSwimLane); + if (planTouchTimer) { + clearTimeout(planTouchTimer); + planTouchTimer = null; + } +} +var planTouchTimer; +var planTouchDuration = 3000; +function detectPlanItemLongTouch(sender, planRecordId, currentSwimLane) { + var touchX = event.touches[0].clientX; + var touchY = event.touches[0].clientY; + if (!planTouchTimer) { + planTouchTimer = setTimeout(function () { showPlanTableContextMenuForMobile(sender, touchX, touchY, planRecordId, currentSwimLane); detectPlanItemTouchEndPremature(sender); }, planTouchDuration); + } +} +function detectPlanItemTouchEndPremature(sender) { + if (planTouchTimer) { + clearTimeout(planTouchTimer); + planTouchTimer = null; + } } \ No newline at end of file diff --git a/wwwroot/js/shared.js b/wwwroot/js/shared.js index 6ce408a..5bc1309 100644 --- a/wwwroot/js/shared.js +++ b/wwwroot/js/shared.js @@ -825,6 +825,10 @@ function duplicateRecords(ids, source) { friendlySource = "Fuel Records"; refreshDataCallBack = getVehicleGasRecords; break; + case "PlanRecord": + friendlySource = "Plan"; + refreshDataCallBack = getVehiclePlanRecords; + break; } Swal.fire({ @@ -894,6 +898,10 @@ function duplicateRecordsToOtherVehicles(ids, source) { friendlySource = "Fuel Records"; refreshDataCallBack = getVehicleGasRecords; break; + case "PlanRecord": + friendlySource = "Plan"; + refreshDataCallBack = getVehiclePlanRecords; + break; } $.get(`/Home/GetVehicleSelector?vehicleId=${GetVehicleId().vehicleId}`, function (data) { diff --git a/wwwroot/js/vehicle.js b/wwwroot/js/vehicle.js index 5c39c3c..94019e1 100644 --- a/wwwroot/js/vehicle.js +++ b/wwwroot/js/vehicle.js @@ -552,6 +552,7 @@ function adjustRecordsOdometer(ids, source) { confirmButtonColor: "#dc3545" }).then((result) => { if (result.isConfirmed) { + saveScrollPosition(); $.post('/Vehicle/AdjustRecordsOdometer', { recordIds: ids, vehicleId: GetVehicleId().vehicleId, importMode: source }, function (data) { if (data) { successToast(`${ids.length} Record(s) Updated`);