Merge pull request #585 from hargata/Hargata/570

Upload files on paste.
This commit is contained in:
Hargata Softworks
2024-08-21 18:13:14 -06:00
committed by GitHub
25 changed files with 92 additions and 27 deletions

View File

@@ -1795,6 +1795,7 @@ namespace CarCareTracker.Controllers
[HttpPost]
public IActionResult SaveNoteToVehicleId(Note note)
{
note.Files = note.Files.Select(x => { return new UploadedFiles { Name = x.Name, Location = _fileHelper.MoveFileFromTemp(x.Location, "documents/") }; }).ToList();
var result = _noteDataAccess.SaveNoteToVehicle(note);
if (result)
{
@@ -2391,6 +2392,12 @@ namespace CarCareTracker.Controllers
#endregion
#region "Shared Methods"
[HttpPost]
public IActionResult GetFilesPendingUpload(List<UploadedFiles> uploadedFiles)
{
var filesPendingUpload = uploadedFiles.Where(x => x.Location.StartsWith("/temp/")).ToList();
return PartialView("_FilesToUpload", filesPendingUpload);
}
[HttpPost]
[TypeFilter(typeof(CollaboratorFilter))]
public IActionResult SearchRecords(int vehicleId, string searchQuery)
{

View File

@@ -89,10 +89,9 @@
}
<label for="collisionRecordFiles">@translator.Translate(userLanguage, "Upload documents(optional)")</label>
<input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept="@config.GetAllowedFileUploadExtensions()" class="form-control-file" id="collisionRecordFiles">
<br />
<small class="text-body-secondary">@translator.Translate(userLanguage, "Max File Size: 28.6MB")</small>
<br /><small class="text-body-secondary">@translator.Translate(userLanguage, "Max File Size: 28.6MB")</small>
}
<div id="filesPendingUpload"></div>
</div>
</div>
</div>

View File

@@ -151,7 +151,7 @@
</div>
<div class="modal fade" data-bs-focus="false" 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" onpaste="handleModalPaste(event, 'collisionRecordFiles')">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content" id="collisionRecordModalContent">
</div>

View File

@@ -0,0 +1,23 @@
@using CarCareTracker.Helper
@inject IConfigHelper config
@inject ITranslationHelper translator
@{
var userConfig = config.GetUserConfig(User);
var userLanguage = userConfig.UserLanguage;
}
@model List<UploadedFiles>
<label id="documentsPendingUploadLabel">@translator.Translate(userLanguage, "Documents Pending Upload")</label>
<ul class="list-group" id="documentsPendingUploadList">
@foreach (UploadedFiles filesUploaded in Model)
{
<li class="list-group-item">
<div class="d-flex justify-content-between">
<a type="button" class="btn btn-link text-truncate uploadedFileName" 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>

View File

@@ -221,7 +221,7 @@
</div>
<div class="modal fade" data-bs-focus="false" 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" onpaste="handleModalPaste(event, 'gasRecordFiles')">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content" id="gasRecordModalContent">
</div>

View File

@@ -121,6 +121,7 @@
<input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept="@config.GetAllowedFileUploadExtensions()" class="form-control-file" id="gasRecordFiles">
<br /><small class="text-body-secondary">@translator.Translate(userLanguage,"Max File Size: 28.6MB")</small>
}
<div id="filesPendingUpload"></div>
</div>
</div>
</div>

View File

@@ -45,6 +45,7 @@
<br />
<small class="text-body-secondary">@translator.Translate(userLanguage, "Max File Size: 28.6MB")</small>
}
<div id="filesPendingUpload"></div>
</div>
<div class="col-12">
<label for="noteRecordTag">@translator.Translate(userLanguage,"Tags(optional)")</label>

View File

@@ -61,7 +61,7 @@
</div>
<div class="modal fade" data-bs-focus="false" id="noteModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal fade" data-bs-focus="false" id="noteModal" tabindex="-1" role="dialog" aria-hidden="true" onpaste="handleModalPaste(event, 'noteFiles')">
<div class="modal-dialog" role="document">
<div class="modal-content" id="noteModalContent">
</div>

View File

@@ -76,6 +76,7 @@
<input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept="@config.GetAllowedFileUploadExtensions()" class="form-control-file" id="odometerRecordFiles">
<br /><small class="text-body-secondary">@translator.Translate(userLanguage,"Max File Size: 28.6MB")</small>
}
<div id="filesPendingUpload"></div>
</div>
</div>
</div>

View File

@@ -151,7 +151,7 @@
</div>
<div class="modal fade" data-bs-focus="false" id="odometerRecordModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal fade" data-bs-focus="false" id="odometerRecordModal" tabindex="-1" role="dialog" aria-hidden="true" onpaste="handleModalPaste(event, 'odometerRecordFiles')">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content" id="odometerRecordModalContent">
</div>

View File

@@ -73,10 +73,9 @@
{
<label for="planRecordFiles">@translator.Translate(userLanguage, "Upload documents(optional)")</label>
<input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept="@config.GetAllowedFileUploadExtensions()" class="form-control-file" id="planRecordFiles">
<br />
<small class="text-body-secondary">@translator.Translate(userLanguage, "Max File Size: 28.6MB")</small>
<br /><small class="text-body-secondary">@translator.Translate(userLanguage, "Max File Size: 28.6MB")</small>
}
<div id="filesPendingUpload"></div>
</div>
</div>
</div>

View File

@@ -65,10 +65,9 @@
{
<label for="planRecordFiles">@translator.Translate(userLanguage, "Upload documents(optional)")</label>
<input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept="@config.GetAllowedFileUploadExtensions()" class="form-control-file" id="planRecordFiles">
<br />
<small class="text-body-secondary">@translator.Translate(userLanguage, "Max File Size: 28.6MB")</small>
<br /><small class="text-body-secondary">@translator.Translate(userLanguage, "Max File Size: 28.6MB")</small>
}
<div id="filesPendingUpload"></div>
</div>
</div>
</div>

View File

@@ -97,14 +97,14 @@
</div>
<div class="modal fade" data-bs-focus="false" id="planRecordModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal fade" data-bs-focus="false" id="planRecordModal" tabindex="-1" role="dialog" aria-hidden="true" onpaste="handleModalPaste(event, 'planRecordFiles')">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content" id="planRecordModalContent">
</div>
</div>
</div>
<div class="modal fade" data-bs-focus="false" id="planRecordTemplateModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal fade" data-bs-focus="false" id="planRecordTemplateModal" tabindex="-1" role="dialog" aria-hidden="true" onpaste="handleModalPaste(event, 'planRecordFiles')">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content" id="planRecordTemplateModalContent">
</div>

View File

@@ -91,6 +91,7 @@
<input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept="@config.GetAllowedFileUploadExtensions()" class="form-control-file" id="serviceRecordFiles">
<br /><small class="text-body-secondary">@translator.Translate(userLanguage,"Max File Size: 28.6MB")</small>
}
<div id="filesPendingUpload"></div>
</div>
</div>
</div>

View File

@@ -149,7 +149,7 @@
</div>
<div class="modal fade" data-bs-focus="false" 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" onpaste="handleModalPaste(event, 'serviceRecordFiles')">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content" id="serviceRecordModalContent">
</div>

View File

@@ -77,6 +77,7 @@
<input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept="@config.GetAllowedFileUploadExtensions()" class="form-control-file" id="supplyRecordFiles">
<br /><small class="text-body-secondary">@translator.Translate(userLanguage,"Max File Size: 28.6MB")</small>
}
<div id="filesPendingUpload"></div>
</div>
</div>
</div>

View File

@@ -167,7 +167,7 @@
</div>
<div class="modal fade" data-bs-focus="false" id="supplyRecordModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal fade" data-bs-focus="false" id="supplyRecordModal" tabindex="-1" role="dialog" aria-hidden="true" onpaste="handleModalPaste(event, 'supplyRecordFiles')">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content" id="supplyRecordModalContent">
</div>

View File

@@ -92,6 +92,7 @@
<input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept="@config.GetAllowedFileUploadExtensions()" class="form-control-file" id="taxRecordFiles">
<br /><small class="text-body-secondary">@translator.Translate(userLanguage,"Max File Size: 28.6MB")</small>
}
<div id="filesPendingUpload"></div>
</div>
</div>
</div>

View File

@@ -143,7 +143,7 @@
</div>
<div class="modal fade" data-bs-focus="false" 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" onpaste="handleModalPaste(event, 'taxRecordFiles')">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content" id="taxRecordModalContent">
</div>

View File

@@ -89,10 +89,9 @@
}
<label for="upgradeRecordFiles">Upload documents(optional)</label>
<input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept="@config.GetAllowedFileUploadExtensions()" class="form-control-file" id="upgradeRecordFiles">
<br />
<small class="text-body-secondary">@translator.Translate(userLanguage, "Max File Size: 28.6MB")</small>
<br /><small class="text-body-secondary">@translator.Translate(userLanguage, "Max File Size: 28.6MB")</small>
}
<div id="filesPendingUpload"></div>
</div>
</div>
</div>

View File

@@ -150,7 +150,7 @@
</div>
</div>
<div class="modal fade" data-bs-focus="false" id="upgradeRecordModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal fade" data-bs-focus="false" id="upgradeRecordModal" tabindex="-1" role="dialog" aria-hidden="true" onpaste="handleModalPaste(event, 'upgradeRecordFiles')">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content" id="upgradeRecordModalContent">
</div>

View File

@@ -6,8 +6,8 @@
var userLanguage = userConfig.UserLanguage;
}
@model List<UploadedFiles>
<label>@translator.Translate(userLanguage, "Uploaded Documents")</label>
<ul class="list-group">
<label id="uploadedDocumentsLabel">@translator.Translate(userLanguage, "Uploaded Documents")</label>
<ul class="list-group" id="uploadedDocumentsList">
@foreach (UploadedFiles filesUploaded in Model)
{
<li class="list-group-item">

File diff suppressed because one or more lines are too long

View File

@@ -375,8 +375,12 @@ function uploadVehicleFilesAsync(event) {
type: 'POST',
success: function (response) {
sloader.hide();
$(event).val(""); //clear out the filename from the uploader
if (response.length > 0) {
uploadedFiles.push.apply(uploadedFiles, response);
$.post('/Vehicle/GetFilesPendingUpload', { uploadedFiles: uploadedFiles }, function (viewData) {
$("#filesPendingUpload").html(viewData);
});
}
},
error: function () {
@@ -388,6 +392,15 @@ function uploadVehicleFilesAsync(event) {
function deleteFileFromUploadedFiles(fileLocation, event) {
event.parentElement.parentElement.parentElement.remove();
uploadedFiles = uploadedFiles.filter(x => x.location != fileLocation);
if (fileLocation.startsWith("/temp/")) {
if ($("#documentsPendingUploadList > li").length == 0) {
$("#documentsPendingUploadLabel").text("");
}
} else if (fileLocation.startsWith("/documents/")) {
if ($("#uploadedDocumentsList > li").length == 0) {
$("#uploadedDocumentsLabel").text("");
}
}
}
function editFileName(fileLocation, event) {
Swal.fire({
@@ -1056,3 +1069,23 @@ function bindModalInputChanges(modalName) {
$(e.currentTarget).attr('data-changed', true);
});
}
function handleModalPaste(e, recordType) {
var clipboardFiles = e.clipboardData.files;
var acceptableFileFormats = $(`#${recordType}`).attr("accept");
var acceptableFileFormatsArray = acceptableFileFormats.split(',');
var acceptableFiles = new DataTransfer();
if (clipboardFiles.length > 0) {
for (var x = 0; x < clipboardFiles.length; x++) {
if (acceptableFileFormats != "*") {
var fileExtension = `.${clipboardFiles[x].name.split('.').pop()}`;
if (acceptableFileFormatsArray.includes(fileExtension)) {
acceptableFiles.items.add(clipboardFiles[x]);
}
} else {
acceptableFiles.items.add(clipboardFiles[x]);
}
}
$(`#${recordType}`)[0].files = acceptableFiles.files;
$(`#${recordType}`).trigger('change');
}
}

View File

@@ -341,14 +341,14 @@
break;
//COPY EVENT
case 67:
if (event.ctrlKey) {
if (event.ctrlKey || event.metaKey) {
event.preventDefault();
navigator.clipboard.writeText(self.itemsArray.join(" "));
}
break;
//PASTE EVENT
case 86:
if (event.ctrlKey) {
if (event.ctrlKey || event.metaKey) {
setTimeout(function () {
var pastedString = $input.val();
//clear pasted string.