@model ZelWiki.Models.ViewModels.Admin.PageCompilationStatisticsViewModel
@using ZelWiki.Library
@using ZelWiki.Models
@{
    Layout = "/Views/Shared/_Layout.cshtml";
    var sessionState = ViewData["SessionState"] as ZelWiki.SessionState ?? throw new Exception("Wiki State Context cannot be null.");
}

<h3>
    数据统计
</h3>

<p>
    <br /><br />
</p>


@if (!string.IsNullOrEmpty(Model.ErrorMessage))
{
    <div class="alert alert-danger">@Html.Raw(Model.ErrorMessage)</div>
}
@if (!string.IsNullOrEmpty(Model.SuccessMessage))
{
    <div class="alert alert-success">@Html.Raw(Model.SuccessMessage)</div>
}

@Html.Raw(ZelWiki.Library.ConfirmActionHelper.GenerateWarnLink(GlobalConfiguration.BasePath, 
    "所有静态数据将会被清除,确定吗?",
    "清除数据", "/Admin/PurgeCompilationStatistics", Context.Request.Path.Value))
<br />
<br />

@if (Model.Statistics.Count > 0)
{
    <table class="table fixedTable100 table-striped" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "Namespace")">页面名称</a></strong></td>
            <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "CreatedDate")">最近访问时间</a></strong></td>
            <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "Compilations")">访问次数</a></strong></td>
            <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "AvgBuildTimeMs")">耗时</a></strong></td>
            <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "AvgWikiMatches")">命中数</a></strong></td>
            <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "TotalErrorCount")">异常数</a></strong></td>
            <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "AvgOutgoingLinkCount")">链接数</a></strong></td>
            <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "AvgTagCount")">Tag数</a></strong></td>
            <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "AvgRawBodySize")">原始大小</a></strong></td>
            <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "AvgWikifiedBodySize")">实际大小</a></strong></td>
        </tr>

        @foreach (var stat in Model.Statistics)
        {

            <tr>
                <td>
                    @if (string.IsNullOrEmpty(@stat.Namespace) == false)
                    {
                        <text><a href="@GlobalConfiguration.BasePath/Admin/Namespace/@stat.Namespace">@stat.Namespace</a> :: </text>
                    } <a href="@GlobalConfiguration.BasePath/@stat.Navigation">@stat.Title</a>
                </td>
                <td>@stat.LatestBuild</td>
                <td>@stat.Compilations.ToString("N0")</td>
                <td>@stat.AvgBuildTimeMs.ToString("N0")ms</td>
                <td>@stat.AvgWikiMatches.ToString("N0")</td>
                <td>@stat.TotalErrorCount.ToString("N0")</td>
                <td>@stat.AvgOutgoingLinkCount.ToString("N0")</td>
                <td>@stat.AvgTagCount.ToString("N0")</td>
                <td>@NTDLS.Helpers.Formatters.FileSize((long)stat.AvgRawBodySize)</td>
                <td>@NTDLS.Helpers.Formatters.FileSize((long)stat.AvgWikifiedBodySize)</td>
            </tr>
        }
    </table>

    @Html.Raw(PageSelectorGenerator.Generate(Context.Request.QueryString, Model.PaginationPageCount))
}
