|
4 | 4 |
|
5 | 5 | namespace JoinRpg.Web.Models.ClaimList; |
6 | 6 |
|
7 | | -public class ClaimListViewModel : IOperationsAwareView |
| 7 | +public abstract class ClaimListViewModel : IOperationsAwareView |
8 | 8 | { |
| 9 | + string? IOperationsAwareView.InlineTitle => Title; |
| 10 | + bool IOperationsAwareView.ShowCharacterCreateButton => false; |
| 11 | + |
| 12 | + public string? Title { get; set; } |
| 13 | + |
9 | 14 | public IEnumerable<ClaimListItemViewModel> Items { get; } |
10 | 15 |
|
11 | 16 | public int? ProjectId { get; } |
12 | 17 | public IReadOnlyCollection<int> ClaimIds { get; } |
13 | 18 | public IReadOnlyCollection<int> CharacterIds { get; } |
14 | 19 |
|
15 | 20 | 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; } |
31 | 22 |
|
32 | 23 | public ClaimListViewModel( |
33 | 24 | int currentUserId, |
34 | 25 | IReadOnlyCollection<Claim> claims, |
35 | 26 | int? projectId, |
36 | 27 | 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) |
42 | 30 | { |
43 | 31 | Items = claims |
44 | 32 | .Select(c => |
45 | 33 | new ClaimListItemViewModel( |
46 | 34 | c, |
47 | 35 | currentUserId, |
48 | 36 | unreadComments.GetValueOrDefault(c.CommentDiscussionId), |
49 | | - claimValidator.Validate(c, projectInfos.Single(pi => pi.ProjectId.Value == c.ProjectId))) |
| 37 | + ValidateClaim(c)) |
50 | 38 | ) |
51 | 39 | .ToList(); |
52 | 40 | ClaimIds = claims.Select(c => c.ClaimId).ToArray(); |
53 | 41 | CharacterIds = claims.Select(c => c.CharacterId).ToArray(); |
54 | 42 | ProjectId = projectId; |
55 | 43 | ShowCount = showCount; |
56 | | - ShowUserColumn = showUserColumn; |
| 44 | + Title = title; |
57 | 45 | } |
| 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) => []; |
58 | 77 | } |
0 commit comments