diff --git a/ValblazeProject/App.razor b/ValblazeProject/App.razor index e839b1b..2d39f98 100644 --- a/ValblazeProject/App.razor +++ b/ValblazeProject/App.razor @@ -1,8 +1,10 @@ - - - - - -

Sorry, there's nothing at this address.

-
-
\ No newline at end of file + + + + + + +

Sorry, there's nothing at this address.

+
+
+
\ No newline at end of file diff --git a/ValblazeProject/Modals/DeleteConfirmation.razor b/ValblazeProject/Modals/DeleteConfirmation.razor new file mode 100644 index 0000000..93f7a46 --- /dev/null +++ b/ValblazeProject/Modals/DeleteConfirmation.razor @@ -0,0 +1,10 @@ +
+ +

+ Are you sure you want to delete @item.DisplayName ? +

+ + + + +
\ No newline at end of file diff --git a/ValblazeProject/Modals/DeleteConfirmation.razor.cs b/ValblazeProject/Modals/DeleteConfirmation.razor.cs new file mode 100644 index 0000000..8692f75 --- /dev/null +++ b/ValblazeProject/Modals/DeleteConfirmation.razor.cs @@ -0,0 +1,38 @@ +using Blazored.Modal.Services; +using Blazored.Modal; +using Microsoft.AspNetCore.Components; +using ValblazeProject.Models; +using ValblazeProject.Services; + +namespace ValblazeProject.Modals +{ + public partial class DeleteConfirmation + { + [CascadingParameter] + public BlazoredModalInstance ModalInstance { get; set; } + + [Inject] + public IDataService DataService { get; set; } + + [Parameter] + public int Id { get; set; } + + private Item item = new Item(); + + protected override async Task OnInitializedAsync() + { + // Get the item + item = await DataService.GetById(Id); + } + + void ConfirmDelete() + { + ModalInstance.CloseAsync(ModalResult.Ok(true)); + } + + void Cancel() + { + ModalInstance.CancelAsync(); + } + } +} diff --git a/ValblazeProject/Pages/ExampleTabSet.razor b/ValblazeProject/Pages/ExampleTabSet.razor new file mode 100644 index 0000000..2a70582 --- /dev/null +++ b/ValblazeProject/Pages/ExampleTabSet.razor @@ -0,0 +1,28 @@ +@page "/example-tab-set" + + + +

Greetings from the first tab!

+ + +
+ + +

Hello from the second tab!

+
+ + @if (showThirdTab) + { + +

Welcome to the disappearing third tab!

+

Toggle this tab from the first tab.

+
+ } +
+ +@code { + private bool showThirdTab; +} \ No newline at end of file diff --git a/ValblazeProject/Pages/List.razor b/ValblazeProject/Pages/List.razor index d0e4a23..a4a8c51 100644 --- a/ValblazeProject/Pages/List.razor +++ b/ValblazeProject/Pages/List.razor @@ -46,6 +46,7 @@ Editer + \ No newline at end of file diff --git a/ValblazeProject/Pages/List.razor.cs b/ValblazeProject/Pages/List.razor.cs index c770a89..d79954d 100644 --- a/ValblazeProject/Pages/List.razor.cs +++ b/ValblazeProject/Pages/List.razor.cs @@ -1,6 +1,9 @@ using Blazored.LocalStorage; +using Blazored.Modal; +using Blazored.Modal.Services; using Blazorise.DataGrid; using Microsoft.AspNetCore.Components; +using ValblazeProject.Modals; using ValblazeProject.Models; using ValblazeProject.Services; @@ -18,6 +21,12 @@ namespace ValblazeProject.Pages [Inject] public IWebHostEnvironment WebHostEnvironment { get; set; } + [Inject] + public NavigationManager NavigationManager { get; set; } + + [CascadingParameter] + public IModalService Modal { get; set; } + private async Task OnReadData(DataGridReadDataEventArgs e) { if (e.CancellationToken.IsCancellationRequested) @@ -31,5 +40,23 @@ namespace ValblazeProject.Pages totalItem = await DataService.Count(); } } + private async void OnDelete(int id) + { + var parameters = new ModalParameters(); + parameters.Add(nameof(Item.Id), id); + + var modal = Modal.Show("Delete Confirmation", parameters); + var result = await modal.Result; + + if (result.Cancelled) + { + return; + } + + await DataService.Delete(id); + + // Reload the page + NavigationManager.NavigateTo("list", true); + } } } diff --git a/ValblazeProject/Pages/ThemedCounter.razor b/ValblazeProject/Pages/ThemedCounter.razor new file mode 100644 index 0000000..5cb97dc --- /dev/null +++ b/ValblazeProject/Pages/ThemedCounter.razor @@ -0,0 +1,31 @@ +@page "/themed-counter" +@using ValblazeProject.UIThemeClasses + +

Themed Counter

+ +

Current count: @currentCount

+ +

+ +

+ +

+ +

+ +@code { + private int currentCount = 0; + + [CascadingParameter] + protected ThemeInfo? ThemeInfo { get; set; } + + private void IncrementCount() + { + currentCount++; + } +} \ No newline at end of file diff --git a/ValblazeProject/Pages/_Layout.cshtml b/ValblazeProject/Pages/_Layout.cshtml index 32be267..5f604c0 100644 --- a/ValblazeProject/Pages/_Layout.cshtml +++ b/ValblazeProject/Pages/_Layout.cshtml @@ -34,5 +34,9 @@ + + + + diff --git a/ValblazeProject/Program.cs b/ValblazeProject/Program.cs index 0779dc9..0c2f3f3 100644 --- a/ValblazeProject/Program.cs +++ b/ValblazeProject/Program.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; using ValblazeProject.Data; using ValblazeProject.Services; +using Blazored.Modal; var builder = WebApplication.CreateBuilder(args); @@ -20,6 +21,8 @@ builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddHttpClient(); +builder.Services.AddBlazoredModal(); + builder.Services .AddBlazorise() .AddBootstrapProviders() diff --git a/ValblazeProject/Services/DataLocalService.cs b/ValblazeProject/Services/DataLocalService.cs index 42a923d..fe670d1 100644 --- a/ValblazeProject/Services/DataLocalService.cs +++ b/ValblazeProject/Services/DataLocalService.cs @@ -138,5 +138,29 @@ namespace ValblazeProject.Services // Save the data await _localStorage.SetItemAsync("data", currentData); } + + public async Task Delete(int id) + { + // Get the current data + var currentData = await _localStorage.GetItemAsync>("data"); + + // Get the item int the list + var item = currentData.FirstOrDefault(w => w.Id == id); + + // Delete item in + currentData.Remove(item); + + // Delete the image + var imagePathInfo = new DirectoryInfo($"{_webHostEnvironment.WebRootPath}/images"); + var fileName = new FileInfo($"{imagePathInfo}/{item.Name}.png"); + + if (fileName.Exists) + { + File.Delete(fileName.FullName); + } + + // Save the data + await _localStorage.SetItemAsync("data", currentData); + } } } diff --git a/ValblazeProject/Services/IDataService.cs b/ValblazeProject/Services/IDataService.cs index b0fd707..40ae93b 100644 --- a/ValblazeProject/Services/IDataService.cs +++ b/ValblazeProject/Services/IDataService.cs @@ -9,5 +9,6 @@ namespace ValblazeProject.Services Task> List(int currentPage, int pageSize); Task GetById(int id); Task Update(int id, ItemModel model); + Task Delete(int id); } } diff --git a/ValblazeProject/Shared/MainLayout.razor b/ValblazeProject/Shared/MainLayout.razor index 01df05c..72000e8 100644 --- a/ValblazeProject/Shared/MainLayout.razor +++ b/ValblazeProject/Shared/MainLayout.razor @@ -1,19 +1,20 @@ @inherits LayoutComponentBase - -ValblazeProject +@using ValblazeProject.UIThemeClasses
-
-
- About -
- -
- @Body -
-
+
+ +
+ @Body +
+
+
+ +@code { + private ThemeInfo theme = new() { ButtonClass = "btn-success" }; +} \ No newline at end of file diff --git a/ValblazeProject/Shared/Tab.razor b/ValblazeProject/Shared/Tab.razor new file mode 100644 index 0000000..0cc0ef2 --- /dev/null +++ b/ValblazeProject/Shared/Tab.razor @@ -0,0 +1,32 @@ +@using ValblazeProject.UIInterfaces +@implements ITab + +
  • + + @Title + +
  • + +@code { + [CascadingParameter] + public TabSet ContainerTabSet { get; set; } + + [Parameter] + public string Title { get; set; } + + [Parameter] + public RenderFragment ChildContent { get; set; } + + private string TitleCssClass => + ContainerTabSet.ActiveTab == this ? "active" : null; + + protected override void OnInitialized() + { + ContainerTabSet.AddTab(this); + } + + private void ActivateTab() + { + ContainerTabSet.SetActiveTab(this); + } +} \ No newline at end of file diff --git a/ValblazeProject/Shared/TabSet.razor b/ValblazeProject/Shared/TabSet.razor new file mode 100644 index 0000000..a5f9adf --- /dev/null +++ b/ValblazeProject/Shared/TabSet.razor @@ -0,0 +1,39 @@ +@using ValblazeProject.UIInterfaces + + + + + + + + + + + +@code { + [Parameter] + public RenderFragment ChildContent { get; set; } + + public ITab ActiveTab { get; private set; } + + public void AddTab(ITab tab) + { + if (ActiveTab == null) + { + SetActiveTab(tab); + } + } + + public void SetActiveTab(ITab tab) + { + if (ActiveTab != tab) + { + ActiveTab = tab; + StateHasChanged(); + } + } +} \ No newline at end of file diff --git a/ValblazeProject/UIInterfaces/ITab.cs b/ValblazeProject/UIInterfaces/ITab.cs new file mode 100644 index 0000000..d3bcaaf --- /dev/null +++ b/ValblazeProject/UIInterfaces/ITab.cs @@ -0,0 +1,9 @@ +using Microsoft.AspNetCore.Components; + +namespace ValblazeProject.UIInterfaces +{ + public interface ITab + { + RenderFragment ChildContent { get; } + } +} diff --git a/ValblazeProject/UIThemeClasses/ThemeInfo.cs b/ValblazeProject/UIThemeClasses/ThemeInfo.cs new file mode 100644 index 0000000..c923b90 --- /dev/null +++ b/ValblazeProject/UIThemeClasses/ThemeInfo.cs @@ -0,0 +1,7 @@ +namespace ValblazeProject.UIThemeClasses +{ + public class ThemeInfo + { + public string? ButtonClass { get; set; } + } +} diff --git a/ValblazeProject/ValblazeProject.csproj b/ValblazeProject/ValblazeProject.csproj index e18d059..8e70e3e 100644 --- a/ValblazeProject/ValblazeProject.csproj +++ b/ValblazeProject/ValblazeProject.csproj @@ -8,6 +8,7 @@ + diff --git a/ValblazeProject/_Imports.razor b/ValblazeProject/_Imports.razor index 9f10276..5966128 100644 --- a/ValblazeProject/_Imports.razor +++ b/ValblazeProject/_Imports.razor @@ -8,4 +8,6 @@ @using Microsoft.JSInterop @using ValblazeProject @using ValblazeProject.Shared -@using Blazorise.DataGrid \ No newline at end of file +@using Blazorise.DataGrid +@using Blazored.Modal +@using Blazored.Modal.Services \ No newline at end of file diff --git a/ValblazeProject/obj/Debug/net6.0/ValblazeProject.assets.cache b/ValblazeProject/obj/Debug/net6.0/ValblazeProject.assets.cache index e5d4ebd..e387151 100644 Binary files a/ValblazeProject/obj/Debug/net6.0/ValblazeProject.assets.cache and b/ValblazeProject/obj/Debug/net6.0/ValblazeProject.assets.cache differ diff --git a/ValblazeProject/obj/ValblazeProject.csproj.nuget.dgspec.json b/ValblazeProject/obj/ValblazeProject.csproj.nuget.dgspec.json index 04f5a0a..25d83a0 100644 --- a/ValblazeProject/obj/ValblazeProject.csproj.nuget.dgspec.json +++ b/ValblazeProject/obj/ValblazeProject.csproj.nuget.dgspec.json @@ -44,6 +44,10 @@ "target": "Package", "version": "[4.2.0, )" }, + "Blazored.Modal": { + "target": "Package", + "version": "[7.1.0, )" + }, "Blazorise.Bootstrap": { "target": "Package", "version": "[1.1.2, )" diff --git a/ValblazeProject/obj/ValblazeProject.csproj.nuget.g.props b/ValblazeProject/obj/ValblazeProject.csproj.nuget.g.props index 6931121..f6e462d 100644 --- a/ValblazeProject/obj/ValblazeProject.csproj.nuget.g.props +++ b/ValblazeProject/obj/ValblazeProject.csproj.nuget.g.props @@ -16,5 +16,6 @@ + \ No newline at end of file diff --git a/ValblazeProject/obj/project.assets.json b/ValblazeProject/obj/project.assets.json index 16d5147..d5754a1 100644 --- a/ValblazeProject/obj/project.assets.json +++ b/ValblazeProject/obj/project.assets.json @@ -14,6 +14,27 @@ "lib/net6.0/Blazored.LocalStorage.dll": {} } }, + "Blazored.Modal/7.1.0": { + "type": "package", + "dependencies": { + "Microsoft.AspNetCore.Components": "6.0.3", + "Microsoft.AspNetCore.Components.Web": "6.0.3", + "Microsoft.Extensions.DependencyInjection.Abstractions": "6.0.0", + "Microsoft.JSInterop.WebAssembly": "6.0.3" + }, + "compile": { + "lib/net6.0/Blazored.Modal.dll": {} + }, + "runtime": { + "lib/net6.0/Blazored.Modal.dll": {} + }, + "build": { + "buildTransitive/Blazored.Modal.props": {} + }, + "buildMultiTargeting": { + "buildMultiTargeting/Blazored.Modal.props": {} + } + }, "Blazorise/1.1.2": { "type": "package", "dependencies": { @@ -290,6 +311,22 @@ } } }, + "Microsoft.JSInterop.WebAssembly/6.0.3": { + "type": "package", + "dependencies": { + "Microsoft.JSInterop": "6.0.3" + }, + "compile": { + "lib/net6.0/Microsoft.JSInterop.WebAssembly.dll": { + "related": ".xml" + } + }, + "runtime": { + "lib/net6.0/Microsoft.JSInterop.WebAssembly.dll": { + "related": ".xml" + } + } + }, "System.IO.Pipelines/6.0.3": { "type": "package", "compile": { @@ -340,6 +377,25 @@ "lib/netstandard2.1/Blazored.LocalStorage.dll" ] }, + "Blazored.Modal/7.1.0": { + "sha512": "ft5bX5barhyzpQc9jjU029ByrAQXgqSMItwhmEbr0pb7r+of8XH0E/OyS8K6O6Disq5R+p4wpt+W+NGg3/OTMA==", + "type": "package", + "path": "blazored.modal/7.1.0", + "files": [ + ".nupkg.metadata", + ".signature.p7s", + "blazored.modal.7.1.0.nupkg.sha512", + "blazored.modal.nuspec", + "build/Blazored.Modal.props", + "build/Microsoft.AspNetCore.StaticWebAssets.props", + "buildMultiTargeting/Blazored.Modal.props", + "buildTransitive/Blazored.Modal.props", + "icon.png", + "lib/net6.0/Blazored.Modal.dll", + "staticwebassets/Blazored.Modal.bundle.scp.css", + "staticwebassets/BlazoredModal.razor.js" + ] + }, "Blazorise/1.1.2": { "sha512": "UGlSOaSiyg3kIN2KbwioNrAoR6Z653NCazo8Tkc5xXoWQKJvkcumhLCZmTbY9pePkOOCU7ey/BSY+cnKYMfhCQ==", "type": "package", @@ -715,6 +771,21 @@ "microsoft.jsinterop.nuspec" ] }, + "Microsoft.JSInterop.WebAssembly/6.0.3": { + "sha512": "4B7RdZ01eKShey9MllKrVjEJZN/Y1Hvku/qTwVKSwt/n+KgFmyYEkEMbSdKDWB7MbvCPZykCQbkKnKfLzML9sg==", + "type": "package", + "path": "microsoft.jsinterop.webassembly/6.0.3", + "files": [ + ".nupkg.metadata", + ".signature.p7s", + "Icon.png", + "THIRD-PARTY-NOTICES.txt", + "lib/net6.0/Microsoft.JSInterop.WebAssembly.dll", + "lib/net6.0/Microsoft.JSInterop.WebAssembly.xml", + "microsoft.jsinterop.webassembly.6.0.3.nupkg.sha512", + "microsoft.jsinterop.webassembly.nuspec" + ] + }, "System.IO.Pipelines/6.0.3": { "sha512": "ryTgF+iFkpGZY1vRQhfCzX0xTdlV3pyaTTqRu2ETbEv+HlV7O6y7hyQURnghNIXvctl5DuZ//Dpks6HdL/Txgw==", "type": "package", @@ -769,6 +840,7 @@ "projectFileDependencyGroups": { "net6.0": [ "Blazored.LocalStorage >= 4.2.0", + "Blazored.Modal >= 7.1.0", "Blazorise.Bootstrap >= 1.1.2", "Blazorise.DataGrid >= 1.1.2", "Blazorise.Icons.FontAwesome >= 1.1.2" @@ -817,6 +889,10 @@ "target": "Package", "version": "[4.2.0, )" }, + "Blazored.Modal": { + "target": "Package", + "version": "[7.1.0, )" + }, "Blazorise.Bootstrap": { "target": "Package", "version": "[1.1.2, )" diff --git a/ValblazeProject/wwwroot/images/prosure.png b/ValblazeProject/wwwroot/images/prosure.png new file mode 100644 index 0000000..f5d5ef9 Binary files /dev/null and b/ValblazeProject/wwwroot/images/prosure.png differ