Skip to content

Commit

Permalink
Add Uri field type
Browse files Browse the repository at this point in the history
  • Loading branch information
leotsarev committed Mar 5, 2024
1 parent 0f44228 commit 0b815c5
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 67 deletions.
1 change: 0 additions & 1 deletion src/JoinRpg.Domain.Test/ProjectFieldTypeTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using JoinRpg.DataModel;
using JoinRpg.PrimitiveTypes.ProjectMetadata;
using JoinRpg.TestHelpers;
using Shouldly;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
}
</div>
break;
case ProjectFieldViewType.Uri:
<a href="@Model.DisplayString">@Model.DisplayString</a>
break;
case ProjectFieldViewType.String:
case ProjectFieldViewType.Text:
case ProjectFieldViewType.Login:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@
case ProjectFieldViewType.String:
<input type="text" @Html.RenderAttrs(attrs) value="@Model.Value" />
break;
case ProjectFieldViewType.Uri:
<input type="text" @Html.RenderAttrs(attrs) value="@Model.Value" />
<a href="@Model.DisplayString">[link]</a>
break;
case ProjectFieldViewType.Login:
<input type="text" @Html.RenderAttrs(attrs) value="@Model.Value"
data-val-regex="Это поле должно состоять из латинских букв и цифр, и начинаться с латинской буквы"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public enum ProjectFieldType
ScheduleRoomField,
ScheduleTimeSlotField,
PinCode,
Uri,
Picture,
}

public enum FieldBoundTo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,94 +7,73 @@ public static class ProjectFieldTypeHelper
/// </summary>
public static bool SupportsPricing(this ProjectFieldType self)
{
switch (self)
return self switch
{
case ProjectFieldType.Dropdown:
case ProjectFieldType.MultiSelect:
case ProjectFieldType.Checkbox:
case ProjectFieldType.Number:
return true;
case ProjectFieldType.String:
case ProjectFieldType.Text:
case ProjectFieldType.Header:
case ProjectFieldType.Login:
case ProjectFieldType.ScheduleRoomField:
case ProjectFieldType.ScheduleTimeSlotField:
case ProjectFieldType.PinCode:
return false;
default:
throw new ArgumentException(self.ToString(), nameof(self));
}
ProjectFieldType.Dropdown or ProjectFieldType.MultiSelect or ProjectFieldType.Checkbox or ProjectFieldType.Number => true,
ProjectFieldType.String or ProjectFieldType.Text or ProjectFieldType.Header or ProjectFieldType.Login
or ProjectFieldType.ScheduleRoomField or ProjectFieldType.ScheduleTimeSlotField or ProjectFieldType.PinCode
or ProjectFieldType.Uri or ProjectFieldType.Picture
=> false,
_ => throw new ArgumentException(self.ToString(), nameof(self)),
};
}

/// <summary>
/// Returns true if price could be entered for field, not for it's values
/// </summary>
public static bool SupportsPricingOnField(this ProjectFieldType self)
{
switch (self)
return self switch
{
case ProjectFieldType.Checkbox:
case ProjectFieldType.Number:
return true;
case ProjectFieldType.String:
case ProjectFieldType.Text:
case ProjectFieldType.Dropdown:
case ProjectFieldType.MultiSelect:
case ProjectFieldType.Header:
case ProjectFieldType.Login:
case ProjectFieldType.ScheduleRoomField:
case ProjectFieldType.ScheduleTimeSlotField:
case ProjectFieldType.PinCode:
return false;
default:
throw new ArgumentException(self.ToString(), nameof(self));
}
ProjectFieldType.Checkbox or ProjectFieldType.Number => true,

ProjectFieldType.String or ProjectFieldType.Text or ProjectFieldType.Dropdown or ProjectFieldType.MultiSelect
or ProjectFieldType.Header or ProjectFieldType.Login or ProjectFieldType.ScheduleRoomField
or ProjectFieldType.ScheduleTimeSlotField or ProjectFieldType.PinCode or ProjectFieldType.Uri or ProjectFieldType.Picture
=> false,
_ => throw new ArgumentException(self.ToString(), nameof(self)),
};
}

/// <summary>
/// Returns true if field has predefined values
/// </summary>
public static bool HasValuesList(this ProjectFieldType self)
{
switch (self)
return self switch
{
case ProjectFieldType.Dropdown:
case ProjectFieldType.MultiSelect:
case ProjectFieldType.ScheduleRoomField:
case ProjectFieldType.ScheduleTimeSlotField:
return true;
case ProjectFieldType.String:
case ProjectFieldType.Text:
case ProjectFieldType.Checkbox:
case ProjectFieldType.Header:
case ProjectFieldType.Number:
case ProjectFieldType.Login:
case ProjectFieldType.PinCode:
return false;
default:
throw new ArgumentException(self.ToString(), nameof(self));
}
ProjectFieldType.Dropdown => true,
ProjectFieldType.MultiSelect => true,
ProjectFieldType.ScheduleRoomField => true,
ProjectFieldType.ScheduleTimeSlotField => true,
ProjectFieldType.String => false,
ProjectFieldType.Text => false,
ProjectFieldType.Checkbox => false,
ProjectFieldType.Header => false,
ProjectFieldType.Number => false,
ProjectFieldType.Login => false,
ProjectFieldType.PinCode => false,
ProjectFieldType.Uri => false,
ProjectFieldType.Picture => false,
_ => throw new ArgumentException(self.ToString(), nameof(self)),
};
}

/// <summary>
/// Returns true if field values could be mass added and doesn't require special setup
/// </summary>
public static bool SupportsMassAdding(this ProjectFieldType self)
{
if (!self.HasValuesList())
{
return false;
}
return self switch
{
ProjectFieldType.Dropdown => true,
ProjectFieldType.MultiSelect => true,
ProjectFieldType.ScheduleRoomField => true,
ProjectFieldType.ScheduleTimeSlotField => false,
ProjectFieldType.String => false,
ProjectFieldType.Text => false,
ProjectFieldType.Checkbox => false,
ProjectFieldType.Header => false,
ProjectFieldType.Number => false,
ProjectFieldType.Login => false,
ProjectFieldType.PinCode => false,
_ => throw new ArgumentException(self.ToString(), nameof(self)),
};
}
Expand Down
20 changes: 20 additions & 0 deletions src/JoinRpg.WebPortal.Models.Test/EnumTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
using System.ComponentModel.DataAnnotations;
using JoinRpg.DataModel;
using JoinRpg.DataModel.Finances;
using JoinRpg.Domain;
using JoinRpg.Helpers;
using JoinRpg.PrimitiveTypes.ProjectMetadata;
using JoinRpg.Services.Interfaces;
using JoinRpg.Services.Interfaces.Projects;
using JoinRpg.TestHelpers;
using JoinRpg.Web.Models;
using JoinRpg.Web.Models.Money;
using MoreLinq;
using Shouldly;
using Xunit;

namespace JoinRpg.Web.Test;
Expand Down Expand Up @@ -43,4 +47,20 @@ public void ProjectType()
[Fact]
public void ContactsAccessType()
=> EnumerationTestComparer.EnsureSame<ContactsAccessType, ContactsAccessTypeView>();

[Theory]
[ClassData(typeof(EnumTheoryDataGenerator<ProjectFieldViewType>))]
public void FieldViewTypeHasCorrectDisplay(ProjectFieldViewType projectFieldType)
{
var displayAttribute = projectFieldType.GetAttribute<DisplayAttribute>();
displayAttribute.ShouldNotBeNull();
displayAttribute.Name.ShouldNotBeNull();
displayAttribute.Order.ShouldBeGreaterThan(0);
}

[Fact]
public void FieldViewTypeHasDisctinctOrder()
{
Enum.GetValues<ProjectFieldViewType>().Select(pft => pft.GetAttribute<DisplayAttribute>()?.Order).Duplicates().ShouldBeEmpty();
}
}
15 changes: 7 additions & 8 deletions src/JoinRpg.WebPortal.Models/FieldModels.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System.ComponentModel.DataAnnotations;
using JetBrains.Annotations;
using JoinRpg.PrimitiveTypes.ProjectMetadata;

namespace JoinRpg.Web.Models;

[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
public enum ProjectFieldViewType
{
[Display(Name = "Строка", Order = 1)]
Expand Down Expand Up @@ -39,6 +37,11 @@ public enum ProjectFieldViewType
Description = "Автоматически сгенерированный пароль персонажа. Если вам нужен пароль для внешней системы",
Order = 11)]
PinCode,
[Display(
Name = "Uri",
Description = "Ссылка на страницу на сайте, гугл-док, чаршит etc",
Order = 12)]
Uri,
}

public static class ProjectFieldViewTypeHelper
Expand Down Expand Up @@ -67,13 +70,11 @@ public enum FieldBoundToViewModel
[Display(
Name = "персонажу",
Description = "Все, что связано с персонажем, его умения, особенности, предыстория. Выбирайте этот вариант по умолчанию.")]
[UsedImplicitly]
Character,

[Display(
Name = "заявке",
Description = "всё, что связано с конкретным игроком: пожелания по завязкам, направлению игры и т.п. После отклонения принятой заявки они не будут доступны новому игроку на этой роли.")]
[UsedImplicitly]
Claim,
}

Expand All @@ -83,13 +84,11 @@ public enum MandatoryStatusViewType
Optional,

[Display(Name = "Рекомендованное",
Description = "При незаполненном поле будет выдаваться предупреждение, а заявка или персонаж — помечаться как проблемные"),
UsedImplicitly]
Description = "При незаполненном поле будет выдаваться предупреждение, а заявка или персонаж — помечаться как проблемные")]
Recommended,

[Display(Name = "Обязательное",
Description = "Сохранение с незаполенным полем будет невозможно."),
UsedImplicitly]
Description = "Сохранение с незаполенным полем будет невозможно.")]
Required,
}

0 comments on commit 0b815c5

Please sign in to comment.