@model ZelWiki.Models.ViewModels.Admin.OrphanedPageAttachmentsViewModel
@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.GenerateDangerLink(GlobalConfiguration.BasePath, 
    "这将永久清除所有孤立的页面附件,继续吗?",
    "清除所有孤立附件", "/Admin/PurgeOrphanedAttachments", Context.Request.Path.Value))
<br />
<br />

@using (Html.BeginForm(null, null, FormMethod.Get, new { action = $"{GlobalConfiguration.BasePath}{Context.Request.Path}" }))
{
    @if (Model.Files.Count > 0)
    {
        <table class="table fixedTable100 table-striped" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "Page")">页面</a></strong></td>
                <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "File")">文件</a></strong></td>
                <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "Size")">大小</a></strong></td>
                <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "Revision")">修订</a></strong></td>
                <td><strong>Action</strong></td>
            </tr>

            @foreach (var p in Model.Files)
            {
                <tr>
                    <td>
                        @if (string.IsNullOrEmpty(@p.Namespace) == false)
                        {
                            <text><a href="@GlobalConfiguration.BasePath/Admin/Namespace/@p.Namespace">@p.Namespace</a> :: </text>
                        } <a href="@GlobalConfiguration.BasePath/@p.PageNavigation">@p.PageTitle</a>
                    </td>
                    <td><a href="@GlobalConfiguration.BasePath/File/Binary/@p.PageNavigation/@p.FileNavigation/@p.FileRevision">@p.FileName</a></td>
                    <td>@NTDLS.Helpers.Formatters.FileSize((long)@p.Size)</td>
                    <td>@p.FileRevision</td>
                    <td>
                        @Html.Raw(ZelWiki.Library.ConfirmActionHelper.GenerateDangerLink(GlobalConfiguration.BasePath, 
                            "这将永久清除这个附件,继续吗?",
                            "删除", $"/Admin/PurgeOrphanedAttachment/{@p.PageFileId}/{@p.FileRevision}", Context.Request.Path.Value))
                    </td>
                </tr>
            }
        </table>

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