Skip to content

Commit

Permalink
View and edit links in changesets view. Closes #249.
Browse files Browse the repository at this point in the history
  • Loading branch information
impworks committed Dec 15, 2023
1 parent f5834e8 commit 530471f
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ public async Task<ChangesetsListVM> GetChangesetsAsync(ChangesetsListRequestVM r
EntityType = x.EntityType,
EntityTitle = GetEntityTitle(x),
EntityThumbnailUrl = GetEntityThumbnailUrl(x),
EntityExists = x.EditedMedia?.IsDeleted == false
|| x.EditedPage?.IsDeleted == false
|| x.EditedRelation?.IsDeleted == false,
EntityKey = x.EditedPage?.Key ?? x.EditedMedia?.Key,
PageType = GetPageType(x),
CanRevert = CanRevert(x)
})
Expand All @@ -133,7 +137,14 @@ public async Task<ChangesetsListVM> GetChangesetsAsync(ChangesetsListRequestVM r
/// </summary>
public async Task<ChangesetDetailsVM> GetChangesetDetailsAsync(Guid id)
{
var (chg, prev) = await GetChangesetPairAsync(id, q => q.AsNoTracking().Include(x => x.Author).Include(x => x.EditedMedia));
var (chg, prev) = await GetChangesetPairAsync(
id,
q => q.AsNoTracking()
.Include(x => x.Author)
.Include(x => x.EditedMedia)
.Include(x => x.EditedPage)
.Include(x => x.EditedRelation)
);

var renderer = _renderers[chg.EntityType];
var prevData = await renderer.RenderValuesAsync(prev?.UpdatedState);
Expand All @@ -146,6 +157,11 @@ public async Task<ChangesetDetailsVM> GetChangesetDetailsAsync(Guid id)
Date = chg.Date,
ChangeType = chg.ChangeType,
EntityType = chg.EntityType,
EntityId = chg.EditedPageId ?? chg.EditedMediaId ?? chg.EditedRelationId ?? Guid.Empty,
EntityExists = chg.EditedMedia?.IsDeleted == false
|| chg.EditedPage?.IsDeleted == false
|| chg.EditedRelation?.IsDeleted == false,
EntityKey = chg.EditedPage?.Key ?? chg.EditedMedia?.Key,
ThumbnailUrl = chg.EditedMedia != null
? MediaPresenterService.GetSizedMediaPath(chg.EditedMedia.FilePath, MediaSize.Small)
: null,
Expand Down
15 changes: 15 additions & 0 deletions src/Bonsai/Areas/Admin/ViewModels/Changesets/ChangesetDetailsVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ public class ChangesetDetailsVM
/// </summary>
public ChangesetEntityType EntityType { get; set; }

/// <summary>
/// ID of the entity that has been edited.
/// </summary>
public Guid EntityId { get; set; }

/// <summary>
/// Flag indicating that the entity has a current version that can be viewed.
/// </summary>
public bool EntityExists { get; set; }

/// <summary>
/// Frontend-based key of the entity.
/// </summary>
public string EntityKey { get; set; }

/// <summary>
/// URL of the thumbnail (for media changesets).
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions src/Bonsai/Areas/Admin/ViewModels/Changesets/ChangesetTitleVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ public class ChangesetTitleVM
/// </summary>
public Guid EntityId { get; set; }

/// <summary>
/// Flag indicating that the entity has a current version that can be viewed.
/// </summary>
public bool EntityExists { get; set; }

/// <summary>
/// Frontend-based key of the entity.
/// </summary>
public string EntityKey { get; set; }

/// <summary>
/// Author of the change.
/// </summary>
Expand Down
26 changes: 26 additions & 0 deletions src/Bonsai/Areas/Admin/Views/Changesets/Details.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using System.Globalization
@using Bonsai.Data.Models
@using Humanizer
@using Impworks.Utils.Format

Expand Down Expand Up @@ -50,4 +51,29 @@
@if (Model.CanRevert)
{
<a class="btn btn-danger" href="@Url.Action("Revert", "Changesets", new {area = "Admin", id = Model.Id})">Восстановить</a>
}

@if (Model.EntityExists)
{
var editUrl = Model.EntityType switch
{
ChangesetEntityType.Page => Url.Action("Update", "Pages", new { area = "Admin", id = Model.EntityId }),
ChangesetEntityType.Media => Url.Action("Update", "Media", new { area = "Admin", id = Model.EntityId }),
ChangesetEntityType.Relation => Url.Action("Update", "Relations", new { area = "Admin", id = Model.EntityId }),
};
var outUrl = Model.EntityType switch
{
ChangesetEntityType.Page => Url.Action("Description", "Page", new { area = "Front", key = Model.EntityKey }),
ChangesetEntityType.Media => Url.Action("Index", "Home", new { area = "Front" }) + "#media-" + Model.EntityKey,
_ => null
};

<a class="btn btn-warning" href="@editUrl">Редактировать</a>

if (outUrl != null)
{
<a class="ml-4" href="@outUrl" target="_blank">
<span class="fa fa-external-link-square"></span> Текущая версия
</a>
}
}
34 changes: 33 additions & 1 deletion src/Bonsai/Areas/Admin/Views/Changesets/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using Bonsai.Areas.Admin.ViewModels.Changesets
@using Bonsai.Data.Models
@using Humanizer
@using Impworks.Utils.Format
@using Impworks.Utils.Strings
Expand Down Expand Up @@ -81,7 +82,22 @@
@(StringHelper.Coalesce(c.EntityTitle, ""))
</a>
</td>
<td>@c.EntityType.GetEnumDescription()</td>
<td>
@if (c.EntityExists)
{
var editUrl = c.EntityType switch
{
ChangesetEntityType.Page => Url.Action("Update", "Pages", new { area = "Admin", id = c.EntityId }),
ChangesetEntityType.Media => Url.Action("Update", "Media", new { area = "Admin", id = c.EntityId }),
ChangesetEntityType.Relation => Url.Action("Update", "Relations", new { area = "Admin", id = c.EntityId }),
};
<a href="@editUrl">@c.EntityType.GetEnumDescription()</a>
}
else
{
<text>@c.EntityType.GetEnumDescription()</text>
}
</td>
<td><span title="@c.Date.LocalDateTime.ToLongDateString()">@c.Date.Humanize()</span></td>
<td>@c.ChangeType.GetEnumDescription()</td>
<td>@c.Author</td>
Expand All @@ -92,6 +108,22 @@
<span class="fa fa-history" title="Восстановить"></span>
</a>
}
@if (c.EntityExists)
{
var outUrl = c.EntityType switch
{
ChangesetEntityType.Page => Url.Action("Description", "Page", new { area = "Front", key = c.EntityKey }),
ChangesetEntityType.Media => Url.Action("Index", "Home", new { area = "Front" }) + "#media-" + c.EntityKey,
_ => null
};

if (outUrl != null)
{
<a href="@outUrl" target="_blank">
<span class="fa fa-external-link-square" title="Просмотреть текущую версию"></span>
</a>
}
}
</td>
</tr>
}
Expand Down

0 comments on commit 530471f

Please sign in to comment.