Skip to content

Commit 3053882

Browse files
authored
Добавить возможность вернуть старую версию вводной (#3302)
fixes #3291
1 parent e1fe8a8 commit 3053882

File tree

3 files changed

+56
-47
lines changed

3 files changed

+56
-47
lines changed

src/JoinRpg.Portal/Controllers/PlotController.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,16 +271,22 @@ public async Task<ActionResult> DeleteElement(int plotelementid, int plotFolderI
271271
private ActionResult ReturnToPlot(PlotFolderIdentification plotFolderId) => RedirectToAction("Edit", new { projectId = plotFolderId.ProjectId.Value, plotFolderId = plotFolderId.PlotFolderId });
272272

273273
[HttpGet, MasterAuthorize()]
274-
public async Task<ActionResult> EditElement(int plotelementid, int plotFolderId, int projectId)
274+
public async Task<ActionResult> EditElement(ProjectIdentification projectId, PlotElementIdentification elementId, int? version)
275275
{
276-
var folder = await plotRepository.GetPlotFolderAsync(new(projectId, plotFolderId));
276+
if (elementId.ProjectId != projectId)
277+
{
278+
return NotFound();
279+
}
280+
var folder = await plotRepository.GetPlotFolderAsync(elementId.PlotFolderId);
277281
if (folder == null)
278282
{
279283
return NotFound();
280284
}
281-
var viewModel = new EditPlotElementViewModel(folder.Elements.Single(e => e.PlotElementId == plotelementid),
282-
folder.HasMasterAccess(CurrentUserId, acl => acl.CanManagePlots),
283-
uriService);
285+
var viewModel = new EditPlotElementViewModel(
286+
folder.Elements.Single(e => e.PlotElementId == elementId.PlotElementId),
287+
folder.HasMasterAccess(CurrentUserId, acl => acl.CanManagePlots),
288+
version
289+
);
284290
return View(viewModel);
285291
}
286292

src/JoinRpg.Portal/Views/Plot/EditElementPartial.cshtml

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,21 @@
5454
@Html.DisplayFor(model => model.Author)
5555
}
5656
</span>
57-
var orderElementsEndpoint = Url.Action("ReorderElements", "Plot", new { Model.ProjectId });
58-
<component type="typeof(JoinMoveControl)"
59-
render-mode="Static"
60-
param-Endpoint="@orderElementsEndpoint"
61-
param-SelfId="@Model.PlotElementIdentification.ToString()"
62-
param-ItemIds="@Model.ItemsIds" />
57+
58+
@if (Model.ItemsIds is not null)
59+
{
60+
var orderElementsEndpoint = Url.Action("ReorderElements", "Plot", new { Model.ProjectId });
61+
<component type="typeof(JoinMoveControl)"
62+
render-mode="Static"
63+
param-Endpoint="@orderElementsEndpoint"
64+
param-SelfId="@Model.PlotElementIdentification.ToString()"
65+
param-ItemIds="@Model.ItemsIds" />
66+
}
6367
}
6468
<div>
6569
<component type="typeof(PlotTargetDisplay)"
66-
render-mode="Static"
67-
param-Target="@Model.Target" />
70+
render-mode="Static"
71+
param-Target="@Model.Target" />
6872
</div>
6973
@if (Model.HasMasterAccess)
7074
{
@@ -116,14 +120,29 @@
116120
<span class="glyphicon glyphicon-print"></span>
117121
Печать
118122
</a>
123+
string? editUrl;
124+
string editLabel;
125+
if (Model.NextModifiedDateTime == null)
126+
{
127+
editUrl = Url.Action("EditElement", "Plot", new { Model.ProjectId, elementId = Model.PlotElementIdentification }, null);
128+
editLabel = "Изменить";
129+
}
130+
else
131+
{
132+
editUrl = Url.Action("EditElement", "Plot", new { Model.ProjectId, elementId = Model.PlotElementIdentification, Version = Model.CurrentVersion }, null);
133+
editLabel = "Вернуть эту версию";
134+
135+
}
136+
<component
137+
type="typeof(JoinButton)"
138+
render-mode="Static"
139+
param-Link="@editUrl"
140+
param-Label="@editLabel"
141+
param-Preset="@ButtonPreset.Edit"
142+
param-Size="@SizeStyleEnum.Small"
143+
/>
119144
if (Model.NextModifiedDateTime == null)
120145
{
121-
<a class="btn btn-default btn-sm"
122-
href="@Url.Action("EditElement", "Plot", new {Model.PlotElementId, Model.PlotFolderId, Model.ProjectId}, null)">
123-
<span class="glyphicon glyphicon-pencil"></span>
124-
Изменить
125-
</a>
126-
127146
if ((Model.CurrentVersion > Model.PublishedVersion || Model.PublishedVersion == null))
128147
{
129148
if (Model.HasEditAccess)

src/JoinRpg.WebPortal.Models/Plot/EditPlotFolderViewModel.cs

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -72,46 +72,30 @@ public EditPlotFolderViewModel() { } //For binding
7272
public bool HasMasterAccess { get; private set; }
7373
}
7474

75-
public class EditPlotElementViewModel : IProjectIdAware
75+
public class EditPlotElementViewModel(PlotElement e, bool hasManageAccess, int? version) : IProjectIdAware
7676
{
77-
78-
public EditPlotElementViewModel(PlotElement e, bool hasManageAccess, IUriService uriService)
79-
{
80-
PlotElementId = e.PlotElementId;
81-
Targets = e.GetElementBindingsForEdit();
82-
Content = e.LastVersion().Content.Contents ?? "";
83-
TodoField = e.LastVersion().TodoField;
84-
ProjectId = e.PlotFolder.ProjectId;
85-
PlotFolderId = e.PlotFolderId;
86-
Status = e.GetStatus();
87-
ElementType = (PlotElementTypeView)e.ElementType;
88-
HasManageAccess = hasManageAccess;
89-
HasPublishedVersion = e.Published != null;
90-
Target = e.ToTarget();
91-
}
92-
9377
[ReadOnly(true)]
94-
public int ProjectId { get; }
78+
public int ProjectId { get; } = e.PlotFolder.ProjectId;
9579
[ReadOnly(true)]
96-
public int PlotFolderId { get; }
80+
public int PlotFolderId { get; } = e.PlotFolderId;
9781
[ReadOnly(true)]
98-
public int PlotElementId { get; }
82+
public int PlotElementId { get; } = e.PlotElementId;
9983

10084
[Display(Name = "Для кого")]
101-
public IEnumerable<string> Targets { get; set; }
85+
public IEnumerable<string> Targets { get; set; } = e.GetElementBindingsForEdit();
10286
[Display(Name = "Текст вводной"), UIHint("MarkdownString")]
103-
public string Content { get; set; }
87+
public string Content { get; set; } = (version is null ? e.LastVersion() : e.SpecificVersion(version.Value))?.Content.Contents ?? "";
10488

10589
[Display(Name = "TODO (что доделать для мастеров)"), DataType(DataType.MultilineText)]
106-
public string TodoField { get; set; }
90+
public string TodoField { get; set; } = e.LastVersion().TodoField;
10791

10892
[ReadOnly(true), Display(Name = "Статус")]
109-
public PlotStatus Status { get; }
93+
public PlotStatus Status { get; } = e.GetStatus();
11094

111-
public PlotElementTypeView ElementType { get; }
112-
public bool HasManageAccess { get; }
113-
public bool HasPublishedVersion { get; }
114-
public TargetsInfo Target { get; }
95+
public PlotElementTypeView ElementType { get; } = (PlotElementTypeView)e.ElementType;
96+
public bool HasManageAccess { get; } = hasManageAccess;
97+
public bool HasPublishedVersion { get; } = e.Published != null;
98+
public TargetsInfo Target { get; } = e.ToTarget();
11599
}
116100

117101
public class PlotElementListItemViewModel : IProjectIdAware

0 commit comments

Comments
 (0)