From 42600422ca0d283408c0616b76a40af0388f9e7a Mon Sep 17 00:00:00 2001 From: Joshua Lester Date: Tue, 22 Oct 2024 15:49:47 -0700 Subject: [PATCH 01/11] Counting mechanism works --- EssentialCSharp.Web/Controllers/HomeController.cs | 1 + EssentialCSharp.Web/Views/Shared/_Layout.cshtml | 7 +++++-- EssentialCSharp.Web/wwwroot/js/site.js | 6 ++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/EssentialCSharp.Web/Controllers/HomeController.cs b/EssentialCSharp.Web/Controllers/HomeController.cs index 21b9d903..a701b201 100644 --- a/EssentialCSharp.Web/Controllers/HomeController.cs +++ b/EssentialCSharp.Web/Controllers/HomeController.cs @@ -30,6 +30,7 @@ public IActionResult Index() ViewBag.PageTitle = siteMapping.IndentLevel is 0 ? siteMapping.ChapterTitle + " " + siteMapping.RawHeading : siteMapping.RawHeading; ViewBag.NextPage = FlipPage(siteMapping!.ChapterNumber, siteMapping.PageNumber, true); + ViewBag.CurrentPageKey = siteMapping.Key; ViewBag.PreviousPage = FlipPage(siteMapping.ChapterNumber, siteMapping.PageNumber, false); ViewBag.HeadContents = headHtml; ViewBag.Contents = html; diff --git a/EssentialCSharp.Web/Views/Shared/_Layout.cshtml b/EssentialCSharp.Web/Views/Shared/_Layout.cshtml index e7e63787..a0c9aa00 100644 --- a/EssentialCSharp.Web/Views/Shared/_Layout.cshtml +++ b/EssentialCSharp.Web/Views/Shared/_Layout.cshtml @@ -124,6 +124,9 @@ {{chapterParentPage.title}} +
@@ -269,7 +272,8 @@ @{ var tocData = _SiteMappings.GetTocData(); } - + CURRENT_PAGE_COUNT = @Json.Serialize(currentPageCount) + TOTAL_PAGE_COUNT = @Json.Serialize(overallCount) PREVIOUS_PAGE = @Json.Serialize(ViewBag.PreviousPage) NEXT_PAGE = @Json.Serialize(ViewBag.NextPage) TOC_DATA = @Json.Serialize(tocData) @@ -320,6 +324,5 @@ - diff --git a/EssentialCSharp.Web/wwwroot/js/site.js b/EssentialCSharp.Web/wwwroot/js/site.js index 917d0b3e..49c5bc82 100644 --- a/EssentialCSharp.Web/wwwroot/js/site.js +++ b/EssentialCSharp.Web/wwwroot/js/site.js @@ -18,6 +18,7 @@ import { useWindowSize } from "vue-window-size"; * @prop {TocItem[]} [items] */ /** @type {TocItem} */ +debugger; const tocData = markRaw(TOC_DATA); //Add new content or features here: @@ -210,6 +211,9 @@ const app = createApp({ const currentPage = findCurrentPage([], tocData) ?? []; + const currentPageCount = CURRENT_PAGE_COUNT; + const totalPageCount = TOTAL_PAGE_COUNT; + const chapterParentPage = currentPage.find((parent) => parent.level === 0); const sectionTitle = ref(currentPage?.[0]?.title || "Essential C#"); @@ -334,6 +338,8 @@ const app = createApp({ tocData, expandedTocs, currentPage, + currentPageCount, + totalPageCount, chapterParentPage, searchQuery, From 3db3d2e78bcd8d9bcb5e9151d87b06e21749042c Mon Sep 17 00:00:00 2001 From: Joshua Lester Date: Wed, 23 Oct 2024 08:59:28 -0700 Subject: [PATCH 02/11] save changes --- EssentialCSharp.Web/Controllers/HomeController.cs | 2 ++ EssentialCSharp.Web/Views/Shared/_Layout.cshtml | 4 +++- EssentialCSharp.Web/wwwroot/js/site.js | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/EssentialCSharp.Web/Controllers/HomeController.cs b/EssentialCSharp.Web/Controllers/HomeController.cs index a701b201..c31f3515 100644 --- a/EssentialCSharp.Web/Controllers/HomeController.cs +++ b/EssentialCSharp.Web/Controllers/HomeController.cs @@ -44,6 +44,8 @@ public IActionResult Index() } } + + [Route("/TermsOfService", Name = "TermsOfService")] public IActionResult TermsOfService() diff --git a/EssentialCSharp.Web/Views/Shared/_Layout.cshtml b/EssentialCSharp.Web/Views/Shared/_Layout.cshtml index a0c9aa00..00701274 100644 --- a/EssentialCSharp.Web/Views/Shared/_Layout.cshtml +++ b/EssentialCSharp.Web/Views/Shared/_Layout.cshtml @@ -125,7 +125,8 @@ {{chapterParentPage.title}}
@@ -274,6 +275,7 @@ } CURRENT_PAGE_COUNT = @Json.Serialize(currentPageCount) TOTAL_PAGE_COUNT = @Json.Serialize(overallCount) + KEY_LIST = @Json.Serialize(keyList) PREVIOUS_PAGE = @Json.Serialize(ViewBag.PreviousPage) NEXT_PAGE = @Json.Serialize(ViewBag.NextPage) TOC_DATA = @Json.Serialize(tocData) diff --git a/EssentialCSharp.Web/wwwroot/js/site.js b/EssentialCSharp.Web/wwwroot/js/site.js index 49c5bc82..34a05d5f 100644 --- a/EssentialCSharp.Web/wwwroot/js/site.js +++ b/EssentialCSharp.Web/wwwroot/js/site.js @@ -213,6 +213,7 @@ const app = createApp({ const currentPageCount = CURRENT_PAGE_COUNT; const totalPageCount = TOTAL_PAGE_COUNT; + const keyList = KEY_LIST const chapterParentPage = currentPage.find((parent) => parent.level === 0); @@ -340,6 +341,7 @@ const app = createApp({ currentPage, currentPageCount, totalPageCount, + keyList, chapterParentPage, searchQuery, From 103a88e1af1fcb665f68610d69ccfe6e9c0fc536 Mon Sep 17 00:00:00 2001 From: Joshua Lester Date: Tue, 12 Nov 2024 12:15:09 -0800 Subject: [PATCH 03/11] save --- EssentialCSharp.Web/Views/Shared/_Layout.cshtml | 1 - 1 file changed, 1 deletion(-) diff --git a/EssentialCSharp.Web/Views/Shared/_Layout.cshtml b/EssentialCSharp.Web/Views/Shared/_Layout.cshtml index 00701274..d4543884 100644 --- a/EssentialCSharp.Web/Views/Shared/_Layout.cshtml +++ b/EssentialCSharp.Web/Views/Shared/_Layout.cshtml @@ -125,7 +125,6 @@ {{chapterParentPage.title}} From 5d32de2c9679011fcd6a5dd6a416ad0bfc4962c5 Mon Sep 17 00:00:00 2001 From: Joshua Lester Date: Fri, 22 Nov 2024 10:17:55 -0800 Subject: [PATCH 04/11] Reimplemented it to account for bug --- .../Services/ISiteMappingService.cs | 3 +- .../Services/SiteMappingService.cs | 34 +++++++++++++++++-- .../Views/Shared/_Layout.cshtml | 9 +++-- EssentialCSharp.Web/wwwroot/js/site.js | 17 +++++----- 4 files changed, 47 insertions(+), 16 deletions(-) diff --git a/EssentialCSharp.Web/Services/ISiteMappingService.cs b/EssentialCSharp.Web/Services/ISiteMappingService.cs index ac2a719e..2c99b1af 100644 --- a/EssentialCSharp.Web/Services/ISiteMappingService.cs +++ b/EssentialCSharp.Web/Services/ISiteMappingService.cs @@ -1,7 +1,8 @@ -namespace EssentialCSharp.Web.Services; +namespace EssentialCSharp.Web.Services; public interface ISiteMappingService { IList SiteMappings { get; } IEnumerable GetTocData(); + string GetPercentComplete(string currentPageKey); } diff --git a/EssentialCSharp.Web/Services/SiteMappingService.cs b/EssentialCSharp.Web/Services/SiteMappingService.cs index 9eafb3a9..64524be0 100644 --- a/EssentialCSharp.Web/Services/SiteMappingService.cs +++ b/EssentialCSharp.Web/Services/SiteMappingService.cs @@ -1,4 +1,6 @@ -using EssentialCSharp.Web.Models; +using System.Globalization; +using EssentialCSharp.Common; +using EssentialCSharp.Web.Models; namespace EssentialCSharp.Web.Services; @@ -12,7 +14,6 @@ public SiteMappingService(IWebHostEnvironment webHostEnvironment) List? siteMappings = System.Text.Json.JsonSerializer.Deserialize>(File.OpenRead(path)) ?? throw new InvalidOperationException("No table of contents found"); SiteMappings = siteMappings; } - public IEnumerable GetTocData() { return SiteMappings.GroupBy(x => x.ChapterNumber).OrderBy(x => x.Key).Select(x => @@ -50,4 +51,33 @@ private static IEnumerable GetItems(IEnumerable cha Items = GetItems(chapterItems.SkipWhile(q => i.Keys.First() != q.Keys.First()).Skip(1), indentLevel + 1) }); } + + public string GetPercentComplete(string currentPageKey) + { + int currentMappingCount = 1; + int overallMappingCount = 1; + bool currentPageFound = false; + IEnumerable> chapterGroupings = SiteMappings.GroupBy(x => x.ChapterNumber).OrderBy(g => g.Key); + foreach (IGrouping chapterGrouping in chapterGroupings) + { + IEnumerable> pageGroupings = chapterGrouping.GroupBy(x => x.PageNumber).OrderBy(g => g.Key); + foreach (IGrouping pageGrouping in pageGroupings) + { + foreach (SiteMapping siteMapping in pageGrouping) + { + if (siteMapping.Key == currentPageKey) + { + currentPageFound = true; + } + if (!currentPageFound) + { + currentMappingCount++; + } + overallMappingCount++; + } + } + } + double result = (double)currentMappingCount / overallMappingCount * 100; + return string.Format(CultureInfo.InvariantCulture, "{0:0.00}", result); + } } diff --git a/EssentialCSharp.Web/Views/Shared/_Layout.cshtml b/EssentialCSharp.Web/Views/Shared/_Layout.cshtml index d4543884..ea59cf52 100644 --- a/EssentialCSharp.Web/Views/Shared/_Layout.cshtml +++ b/EssentialCSharp.Web/Views/Shared/_Layout.cshtml @@ -124,8 +124,8 @@ {{chapterParentPage.title}} -