diff --git a/Enum/ImportMode.cs b/Enum/ImportMode.cs index 27e3f58..b2f5f01 100644 --- a/Enum/ImportMode.cs +++ b/Enum/ImportMode.cs @@ -9,6 +9,7 @@ UpgradeRecord = 4, ReminderRecord = 5, NoteRecord = 6, - SupplyRecord = 7 + SupplyRecord = 7, + Dashboard = 8 } } diff --git a/Helper/ConfigHelper.cs b/Helper/ConfigHelper.cs index 50c3d99..6d7b50c 100644 --- a/Helper/ConfigHelper.cs +++ b/Helper/ConfigHelper.cs @@ -95,7 +95,8 @@ namespace CarCareTracker.Helper HideZero = bool.Parse(_config[nameof(UserConfig.HideZero)]), UseUKMPG = bool.Parse(_config[nameof(UserConfig.UseUKMPG)]), UseThreeDecimalGasCost = bool.Parse(_config[nameof(UserConfig.UseThreeDecimalGasCost)]), - VisibleTabs = _config.GetSection("VisibleTabs").Get>() + VisibleTabs = _config.GetSection("VisibleTabs").Get>(), + DefaultTab = (ImportMode)int.Parse(_config[nameof(UserConfig.DefaultTab)]) }; int userId = 0; if (user != null) diff --git a/Helper/StaticHelper.cs b/Helper/StaticHelper.cs index 04633cc..96036d2 100644 --- a/Helper/StaticHelper.cs +++ b/Helper/StaticHelper.cs @@ -1,4 +1,6 @@ -namespace CarCareTracker.Helper +using CarCareTracker.Models; + +namespace CarCareTracker.Helper { /// /// helper method for static vars @@ -18,10 +20,48 @@ if (input.Length > maxLength) { return (input.Substring(0, maxLength) + "..."); - } else + } + else { return input; } } + public static string DefaultActiveTab(UserConfig userConfig, ImportMode tab) + { + var defaultTab = userConfig.DefaultTab; + var visibleTabs = userConfig.VisibleTabs; + if (visibleTabs.Contains(tab) && tab == defaultTab) + { + return "active"; + } + else if (!visibleTabs.Contains(tab)) + { + return "d-none"; + } + return ""; + } + public static string DefaultActiveTabContent(UserConfig userConfig, ImportMode tab) + { + var defaultTab = userConfig.DefaultTab; + if (tab == defaultTab) + { + return "show active"; + } + return ""; + } + public static string DefaultTabSelected(UserConfig userConfig, ImportMode tab) + { + var defaultTab = userConfig.DefaultTab; + var visibleTabs = userConfig.VisibleTabs; + if (!visibleTabs.Contains(tab)) + { + return "disabled"; + } + else if (tab == defaultTab) + { + return "selected"; + } + return ""; + } } } diff --git a/Models/UserConfig.cs b/Models/UserConfig.cs index 94d45be..7029050 100644 --- a/Models/UserConfig.cs +++ b/Models/UserConfig.cs @@ -12,6 +12,15 @@ public bool UseThreeDecimalGasCost { get; set; } public string UserNameHash { get; set; } public string UserPasswordHash { get; set;} - public List VisibleTabs { get; set; } = new List(); + public List VisibleTabs { get; set; } = new List() { + ImportMode.Dashboard, + ImportMode.ServiceRecord, + ImportMode.RepairRecord, + ImportMode.GasRecord, + ImportMode.UpgradeRecord, + ImportMode.TaxRecord, + ImportMode.ReminderRecord, + ImportMode.NoteRecord}; + public ImportMode DefaultTab { get; set; } = ImportMode.Dashboard; } } \ No newline at end of file diff --git a/Views/Home/_Settings.cshtml b/Views/Home/_Settings.cshtml index b687291..32dfc4f 100644 --- a/Views/Home/_Settings.cshtml +++ b/Views/Home/_Settings.cshtml @@ -1,4 +1,5 @@ -@model UserConfig +@using CarCareTracker.Helper +@model UserConfig
@@ -53,6 +54,10 @@ +
  • + + +
  • @@ -88,7 +93,24 @@
  • - +
    +
    + Default Tab +
    +
    + +
    +
    @@ -140,6 +162,10 @@ } function updateSettings(){ var visibleTabs = getCheckedTabs(); + var defaultTab = $("#defaultTab").val(); + if (!visibleTabs.includes(defaultTab)){ + defaultTab = "Dashboard"; //default to dashboard. + } var userConfigObject = { useDarkMode: $("#enableDarkMode").is(':checked'), enableCsvImports: $("#enableCsvImports").is(':checked'), @@ -148,7 +174,8 @@ hideZero: $("#hideZero").is(":checked"), useUKMpg: $("#useUKMPG").is(":checked"), useThreeDecimalGasCost: $("#useThreeDecimal").is(":checked"), - visibleTabs: visibleTabs + visibleTabs: visibleTabs, + defaultTab: defaultTab } sloader.show(); $.post('/Home/WriteToSettings', { userConfig: userConfigObject}, function(data){ diff --git a/Views/Vehicle/Index.cshtml b/Views/Vehicle/Index.cshtml index 711b3ac..4b93dee 100644 --- a/Views/Vehicle/Index.cshtml +++ b/Views/Vehicle/Index.cshtml @@ -4,7 +4,7 @@ } @inject IConfigHelper config @{ - var visibleTabs = config.GetUserConfig(User).VisibleTabs; + var userConfig = config.GetUserConfig(User); } @model Vehicle @section Scripts { @@ -28,28 +28,28 @@