Skip to content

Commit

Permalink
Remove ability to move claims to groups because this feature is phase…
Browse files Browse the repository at this point in the history
…d out (#2313)
  • Loading branch information
leotsarev authored Aug 8, 2023
1 parent ca4b282 commit e5927e5
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 66 deletions.
27 changes: 27 additions & 0 deletions src/JoinRpg.Portal/AppCodeCompiled/SearchableDropdownMvcHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,33 @@ public static IHtmlContent SearchableDropdown(this IHtmlHelper self,
itemsString,
name));
}

public static IHtmlContent SearchableDropdown(this IHtmlHelper self,
string name,
IEnumerable<JoinSelectListItem> items)
{
//TODO: selected value from model
var itemsString =
string.Join("\n",
items.Select(item => string.Format(
"<option data-tokens=\"{0} {1} {3}\" data-subtext=\"{1}\" value=\"{2}\">{3}</option >",
item.ExtraSearch,
item.Subtext,
item.Value,
item.Text)));

// ReSharper disable once UseStringInterpolation we are inside Razor
return new HtmlString(string.Format(@" <select
class=""selectpicker""
data-live-search = ""true""
data-live-search-normalize = ""true""
data-size = ""10""
name=""{1}"">
{0}
</select>",
itemsString,
name));
}
}


12 changes: 3 additions & 9 deletions src/JoinRpg.Portal/Controllers/ClaimController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,9 @@ public async Task<ActionResult> ChangeResponsible(int projectId, int claimId, in

}

/// <param name="projectId"></param>
/// <param name="claimId"></param>
/// <param name="viewModel"></param>
/// <param name="claimTarget">Note that name is hardcoded in view. (TODO improve)</param>
[MasterAuthorize()]
[HttpPost]
public async Task<ActionResult> Move(int projectId, int claimId, ClaimOperationViewModel viewModel, string claimTarget)
public async Task<ActionResult> Move(int projectId, int claimId, ClaimOperationViewModel viewModel, int characterId)
{
var claim = await _claimsRepository.GetClaim(projectId, claimId);
if (claim == null)
Expand All @@ -434,10 +430,8 @@ public async Task<ActionResult> Move(int projectId, int claimId, ClaimOperationV
{
return await ShowClaim(claim);
}
var characterGroupId = claimTarget.UnprefixNumber(CharacterAndGroupPrefixer.GroupFieldPrefix);
var characterId = claimTarget.UnprefixNumber(CharacterAndGroupPrefixer.CharFieldPrefix);
await
_claimService.MoveByMaster(claim.ProjectId, claim.ClaimId, CurrentUserId, viewModel.CommentText, characterGroupId, characterId);

await _claimService.MoveByMaster(claim.ProjectId, claim.ClaimId, viewModel.CommentText, characterId);

return ReturnToClaim(projectId, claimId);
}
Expand Down
7 changes: 1 addition & 6 deletions src/JoinRpg.Portal/Views/Claim/Edit.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,9 @@ new { Model.ProjectId, Model.Player.UserId }, null).
Если вы хотите изменить состав групп у <b>существующего</b> персонажа,
<b>@Html.ActionLink("отредактируйте", "Edit", "Character", new { Model.ProjectId, Model.CharacterId }, null)</b> его.
</div>
ViewBag.ShowGroupsInAvailClaim = false;
}
else
{
ViewBag.ShowGroupsInAvailClaim = true;
}
<form asp-action="Move" asp-route-projectId="@Model.ProjectId" asp-route-claimId="@Model.ClaimId" method="post">
@await Html.PartialAsync("AvailClaimTargetsPartial", Model.Data)
@await Html.PartialAsync("AvailClaimTargetsPartial", Model.PotentialCharactersToMove)
@await Html.PartialAsync("ClaimOperationPartial", new ClaimOperationViewModel
{
ActionName = "Переместить заявку"
Expand Down
34 changes: 4 additions & 30 deletions src/JoinRpg.Portal/Views/Shared/AvailClaimTargetsPartial.cshtml
Original file line number Diff line number Diff line change
@@ -1,39 +1,13 @@
@using JoinRpg.Web.Models.Characters
@model IList<CharacterTreeItem>


@functions {
private static string GetName(CharacterTreeItem gr)
{
return gr.Name; //* + (gr.AvaiableDirectSlots > 0 ? (" " + Html.DisplayCount_OfX(gr.AvaiableDirectSlots, "вакансия", "вакансии", "вакансий")) : "");*@
}

}
@using JoinRpg.Web.Models.CommonTypes;
@model IList<JoinSelectListItem>

<div class="form-horizontal">
<div class="form-group">
@Html.Label("", "Переместить заявку", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<select name="claimTarget" id="claimTarget" class="form-control col-md-10">
@foreach (var element in Model.Where(g => g.FirstCopy && !g.IsSpecial))
{
if (/*element.AvaiableDirectSlots != 0 &&*/ ViewBag.ShowGroupsInAvailClaim == true)
{
var value = "group^" + element.CharacterGroupId;
<option value="@value">@("Группа " + GetName(element))</option>

}

foreach (var character in element.Characters.Where(ch => ch.IsAvailable))
{
var label = string.Join("", element.Path.Skip(1).Union(new[] { element }).Select(p => p.Name)) + "" + character.CharacterName;

var value = "character^" + character.CharacterId;
<option value="@value">@label</option>
}
}
</select>
@Html.SearchableDropdown("CharacterId", Model)
</div>
</div>

</div>
</div>
17 changes: 6 additions & 11 deletions src/JoinRpg.Services.Impl/ClaimServiceImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,10 @@ public async Task RestoreByMaster(int projectId, int claimId, int currentUserId,
await EmailService.Email(email);
}

public async Task MoveByMaster(int projectId, int claimId, int currentUserId, string contents, int? characterGroupId, int? characterId)
public async Task MoveByMaster(int projectId, int claimId, string contents, int characterId)
{
var (claim, _) = await LoadClaimForApprovalDecline(projectId, claimId);
var source = await ProjectRepository.GetClaimSource(projectId, characterGroupId, characterId);
var source = (Character)await ProjectRepository.GetClaimSource(projectId, null, characterId);

//Grab subscribtions before change
var subscribe = claim.GetSubscriptions(s => s.ClaimStatusChange);
Expand All @@ -777,23 +777,18 @@ public async Task MoveByMaster(int projectId, int claimId, int currentUserId, st
{
claim.Character.ApprovedClaim = null;
}
claim.CharacterGroupId = characterGroupId;
claim.CharacterGroupId = null;
claim.CharacterId = characterId;
claim.Group = source as CharacterGroup; //That fields is required later
claim.Character = source as Character; //That fields is required later
claim.Group = null;
claim.Character = source; //That fields is required later

if (claim.Character != null && claim.IsApproved)
if (claim.IsApproved)
{
claim.Character.ApprovedClaim = claim;
}

MarkCharacterChangedIfApproved(claim); // after move

if (claim.IsApproved && claim.CharacterId == null)
{
throw new DbEntityValidationException();
}

var email =
await
AddCommentWithEmail<MoveByMasterEmail>(contents, claim,
Expand Down
5 changes: 1 addition & 4 deletions src/JoinRpg.Services.Interfaces/IClaimService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ Task AddClaimFromUser(int projectId,

Task RestoreByMaster(int projectId, int claimId, int currentUserId, string commentText);

Task MoveByMaster(int projectId, int claimId, int currentUserId, string contents, int? characterGroupId,
int? characterId);
Task MoveByMaster(int projectId, int claimId, string contents, int characterId);

Task UpdateReadCommentWatermark(int projectId, int commentDiscussionId, int maxCommentId);

Expand Down Expand Up @@ -49,8 +48,6 @@ Task SaveFieldsFromClaim(int projectId,
Task<AccommodationRequest?> LeaveAccommodationGroupAsync(int projectId, int claimId);

Task ConcealComment(int projectId, int commentId, int commentDiscussionId, int currentUserId);


}

public enum FinanceOperationAction
Expand Down
19 changes: 17 additions & 2 deletions src/JoinRpg.WebPortal.Models/Claims/ClaimViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
using JoinRpg.Helpers;
using JoinRpg.Helpers.Web;
using JoinRpg.Markdown;
using JoinRpg.PrimitiveTypes;
using JoinRpg.PrimitiveTypes.ProjectMetadata;
using JoinRpg.Services.Interfaces;
using JoinRpg.Web.Models.CharacterGroups;
using JoinRpg.Web.Models.Characters;
using JoinRpg.Web.Models.CommonTypes;
using JoinRpg.Web.Models.Money;
using JoinRpg.Web.Models.Plot;
using JoinRpg.Web.Models.UserProfile;
Expand Down Expand Up @@ -67,7 +69,7 @@ public class ClaimViewModel : ICharacterWithPlayerViewModel, IEntityWithComments
public bool HasOtherApprovedClaim { get; }

[ReadOnly(true)]
public IList<CharacterTreeItem> Data { get; }
public IList<JoinSelectListItem> PotentialCharactersToMove { get; }

public bool HidePlayer => false;

Expand Down Expand Up @@ -153,7 +155,11 @@ public ClaimViewModel(User currentUser,
OutgoingInvite = outgoingInvite;
HasBlockingOtherClaimsForThisCharacter = claim.HasOtherClaimsForThisCharacter();
HasOtherApprovedClaim = claim.Character?.ApprovedClaim is not null && claim.Character.ApprovedClaim != claim;
Data = new CharacterTreeBuilder(claim.Project.RootGroup, currentUser.UserId).Generate();
PotentialCharactersToMove = claim.Project.Characters
.Where(x => x.IsAvailable)
.Where(x => !claim.IsApproved || x.CharacterType != CharacterType.Slot)
.Select(ToJoinSelectListItem)
.ToList();
OtherClaimsFromThisPlayerCount =
OtherClaimsFromThisPlayerCount =
claim.IsApproved || claim.Project.Details.EnableManyCharacters
Expand Down Expand Up @@ -213,6 +219,15 @@ public ClaimViewModel(User currentUser,
}
}

private static JoinSelectListItem ToJoinSelectListItem(Character x)
{
return new JoinSelectListItem()
{
Value = x.CharacterId,
Text = x.CharacterName,
};
}

public UserSubscriptionTooltip GetFullSubscriptionTooltip(IEnumerable<CharacterGroup> parents,
IReadOnlyCollection<UserSubscription> subscriptions, int claimId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ namespace JoinRpg.Web.Models.CommonTypes;

public class JoinSelectListItem
{
public string ExtraSearch { get; set; }
public string Subtext { get; set; }
public string? ExtraSearch { get; set; }
public string? Subtext { get; set; }

public bool Disabled { get; set; }
public bool Selected { get; set; }
public string Text { get; set; }
public int Value { get; set; }
public required string Text { get; set; }
public required int Value { get; set; }
}

public static class JoinSelectListItemHelpers
Expand Down
2 changes: 2 additions & 0 deletions src/JoinRpg.WebPortal.Models/Money/RecipientClaimViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using JoinRpg.DataModel;
using JoinRpg.Domain;
using JoinRpg.Helpers;
Expand All @@ -15,6 +16,7 @@ public class RecipientClaimViewModel : JoinSelectListItem

public string Status { get; }

[SetsRequiredMembers]
public RecipientClaimViewModel(Claim source)
{
ClaimId = source.ClaimId;
Expand Down

0 comments on commit e5927e5

Please sign in to comment.