Skip to content

Commit d82c2d9

Browse files
authored
A lot of fixes for default template (#2831)
* Remove duplicate button * Improve and streamline hacks * Disable making default template not template or delete it * Remove groups editor and viewer if possible * fix unit test
1 parent da75c4e commit d82c2d9

File tree

16 files changed

+123
-92
lines changed

16 files changed

+123
-92
lines changed

src/JoinRpg.Dal.Impl/Repositories/ProjectRepository.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,9 @@ internal static ProjectInfo CreateInfoFromProject(Project project, ProjectIdenti
340340
fieldSettings,
341341
financeSettings,
342342
project.Details.EnableAccommodation,
343-
CharacterIdentification.FromOptional(projectId, project.Details.DefaultTemplateCharacterId));
343+
CharacterIdentification.FromOptional(projectId, project.Details.DefaultTemplateCharacterId),
344+
allowToSetGroups: project.CharacterGroups.Any(x => x.IsActive && !x.IsRoot && !x.IsSpecial),
345+
rootCharacterGroupId: project.RootGroup.CharacterGroupId);
344346

345347
IEnumerable<ProjectFieldInfo> CreateFields(Project project, ProjectFieldSettings fieldSettings)
346348
{

src/JoinRpg.DataModel.Mocks/MockedProject.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public MockedProject()
131131
{
132132
AvaiableDirectSlots = 1,
133133
HaveDirectSlots = true,
134+
IsRoot = true,
134135
});
135136

136137
Character.ParentCharacterGroupIds = new[] { Group.CharacterGroupId };

src/JoinRpg.Portal/Controllers/ClaimController.cs

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,7 @@ public async Task<ActionResult> AddForCharacter(int projectId, int characterid)
5555

5656
[HttpGet("/{projectid}/apply")]
5757
[Authorize]
58-
public async Task<ActionResult> AddForGroup(int projectid)
59-
{
60-
var projectInfo = await projectMetadataRepository.GetProjectMetadata(new ProjectIdentification(projectid));
61-
62-
if (projectInfo.DefaultTemplateCharacter is not null)
63-
{
64-
return RedirectToDefaultTemplateCharacter(projectInfo);
65-
}
66-
67-
//TODO remove when groups claims will die
68-
var project = await ProjectRepository.GetProjectAsync(projectid);
69-
70-
if (project.RootGroup.HaveDirectSlots)
71-
{
72-
return RedirectToAction("AddForGroup", new { project.ProjectId, project.RootGroup.CharacterGroupId });
73-
}
74-
return Redirect($"/{projectInfo.ProjectId}/default-slot-not-set");
75-
}
58+
public async Task<ActionResult> AddForGroup(int projectid) => await RedirectToDefaultTemplate(projectid);
7659

7760
[HttpGet("/{projectid}/roles/{characterGroupId}/apply")]
7861
[Authorize]
@@ -88,24 +71,11 @@ public async Task<ActionResult> AddForGroup(int projectId, int characterGroupId)
8871

8972
var viewModel = AddClaimViewModel.Create(field, CurrentUserId, projectInfo);
9073

91-
if (viewModel.ValidationStatus.Contains(CommonUI.Models.AddClaimForbideReasonViewModel.NotForDirectClaims))
74+
if (viewModel.ValidationStatus.Contains(CommonUI.Models.AddClaimForbideReasonViewModel.NotForDirectClaims) && field.IsRoot)
9275
{
93-
if (field.IsRoot && projectInfo.DefaultTemplateCharacter is not null)
94-
{
95-
return RedirectToDefaultTemplateCharacter(projectInfo);
96-
}
97-
98-
var childSlots = field.Characters.Where(c => c.CharacterType == CharacterType.Slot).ToList();
99-
if (childSlots.Count == 1)
100-
{
101-
return RedirectToAction("AddForCharacter", new { field.ProjectId, childSlots.Single().CharacterId });
102-
}
103-
104-
if (field.IsRoot)
105-
{
106-
return RedirectToPage("DefaultSlotNotSetModel");
107-
}
76+
return await RedirectToDefaultTemplate(projectId);
10877
}
78+
10979
return base.View("Add", viewModel);
11080
}
11181

@@ -440,9 +410,6 @@ public async Task<ActionResult> Move(int projectId, int claimId, ClaimOperationV
440410
}
441411
}
442412

443-
[MustUseReturnValue]
444-
private ActionResult ReturnToClaim(int projectId, int claimId) => RedirectToAction("Edit", "Claim", new { claimId, projectId });
445-
446413
[HttpGet("/{projectId}/myclaim")]
447414
[Authorize, HttpGet]
448415
public async Task<ActionResult> MyClaim(int projectId)
@@ -451,8 +418,7 @@ public async Task<ActionResult> MyClaim(int projectId)
451418

452419
if (claims.Count == 0)
453420
{
454-
var project = await ProjectRepository.GetProjectAsync(projectId);
455-
return RedirectToAction("AddForGroup", new { projectId, project.RootGroup.CharacterGroupId });
421+
return await RedirectToDefaultTemplate(projectId);
456422
}
457423

458424
var claimId = claims.TrySelectSingleClaim()?.ClaimId;
@@ -866,9 +832,34 @@ public async Task<ActionResult> TransferClaimPayment(int projectId, int claimId)
866832
return View("PaymentTransfer", new PaymentTransferViewModel(claim, claims));
867833
}
868834

869-
private RedirectToActionResult RedirectToDefaultTemplateCharacter(PrimitiveTypes.ProjectMetadata.ProjectInfo projectInfo)
835+
private async Task<ActionResult> RedirectToDefaultTemplate(int projectid)
870836
{
871-
ArgumentNullException.ThrowIfNull(projectInfo.DefaultTemplateCharacter);
872-
return RedirectToAction("AddForCharacter", new { projectInfo.ProjectId, CharacterId = projectInfo.DefaultTemplateCharacter.CharacterId });
837+
var projectInfo = await projectMetadataRepository.GetProjectMetadata(new ProjectIdentification(projectid));
838+
839+
if (projectInfo.DefaultTemplateCharacter is not null)
840+
{
841+
return RedirectToAction("AddForCharacter", new { projectid, CharacterId = projectInfo.DefaultTemplateCharacter.CharacterId });
842+
}
843+
844+
//TODO Start of HACKS remove when groups claims will die
845+
var project = await ProjectRepository.GetProjectAsync(projectid);
846+
847+
if (project.RootGroup.HaveDirectSlots)
848+
{
849+
return RedirectToAction("AddForGroup", new { projectid, project.RootGroup.CharacterGroupId });
850+
}
851+
852+
var childSlots = project.RootGroup.Characters.Where(c => c.CharacterType == CharacterType.Slot).ToList();
853+
if (childSlots.Count == 1)
854+
{
855+
return RedirectToAction("AddForCharacter", new { projectid, childSlots.Single().CharacterId });
856+
}
857+
858+
//TODO end of hacks
859+
860+
return Redirect($"/{projectInfo.ProjectId}/default-slot-not-set");
873861
}
862+
863+
[MustUseReturnValue]
864+
private ActionResult ReturnToClaim(int projectId, int claimId) => RedirectToAction("Edit", "Claim", new { claimId, projectId });
874865
}

src/JoinRpg.Portal/Views/Character/Create.cshtml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@
1818

1919
<div class="form-horizontal">
2020

21-
<div class="form-group">
21+
<component type="typeof(JoinRpg.Web.CharacterGroups.CharacterTypeSelector)"
22+
param-Name="@("CharacterTypeInfo")"
23+
param-CharactersHaveNameField="@Model.CharactersHaveNameField"
24+
render-mode="WebAssemblyPrerendered"
25+
/>
26+
@if (Model.AllowToSetGroups)
27+
{
28+
29+
<div class="form-group">
2230
@Html.LabelFor(model => model.ParentCharacterGroupIds, htmlAttributes: new { @class = "control-label col-md-2" })
2331
<div class="col-md-10">
2432
<component type="typeof(JoinRpg.Web.ProjectCommon.CharacterGroupSelector)"
@@ -28,12 +36,7 @@
2836
render-mode="WebAssemblyPrerendered" />
2937
</div>
3038
</div>
31-
32-
<component type="typeof(JoinRpg.Web.CharacterGroups.CharacterTypeSelector)"
33-
param-Name="@("CharacterTypeInfo")"
34-
param-CharactersHaveNameField="@Model.CharactersHaveNameField"
35-
render-mode="WebAssemblyPrerendered"
36-
/>
39+
}
3740

3841
@await Html.PartialAsync("_EditFieldsPartial", Model.Fields)
3942

src/JoinRpg.Portal/Views/Character/Delete.cshtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
{
1010
<p>Удалить персонажа, пока на него есть активные заявки, нельзя. Отклоните или перенаправьте заявки </p>
1111
}
12-
else
12+
else if (Model.Project.Details.DefaultTemplateCharacter == Model)
1313
{
14+
<p>Удалить персонажа, пока он является шаблоном по умолчанию, нельзя. Это можно изменить в настройках </p>
15+
}
16+
else {
1417
using (Html.BeginForm())
1518
{
1619
@Html.AntiForgeryToken()

src/JoinRpg.Portal/Views/Character/Details.cshtml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
}
2222
<dt>Игрок</dt>
2323
<dd>@Html.DisplayFor(model => model, "IPlayerCharacter")</dd>
24-
<dt>@Html.DisplayNameFor(model => model.ParentGroups)</dt>
25-
<dd>@Html.DisplayFor(model => model.ParentGroups)</dd>
24+
@if (Model.ParentGroups.HasAnyGroups)
25+
{
26+
<dt>@Html.DisplayNameFor(model => model.ParentGroups)</dt>
27+
<dd>@Html.DisplayFor(model => model.ParentGroups)</dd>
28+
}
2629
</dl>
2730
</div>
2831
</div>

src/JoinRpg.Portal/Views/Character/Edit.cshtml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@
4242
<component type="typeof(JoinRpg.Web.CharacterGroups.CharacterTypeSelector)"
4343
param-Name="@("CharacterTypeInfo")"
4444
param-InitialModel="@(Model.CharacterTypeInfo)"
45+
param-IsDefaultTemplate="@Model.IsDefaultTemplate"
4546
param-ActiveClaimsCount="@Model.ActiveClaimsCount"
4647
param-HasApprovedClaim="@Model.HasApprovedClaim"
4748
param-CharactersHaveNameField="@Model.CharactersHaveNameField"
4849
render-mode="WebAssemblyPrerendered"
4950
/>
5051

52+
@if (Model.AllowToSetGroups)
53+
{
54+
5155
<div class="form-group">
5256
@Html.LabelFor(model => model.ParentCharacterGroupIds, htmlAttributes: new { @class = "control-label col-md-2" })
5357
<div class="col-md-10">
@@ -58,6 +62,7 @@
5862
render-mode="WebAssembly" />
5963
</div>
6064
</div>
65+
}
6166

6267
@await Html.PartialAsync("_EditFieldsPartial", Model.Fields)
6368

@@ -72,7 +77,7 @@
7277
value="@(Model.IsActive ? "Сохранить персонажа" : "Восстановить персонажа")"
7378
class="btn btn-success" />
7479

75-
@if (Model.IsActive & Model.ActiveClaimsCount == 0)
80+
@if (Model.IsActive && Model.ActiveClaimsCount == 0 &&!Model.IsDefaultTemplate)
7681
{
7782
<a href="@Url.Action("Delete", "Character", new {Model.ProjectId, Model.CharacterId}, null)" class="btn btn-danger">
7883
<span title="удалить" class="glyphicon glyphicon-trash"></span> Удалить персонажа

src/JoinRpg.Portal/Views/Claim/Edit.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
<dd>
7373
@Html.DisplayFor(model => model.Status)
7474
</dd>
75-
@if (Model.ParentGroups != null)
75+
@if (Model.ParentGroups != null && Model.AllowToSetGroups)
7676
{
7777
<dt>@Html.DisplayNameFor(model => model.ParentGroups)</dt>
7878
<dd>

src/JoinRpg.Portal/Views/Shared/ProjectCard.cshtml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@
1313
role="button"
1414
title="У меня есть права мастера на этой игре">Мой проект</a>
1515
}
16-
@if (Model.HasMyClaims)
17-
{
18-
<a href="@Url.Action("MyClaim", "Claim", new {Model.ProjectId, area = ""}, null)"
19-
class="btn btn-success btn-sm"
20-
role="button"
21-
title="Моя заявка">
22-
Моя заявка
23-
</a>
24-
}
2516

2617
<a href="@Url.Action("Index", "GameGroups", new {Model.ProjectId, area = ""}, null)"
2718
class="btn btn-primary btn-sm"

src/JoinRpg.PrimitiveTypes/ProjectMetadata/ProjectInfo.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public record class ProjectInfo
2121
public bool AccomodationEnabled { get; }
2222

2323
public CharacterIdentification? DefaultTemplateCharacter { get; }
24+
public bool AllowToSetGroups { get; }
25+
26+
public int RootCharacterGroupId { get; }
2427

2528
public ProjectInfo(
2629
ProjectIdentification projectId,
@@ -30,8 +33,9 @@ public ProjectInfo(
3033
ProjectFieldSettings projectFieldSettings,
3134
ProjectFinanceSettings projectFinanceSettings,
3235
bool accomodationEnabled,
33-
CharacterIdentification? defaultTemplateCharacter
34-
)
36+
CharacterIdentification? defaultTemplateCharacter,
37+
bool allowToSetGroups,
38+
int rootCharacterGroupId)
3539
{
3640
UnsortedFields = fields;
3741
ProjectId = projectId;
@@ -54,6 +58,8 @@ public ProjectInfo(
5458
RoomField = UnsortedFields.SingleOrDefault(f => f.Type == ProjectFieldType.ScheduleRoomField && f.IsActive);
5559

5660
DefaultTemplateCharacter = defaultTemplateCharacter;
61+
AllowToSetGroups = allowToSetGroups;
62+
RootCharacterGroupId = rootCharacterGroupId;
5763
}
5864

5965
public ProjectFieldInfo GetFieldById(ProjectFieldIdentification id)

0 commit comments

Comments
 (0)