From 4079a93c3e448c35e021d1b4f1faf21786d36564 Mon Sep 17 00:00:00 2001 From: "DESKTOP-T0O5CDB\\DESK-555BD" Date: Fri, 28 Mar 2025 09:40:13 -0600 Subject: [PATCH] Add extra field type. --- Enum/ExtraFieldType.cs | 12 ++++++ Helper/StaticHelper.cs | 4 +- Models/Shared/ExtraField.cs | 1 + Views/Home/_ExtraFields.cshtml | 23 ++++++++-- Views/Vehicle/_CollisionRecordModal.cshtml | 9 +--- Views/Vehicle/_ExtraField.cshtml | 42 +++++++++++++++++++ Views/Vehicle/_OdometerRecordModal.cshtml | 9 +--- Views/Vehicle/_PlanRecordModal.cshtml | 9 +--- .../_PlanRecordTemplateEditModal.cshtml | 9 +--- Views/Vehicle/_ServiceRecordModal.cshtml | 9 +--- Views/Vehicle/_SupplyRecordModal.cshtml | 9 +--- Views/Vehicle/_TaxRecordModal.cshtml | 9 +--- Views/Vehicle/_UpgradeRecordModal.cshtml | 9 +--- Views/Vehicle/_VehicleModal.cshtml | 9 +--- wwwroot/defaults/en_US.json | 2 +- wwwroot/js/shared.js | 37 +++++++++++++++- 16 files changed, 124 insertions(+), 78 deletions(-) create mode 100644 Enum/ExtraFieldType.cs create mode 100644 Views/Vehicle/_ExtraField.cshtml diff --git a/Enum/ExtraFieldType.cs b/Enum/ExtraFieldType.cs new file mode 100644 index 0000000..eff2212 --- /dev/null +++ b/Enum/ExtraFieldType.cs @@ -0,0 +1,12 @@ +namespace CarCareTracker.Models +{ + public enum ExtraFieldType + { + Text = 0, + Number = 1, + Decimal = 2, + Date = 3, + Time = 4, + Location = 5 + } +} diff --git a/Helper/StaticHelper.cs b/Helper/StaticHelper.cs index 67c5427..2a2fd6a 100644 --- a/Helper/StaticHelper.cs +++ b/Helper/StaticHelper.cs @@ -262,7 +262,9 @@ namespace CarCareTracker.Helper //update isrequired setting foreach (ExtraField extraField in recordExtraFields) { - extraField.IsRequired = templateExtraFields.Where(x => x.Name == extraField.Name).First().IsRequired; + var firstMatchingField = templateExtraFields.First(x => x.Name == extraField.Name); + extraField.IsRequired = firstMatchingField.IsRequired; + extraField.FieldType = firstMatchingField.FieldType; } //append extra fields foreach (ExtraField extraField in templateExtraFields) diff --git a/Models/Shared/ExtraField.cs b/Models/Shared/ExtraField.cs index 9a4ed8c..9b5e3ec 100644 --- a/Models/Shared/ExtraField.cs +++ b/Models/Shared/ExtraField.cs @@ -5,5 +5,6 @@ public string Name { get; set; } public string Value { get; set; } public bool IsRequired { get; set; } + public ExtraFieldType FieldType { get; set; } = ExtraFieldType.Text; } } diff --git a/Views/Home/_ExtraFields.cshtml b/Views/Home/_ExtraFields.cshtml index ec1b25b..cb28de0 100644 --- a/Views/Home/_ExtraFields.cshtml +++ b/Views/Home/_ExtraFields.cshtml @@ -36,8 +36,9 @@ - + + @@ -47,11 +48,21 @@ @foreach (ExtraField extraField in Model.ExtraFields) { - + + } @@ -99,6 +110,12 @@ extraFieldToEdit.isRequired = $(checkbox).is(":checked"); updateExtraFields(); } + function updateExtraFieldType(fieldId, dropDown){ + var indexToEdit = extraFields.findIndex(x => x.name == fieldId); + var extraFieldToEdit = extraFields[indexToEdit]; + extraFieldToEdit.fieldType = $(dropDown).val(); + updateExtraFields(); + } function deleteExtraField(fieldId) { extraFields = extraFields.filter(x => x.name != fieldId); updateExtraFields(); diff --git a/Views/Vehicle/_CollisionRecordModal.cshtml b/Views/Vehicle/_CollisionRecordModal.cshtml index 2ba92a0..692715e 100644 --- a/Views/Vehicle/_CollisionRecordModal.cshtml +++ b/Views/Vehicle/_CollisionRecordModal.cshtml @@ -52,14 +52,7 @@ @tag } - @foreach (ExtraField field in Model.ExtraFields) - { - var elementId = Guid.NewGuid(); -
- - -
- } + @await Html.PartialAsync("_ExtraField", Model.ExtraFields)
diff --git a/Views/Vehicle/_ExtraField.cshtml b/Views/Vehicle/_ExtraField.cshtml new file mode 100644 index 0000000..f87e0c1 --- /dev/null +++ b/Views/Vehicle/_ExtraField.cshtml @@ -0,0 +1,42 @@ +@model List +@if (Model.Any()){ + @foreach (ExtraField field in Model) + { + var elementId = Guid.NewGuid(); +
+ + @switch(field.FieldType){ + case (ExtraFieldType.Text): + + break; + case (ExtraFieldType.Number): + + break; + case (ExtraFieldType.Decimal): + + break; + case (ExtraFieldType.Date): +
+ + +
+ + break; + case (ExtraFieldType.Time): + + break; + case (ExtraFieldType.Location): +
+ +
+ +
+
+ break; + default: + + break; + } +
+ } +} \ No newline at end of file diff --git a/Views/Vehicle/_OdometerRecordModal.cshtml b/Views/Vehicle/_OdometerRecordModal.cshtml index 94fd691..5001909 100644 --- a/Views/Vehicle/_OdometerRecordModal.cshtml +++ b/Views/Vehicle/_OdometerRecordModal.cshtml @@ -72,14 +72,7 @@ @tag } - @foreach (ExtraField field in Model.ExtraFields) - { - var elementId = Guid.NewGuid(); -
- - -
- } + @await Html.PartialAsync("_ExtraField", Model.ExtraFields)
diff --git a/Views/Vehicle/_PlanRecordModal.cshtml b/Views/Vehicle/_PlanRecordModal.cshtml index d774916..598610c 100644 --- a/Views/Vehicle/_PlanRecordModal.cshtml +++ b/Views/Vehicle/_PlanRecordModal.cshtml @@ -40,14 +40,7 @@ @translator.Translate(userLanguage, "Doing") @translator.Translate(userLanguage, "Testing") - @foreach (ExtraField field in Model.ExtraFields) - { - var elementId = Guid.NewGuid(); -
- - -
- } + @await Html.PartialAsync("_ExtraField", Model.ExtraFields) @if (!isNew) { diff --git a/Views/Vehicle/_PlanRecordTemplateEditModal.cshtml b/Views/Vehicle/_PlanRecordTemplateEditModal.cshtml index a69e48c..8635504 100644 --- a/Views/Vehicle/_PlanRecordTemplateEditModal.cshtml +++ b/Views/Vehicle/_PlanRecordTemplateEditModal.cshtml @@ -40,14 +40,7 @@ @translator.Translate(userLanguage, "Doing") @translator.Translate(userLanguage, "Testing") - @foreach (ExtraField field in Model.ExtraFields) - { - var elementId = Guid.NewGuid(); -
- - -
- } + @await Html.PartialAsync("_ExtraField", Model.ExtraFields)
diff --git a/Views/Vehicle/_ServiceRecordModal.cshtml b/Views/Vehicle/_ServiceRecordModal.cshtml index e1e136a..344cbe0 100644 --- a/Views/Vehicle/_ServiceRecordModal.cshtml +++ b/Views/Vehicle/_ServiceRecordModal.cshtml @@ -52,14 +52,7 @@ @tag } - @foreach (ExtraField field in Model.ExtraFields) - { - var elementId = Guid.NewGuid(); -
- - -
- } + @await Html.PartialAsync("_ExtraField", Model.ExtraFields)
diff --git a/Views/Vehicle/_SupplyRecordModal.cshtml b/Views/Vehicle/_SupplyRecordModal.cshtml index 6b9aa76..d77ac8c 100644 --- a/Views/Vehicle/_SupplyRecordModal.cshtml +++ b/Views/Vehicle/_SupplyRecordModal.cshtml @@ -50,14 +50,7 @@ @tag } - @foreach (ExtraField field in Model.ExtraFields) - { - var elementId = Guid.NewGuid(); -
- - -
- } + @await Html.PartialAsync("_ExtraField", Model.ExtraFields)
diff --git a/Views/Vehicle/_TaxRecordModal.cshtml b/Views/Vehicle/_TaxRecordModal.cshtml index 6517de2..69f2080 100644 --- a/Views/Vehicle/_TaxRecordModal.cshtml +++ b/Views/Vehicle/_TaxRecordModal.cshtml @@ -41,14 +41,7 @@ @tag } - @foreach (ExtraField field in Model.ExtraFields) - { - var elementId = Guid.NewGuid(); -
- - -
- } + @await Html.PartialAsync("_ExtraField", Model.ExtraFields)
diff --git a/Views/Vehicle/_UpgradeRecordModal.cshtml b/Views/Vehicle/_UpgradeRecordModal.cshtml index b683a91..ab5ebc2 100644 --- a/Views/Vehicle/_UpgradeRecordModal.cshtml +++ b/Views/Vehicle/_UpgradeRecordModal.cshtml @@ -52,14 +52,7 @@ @tag } - @foreach (ExtraField field in Model.ExtraFields) - { - var elementId = Guid.NewGuid(); -
- - -
- } + @await Html.PartialAsync("_ExtraField", Model.ExtraFields)
diff --git a/Views/Vehicle/_VehicleModal.cshtml b/Views/Vehicle/_VehicleModal.cshtml index cdb3201..11f9ae7 100644 --- a/Views/Vehicle/_VehicleModal.cshtml +++ b/Views/Vehicle/_VehicleModal.cshtml @@ -36,14 +36,7 @@ - @foreach (ExtraField field in Model.ExtraFields) - { - var elementId = Guid.NewGuid(); -
- - -
- } + @await Html.PartialAsync("_ExtraField", Model.ExtraFields)
@translator.Translate(userLanguage, "Name")@translator.Translate(userLanguage, "Name") @translator.Translate(userLanguage, "Required")@translator.Translate(userLanguage, "Type") @translator.Translate(userLanguage, "Delete")
@extraField.Name@extraField.Name + +