Skip to content

Commit de7a724

Browse files
authored
Merge pull request #94 from telerik/new-structure
chore: implement new structure
2 parents f7bc5d8 + a6b833c commit de7a724

File tree

6 files changed

+314
-97
lines changed

6 files changed

+314
-97
lines changed

Telerik.Examples.Mvc/Telerik.Examples.Mvc/Controllers/HomeController.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
using Microsoft.AspNetCore.Mvc.Infrastructure;
1010
using Microsoft.AspNetCore.Mvc.Controllers;
1111
using System.Text.RegularExpressions;
12+
using System.IO;
13+
using System.Text.Json;
1214

1315
namespace Telerik.Examples.Mvc.Controllers
1416
{
@@ -24,9 +26,8 @@ public HomeController(ILogger<HomeController> logger, IActionDescriptorCollectio
2426
}
2527

2628
public IActionResult Index()
27-
{
28-
29-
var demoEndpoints = this._actionDescriptorCollectionProvider.ActionDescriptors.Items
29+
{
30+
var list = this._actionDescriptorCollectionProvider.ActionDescriptors.Items
3031
.OfType<ControllerActionDescriptor>()
3132
.Where(w => w.ControllerName.Replace("Controller",String.Empty) == w.ActionName)
3233
.Select(s => new Demo
@@ -35,10 +36,11 @@ public IActionResult Index()
3536
ControllerName = s.ControllerName,
3637
ActionName = s.ActionName
3738
})
38-
.GroupBy(g => g.ComponentName)
3939
.ToList();
40+
41+
System.IO.File.WriteAllBytes(Directory.GetCurrentDirectory() + "/wwwroot/files/ExamplesEndpoints.txt", JsonSerializer.SerializeToUtf8Bytes(list));
4042

41-
return View(demoEndpoints);
43+
return View();
4244
}
4345

4446
public IActionResult Privacy()
Lines changed: 5 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,9 @@
11
@{
2-
ViewData["Title"] = "Home Page";
2+
ViewBag.Title = "Home Page";
33
}
44

5-
@model IEnumerable<IGrouping<string,Demo>>
6-
7-
<h2 class="text-center">Navigate to an example of your choice</h2>
8-
<p>The Telerik.Examples.Mvc project is comprised of a number of pages that aim to depict a certain functionality or behavior of the different Telerik UI components.</p>
9-
10-
<div class="nav-list">
11-
@foreach (var component in Model)
12-
{
13-
<h4 class="nav-list-header">
14-
@component.Key
15-
</h4>
16-
foreach (var demoName in component.Select(s => s.ActionName).Distinct())
17-
{
18-
var href = "/" + demoName + "/" + demoName;
19-
<li class="nav-list-item">
20-
<a href="@href">@demoName</a>
21-
</li>
22-
}
23-
24-
}
5+
<div class="jumbotron index-container">
6+
<h1>Welcome to the Telerik UI for Core Examples Repository</h1>
7+
<p class="lead text-muted">Select an example from the list to the left and then you can see it in action. Furthermore, you can select the tab options in order to see the code files in a convenient fashion. Click on the image below to read more about the product:</p>
8+
<a href="https://www.telerik.com/aspnet-core-ui" alt="https://www.telerik.com/aspnet-core-ui" target="_blank"><img style="width: 1110px" src="~/images/logo.png" /></a>
259
</div>
26-
27-
<script>
28-
$(document).ready(function () {
29-
var headers = $(".nav-list").find(".nav-list-header");
30-
31-
headers.each(function (i, e) {
32-
var header = $(e);
33-
var list = header.nextUntil(".nav-list-header").wrapAll("<ul class='nav-list-items-wrap'></ul>");
34-
35-
header.wrap("<div class='nav-list-col'></div>");
36-
header.parent().append(list.parent());
37-
});
38-
});
39-
</script>
40-
41-
<style>
42-
.nav-list {
43-
display: flex;
44-
flex-wrap: wrap;
45-
}
46-
.nav-list-col {
47-
flex: 1 1 50%;
48-
min-width: 400px;
49-
}
50-
.nav-list-header {
51-
margin-top: 30px;
52-
}
53-
.nav-list-items-wrap {
54-
list-style: none;
55-
}
56-
.nav-list-item {
57-
overflow: hidden;
58-
text-overflow: ellipsis;
59-
}
60-
</style>

Telerik.Examples.Mvc/Telerik.Examples.Mvc/Views/Shared/_Layout.cshtml

Lines changed: 126 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<!DOCTYPE html>
1+
@using System.IO
2+
@using System.Text.Json
3+
<!DOCTYPE html>
24
<html lang="en">
35
<head>
46
<meta charset="utf-8" />
@@ -9,14 +11,63 @@
911
var themeVersion = "11.0.2";
1012
}
1113
<link href="https://kendo.cdn.telerik.com/themes/@themeVersion/default/default-ocean-blue.css" rel="stylesheet" type="text/css" />
12-
14+
1315
<script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
1416
<script src="https://unpkg.com/jszip/dist/jszip.min.js"></script>
1517
<script src="https://kendo.cdn.telerik.com/@kendoVersion/js/kendo.all.min.js"></script>
1618
<script src="https://kendo.cdn.telerik.com/@kendoVersion/js/kendo.aspnetmvc.min.js"></script>
1719

1820
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
1921
<link rel="stylesheet" href="~/css/site.css" />
22+
23+
<script>
24+
function searchExamples() {
25+
sessionStorage["searchValue"] = $(".k-searchbox input").val();
26+
27+
$("#panelbar").data().kendoPanelBar.items().each(function (i, el) {
28+
var item = $(el);
29+
var condition = true;
30+
var literals = $(".k-searchbox input").val().split(' ');
31+
for (var i = 0; i < literals.length; i++) {
32+
if (!item.text().replaceAll(' ', '').toLowerCase().includes(literals[i].toLowerCase())) {
33+
condition = false;
34+
break;
35+
}
36+
}
37+
if (condition) {
38+
item.parent().show();
39+
}
40+
else {
41+
item.parent().hide();
42+
}
43+
})
44+
}
45+
function gridSelect(e) {
46+
sessionStorage["position"] = e.sender.element.scrollTop();
47+
var literalParts=e.item.textContent.split(" ");
48+
literalParts.shift();
49+
var exampleName= literalParts.toString().replaceAll(",", "");
50+
window.location ="../"+ exampleName+"/"+exampleName;
51+
}
52+
$(document).ready(function () {
53+
setTimeout(function () {
54+
if (sessionStorage["searchValue"]) {
55+
$(".k-searchbox input").val(sessionStorage["searchValue"]);
56+
$(".k-searchbox input").trigger("onkeyup");
57+
}
58+
59+
var item = $(".k-panelbar-item")
60+
.filter(function (index) {
61+
return $(this).find(".k-panelbar-item-text").text().endsWith($(".title-container").text().trim());
62+
})
63+
var panelBar = $("#panelbar").data().kendoPanelBar;
64+
panelBar.select(item);
65+
if (sessionStorage["position"]) {
66+
panelBar.element.scrollTop(sessionStorage["position"]);
67+
}
68+
}, 20)
69+
})
70+
</script>
2071
</head>
2172
<body>
2273
<header>
@@ -33,23 +84,90 @@
3384
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
3485
</li>
3586
</ul>
36-
@if(ViewContext.RouteData.Values.ContainsKey("controller") && ViewContext.RouteData.Values["controller"].ToString() == "SecurityTrimming")
87+
@if (ViewContext.RouteData.Values.ContainsKey("controller") && ViewContext.RouteData.Values["controller"].ToString() == "SecurityTrimming")
3788
{
38-
<partial name="_LoginPartial"/>
89+
<partial name="_LoginPartial" />
3990
}
4091
</div>
4192
</div>
4293
</nav>
4394
</header>
95+
<div class="toc">
96+
<span class="k-searchbox k-input k-input-md k-rounded-md k-input-solid">
97+
<span class="k-icon k-svg-icon k-svg-i-search k-input-icon">
98+
<svg viewBox="0 0 512 512" focusable="false" xmlns="http://www.w3.org/2000/svg">
99+
<path d="M365.3 320h-22.7l-26.7-26.7C338.5 265.7 352 230.4 352 192c0-88.4-71.6-160-160-160S32 103.6 32 192s71.6 160 160 160c38.4 0 73.7-13.5 101.3-36.1l26.7 26.7v22.7L434.7 480l45.3-45.3zM64 192c0-70.7 57.3-128 128-128s128 57.3 128 128-57.3 128-128 128S64 262.7 64 192">
100+
</path>
101+
</svg>
102+
</span>
103+
<input autocomplete="off" placeholder="Search..." title="Search..." aria-label="Search..." class="k-input-inner" onkeyup="searchExamples();">
104+
</span>
105+
@(Html.Kendo().PanelBar()
106+
.Name("panelbar")
107+
.Events(e => e.Select("gridSelect"))
108+
.ExpandMode(PanelBarExpandMode.Single)
109+
.Items(panelbar =>
110+
{
111+
foreach (var example in (List<Demo>)JsonSerializer.Deserialize<List<Demo>>(File.ReadAllBytes(Directory.GetCurrentDirectory() + "/wwwroot/files/ExamplesEndpoints.txt")))
112+
{
113+
panelbar.Add().Text(example.ComponentName + " " + System.Text.RegularExpressions.Regex.Replace(example.ActionName, "(\\B[A-Z])", " $1"));
114+
}
115+
}))
116+
</div>
44117
<div class="container">
45-
<main role="main" class="pb-3">
46-
@RenderBody()
47-
</main>
118+
<h4 class="title-container">@(System.Text.RegularExpressions.Regex.Replace(ViewContext.HttpContext.Request.Path.Value.Split('/')[1], "(\\B[A-Z])", " $1"))</h4>
119+
@{
120+
RenderBody();
121+
var controllerPath = ViewContext.View.Path.Replace("Views","Controllers").Replace(".cshtml", "")+"Controller.cs";
122+
}
123+
@(Html.Kendo().TabStrip()
124+
.Name("tabstrip-images")
125+
.Items(tabstrip =>
126+
{
127+
tabstrip.Add().Text("Sample")
128+
.Selected(true)
129+
.Content(@<text>
130+
<main role="main" class="pb-3">
131+
@RenderBody()
132+
</main>
133+
</text>);
134+
if (!ViewContext.View.Path.Contains("/Home/")){
135+
tabstrip.Add().Text(ViewContext.View.Path.Split("/")[3])
136+
.Content(@<text>
137+
@{
138+
string line;
139+
System.IO.StreamReader file = new System.IO.StreamReader(Directory.GetCurrentDirectory() + ViewContext.View.Path);
140+
var fileLines = new List<string>();
141+
while ((line = file.ReadLine()) != null)
142+
{
143+
<pre>@line</pre>
144+
}
145+
}
146+
</text>);
147+
}
148+
149+
if (File.Exists(Directory.GetCurrentDirectory()+ViewContext.View.Path.Replace("Views", "Controllers").Replace(".cshtml", "") + "Controller.cs"))
150+
{
151+
tabstrip.Add().Text(ViewContext.View.Path.Split("/")[3].Replace(".cshtml","")+"Controller.cs")
152+
.Content(@<text>
153+
@{
154+
string line;
155+
System.IO.StreamReader file = new System.IO.StreamReader(Directory.GetCurrentDirectory()+
156+
ViewContext.View.Path.Replace("Views","Controllers").Replace(".cshtml", "")+"Controller.cs");
157+
var fileLines = new List<string>();
158+
while ((line = file.ReadLine()) != null)
159+
{
160+
<pre>@line</pre>
161+
}
162+
}
163+
</text>);
164+
}
165+
}))
48166
</div>
49167

50168
<footer class="border-top footer text-muted">
51169
<div class="container">
52-
&copy; @DateTime.Now.Year Telerik.Examples.Mvc
170+
<p>Copyright &copy; @DateTime.Now.Year Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.</p>
53171
</div>
54172
</footer>
55173
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>

0 commit comments

Comments
 (0)