-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Email & phone contact types, @username links accepted for Telegram\Tw…
- Loading branch information
Showing
8 changed files
with
160 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...sets/Facts/SocialProfilesFactModel.cshtml → ...Changesets/Facts/ContactsFactModel.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/Bonsai/Areas/Front/Views/Page/Facts/ContactsFactModel.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
@using Bonsai.Code.DomainModel.Facts.Models | ||
@using Impworks.Utils.Format | ||
@model ContactsFactModel | ||
|
||
<tr class="fact"> | ||
<th class="fact-title">@Model.ShortTitle</th> | ||
</tr> | ||
<tr class="fact"> | ||
<td class="fact-value big-icons"> | ||
@foreach (var item in Model.Values) | ||
{ | ||
<a class="big-icon" href="@item.GetLink()" target="_blank" title="@item.Type.GetEnumDescription()"> | ||
<span class="fa @(GetIcon(item.Type))"></span> | ||
</a> | ||
} | ||
</td> | ||
</tr> | ||
|
||
@functions { | ||
string GetIcon(ContactType type) | ||
{ | ||
return type switch | ||
{ | ||
ContactType.Facebook => "fa-facebook-square", | ||
ContactType.Twitter => "fa-twitter-square", | ||
ContactType.Github => "fa-github", | ||
ContactType.Youtube => "fa-youtube-play", | ||
ContactType.Telegram => "fa-telegram", | ||
ContactType.Odnoklassniki => "fa-odnoklassniki-square", | ||
ContactType.Vkontakte => "fa-vk", | ||
ContactType.Email => "fa-envelope", | ||
ContactType.Phone => "fa-phone-square", | ||
_ => null | ||
}; | ||
} | ||
} |
34 changes: 0 additions & 34 deletions
34
src/Bonsai/Areas/Front/Views/Page/Facts/SocialProfilesFactModel.cshtml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
src/Bonsai/Code/DomainModel/Facts/Models/ContactsFactModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Text.RegularExpressions; | ||
using Bonsai.Code.Utils.Validation; | ||
using Bonsai.Data.Models; | ||
|
||
namespace Bonsai.Code.DomainModel.Facts.Models | ||
{ | ||
/// <summary> | ||
/// Template for specifying known social profile links. | ||
/// </summary> | ||
public class ContactsFactModel: FactListModelBase<ContactFactItem> | ||
{ | ||
public override void Validate() | ||
{ | ||
for (var i = 1; i <= Values.Length; i++) | ||
{ | ||
var item = Values[i-1]; | ||
if (!Enum.IsDefined(item.Type)) | ||
throw new ValidationException(nameof(Page.Facts), $"Контакт #{i}: тип не указан"); | ||
|
||
if(string.IsNullOrEmpty(item.Value)) | ||
throw new ValidationException(nameof(Page.Facts), $"Контакт #{i}: значение не указано"); | ||
|
||
if (item.Type == ContactType.Email) | ||
{ | ||
if(!Regex.IsMatch(item.Value, ".+@.+\\..+")) | ||
throw new ValidationException(nameof(Page.Facts), $"Контакт #{i}: адрес почты имеет некорректный формат"); | ||
} | ||
else if (item.Type == ContactType.Phone) | ||
{ | ||
if (!Regex.IsMatch(item.Value, "\\+[0-9]+")) | ||
throw new ValidationException(nameof(Page.Facts), $"Контакт #{i}: телефон должен начинаться с + и содержать только цифры"); | ||
} | ||
else if (item.Type == ContactType.Telegram || item.Type == ContactType.Twitter) | ||
{ | ||
if(!item.Value.StartsWith("https://")) | ||
if(!Regex.IsMatch(item.Value, "@[a-z0-9_-]+")) | ||
throw new ValidationException(nameof(Page.Facts), $"Контакт #{i}: значение должно быть ссылкой, либо начинаться с @"); | ||
} | ||
else if (!item.Value.StartsWith("https://")) | ||
throw new ValidationException(nameof(Page.Facts), $"Контакт #{i}: ссылка должна начинаться с 'https://'"); | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Single social profile link. | ||
/// </summary> | ||
public class ContactFactItem | ||
{ | ||
/// <summary> | ||
/// Type of the profile. | ||
/// </summary> | ||
public ContactType Type { get; set; } | ||
|
||
/// <summary> | ||
/// Link to the profile. | ||
/// </summary> | ||
public string Value { get; set; } | ||
|
||
/// <summary> | ||
/// Returns the public hyperlink to this contact. | ||
/// </summary> | ||
public string GetLink() | ||
{ | ||
return Type switch | ||
{ | ||
ContactType.Phone => "tel:" + Value, | ||
ContactType.Email => "mailto:" + Value, | ||
ContactType.Telegram => Value.StartsWith('@') ? "https://t.me/" + Value.Substring(1) : Value, | ||
ContactType.Twitter => Value.StartsWith('@') ? "https://twitter.com/" + Value.Substring(1) : Value, | ||
_ => Value | ||
}; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Known social profile links (to display icons properly). | ||
/// </summary> | ||
public enum ContactType | ||
{ | ||
[Description("Facebook")] | ||
Facebook, | ||
|
||
[Description("Twitter")] | ||
Twitter, | ||
|
||
[Description("Одноклассники")] | ||
Odnoklassniki, | ||
|
||
[Description("Вконтакте")] | ||
Vkontakte, | ||
|
||
[Description("Telegram")] | ||
Telegram, | ||
|
||
[Description("Youtube")] | ||
Youtube, | ||
|
||
[Description("Github")] | ||
Github, | ||
|
||
[Description("E-mail")] | ||
Email, | ||
|
||
[Description("Телефон")] | ||
Phone, | ||
} | ||
} |
69 changes: 0 additions & 69 deletions
69
src/Bonsai/Code/DomainModel/Facts/Models/SocialProfilesFactModel.cs
This file was deleted.
Oops, something went wrong.