diff --git a/Controllers/VehicleController.cs b/Controllers/VehicleController.cs index f4fc3fd..7be9f77 100644 --- a/Controllers/VehicleController.cs +++ b/Controllers/VehicleController.cs @@ -1188,6 +1188,12 @@ namespace CarCareTracker.Controllers [HttpPost] public IActionResult SavePlanRecordToVehicleId(PlanRecordInput planRecord) { + //populate createdDate + if (planRecord.Id == default) + { + planRecord.DateCreated = DateTime.Now.ToString("G"); + } + planRecord.DateModified = DateTime.Now.ToString("G"); //move files from temp. planRecord.Files = planRecord.Files.Select(x => { return new UploadedFiles { Name = x.Name, Location = _fileHelper.MoveFileFromTemp(x.Location, "documents/") }; }).ToList(); var result = _planRecordDataAccess.SavePlanRecordToVehicle(planRecord.ToPlanRecord()); @@ -1198,6 +1204,15 @@ namespace CarCareTracker.Controllers { return PartialView("_PlanRecordModal", new PlanRecordInput()); } + [HttpPost] + public IActionResult UpdatePlanRecordProgress(int planRecordId, PlanProgress planProgress) + { + var existingRecord = _planRecordDataAccess.GetPlanRecordById(planRecordId); + existingRecord.Progress = planProgress; + existingRecord.DateModified = DateTime.Now; + var result = _planRecordDataAccess.SavePlanRecordToVehicle(existingRecord); + return Json(result); + } [HttpGet] public IActionResult GetPlanRecordForEditById(int planRecordId) { @@ -1207,12 +1222,12 @@ namespace CarCareTracker.Controllers { Id = result.Id, Description = result.Description, - DateCreated = result.DateCreated.ToShortDateString(), - DateModified = result.DateModified.ToShortDateString(), + DateCreated = result.DateCreated.ToString("G"), + DateModified = result.DateModified.ToString("G"), ImportMode = result.ImportMode, Priority = result.Priority, Progress = result.Progress, - Costs = result.Costs, + Cost = result.Cost, Notes = result.Notes, VehicleId = result.VehicleId, Files = result.Files diff --git a/Enum/PlanPriority.cs b/Enum/PlanPriority.cs index d061835..09237d1 100644 --- a/Enum/PlanPriority.cs +++ b/Enum/PlanPriority.cs @@ -1,4 +1,4 @@ -namespace CarCareTracker.Enum +namespace CarCareTracker.Models { public enum PlanPriority { diff --git a/Enum/PlanProgress.cs b/Enum/PlanProgress.cs index f252087..d14785a 100644 --- a/Enum/PlanProgress.cs +++ b/Enum/PlanProgress.cs @@ -1,4 +1,4 @@ -namespace CarCareTracker.Enum +namespace CarCareTracker.Models { public enum PlanProgress { diff --git a/Models/PlanRecord/PlanRecord.cs b/Models/PlanRecord/PlanRecord.cs index 687f21a..98f724c 100644 --- a/Models/PlanRecord/PlanRecord.cs +++ b/Models/PlanRecord/PlanRecord.cs @@ -1,6 +1,4 @@ -using CarCareTracker.Enum; - -namespace CarCareTracker.Models +namespace CarCareTracker.Models { public class PlanRecord { @@ -14,6 +12,6 @@ namespace CarCareTracker.Models public ImportMode ImportMode { get; set; } public PlanPriority Priority { get; set; } public PlanProgress Progress { get; set; } - public List Costs { get; set; } = new List(); + public decimal Cost { get; set; } } } diff --git a/Models/PlanRecord/PlanRecordInput.cs b/Models/PlanRecord/PlanRecordInput.cs index 95dcc7b..19772e2 100644 --- a/Models/PlanRecord/PlanRecordInput.cs +++ b/Models/PlanRecord/PlanRecordInput.cs @@ -1,6 +1,4 @@ -using CarCareTracker.Enum; - -namespace CarCareTracker.Models +namespace CarCareTracker.Models { public class PlanRecordInput { @@ -14,7 +12,7 @@ namespace CarCareTracker.Models public ImportMode ImportMode { get; set; } public PlanPriority Priority { get; set; } public PlanProgress Progress { get; set; } - public List Costs { get; set; } = new List(); + public decimal Cost { get; set; } public PlanRecord ToPlanRecord() { return new PlanRecord { Id = Id, VehicleId = VehicleId, @@ -24,7 +22,7 @@ namespace CarCareTracker.Models Notes = Notes, Files = Files, ImportMode = ImportMode, - Costs = Costs, + Cost = Cost, Priority = Priority, Progress = Progress }; } diff --git a/Views/Vehicle/Index.cshtml b/Views/Vehicle/Index.cshtml index 164d291..6440912 100644 --- a/Views/Vehicle/Index.cshtml +++ b/Views/Vehicle/Index.cshtml @@ -18,6 +18,7 @@ + }
@@ -31,6 +32,9 @@ + @@ -46,9 +50,6 @@ - @@ -79,6 +80,9 @@ + @@ -94,9 +98,6 @@ - diff --git a/Views/Vehicle/_PlanRecordItem.cshtml b/Views/Vehicle/_PlanRecordItem.cshtml new file mode 100644 index 0000000..677d29d --- /dev/null +++ b/Views/Vehicle/_PlanRecordItem.cshtml @@ -0,0 +1,43 @@ +@model PlanRecord +
+
+
+
+ @Model.Description +
+
+ @Model.Cost.ToString("C2") +
+
+
+
+ @if (Model.ImportMode == ImportMode.ServiceRecord) + { + + } + else if (Model.ImportMode == ImportMode.UpgradeRecord) + { + + } + else if (Model.ImportMode == ImportMode.RepairRecord) + { + + } +
+
+ @if (Model.Priority == PlanPriority.Critical) + { + + } + else if (Model.Priority == PlanPriority.Normal) + { + + } + else if (Model.Priority == PlanPriority.Low) + { + + } +
+
+
+
\ No newline at end of file diff --git a/Views/Vehicle/_PlanRecordModal.cshtml b/Views/Vehicle/_PlanRecordModal.cshtml new file mode 100644 index 0000000..f155ebe --- /dev/null +++ b/Views/Vehicle/_PlanRecordModal.cshtml @@ -0,0 +1,95 @@ +@model PlanRecordInput +@{ + var isNew = Model.Id == 0; +} + + + + \ No newline at end of file diff --git a/Views/Vehicle/_PlanRecords.cshtml b/Views/Vehicle/_PlanRecords.cshtml index cff97f2..c57ccd8 100644 --- a/Views/Vehicle/_PlanRecords.cshtml +++ b/Views/Vehicle/_PlanRecords.cshtml @@ -3,10 +3,10 @@ @{ var enableCsvImports = config.GetUserConfig(User).EnableCsvImports; var hideZero = config.GetUserConfig(User).HideZero; - var backLogItems = Model.Where(x => x.Progress == CarCareTracker.Enum.PlanProgress.Backlog).OrderBy(x=>x.Priority); - var inProgressItems = Model.Where(x => x.Progress == CarCareTracker.Enum.PlanProgress.InProgress).OrderBy(x => x.Priority); - var testingItems = Model.Where(x => x.Progress == CarCareTracker.Enum.PlanProgress.Testing).OrderBy(x => x.Priority); - var doneItems = Model.Where(x => x.Progress == CarCareTracker.Enum.PlanProgress.Done).OrderBy(x => x.Priority); + var backLogItems = Model.Where(x => x.Progress == PlanProgress.Backlog).OrderBy(x=>x.Priority); + var inProgressItems = Model.Where(x => x.Progress == PlanProgress.InProgress).OrderBy(x => x.Priority); + var testingItems = Model.Where(x => x.Progress == PlanProgress.Testing).OrderBy(x => x.Priority); + var doneItems = Model.Where(x => x.Progress == PlanProgress.Done).OrderBy(x => x.Priority); } @model List
@@ -43,39 +43,49 @@
-
+
Planned
-
-
-
Test
-
$120
-
-
+ @foreach (PlanRecord planRecord in backLogItems) + { + @await Html.PartialAsync("_PlanRecordItem", planRecord) + }
-
+
Doing
+ @foreach (PlanRecord planRecord in inProgressItems) + { + @await Html.PartialAsync("_PlanRecordItem", planRecord) + }
-
+
Testing
+ @foreach (PlanRecord planRecord in testingItems) + { + @await Html.PartialAsync("_PlanRecordItem", planRecord) + }
-
+
Done
+ @foreach (PlanRecord planRecord in doneItems) + { + @await Html.PartialAsync("_PlanRecordItem", planRecord) + }
@@ -87,26 +97,4 @@
-
- \ No newline at end of file +
\ No newline at end of file diff --git a/wwwroot/css/site.css b/wwwroot/css/site.css index 86a4a12..a6e63f8 100644 --- a/wwwroot/css/site.css +++ b/wwwroot/css/site.css @@ -272,13 +272,19 @@ input[type="file"] { } .taskCard { - height: 10vh; + max-height: 20vh; padding:0.5rem; + overflow:hidden; border-radius: 4px; box-shadow: 0 6px 10px rgba(0,0,0,.08), 0 0 6px rgba(0,0,0,.05); transition: .3s transform cubic-bezier(.155,1.105,.295,1.12),.3s box-shadow,.3s -webkit-transform cubic-bezier(.155,1.105,.295,1.12); cursor: pointer; } +.taskCard-title{ + font-size:1.5rem; + font-weight:300; + max-height:10vh; +} [data-bs-theme=dark] .taskCard { color: #000; background-color: rgba(255,255,255,0.5); diff --git a/wwwroot/js/planrecord.js b/wwwroot/js/planrecord.js new file mode 100644 index 0000000..8e3a868 --- /dev/null +++ b/wwwroot/js/planrecord.js @@ -0,0 +1,146 @@ +function showAddPlanRecordModal() { + $.get('/Vehicle/GetAddPlanRecordPartialView', function (data) { + if (data) { + $("#planRecordModalContent").html(data); + //initiate datepicker + initDatePicker($('#planRecordDate')); + $('#planRecordModal').modal('show'); + } + }); +} +function showEditPlanRecordModal(planRecordId) { + $.get(`/Vehicle/GetPlanRecordForEditById?planRecordId=${planRecordId}`, function (data) { + if (data) { + $("#planRecordModalContent").html(data); + //initiate datepicker + initDatePicker($('#planRecordDate')); + $('#planRecordModal').modal('show'); + } + }); +} +function hideAddPlanRecordModal() { + $('#planRecordModal').modal('hide'); +} +function deletePlanRecord(planRecordId) { + $("#workAroundInput").show(); + Swal.fire({ + title: "Confirm Deletion?", + text: "Deleted Plan Records cannot be restored.", + showCancelButton: true, + confirmButtonText: "Delete", + confirmButtonColor: "#dc3545" + }).then((result) => { + if (result.isConfirmed) { + $.post(`/Vehicle/DeletePlanRecordById?planRecordId=${planRecordId}`, function (data) { + if (data) { + hideAddPlanRecordModal(); + successToast("Plan Record Deleted"); + var vehicleId = GetVehicleId().vehicleId; + getVehiclePlanRecords(vehicleId); + } else { + errorToast("An error has occurred, please try again later."); + } + }); + } else { + $("#workAroundInput").hide(); + } + }); +} +function savePlanRecordToVehicle(isEdit) { + //get values + var formValues = getAndValidatePlanRecordValues(); + //validate + if (formValues.hasError) { + errorToast("Please check the form data"); + return; + } + //save to db. + $.post('/Vehicle/SavePlanRecordToVehicleId', { planRecord: formValues }, function (data) { + if (data) { + successToast(isEdit ? "Plan Record Updated" : "Plan Record Added."); + hideAddPlanRecordModal(); + saveScrollPosition(); + getVehiclePlanRecords(formValues.vehicleId); + if (formValues.addReminderRecord) { + setTimeout(function () { showAddReminderModal(formValues); }, 500); + } + } else { + errorToast("An error has occurred, please try again later."); + } + }) +} +function getAndValidatePlanRecordValues() { + var planDescription = $("#planRecordDescription").val(); + var planCost = $("#planRecordCost").val(); + var planNotes = $("#planRecordNotes").val(); + var planType = $("#planRecordType").val(); + var planPriority = $("#planRecordPriority").val(); + var planProgress = $("#planRecordProgress").val(); + var planDateCreated = getPlanRecordModelData().dateCreated; + var vehicleId = GetVehicleId().vehicleId; + var planRecordId = getPlanRecordModelData().id; + //validation + var hasError = false; + if (planDescription.trim() == '') { + hasError = true; + $("#planRecordDescription").addClass("is-invalid"); + } else { + $("#planRecordDescription").removeClass("is-invalid"); + } + if (planCost.trim() == '' || !isValidMoney(planCost)) { + hasError = true; + $("#planRecordCost").addClass("is-invalid"); + } else { + $("#planRecordCost").removeClass("is-invalid"); + } + return { + id: planRecordId, + hasError: hasError, + vehicleId: vehicleId, + dateCreated: planDateCreated, + description: planDescription, + cost: planCost, + notes: planNotes, + files: uploadedFiles, + priority: planPriority, + progress: planProgress, + importMode: planType + } +} +//drag and drop stuff. + +let dragged = null; +let draggedId = 0; +function dragEnter(event) { + event.preventDefault(); +} +function dragStart(event, planRecordId) { + dragged = event.target; + draggedId = planRecordId; + event.dataTransfer.setData('text/plain', draggedId); +} +function dragOver(event) { + event.preventDefault(); +} +function dropBox(event, newProgress) { + if ($(event.target).hasClass("swimlane")) { + if (dragged.parentElement != event.target && event.target != dragged) { + updatePlanRecordProgress(newProgress); + } + } + event.preventDefault(); +} +function updatePlanRecordProgress(newProgress) { + if (draggedId > 0) { + $.post('/Vehicle/UpdatePlanRecordProgress', { planRecordId: draggedId, planProgress: newProgress }, function (data) { + if (data) { + successToast("Plan Progress Updated"); + var vehicleId = GetVehicleId().vehicleId; + getVehiclePlanRecords(vehicleId); + } else { + errorToast("An error has occurred, please try again later."); + } + }); + } + draggedId = 0; +} \ No newline at end of file