Skip to content

Commit ae46070

Browse files
authored
Ужать заголовок списка заявок; оптимизировать загрузку заявок в профиле (#3033)
1 parent 843f218 commit ae46070

File tree

12 files changed

+86
-85
lines changed

12 files changed

+86
-85
lines changed

src/JoinRpg.Portal/Controllers/ClaimListController.cs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ private async Task<ActionResult> ___ShowMasterClaimList(int projectId, string ex
4242
if (exportType == null)
4343
{
4444
ViewBag.MasterAccessColumn = true;
45-
ViewBag.Title = title;
4645
var unreadComments = await claimsRepository.GetUnreadDiscussionsForClaims(projectId, claimStatusSpec, CurrentUserId, hasMasterAccess: true);
47-
var view = new ClaimListViewModel(CurrentUserId, claims, projectId, unreadComments, claimValidator, projectInfo);
46+
var view = new RegularClaimListViewModel(CurrentUserId, claims, projectId, unreadComments, claimValidator, projectInfo, title);
4847
return View("Index", view);
4948
}
5049
else
@@ -106,9 +105,8 @@ private async Task<ActionResult> ShowMasterClaimListForGroup(CharacterGroup char
106105
if (exportType == null)
107106
{
108107
var unreadComments = await claimsRepository.GetUnreadDiscussionsForClaims(characterGroup.ProjectId, claimStatusSpec, CurrentUserId, hasMasterAccess: true);
109-
var view = new ClaimListForGroupViewModel(CurrentUserId, claims, characterGroup, page, unreadComments, claimValidator, projectInfo);
108+
var view = new ClaimListForGroupViewModel(CurrentUserId, claims, characterGroup, page, unreadComments, claimValidator, projectInfo, title);
110109
ViewBag.MasterAccessColumn = true;
111-
ViewBag.Title = title + " " + characterGroup.CharacterGroupName;
112110
return View("ByGroup", view);
113111
}
114112
else
@@ -145,11 +143,11 @@ public async Task<ActionResult> ListForRoomType(int projectId, int? roomTypeId,
145143
string title;
146144
if (roomTypeId == null)
147145
{
148-
title = "Активные заявки без поселения";
146+
title = "Заявки без поселения";
149147
}
150148
else
151149
{
152-
title = "Активные заявки по типу поселения: " +
150+
title = "Заявки с поселением:" +
153151
(await accommodationRepository.GetRoomTypeById(roomTypeId.Value)).Name;
154152
}
155153

@@ -264,8 +262,6 @@ public async Task<ActionResult> My(string? export)
264262
var user = await GetCurrentUserAsync();
265263
var title = "Мои заявки";
266264

267-
ViewBag.Title = title;
268-
269265
var exportType = ExportTypeNameParserHelper.ToExportType(export);
270266

271267
var claims = user.Claims.ToList();
@@ -277,14 +273,10 @@ public async Task<ActionResult> My(string? export)
277273

278274
if (exportType == null)
279275
{
280-
var viewModel = new ClaimListViewModel(
276+
var viewModel = new MyClaimListViewModel(
281277
CurrentUserId,
282278
claims,
283-
projectId: null,
284-
showCount: false,
285-
claimValidator: claimValidator,
286-
projectInfos: projectInfos,
287-
showUserColumn: false,
279+
title: "Мои заявки",
288280
unreadComments: new Dictionary<int, int>()); ; //TODO Pass unread info here
289281
return base.View("Index", viewModel);
290282
}

src/JoinRpg.Portal/Controllers/FinancesController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
using JoinRpg.Services.Interfaces.Projects;
1515
using JoinRpg.Web.Models;
1616
using JoinRpg.Web.Models.Exporters;
17-
using JoinRpg.Web.Models.Masters;
17+
using JoinRpg.Web.Models.Money;
1818
using Microsoft.AspNetCore.Authorization;
1919
using Microsoft.AspNetCore.Mvc;
2020

src/JoinRpg.Portal/Controllers/UserProfile/UserController.cs

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
using JoinRpg.Data.Interfaces;
2-
using JoinRpg.DataModel;
32
using JoinRpg.Domain;
4-
using JoinRpg.Domain.Problems;
53
using JoinRpg.Interfaces;
6-
using JoinRpg.PrimitiveTypes.ProjectMetadata;
74
using JoinRpg.Web.Models;
85
using JoinRpg.Web.Models.ClaimList;
96
using Microsoft.AspNetCore.Authorization;
107
using Microsoft.AspNetCore.Mvc;
118

129
namespace JoinRpg.Portal.Controllers;
1310

14-
public class UserController : Common.ControllerBase
11+
public class UserController(IUserRepository userRepository, ICurrentUserAccessor currentUserAccessor) : Common.ControllerBase()
1512
{
16-
private readonly IProblemValidator<Claim> claimValidator;
17-
private readonly IProjectMetadataRepository projectMetadataRepository;
18-
19-
public IUserRepository UserRepository { get; }
20-
public ICurrentUserAccessor CurrentUserAccessor { get; }
13+
public IUserRepository UserRepository { get; } = userRepository;
14+
public ICurrentUserAccessor CurrentUserAccessor { get; } = currentUserAccessor;
2115

2216
[HttpGet("user/{userId}")]
2317
[AllowAnonymous]
@@ -45,32 +39,15 @@ public async Task<ActionResult> Details(int userId)
4539
? user.Claims.ToArray()
4640
: user.Claims.Where(claim => claim.HasAccess(CurrentUserAccessor.UserId, ExtraAccessReason.Player)).ToArray();
4741

48-
var projectInfos = new List<ProjectInfo>();
49-
foreach (var projectId in claims.Select(c => c.ProjectId).Distinct())
50-
{
51-
projectInfos.Add(await projectMetadataRepository.GetProjectMetadata(new(projectId)));
52-
}
53-
userProfileViewModel.Claims = new ClaimListViewModel(CurrentUserAccessor.UserId,
42+
userProfileViewModel.Claims = new MyClaimListViewModel(CurrentUserAccessor.UserId,
5443
claims,
55-
null,
5644
new Dictionary<int, int>(), //TODO pass unread data here
57-
claimValidator,
58-
projectInfos, showCount: false,
59-
showUserColumn: false);
45+
title: null);
6046
}
6147

6248
return View(userProfileViewModel);
6349
}
6450

65-
public UserController(IUserRepository userRepository, ICurrentUserAccessor currentUserAccessor, IProblemValidator<Claim> claimValidator, IProjectMetadataRepository projectMetadataRepository)
66-
: base()
67-
{
68-
UserRepository = userRepository;
69-
CurrentUserAccessor = currentUserAccessor;
70-
this.claimValidator = claimValidator;
71-
this.projectMetadataRepository = projectMetadataRepository;
72-
}
73-
7451
[Authorize]
7552
[HttpGet("user/me")]
7653
public ActionResult Me() => RedirectToAction("Details", new { CurrentUserAccessor.UserId });
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
@model JoinRpg.Web.Models.ClaimList.ClaimListForGroupViewModel
2+
@{
3+
ViewBag.Title = Model.Title;
4+
}
25

36
@Html.DisplayFor(model => model.GroupModel)
47
@await Html.PartialAsync("_ClaimList", Model)
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@model JoinRpg.Web.Models.ClaimList.ClaimListViewModel
2-
3-
<h2>@ViewBag.Title</h2>
4-
2+
@{
3+
ViewBag.Title = Model.Title;
4+
}
55
@await Html.PartialAsync("_ClaimList", Model)

src/JoinRpg.Portal/Views/Finances/Operations.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@model JoinRpg.Web.Models.FinOperationListViewModel
1+
@model JoinRpg.Web.Models.Money.FinOperationListViewModel
22

33
@{
44
ViewBag.Title = "Список финансовых операций";

src/JoinRpg.WebPortal.Models/ClaimList/ClaimListForGroupViewModel.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,25 @@
55

66
namespace JoinRpg.Web.Models.ClaimList;
77

8-
public class ClaimListForGroupViewModel : ClaimListViewModel, IOperationsAwareView
8+
public class ClaimListForGroupViewModel(int currentUserId,
9+
IReadOnlyCollection<Claim> claims,
10+
CharacterGroup @group,
11+
GroupNavigationPage page,
12+
Dictionary<int, int> unreadComments,
13+
IProblemValidator<Claim> claimValidator,
14+
ProjectInfo projectInfo,
15+
string title) : ClaimListViewModel(currentUserId, claims, group.ProjectId, unreadComments, title), IOperationsAwareView
916
{
10-
public CharacterGroupDetailsViewModel GroupModel { get; }
11-
public ClaimListForGroupViewModel
12-
(int currentUserId,
13-
IReadOnlyCollection<Claim> claims,
14-
CharacterGroup @group,
15-
GroupNavigationPage page,
16-
Dictionary<int, int> unreadComments,
17-
IProblemValidator<Claim> claimValidator,
18-
ProjectInfo projectInfo)
19-
: base(currentUserId, claims, group.ProjectId, unreadComments, claimValidator, projectInfo)
20-
=> GroupModel = new CharacterGroupDetailsViewModel(group, currentUserId, page);
17+
public CharacterGroupDetailsViewModel GroupModel { get; } = new CharacterGroupDetailsViewModel(group, currentUserId, page);
18+
19+
private readonly IProblemValidator<Claim> claimValidator = claimValidator;
20+
private readonly ProjectInfo projectInfo = projectInfo;
2121

2222
int? IOperationsAwareView.CharacterGroupId => GroupModel.CharacterGroupId;
23+
24+
string? IOperationsAwareView.InlineTitle => null; //Не вливаем заголовок в строку с кнопочками, она внутри контрола управления группами.
25+
26+
public override bool ShowUserColumn => true;
27+
28+
protected override IEnumerable<ClaimProblem> ValidateClaim(Claim c) => claimValidator.Validate(c, projectInfo);
2329
}

src/JoinRpg.WebPortal.Models/ClaimList/ClaimListViewModel.cs

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,74 @@
44

55
namespace JoinRpg.Web.Models.ClaimList;
66

7-
public class ClaimListViewModel : IOperationsAwareView
7+
public abstract class ClaimListViewModel : IOperationsAwareView
88
{
9+
string? IOperationsAwareView.InlineTitle => Title;
10+
bool IOperationsAwareView.ShowCharacterCreateButton => false;
11+
12+
public string? Title { get; set; }
13+
914
public IEnumerable<ClaimListItemViewModel> Items { get; }
1015

1116
public int? ProjectId { get; }
1217
public IReadOnlyCollection<int> ClaimIds { get; }
1318
public IReadOnlyCollection<int> CharacterIds { get; }
1419

1520
public bool ShowCount { get; }
16-
public bool ShowUserColumn { get; }
17-
18-
public ClaimListViewModel(
19-
int currentUserId,
20-
IReadOnlyCollection<Claim> claims,
21-
int? projectId,
22-
Dictionary<int, int> unreadComments,
23-
IProblemValidator<Claim> claimValidator,
24-
ProjectInfo projectInfo,
25-
bool showCount = true,
26-
bool showUserColumn = true
27-
)
28-
: this(currentUserId, claims, projectId, unreadComments, claimValidator, new[] { projectInfo }, showCount, showUserColumn)
29-
{
30-
}
21+
public abstract bool ShowUserColumn { get; }
3122

3223
public ClaimListViewModel(
3324
int currentUserId,
3425
IReadOnlyCollection<Claim> claims,
3526
int? projectId,
3627
Dictionary<int, int> unreadComments,
37-
IProblemValidator<Claim> claimValidator,
38-
IReadOnlyCollection<ProjectInfo> projectInfos,
39-
bool showCount = true,
40-
bool showUserColumn = true
41-
)
28+
string? title,
29+
bool showCount = true)
4230
{
4331
Items = claims
4432
.Select(c =>
4533
new ClaimListItemViewModel(
4634
c,
4735
currentUserId,
4836
unreadComments.GetValueOrDefault(c.CommentDiscussionId),
49-
claimValidator.Validate(c, projectInfos.Single(pi => pi.ProjectId.Value == c.ProjectId)))
37+
ValidateClaim(c))
5038
)
5139
.ToList();
5240
ClaimIds = claims.Select(c => c.ClaimId).ToArray();
5341
CharacterIds = claims.Select(c => c.CharacterId).ToArray();
5442
ProjectId = projectId;
5543
ShowCount = showCount;
56-
ShowUserColumn = showUserColumn;
44+
Title = title;
5745
}
46+
47+
protected abstract IEnumerable<ClaimProblem> ValidateClaim(Claim c);
48+
}
49+
50+
public class RegularClaimListViewModel(
51+
int currentUserId,
52+
IReadOnlyCollection<Claim> claims,
53+
int? projectId,
54+
Dictionary<int, int> unreadComments,
55+
IProblemValidator<Claim> claimValidator,
56+
ProjectInfo projectInfo,
57+
string title
58+
) : ClaimListViewModel(currentUserId, claims, projectId, unreadComments, title, showCount: true)
59+
{
60+
protected override IEnumerable<ClaimProblem> ValidateClaim(Claim c) => claimValidator.Validate(c, projectInfo);
61+
62+
public override bool ShowUserColumn => true;
63+
}
64+
65+
public class MyClaimListViewModel : ClaimListViewModel
66+
{
67+
public MyClaimListViewModel(
68+
int currentUserId,
69+
IReadOnlyCollection<Claim> claims,
70+
Dictionary<int, int> unreadComments,
71+
string? title)
72+
: base(currentUserId, claims, projectId: null, unreadComments: unreadComments, title: title) { }
73+
74+
public override bool ShowUserColumn => false;
75+
76+
protected override IEnumerable<ClaimProblem> ValidateClaim(Claim c) => [];
5877
}

src/JoinRpg.WebPortal.Models/IOperationsAwareView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ public interface IOperationsAwareView
1212

1313
IReadOnlyCollection<int> CharacterIds { get; }
1414

15-
public string? InlineTitle => null;
15+
public string? InlineTitle { get; }
1616
}

src/JoinRpg.WebPortal.Models/Money/FinOperationListViewModel.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using JoinRpg.DataModel;
22
using JoinRpg.Services.Interfaces;
33

4-
namespace JoinRpg.Web.Models;
4+
namespace JoinRpg.Web.Models.Money;
55

66
public class FinOperationListViewModel : IOperationsAwareView
77
{
@@ -11,10 +11,12 @@ public class FinOperationListViewModel : IOperationsAwareView
1111

1212
public IReadOnlyCollection<int> ClaimIds { get; }
1313

14-
IReadOnlyCollection<int> IOperationsAwareView.CharacterIds => Array.Empty<int>();
14+
IReadOnlyCollection<int> IOperationsAwareView.CharacterIds => [];
1515
int? IOperationsAwareView.ProjectId => ProjectId;
1616
bool IOperationsAwareView.ShowCharacterCreateButton => false;
1717

18+
string? IOperationsAwareView.InlineTitle => null;
19+
1820
public FinOperationListViewModel(Project project, IUriService urlHelper, IReadOnlyCollection<FinanceOperation> operations)
1921
{
2022
Items = operations

0 commit comments

Comments
 (0)