Skip to content

Commit

Permalink
Feature/#73 (#74)
Browse files Browse the repository at this point in the history
* WatchList - Add table "WatchCinemaTable".

* (Solution)WatchList.MudBlazor - Add Implementation button "Add" watch item.

* WatchList.MudBlazor - Fixed Linter.

* Solution - Fixed bug. Change IMessageBox (void -> Task). Refactoring.

* WatchList.MudBlazor - Clear non used code.

* WatchList.MudBlazor - Refactoring and chenge interface app.

* WatchList.MudBlazor - Fixed bug/linter and unused code.

* WatchList.MudBlazor - Fix file encoding.

* WatchList.MudBlazor - Add "FilterModel" and used it in the project.

* WatchList.MudBlazor - Add "SorterField" and use it in project.

* WatchList.MudBlazor - Change icons button.
  • Loading branch information
Stan-Kudri authored Feb 14, 2024
1 parent a650d2f commit 87f9f8c
Show file tree
Hide file tree
Showing 44 changed files with 897 additions and 114 deletions.
6 changes: 3 additions & 3 deletions WatchList.Core/PageItem/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ namespace WatchList.Core.PageItem
{
public class Page
{
protected int _number;
protected int _size;

private const int StartPageSize = 10;
private const int NumberStartPage = 1;

private int _number;
private int _size;

public Page(int number = NumberStartPage, int size = StartPageSize)
{
if (number <= 0)
Expand Down
2 changes: 2 additions & 0 deletions WatchList.Core/Repository/WatchItemRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,7 @@ public List<Guid> DuplicateItemsCaseSensitive(WatchItem item)
=> _db.WatchItem.ToList().
Where(x => x.TitleNormalized == item.TitleNormalized && x.Sequel == item.Sequel && x.Type == item.Type).
Take(2).Select(x => x.Id).ToList();

public WatchItem GetItemById(Guid id) => _db.WatchItem.FirstOrDefault(e => e.Id == id) ?? throw new ArgumentException("Interaction element not found.");
}
}
12 changes: 6 additions & 6 deletions WatchList.Core/Service/Component/IMessageBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ namespace WatchList.Core.Service.Component
{
public interface IMessageBox
{
public void ShowInfo(string message);
public Task ShowInfo(string message);

public void ShowWarning(string message);
public Task ShowWarning(string message);

public void ShowError(string message);
public Task ShowError(string message);

public bool ShowQuestion(string message);
public Task<bool> ShowQuestion(string message);

public bool ShowQuestionSaveItem(string message);
public Task<bool> ShowQuestionSaveItem(string message);

public DialogReplaceItemQuestion ShowDataReplaceQuestion(string titleItem);
public Task<DialogReplaceItemQuestion> ShowDataReplaceQuestion(string titleItem);
}
}
4 changes: 2 additions & 2 deletions WatchList.Core/Service/DataLoading/DownloadDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private void AddItems(WatchItemCollection itemCollection)
}
}

private void UpdateItems(WatchItemCollection itemCollection)
private async Task UpdateItems(WatchItemCollection itemCollection)
{
var dialogResultReplaceItem = DialogReplaceItemQuestion.Unknown;

Expand All @@ -73,7 +73,7 @@ private void UpdateItems(WatchItemCollection itemCollection)
case QuestionResultEnum.Unknown:
case QuestionResultEnum.Yes:
case QuestionResultEnum.No:
dialogResultReplaceItem = _messageBox.ShowDataReplaceQuestion(item.Title);
dialogResultReplaceItem = await _messageBox.ShowDataReplaceQuestion(item.Title);
break;
}

Expand Down
10 changes: 6 additions & 4 deletions WatchList.Core/Service/WatchItemService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public WatchItemService(WatchItemRepository itemRepository, IMessageBox messageB

public void Remove(Guid id) => _repository.Remove(id);

public void Add(WatchItem item)
public async Task AddAsync(WatchItem item)
{
var selectItem = _repository.SelectDuplicateItems(item);
var countDuplicate = selectItem.Count;
Expand All @@ -34,21 +34,21 @@ public void Add(WatchItem item)
return;
}

if (_messageBox.ShowQuestionSaveItem(DuplicateReplaceMessage))
if (await _messageBox.ShowQuestionSaveItem(DuplicateReplaceMessage))
{
item.Id = selectItem[0];
Update(item);
}
}

public void Update(WatchItem oldItem, WatchItem modifiedItem)
public async Task UpdateAsync(WatchItem oldItem, WatchItem modifiedItem)
{
var selectItem = _repository.SelectDuplicateItems(modifiedItem);
var countDuplicate = selectItem.Count;

if (countDuplicate == 1 && oldItem.Title != modifiedItem.Title)
{
if (_messageBox.ShowQuestionSaveItem(DuplicateReplaceMessage))
if (await _messageBox.ShowQuestionSaveItem(DuplicateReplaceMessage))
{
modifiedItem.Id = selectItem[0];
Remove(oldItem.Id);
Expand All @@ -62,6 +62,8 @@ public void Update(WatchItem oldItem, WatchItem modifiedItem)
Update(modifiedItem);
}

public WatchItem GetItemById(Guid id) => _repository.GetItemById(id);

private void Update(WatchItem item) => _repository.Update(item);
}
}
78 changes: 78 additions & 0 deletions WatchList.MudBlazors/Dialog/WatchItemDialog.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
@using WatchList.Core.Model.ItemCinema.Components

<MudContainer>

<MudForm @bind-Errors="@_errors" Model="@_watchItemModel">

<MudTextField T="string" Label="Title"
InputType="InputType.Text"
Required="true"
@bind-Value=@_watchItemModel.Title
Validation="@(new Func<string, IEnumerable<string>>(ValidFormatText))" />

<MudSelect T="TypeCinema" Label="Type" @bind-Value="_watchItemModel.Type" AdornmentIcon="@Icons.Material.Filled.ShortText">
@foreach (var item in TypeCinema.List.Where(x => x != TypeCinema.AllType).ToList())
{
<MudSelectItem T="TypeCinema" Value="@item" />
}
</MudSelect>

<MudSelect T="StatusCinema" Label="Status" @bind-Value="_watchItemModel.Status" AdornmentIcon="@Icons.Material.Filled.ShortText">
@foreach (var item in StatusCinema.List.Where(x => x != StatusCinema.AllStatus).ToList())
{
<MudSelectItem T="StatusCinema" Value="@item" />
}
</MudSelect>


<MudNumericField @bind-Value="_watchItemModel.Sequel" Label="@_watchItemModel.Type.TypeSequel" Variant="Variant.Text" Min="1"/>

@if (_watchItemModel.Status != StatusCinema.Planned)
{
<MudNumericField @bind-Value="_watchItemModel.Grade"
Label="Grade"
Variant="Variant.Text"
Min="1" Max="10"/>
}
@if (_watchItemModel.Status == StatusCinema.Viewed)
{
<MudDatePicker @bind-Date=@_watchItemModel.Date
Label="Date"
MaxDate="DateTime.Now"
Required="true"/>
}

</MudForm>

<MudSpacer />

<MudToolBar DisableGutters="true" Class="relative d-flex justify-end gap-1">

@if (_isAddItem)
{
<MudTooltip Text="Save" Placement="Placement.Bottom">
<MudButton Style="max-width: 100px; max-height : 40px;" Size="Size.Medium" Color="Color.Primary" Variant="Variant.Outlined" OnClick="Add">Save</MudButton>
</MudTooltip>
<MudTooltip Text="Clear" Placement="Placement.Bottom">
<MudButton Style="max-width: 100px; max-height : 40px;" Size="Size.Medium" Color="Color.Primary" Variant="Variant.Outlined" OnClick="ClearData">Clear</MudButton>
</MudTooltip>
}
else
{
<MudTooltip Text="Save" Placement="Placement.Bottom">
<MudButton Style="max-width: 100px; max-height : 40px;" Size="Size.Medium" Color="Color.Primary" Variant="Variant.Outlined" OnClick="Updata">Save</MudButton>
</MudTooltip>
<MudTooltip Text="Replace" Placement="Placement.Bottom">
<MudButton Class="ml-1" Style="max-width: 100px; max-height : 40px;" Size="Size.Medium" Color="Color.Primary" Variant="Variant.Outlined" OnClick="RecoverPastData">Recover</MudButton>
</MudTooltip>
}

<MudTooltip Text="Close" Placement="Placement.Bottom">
<MudButton Style="max-width: 100px; max-height : 40px;" Size="Size.Medium" Color="Color.Primary" Variant="Variant.Outlined" OnClick="Close">Close</MudButton>
</MudTooltip>

</MudToolBar>

</MudContainer>


138 changes: 138 additions & 0 deletions WatchList.MudBlazors/Dialog/WatchItemDialog.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
using Microsoft.AspNetCore.Components;
using MudBlazor;
using WatchList.Core.Model.ItemCinema;
using WatchList.Core.Model.ItemCinema.Components;
using WatchList.Core.Service;
using WatchList.Core.Service.Component;
using WatchList.MudBlazors.Extension;
using WatchList.MudBlazors.Model;

namespace WatchList.MudBlazors.Dialog
{
public partial class WatchItemDialog
{
[CascadingParameter] MudDialogInstance MudDialog { get; set; } = null!;
[Inject] private WatchItemService WatchItemService { get; set; } = null!;
[Inject] IMessageBox MessageBoxDialog { get; set; } = null!;

private WatchItemModel _watchItemModel { get; set; } = new WatchItemModel();
private string[] _errors = { };
private bool _isAddItem = true;

private WatchItem? _oldWatchItem;

[Parameter] public Guid? Id { get; set; } = null;

protected override void OnInitialized()
{
if (Id == null)
{
_isAddItem = true;
return;
}

_isAddItem = false;
_oldWatchItem = WatchItemService.GetItemById((Guid)Id);
_watchItemModel = _oldWatchItem.GetItemModel();
}

private void Close() => MudDialog.Cancel();

private async Task Add()
{
if (_errors.Length != 0)
{
return;
}

if (!ValidateFields(out var message))
{
await MessageBoxDialog.ShowWarning(message);
return;
}

var item = _watchItemModel.ToWatchItem();
await WatchItemService.AddAsync(item);

MudDialog.Close();
}

private void ClearData() => _watchItemModel.ClearData();

private async Task Updata()
{
if (_errors.Length != 0)
{
return;
}

if (!ValidateFields(out var message))
{
await MessageBoxDialog.ShowWarning(message);
return;
}

var item = _watchItemModel.ToWatchItem();
if (!_oldWatchItem.Equals(item))
{
await WatchItemService.UpdateAsync(_oldWatchItem, item);
}

MudDialog.Close();
}

private void RecoverPastData() => _watchItemModel = _oldWatchItem.GetItemModel();

private IEnumerable<string> ValidFormatText(string str)
{
if (string.IsNullOrWhiteSpace(str))
{
yield return "Field is required.";
}
}

private bool ValidateFields(out string message)
{
message = string.Empty;

if (_watchItemModel.Title == null || _watchItemModel.Title == string.Empty)
{
message = "Title is required.";
return false;
}

if (_watchItemModel.Type == null)
{
message = "Type cinema not selected.";
return false;
}

if (_watchItemModel.Status == null)
{
message = "Status not selected.";
return false;
}

if ((_watchItemModel.Grade == null || _watchItemModel.Grade <= 0)
&& _watchItemModel.Status != StatusCinema.Planned)
{
message = "Grade cinema above in zero.";
return false;
}

if (_watchItemModel.Sequel == 0)
{
message = $"Enter number {_watchItemModel.Title}";
return false;
}

if (_watchItemModel.Date == null && _watchItemModel.Status == StatusCinema.Viewed)
{
message = "Ener the viewing date.";
return false;
}

return true;
}
}
}
37 changes: 37 additions & 0 deletions WatchList.MudBlazors/Extension/DialogServiceShow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using MudBlazor;
using WatchList.MudBlazors.Message;

namespace WatchList.MudBlazors.Extension
{
public static class DialogServiceShow
{
public static async Task<bool> DialogYesNoShow(this IDialogService dialogService, string title, string content)
{
var parameters = new DialogParameters<DialogYesNo> { { x => x.Content, content } };
return await DialogShowAsync(parameters, dialogService, title, content);
}

public static async Task<bool> DialogOkCloseShowAsync(this IDialogService dialogService, string title, string content)
{
var parameters = new DialogParameters<DialogYesNo>
{
{x => x.Content, content },
{x => x.SelectButtonDialog, new Dictionary<bool, string>
{
{true, "Ok"},
{false, "Close"},
}
}
};
return await DialogShowAsync(parameters, dialogService, title, content);
}

private static async Task<bool> DialogShowAsync(DialogParameters<DialogYesNo> dialogParameters, IDialogService dialogService, string title, string content)
{
var options = new DialogOptions { CloseOnEscapeKey = true };
var dialog = await dialogService.ShowAsync<DialogYesNo>(title, dialogParameters, options);
var result = await dialog.Result;
return result == null || !result.Cancelled;
}
}
}
11 changes: 11 additions & 0 deletions WatchList.MudBlazors/Extension/GetModelItemExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using WatchList.Core.Model.ItemCinema;
using WatchList.MudBlazors.Model;

namespace WatchList.MudBlazors.Extension
{
public static class GetModelItemExtension
{
public static WatchItemModel GetItemModel(this WatchItem item)
=> new WatchItemModel(item.Title, item.Sequel, item.Date, item.Grade, item.Status, item.Type, item.Id);
}
}
21 changes: 21 additions & 0 deletions WatchList.MudBlazors/Message/DialogYesNo.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<MudDialog DefaultFocus="DefaultFocus.LastChild">
<DialogContent>
@Content
</DialogContent>
<DialogActions>
<MudButton Variant="Variant.Filled" Class="ml-2" OnClick="Submit">@SelectButtonDialog[true]</MudButton>
<MudButton Variant="Variant.Filled" OnClick="Cancel">@SelectButtonDialog[false]</MudButton>
</DialogActions>
</MudDialog>

@code {
[CascadingParameter] MudDialogInstance MudDialog { get; set; } = null!;

[Parameter] public string Content { get; set; } = string.Empty;

[Parameter] public Dictionary<bool, string> SelectButtonDialog { get; set; } = new Dictionary<bool, string> { { true, "Yes" }, { false, "No" } };

void Submit() => MudDialog.Close(DialogResult.Ok(true));

void Cancel() => MudDialog.Cancel();
}
Loading

0 comments on commit 87f9f8c

Please sign in to comment.