-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#289 - Preparations for customizable mobile menu.
- Loading branch information
Showing
12 changed files
with
249 additions
and
68 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,30 @@ | ||
<div class="row my-2 [email protected]"> | ||
@foreach (var item in Items) | ||
{ | ||
<div class="col"> | ||
@if (item.Url != null) | ||
{ | ||
<Match Url="@item.Url" PageType="@item.PageType" Context="IsActive"> | ||
<a href="@item.Url" class="btn btn-block @(IsActive ? "btn-primary" : "btn-light")"> | ||
@if (Items != null) | ||
{ | ||
<div class="row my-2 [email protected]"> | ||
@foreach (var item in Items) | ||
{ | ||
<div class="col"> | ||
@if (item.Url != null) | ||
{ | ||
<Match Url="@item.Url" PageType="@item.PageType" Context="IsActive"> | ||
<a href="@item.Url" class="btn btn-block @(IsActive ? "btn-primary" : "btn-light")"> | ||
<Icon Identifier="@item.Icon" /> | ||
<span class="text"> | ||
@item.Text | ||
</span> | ||
</a> | ||
</Match> | ||
} | ||
else | ||
{ | ||
<button @onclick="@item.OnClick" class="btn btn-block btn-light"> | ||
<Icon Identifier="@item.Icon" /> | ||
<span class="text"> | ||
@item.Text | ||
</span> | ||
</a> | ||
</Match> | ||
} | ||
else | ||
{ | ||
<button @onclick="@item.OnClick" class="btn btn-block btn-light"> | ||
<Icon Identifier="@item.Icon" /> | ||
<span class="text"> | ||
@item.Text | ||
</span> | ||
</button> | ||
} | ||
</div> | ||
} | ||
</div> | ||
</button> | ||
} | ||
</div> | ||
} | ||
</div> | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using Money.Models; | ||
using Money.Models.Queries; | ||
using Money.Pages; | ||
using Money.Services; | ||
using Neptuo; | ||
using Neptuo.Queries; | ||
using Neptuo.Queries.Handlers; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Money | ||
{ | ||
internal class MenuItemService : HttpQueryDispatcher.IMiddleware | ||
{ | ||
private const string DefaultValue = "summary-month,expense-create"; | ||
|
||
private readonly Navigator navigator; | ||
private readonly List<MenuItemModel> storage; | ||
|
||
public MenuItemService(Navigator navigator) | ||
{ | ||
Ensure.NotNull(navigator, "navigator"); | ||
this.navigator = navigator; | ||
|
||
storage = new List<MenuItemModel>() | ||
{ | ||
new MenuItemModel() | ||
{ | ||
Identifier = "summary-month", | ||
Icon = "chart-pie", | ||
Text = "Monthly", | ||
Url = navigator.UrlSummary(), | ||
PageType = typeof(SummaryMonth) | ||
}, | ||
new MenuItemModel() | ||
{ | ||
Identifier = "search", | ||
Icon = "search", | ||
Text = "Search", | ||
Url = navigator.UrlSearch() | ||
}, | ||
new MenuItemModel() | ||
{ | ||
Identifier = "categories", | ||
Icon = "tag", | ||
Text = "Categories", | ||
Url = navigator.UrlCategories() | ||
}, | ||
new MenuItemModel() | ||
{ | ||
Identifier = "expense-create", | ||
Icon = "minus-circle", | ||
Text = "New Expense", | ||
OnClick = navigator.OpenExpenseCreate | ||
} | ||
}; | ||
} | ||
|
||
async Task<object> HttpQueryDispatcher.IMiddleware.ExecuteAsync(object query, HttpQueryDispatcher dispatcher, HttpQueryDispatcher.Next next) | ||
{ | ||
if (query is ListBottomMenuItem) | ||
{ | ||
return storage.ToList<IActionMenuItemModel>(); | ||
} | ||
else if (query is ListAvailableMenuItem) | ||
{ | ||
return storage.ToList<IAvailableMenuItemModel>(); | ||
} | ||
else if (query is FindUserProperty findProperty && findProperty.Key == "MobileMenu") | ||
{ | ||
var value = (string)await next(findProperty); | ||
if (String.IsNullOrEmpty(value)) | ||
return DefaultValue; | ||
} | ||
else if (query is ListUserProperty listProperty) | ||
{ | ||
var value = (List<UserPropertyModel>)await next(listProperty); | ||
var property = value.FirstOrDefault(p => p.Key == "MobileMenu"); | ||
if (property != null && String.IsNullOrEmpty(property.Value)) | ||
property.Value = DefaultValue; | ||
|
||
return value; | ||
} | ||
|
||
return await next(query); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Money.Blazor.Host/MenuItems/Models/IActionMenuItemModel.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,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Money.Models | ||
{ | ||
public interface IActionMenuItemModel | ||
{ | ||
string Icon { get; } | ||
string Text { get; } | ||
string Url { get; } | ||
Type PageType { get; } | ||
Action OnClick { get; } | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Money.Blazor.Host/MenuItems/Models/IAvailableMenuItemModel.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,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Money.Models | ||
{ | ||
public interface IAvailableMenuItemModel | ||
{ | ||
string Identifier { get; } | ||
string Icon { get; } | ||
string Text { get; } | ||
} | ||
} |
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,19 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Money.Models | ||
{ | ||
public class MenuItemModel : IActionMenuItemModel, IAvailableMenuItemModel | ||
{ | ||
public string Identifier { get; set; } | ||
public string Icon { get; set; } | ||
public string Text { get; set; } | ||
public string Url { get; set; } | ||
public Type PageType { get; set; } | ||
public Action OnClick { get; set; } | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Money.Blazor.Host/MenuItems/Models/Queries/ListAvailableMenuItem.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,16 @@ | ||
using Money.Models.Queries; | ||
using Neptuo.Queries; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Money.Models.Queries | ||
{ | ||
public class ListAvailableMenuItem : UserQuery, IQuery<List<IAvailableMenuItemModel>> | ||
{ | ||
|
||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Money.Blazor.Host/MenuItems/Models/Queries/ListBottomMenuItem.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,17 @@ | ||
using Money.Models; | ||
using Neptuo.Queries; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Money.Models.Queries | ||
{ | ||
/// <summary> | ||
/// A query providing selected bottom menu items. | ||
/// </summary> | ||
public class ListBottomMenuItem : UserQuery, IQuery<List<IActionMenuItemModel>> | ||
{ } | ||
} |
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