Skip to content

Commit 6aad531

Browse files
authored
Merge pull request #1040 from hargata/Hargata/1039
use culture invariant when converting opacity to string.
2 parents 31690bc + 10b420c commit 6aad531

File tree

7 files changed

+85
-8
lines changed

7 files changed

+85
-8
lines changed

Helper/FileHelper.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using CarCareTracker.Models;
2+
using CsvHelper;
3+
using System.Globalization;
24
using System.IO.Compression;
35

46
namespace CarCareTracker.Helper
@@ -241,14 +243,41 @@ public string MakeAttachmentsExport(List<GenericReportModel> exportData)
241243
if (!Directory.Exists(tempPath))
242244
Directory.CreateDirectory(tempPath);
243245
int fileIndex = 0;
246+
List<AttachmentExportModel> urlAttachments = new List<AttachmentExportModel>();
244247
foreach (GenericReportModel reportModel in exportData)
245248
{
246249
foreach (UploadedFiles file in reportModel.Files)
247250
{
248251
var fileToCopy = GetFullFilePath(file.Location);
249252
var destFileName = $"{tempPath}/{fileIndex}_{reportModel.DataType}_{reportModel.Date.ToString("yyyy-MM-dd")}_{file.Name}{Path.GetExtension(file.Location)}";
250-
File.Copy(fileToCopy, destFileName);
251-
fileIndex++;
253+
if (File.Exists(fileToCopy))
254+
{
255+
File.Copy(fileToCopy, destFileName);
256+
fileIndex++;
257+
} else
258+
{
259+
//file not found, must be a URL
260+
urlAttachments.Add(new AttachmentExportModel {
261+
DataType = reportModel.DataType.ToString(),
262+
Date = reportModel.Date.ToString("yyyy-MM-dd"),
263+
Name = file.Name,
264+
Location = file.Location
265+
});
266+
}
267+
}
268+
}
269+
if (urlAttachments.Any())
270+
{
271+
//write csv file detailing all urls.
272+
var destFileName = $"{tempPath}/link_attachments.csv";
273+
using (var writer = new StreamWriter(destFileName))
274+
{
275+
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
276+
{
277+
//custom writer
278+
StaticHelper.WriteAttachmentExportModel(csv, urlAttachments);
279+
}
280+
writer.Dispose();
252281
}
253282
}
254283
var destFilePath = $"{tempPath}.zip";

Helper/StaticHelper.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace CarCareTracker.Helper
1212
/// </summary>
1313
public static class StaticHelper
1414
{
15-
public const string VersionNumber = "1.5.0";
15+
public const string VersionNumber = "1.5.1";
1616
public const string DbName = "data/cartracker.db";
1717
public const string UserConfigPath = "data/config/userConfig.json";
1818
public const string ServerConfigPath = "data/config/serverConfig.json";
@@ -709,6 +709,23 @@ public static void WritePlanRecordExportModel(CsvWriter _csv, IEnumerable<PlanRe
709709
_csv.NextRecord();
710710
}
711711
}
712+
public static void WriteAttachmentExportModel(CsvWriter _csv, IEnumerable<AttachmentExportModel> genericRecords)
713+
{
714+
//write headers
715+
_csv.WriteField(nameof(AttachmentExportModel.DataType));
716+
_csv.WriteField(nameof(AttachmentExportModel.Date));
717+
_csv.WriteField(nameof(AttachmentExportModel.Name));
718+
_csv.WriteField(nameof(AttachmentExportModel.Location));
719+
_csv.NextRecord();
720+
foreach (AttachmentExportModel genericRecord in genericRecords)
721+
{
722+
_csv.WriteField(genericRecord.DataType);
723+
_csv.WriteField(genericRecord.Date);
724+
_csv.WriteField(genericRecord.Name);
725+
_csv.WriteField(genericRecord.Location);
726+
_csv.NextRecord();
727+
}
728+
}
712729
public static string HideZeroCost(string input, bool hideZero, string decorations = "")
713730
{
714731
if (input == 0M.ToString("C2") && hideZero)

Models/Shared/ImportModel.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,11 @@ public class UserExportModel
176176
[JsonConverter(typeof(FromBoolOptional))]
177177
public string IsRoot { get; set; }
178178
}
179+
public class AttachmentExportModel
180+
{
181+
public string DataType { get; set; }
182+
public string Date { get; set; }
183+
public string Name { get; set; }
184+
public string Location { get; set; }
185+
}
179186
}

Views/Vehicle/Index.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,11 @@
187187
<button type="button" class="btn btn-outline-secondary" onclick="performGlobalSearch()"><i class="bi bi-search"></i></button>
188188
</div>
189189
<div class="form-check form-check-inline form-switch mt-1">
190-
<input class="form-check-input" type="checkbox" role="switch" id="globalSearchAutoSearchCheck" checked>
190+
<input class="form-check-input" type="checkbox" role="switch" onchange="saveGlobalSearchSettings()" id="globalSearchAutoSearchCheck" checked>
191191
<label class="form-check-label" for="globalSearchAutoSearchCheck">@translator.Translate(userLanguage, "Incremental Search")</label>
192192
</div>
193193
<div class="form-check form-check-inline form-switch mt-1">
194-
<input class="form-check-input" type="checkbox" onChange="performGlobalSearch()" role="switch" id="globalSearchCaseSensitiveCheck" checked>
194+
<input class="form-check-input" type="checkbox" onchange="performGlobalSearch()" role="switch" id="globalSearchCaseSensitiveCheck" checked>
195195
<label class="form-check-label" for="globalSearchCaseSensitiveCheck">@translator.Translate(userLanguage, "Case Sensitive")</label>
196196
</div>
197197
<div id="globalSearchModalResults"></div>

Views/Vehicle/Plan/_PlanRecordItem.cshtml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
@model PlanRecord
1+
@using CarCareTracker.Helper
2+
@inject IConfigHelper config
3+
@{
4+
var userConfig = config.GetUserConfig(User);
5+
var hideZero = userConfig.HideZero;
6+
}
7+
@model PlanRecord
28
<div class="taskCard @(Model.Progress == PlanProgress.Done ? "nodrag" : "") text-dark user-select-none mt-2 mb-2" draggable="@(Model.Progress == PlanProgress.Done ? "false" : "true")" ondragstart="dragStart(event, @Model.Id)" onclick="@(Model.Progress == PlanProgress.Done ? $"deletePlanRecord({Model.Id}, true)" : $"showEditPlanRecordModal({Model.Id})")" oncontextmenu="@($"showPlanTableContextMenu(this, {Model.Id}, '{Model.Progress}')")" onmouseup="stopEvent()" ontouchstart="detectPlanItemLongTouch(this, @Model.Id, '@Model.Progress')" ontouchend="detectPlanItemTouchEndPremature(this)">
39
<div class="card-body">
410
<div class="row">
@@ -12,7 +18,7 @@
1218
}
1319
</div>
1420
<div class="col-12 col-lg-4 d-flex align-items-center">
15-
<span class="text-truncate">@Model.Cost.ToString("C2")</span>
21+
<span class="text-truncate">@(StaticHelper.HideZeroCost(Model.Cost, hideZero))</span>
1622
</div>
1723
</div>
1824
<div class="row">

Views/Vehicle/_VehicleImageMap.cshtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@using CarCareTracker.Helper
2+
@using System.Globalization
23
@inject IConfigHelper config
34
@inject ITranslationHelper translator
45
@{
@@ -22,7 +23,7 @@
2223
@foreach(ImageMap imageMap in Model.Map)
2324
{
2425
<a style='cursor:pointer;' onclick='loadRecordsByTags("@imageMap.Tags")'>
25-
<polygon points="@imageMap.Coordinates" fill="@imageMap.Color" opacity="@imageMap.Opacity"></polygon>
26+
<polygon points="@imageMap.Coordinates" fill="@imageMap.Color" opacity="@imageMap.Opacity.ToString(CultureInfo.InvariantCulture)"></polygon>
2627
</a>
2728
}
2829
</svg>

wwwroot/js/vehicle.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,10 +660,26 @@ function getLastOdometerReadingAndIncrement(odometerFieldName) {
660660

661661
function showGlobalSearch() {
662662
$('#globalSearchModal').modal('show');
663+
restoreGlobalSearchSettings();
663664
}
664665
function hideGlobalSearch() {
665666
$('#globalSearchModal').modal('hide');
666667
}
668+
function saveGlobalSearchSettings() {
669+
let globalSearchSettings = {
670+
incrementalSearch: $('#globalSearchAutoSearchCheck').is(':checked'),
671+
caseSensitive: $('#globalSearchCaseSensitiveCheck').is(':checked')
672+
};
673+
localStorage.setItem('globalSearchSettings', JSON.stringify(globalSearchSettings));
674+
}
675+
function restoreGlobalSearchSettings() {
676+
let globalSearchSettings = localStorage.getItem('globalSearchSettings');
677+
if (globalSearchSettings != null) {
678+
let parsedGlobalSearchSettings = JSON.parse(globalSearchSettings);
679+
$('#globalSearchAutoSearchCheck').attr('checked', parsedGlobalSearchSettings.incrementalSearch);
680+
$('#globalSearchCaseSensitiveCheck').attr('checked', parsedGlobalSearchSettings.caseSensitive);
681+
}
682+
}
667683
function performGlobalSearch() {
668684
var searchQuery = $('#globalSearchInput').val();
669685
if (searchQuery.trim() == '') {
@@ -672,6 +688,7 @@ function performGlobalSearch() {
672688
$('#globalSearchInput').removeClass('is-invalid');
673689
}
674690
let caseSensitiveSearch = $("#globalSearchCaseSensitiveCheck").is(':checked');
691+
saveGlobalSearchSettings();
675692
$.post('/Vehicle/SearchRecords', { vehicleId: GetVehicleId().vehicleId, searchQuery: searchQuery, caseSensitive: caseSensitiveSearch }, function (data) {
676693
$('#globalSearchModalResults').html(data);
677694
});

0 commit comments

Comments
 (0)