|
1 | 1 | @inherits RazorSliceHttpResult<Elastic.ApiExplorer.Landing.LandingViewModel> |
| 2 | +@using Elastic.ApiExplorer.Landing |
| 3 | +@using Elastic.ApiExplorer.Operations |
| 4 | +@using Elastic.Documentation.Site.Navigation |
2 | 5 | @implements IUsesLayout<Elastic.ApiExplorer._Layout, GlobalLayoutViewModel> |
3 | 6 | @functions { |
4 | 7 | public GlobalLayoutViewModel LayoutModel => Model.CreateGlobalLayoutModel(); |
| 8 | + |
| 9 | + private IHtmlContent RenderOp(IReadOnlyCollection<OperationNavigationItem> endpointOperations) |
| 10 | + { |
| 11 | + <ul class="api-url-listing"> |
| 12 | + @foreach (var overload in endpointOperations) |
| 13 | + { |
| 14 | + var method = overload.Model.OperationType.ToString().ToLowerInvariant(); |
| 15 | + <li class="api-url-list-item"> |
| 16 | + <a href="@overload.Url" class="current api-url-list-item-landing" hx-disable="true"> |
| 17 | + <span class="api-method api-method-@method">@method.ToUpperInvariant()</span> |
| 18 | + <span class="api-url">@overload.Model.Route</span> |
| 19 | + </a> |
| 20 | + </li> |
| 21 | + } |
| 22 | + </ul> |
| 23 | + |
| 24 | + return HtmlString.Empty; |
| 25 | + } |
| 26 | + |
| 27 | + private IHtmlContent RenderProduct(INavigationItem item) |
| 28 | + { |
| 29 | + if (item is INodeNavigationItem<INavigationModel, INavigationItem> node) |
| 30 | + { |
| 31 | + foreach (var navigationItem in node.NavigationItems) |
| 32 | + { |
| 33 | + if (navigationItem is ClassificationNavigationItem classification) |
| 34 | + { |
| 35 | + <tr> |
| 36 | + <td colspan="2"><h2>@(classification.NavigationTitle)</h2></td> |
| 37 | + </tr> |
| 38 | + @RenderProduct(classification) |
| 39 | + } |
| 40 | + else if (navigationItem is TagNavigationItem tag) |
| 41 | + { |
| 42 | + <tr> |
| 43 | + <td colspan="2"><h3>@(tag.NavigationTitle)</h3><td> |
| 44 | + </tr> |
| 45 | + @RenderProduct(tag) |
| 46 | + } |
| 47 | + else if (navigationItem is EndpointNavigationItem endpoint) |
| 48 | + { |
| 49 | + var endpointOperations = |
| 50 | + endpoint is { NavigationItems.Count: > 0 } && endpoint.NavigationItems.All(n => n.Hidden) |
| 51 | + ? endpoint.NavigationItems |
| 52 | + : []; |
| 53 | + if (endpointOperations.Count > 0) |
| 54 | + { |
| 55 | + <tr> |
| 56 | + <td class="api-name">@(endpoint.NavigationTitle)</td> |
| 57 | + <td>@RenderOp(endpointOperations)</td> |
| 58 | + </tr> |
| 59 | + } |
| 60 | + else |
| 61 | + { |
| 62 | + @RenderProduct(endpoint) |
| 63 | + } |
| 64 | + } |
| 65 | + else if (navigationItem is OperationNavigationItem operation) |
| 66 | + { |
| 67 | + <tr> |
| 68 | + <td class="api-name">@(operation.NavigationTitle)</td> |
| 69 | + <td>@RenderOp([operation])</td> |
| 70 | + </tr> |
| 71 | + } |
| 72 | + else |
| 73 | + { |
| 74 | + throw new Exception($"Unexpected type: {item.GetType().FullName}"); |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + return HtmlString.Empty; |
| 80 | + |
| 81 | + } |
5 | 82 | } |
6 | 83 | <section id="elastic-docs-v3"> |
7 | 84 | <h1>@Model.ApiInfo.Title</h1> |
8 | 85 | <p>@Model.ApiInfo.Description</p> |
9 | | - <p>License: @Model.ApiInfo.License?.Identifier</p> |
| 86 | + <p>License: @Model.ApiInfo.License?.Name</p> |
| 87 | + <div class="api-overview"> |
| 88 | + <table> |
| 89 | + @RenderProduct(Model.CurrentNavigationItem.NavigationRoot) |
| 90 | + </table> |
| 91 | + </div> |
10 | 92 | </section> |
0 commit comments