Skip to content

Commit

Permalink
Merge pull request #27 from hargata/Hargata/rename.uploadedfiles
Browse files Browse the repository at this point in the history
Rename Uploaded Files
  • Loading branch information
hargata authored Jan 8, 2024
2 parents b4258dc + 2ef281b commit ba14956
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 59 deletions.
3 changes: 2 additions & 1 deletion Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public IActionResult Settings()
UseDarkMode = bool.Parse(_config[nameof(UserConfig.UseDarkMode)]),
UseMPG = bool.Parse(_config[nameof(UserConfig.UseMPG)]),
UseDescending = bool.Parse(_config[nameof(UserConfig.UseDescending)]),
EnableAuth = bool.Parse(_config[nameof(UserConfig.EnableAuth)])
EnableAuth = bool.Parse(_config[nameof(UserConfig.EnableAuth)]),
HideZero = bool.Parse(_config[nameof(UserConfig.HideZero)])
};
return PartialView("_Settings", userConfig);
}
Expand Down
1 change: 1 addition & 0 deletions Models/UserConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class UserConfig
public bool UseMPG { get; set; }
public bool UseDescending { get; set; }
public bool EnableAuth { get; set; }
public bool HideZero { get; set; }
public string UserNameHash { get; set; }
public string UserPasswordHash { get; set;}
}
Expand Down
7 changes: 6 additions & 1 deletion Views/Home/_Settings.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
<input class="form-check-input" onChange="updateSettings()" type="checkbox" role="switch" id="useDescending" checked="@Model.UseDescending">
<label class="form-check-label" for="useDescending">Sort lists in Descending Order(Newest to Oldest)</label>
</div>
<div class="form-check form-switch">
<input class="form-check-input" onChange="updateSettings()" type="checkbox" role="switch" id="hideZero" checked="@Model.HideZero">
<label class="form-check-label" for="hideZero">Replace @(0.ToString("C")) Costs with ---</label>
</div>
<div class="form-check form-switch">
<input class="form-check-input" onChange="enableAuthCheckChanged()" type="checkbox" role="switch" id="enableAuth" checked="@Model.EnableAuth">
<label class="form-check-label" for="enableAuth">Enable Authentication</label>
Expand Down Expand Up @@ -76,7 +80,8 @@
useDarkMode: $("#enableDarkMode").is(':checked'),
enableCsvImports: $("#enableCsvImports").is(':checked'),
useMPG: $("#useMPG").is(':checked'),
useDescending: $("#useDescending").is(':checked')
useDescending: $("#useDescending").is(':checked'),
hideZero: $("#hideZero").is(":checked")
}
$.post('/Home/WriteToSettings', { userConfig: userConfigObject}, function(data){
if (data) {
Expand Down
9 changes: 1 addition & 8 deletions Views/Vehicle/_CollisionRecordModal.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@
@if (Model.Files.Any())
{
<div>
<label>Uploaded Documents</label>
@foreach (UploadedFiles filesUploaded in Model.Files)
{
<div class="d-flex justify-content-between">
<a type="button" class="btn btn-link" href="@filesUploaded.Location" target="_blank">@filesUploaded.Name</a>
<button type="button" class="btn btn-sm btn-outline-danger" onclick="deleteCollisionRecordFile('@filesUploaded.Location', this)"><i class="bi bi-trash"></i></button>
</div>
}
@await Html.PartialAsync("_UploadedFiles", Model.Files)
<label for="collisionRecordFiles">Upload more documents</label>
<input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept=".png,.jpg,.jpeg,.pdf,.xls,.xlsx,.docx" class="form-control-file" id="collisionRecordFiles">
</div>
Expand Down
5 changes: 3 additions & 2 deletions Views/Vehicle/_CollisionRecords.cshtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@inject IConfiguration Configuration
@{
var enableCsvImports = bool.Parse(Configuration[nameof(UserConfig.EnableCsvImports)]);
var hideZero = bool.Parse(Configuration[nameof(UserConfig.HideZero)]);
}
@model List<CollisionRecord>
<div class="row">
Expand Down Expand Up @@ -48,7 +49,7 @@
<td class="col-1">@collisionRecord.Date.ToShortDateString()</td>
<td class="col-2">@collisionRecord.Mileage</td>
<td class="col-4">@collisionRecord.Description</td>
<td class="col-2">@collisionRecord.Cost.ToString("C")</td>
<td class="col-2">@((hideZero && collisionRecord.Cost == default) ? "---" : collisionRecord.Cost.ToString("C"))</td>
<td class="col-3 text-truncate">@collisionRecord.Notes</td>
</tr>
}
Expand All @@ -58,7 +59,7 @@
</div>


<div class="modal fade" id="collisionRecordModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal fade" data-bs-focus="false" id="collisionRecordModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content" id="collisionRecordModalContent">
</div>
Expand Down
7 changes: 4 additions & 3 deletions Views/Vehicle/_Gas.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@{
var enableCsvImports = bool.Parse(Configuration[nameof(UserConfig.EnableCsvImports)]);
var useMPG = bool.Parse(Configuration[nameof(UserConfig.UseMPG)]);
var hideZero = bool.Parse(Configuration[nameof(UserConfig.HideZero)]);
var useKwh = Model.UseKwh;
string consumptionUnit;
string fuelEconomyUnit;
Expand Down Expand Up @@ -66,8 +67,8 @@
<td class="col-2">@gasRecord.Mileage</td>
<td class="col-2">@gasRecord.Gallons.ToString("F")</td>
<td class="col-4">@(gasRecord.MilesPerGallon == 0 ? "---" : gasRecord.MilesPerGallon.ToString("F"))</td>
<td class="col-1">@gasRecord.Cost.ToString("C3")</td>
<td class="col-1">@gasRecord.CostPerGallon.ToString("C3")</td>
<td class="col-1">@((hideZero && gasRecord.Cost == default) ? "---" : gasRecord.Cost.ToString("C3"))</td>
<td class="col-1">@((hideZero && gasRecord.CostPerGallon == default) ? "---" : gasRecord.CostPerGallon.ToString("C3"))</td>
</tr>
}
</tbody>
Expand All @@ -76,7 +77,7 @@
</div>


<div class="modal fade" id="gasRecordModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal fade" data-bs-focus="false" id="gasRecordModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content" id="gasRecordModalContent">

Expand Down
9 changes: 1 addition & 8 deletions Views/Vehicle/_GasModal.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,7 @@
@if (Model.GasRecord.Files.Any())
{
<div>
<label>Uploaded Documents</label>
@foreach (UploadedFiles filesUploaded in Model.GasRecord.Files)
{
<div class="d-flex justify-content-between">
<a type="button" class="btn btn-link" href="@filesUploaded.Location" target="_blank">@filesUploaded.Name</a>
<button type="button" class="btn btn-sm btn-outline-danger" onclick="deleteGasRecordFile('@filesUploaded.Location', this)"><i class="bi bi-trash"></i></button>
</div>
}
@await Html.PartialAsync("_UploadedFiles", Model.GasRecord.Files)
<label for="gasRecordFiles">Upload more documents</label>
<input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept=".png,.jpg,.jpeg,.pdf,.xls,.xlsx,.docx" class="form-control-file" id="gasRecordFiles">
</div>
Expand Down
9 changes: 1 addition & 8 deletions Views/Vehicle/_ServiceRecordModal.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@
@if (Model.Files.Any())
{
<div>
<label>Uploaded Documents</label>
@foreach (UploadedFiles filesUploaded in Model.Files)
{
<div class="d-flex justify-content-between">
<a type="button" class="btn btn-link" href="@filesUploaded.Location" target="_blank">@filesUploaded.Name</a>
<button type="button" class="btn btn-sm btn-outline-danger" onclick="deleteServiceRecordFile('@filesUploaded.Location', this)"><i class="bi bi-trash"></i></button>
</div>
}
@await Html.PartialAsync("_UploadedFiles", Model.Files)
<label for="serviceRecordFiles">Upload more documents</label>
<input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept=".png,.jpg,.jpeg,.pdf,.xls,.xlsx,.docx" class="form-control-file" id="serviceRecordFiles">
</div>
Expand Down
5 changes: 3 additions & 2 deletions Views/Vehicle/_ServiceRecords.cshtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@inject IConfiguration Configuration
@{
var enableCsvImports = bool.Parse(Configuration[nameof(UserConfig.EnableCsvImports)]);
var hideZero = bool.Parse(Configuration[nameof(UserConfig.HideZero)]);
}
@model List<ServiceRecord>
<div class="row">
Expand Down Expand Up @@ -48,7 +49,7 @@
<td class="col-1">@serviceRecord.Date.ToShortDateString()</td>
<td class="col-2">@serviceRecord.Mileage</td>
<td class="col-4">@serviceRecord.Description</td>
<td class="col-2">@serviceRecord.Cost.ToString("C")</td>
<td class="col-2">@((hideZero && serviceRecord.Cost == default) ? "---" : serviceRecord.Cost.ToString("C"))</td>
<td class="col-3 text-truncate">@serviceRecord.Notes</td>
</tr>
}
Expand All @@ -58,7 +59,7 @@
</div>


<div class="modal fade" id="serviceRecordModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal fade" data-bs-focus="false" id="serviceRecordModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content" id="serviceRecordModalContent">

Expand Down
9 changes: 1 addition & 8 deletions Views/Vehicle/_TaxRecordModal.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,7 @@
@if (Model.Files.Any())
{
<div>
<label>Uploaded Documents</label>
@foreach (UploadedFiles filesUploaded in Model.Files)
{
<div class="d-flex justify-content-between">
<a type="button" class="btn btn-link" href="@filesUploaded.Location" target="_blank">@filesUploaded.Name</a>
<button type="button" class="btn btn-sm btn-outline-danger" onclick="deleteTaxRecordFile('@filesUploaded.Location', this)"><i class="bi bi-trash"></i></button>
</div>
}
@await Html.PartialAsync("_UploadedFiles", Model.Files)
<label for="taxRecordFiles">Upload more documents</label>
<input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept=".png,.jpg,.jpeg,.pdf,.xls,.xlsx,.docx" class="form-control-file" id="taxRecordFiles">
</div>
Expand Down
5 changes: 3 additions & 2 deletions Views/Vehicle/_TaxRecords.cshtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@inject IConfiguration Configuration
@{
var enableCsvImports = bool.Parse(Configuration[nameof(UserConfig.EnableCsvImports)]);
var hideZero = bool.Parse(Configuration[nameof(UserConfig.HideZero)]);
}
@model List<TaxRecord>
<div class="row">
Expand Down Expand Up @@ -46,7 +47,7 @@
<tr class="d-flex" style="cursor:pointer;" onclick="showEditTaxRecordModal(@taxRecord.Id)">
<td class="col-1">@taxRecord.Date.ToShortDateString()</td>
<td class="col-6">@taxRecord.Description</td>
<td class="col-2">@taxRecord.Cost.ToString("C")</td>
<td class="col-2">@((hideZero && taxRecord.Cost == default) ? "---" : taxRecord.Cost.ToString("C"))</td>
<td class="col-3 text-truncate">@taxRecord.Notes</td>
</tr>
}
Expand All @@ -56,7 +57,7 @@
</div>


<div class="modal fade" id="taxRecordModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal fade" data-bs-focus="false" id="taxRecordModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content" id="taxRecordModalContent">
</div>
Expand Down
16 changes: 16 additions & 0 deletions Views/Vehicle/_UploadedFiles.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@model List<UploadedFiles>
<label>Uploaded Documents</label>
<ul class="list-group">
@foreach (UploadedFiles filesUploaded in Model)
{
<li class="list-group-item">
<div class="d-flex justify-content-between">
<a type="button" class="btn btn-link" href="@filesUploaded.Location" target="_blank">@filesUploaded.Name</a>
<div class="d-flex align-items-center">
<button type="button" class="btn btn-sm btn-outline-secondary me-2" onclick="editFileName('@filesUploaded.Location', this)"><i class="bi bi-pencil"></i></button>
<button type="button" class="btn btn-sm btn-outline-danger" onclick="deleteFileFromUploadedFiles('@filesUploaded.Location', this)"><i class="bi bi-trash"></i></button>
</div>
</div>
</li>
}
</ul>
1 change: 1 addition & 0 deletions appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"UseMPG": true,
"UseDescending": false,
"EnableAuth": false,
"HideZero": false,
"UserNameHash": "",
"UserPasswordHash": ""
}
4 changes: 0 additions & 4 deletions wwwroot/js/collisionrecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,4 @@ function getAndValidateCollisionRecordValues() {
files: uploadedFiles,
addReminderRecord: addReminderRecord
}
}
function deleteCollisionRecordFile(fileLocation, event) {
event.parentElement.remove();
uploadedFiles = uploadedFiles.filter(x => x.location != fileLocation);
}
4 changes: 0 additions & 4 deletions wwwroot/js/gasrecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,4 @@ function getAndValidateGasRecordValues() {
files: uploadedFiles,
isFillToFull: gasIsFillToFull
}
}
function deleteGasRecordFile(fileLocation, event) {
event.parentElement.remove();
uploadedFiles = uploadedFiles.filter(x => x.location != fileLocation);
}
4 changes: 0 additions & 4 deletions wwwroot/js/servicerecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,4 @@ function getAndValidateServiceRecordValues() {
files: uploadedFiles,
addReminderRecord: addReminderRecord
}
}
function deleteServiceRecordFile(fileLocation, event) {
event.parentElement.remove();
uploadedFiles = uploadedFiles.filter(x => x.location != fileLocation);
}
4 changes: 0 additions & 4 deletions wwwroot/js/taxrecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,4 @@ function getAndValidateTaxRecordValues() {
files: uploadedFiles,
addReminderRecord: addReminderRecord
}
}
function deleteTaxRecordFile(fileLocation, event) {
event.parentElement.remove();
uploadedFiles = uploadedFiles.filter(x => x.location != fileLocation);
}
29 changes: 29 additions & 0 deletions wwwroot/js/vehicle.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,33 @@ function getVehicleHaveImportantReminders(vehicleId) {
}
});
}, 500);
}

function deleteFileFromUploadedFiles(fileLocation, event) {
event.parentElement.parentElement.parentElement.remove();
uploadedFiles = uploadedFiles.filter(x => x.location != fileLocation);
}
function editFileName(fileLocation, event) {
Swal.fire({
title: 'Rename File',
html: `
<input type="text" id="newFileName" class="swal2-input" placeholder="New File Name">
`,
confirmButtonText: 'Rename',
focusConfirm: false,
preConfirm: () => {
const newFileName = $("#newFileName").val();
if (!newFileName) {
Swal.showValidationMessage(`Please enter a valid file name`)
}
return { newFileName }
},
}).then(function (result) {
if (result.isConfirmed) {
var linkDisplayObject = $(event.parentElement.parentElement).find('a')[0];
linkDisplayObject.text = result.value.newFileName;
var editFileIndex = uploadedFiles.findIndex(x => x.location == fileLocation);
uploadedFiles[editFileIndex].name = result.value.newFileName;
}
});
}

0 comments on commit ba14956

Please sign in to comment.