Skip to content

Commit 245bea8

Browse files
Counting mechanism works
1 parent c41630a commit 245bea8

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

EssentialCSharp.Web/Controllers/HomeController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public IActionResult Index(string key)
4141

4242
ViewBag.PageTitle = siteMapping.IndentLevel is 0 ? siteMapping.ChapterTitle + " " + siteMapping.RawHeading : siteMapping.RawHeading;
4343
ViewBag.NextPage = FlipPage(siteMapping!.ChapterNumber, siteMapping.PageNumber, true);
44+
ViewBag.CurrentPageKey = siteMapping.Key;
4445
ViewBag.PreviousPage = FlipPage(siteMapping.ChapterNumber, siteMapping.PageNumber, false);
4546
ViewBag.HeadContents = headHtml;
4647
ViewBag.Contents = html;

EssentialCSharp.Web/Views/Shared/_Layout.cshtml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@
123123
<a v-if="chapterParentPage" :href="chapterParentPage.href" class="menu-chapter-title text-light">
124124
<span v-cloak>{{chapterParentPage.title}}</span>
125125
</a>
126+
<div class="menu-chapter-title text-light">
127+
{{currentPageCount}} / {{totalPageCount}}
128+
</div>
126129

127130
<div class="d-flex align-items-center">
128131
<div class="border-end pe-3 d-none d-md-block">
@@ -292,8 +295,29 @@
292295
Title = $"Chapter {x.Key}: {x.First().ChapterTitle}",
293296
Items = GetItems(x, 1)
294297
});
298+
var groupedTocData = _SiteMappings.SiteMappings.GroupBy(x => x.ChapterNumber).OrderBy(x => x.Key);
299+
int currentPageCount = 0;
300+
int overallCount = 0;
301+
bool currentPageFound = false;
302+
foreach (IGrouping<int, SiteMapping> group in groupedTocData)
303+
{
304+
var orderedGroup = group.OrderBy(x => x.PageNumber);
305+
foreach (SiteMapping siteMapping in orderedGroup)
306+
{
307+
if (siteMapping.Key == ViewBag.CurrentPageKey)
308+
{
309+
currentPageFound = true;
310+
}
311+
if (!currentPageFound)
312+
{
313+
currentPageCount++;
314+
}
315+
overallCount++;
316+
}
317+
}
295318
}
296-
319+
CURRENT_PAGE_COUNT = @Json.Serialize(currentPageCount)
320+
TOTAL_PAGE_COUNT = @Json.Serialize(overallCount)
297321
PREVIOUS_PAGE = @Json.Serialize(ViewBag.PreviousPage)
298322
NEXT_PAGE = @Json.Serialize(ViewBag.NextPage)
299323
TOC_DATA = @Json.Serialize(tocData)
@@ -343,6 +367,5 @@
343367
</li>
344368
</template>
345369
<script src="~/js/site.js" type="module" asp-append-version="true"></script>
346-
347370
</body>
348371
</html>

EssentialCSharp.Web/wwwroot/js/site.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { useWindowSize } from "vue-window-size";
1818
* @prop {TocItem[]} [items]
1919
*/
2020
/** @type {TocItem} */
21+
debugger;
2122
const tocData = markRaw(TOC_DATA);
2223

2324
//Add new content or features here:
@@ -194,6 +195,9 @@ const app = createApp({
194195

195196
const currentPage = findCurrentPage([], tocData) ?? [];
196197

198+
const currentPageCount = CURRENT_PAGE_COUNT;
199+
const totalPageCount = TOTAL_PAGE_COUNT;
200+
197201
const chapterParentPage = currentPage.find((parent) => parent.level === 0);
198202

199203
const sectionTitle = ref(currentPage?.[0]?.title || "Essential C#");
@@ -311,6 +315,8 @@ const app = createApp({
311315
tocData,
312316
expandedTocs,
313317
currentPage,
318+
currentPageCount,
319+
totalPageCount,
314320
chapterParentPage,
315321

316322
searchQuery,

0 commit comments

Comments
 (0)