Added Category Manage Page

This commit is contained in:
Mia Rose Winter 2024-01-26 13:06:03 +01:00
parent c53ecd2ada
commit df7c7c7534
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E
9 changed files with 488 additions and 4 deletions

View file

@ -26,6 +26,11 @@
<li><NavLink href="future">@Localizer["Future_Label"]</NavLink></li>
</Authorized>
</AuthorizeView>
<AuthorizeView Policy="CategoryManagePermissions">
<Authorized>
<li><NavLink href="manage/categories">@Localizer["ManageCategories_Label"]</NavLink></li>
</Authorized>
</AuthorizeView>
<AuthorizeView Policy="RoleAssignPermissions">
<Authorized>
<li><NavLink href="manage/users">@Localizer["ManageUsers_Label"]</NavLink></li>

View file

@ -0,0 +1,86 @@
@page "/manage/categories"
@using Microsoft.EntityFrameworkCore
@using Wave.Data
@using System.ComponentModel.DataAnnotations
@using Wave.Utilities
@attribute [Authorize(Policy = "CategoryManagePermissions")]
@inject IDbContextFactory<ApplicationDbContext> ContextFactory
@inject IStringLocalizer<ManageCategories> Localizer
<PageTitle>@(TitlePrefix + Localizer["Title"])</PageTitle>
<h1 class="text-3xl lg:text-5xl font-light mb-6 text-primary">@Localizer["Title"]</h1>
<!-- DaisyUI doesn't seem to respect tailwinds safelist, so we add these classes to trick it
into generating the corresponding css classes
<div class="text-primary text-error text-warning text-info text-secondary text-accent"></div>
<div class="text-primary-content text-error-content text-warning-content text-info-content text-secondary-content text-accent-content"></div>
<div class="bg-primary bg-error bg-warning bg-info bg-secondary bg-accent"></div>
-->
<section class="w-full">
<EditForm method="post" class="w-full" FormName="add-category"
Model="Model" OnValidSubmit="AddCategory_OnValidSubmit">
<InputLabelComponent LabelText="@Localizer["Category_Label"]" For="() => Model.Name">
<div class="join join-vertical md:join-horizontal">
<InputText @bind-Value="Model.Name" required aria-required class="input input-bordered md:flex-1 md:max-w-xs join-item"
autocomplete="off" placeholder="@Localizer["Category_Name_Placeholder"]" />
<InputSelect @bind-Value="Model.Color" required aria-required class="select select-bordered join-item">
@foreach (var color in Enum.GetValues<CategoryColors>()) {
string postfix = CategoryUtilities.GetCssClassPostfixForColor(color);
<option value="@color" class="text-@postfix-content bg-@postfix">
@Localizer["Category_Color_" + color]
</option>
}
</InputSelect>
<button type="submit" class="btn btn-primary join-item">@Localizer["Category_Submit"]</button>
</div>
</InputLabelComponent>
</EditForm>
</section>
<ul class="flex flex-col gap-2 max-w-xs">
@foreach (var category in Categories) {
string postfix = CategoryUtilities.GetCssClassPostfixForColor(category.Color);
<li class="bg-@postfix text-@postfix-content p-2 border-2 border-current">@category.Name</li>
}
</ul>
@code {
[CascadingParameter(Name = "TitlePrefix")]
private string TitlePrefix { get; set; } = default!;
[SupplyParameterFromForm]
private InputModel Model { get; set; } = new();
private List<Category> Categories { get; set; } = new();
protected override async Task OnInitializedAsync() {
await using var context = await ContextFactory.CreateDbContextAsync();
Categories = await context.Set<Category>().OrderBy(c => c.Color).ToListAsync();
}
private async Task AddCategory_OnValidSubmit() {
await using var context = await ContextFactory.CreateDbContextAsync();
var category = new Category {
Name = Model.Name.Trim(),
Color = Model.Color
};
await context.AddAsync(category);
await context.SaveChangesAsync();
Categories.Add(category);
Model = new();
}
private sealed class InputModel {
[Required(AllowEmptyStrings = false), MaxLength(128)]
public string Name { get; set; } = string.Empty;
[Required]
public CategoryColors Color { get; set; } = CategoryColors.Default;
}
}

View file

@ -125,4 +125,7 @@
<data name="Future_Label" xml:space="preserve">
<value>In Veröffentlichung</value>
</data>
<data name="ManageCategories_Label" xml:space="preserve">
<value>Kategorien Verwalten</value>
</data>
</root>

View file

@ -125,4 +125,7 @@
<data name="Future_Label" xml:space="preserve">
<value>Publishing</value>
</data>
<data name="ManageCategories_Label" xml:space="preserve">
<value>Manage Categories</value>
</data>
</root>

View file

@ -0,0 +1,134 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 1.3
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">1.3</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1">this is my long string</data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
[base64 mime encoded serialized .NET Framework object]
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
[base64 mime encoded string representing a byte array form of the .NET Framework object]
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Title" xml:space="preserve">
<value>Kategorien Verwalten</value>
</data>
<data name="Category_Label" xml:space="preserve">
<value>Kategorie Hinzufügen</value>
</data>
<data name="Category_Name_Placeholder" xml:space="preserve">
<value>Kochen</value>
</data>
<data name="Category_Submit" xml:space="preserve">
<value>Hinzufügen</value>
</data>
<data name="Category_Color_Dangerous" xml:space="preserve">
<value>Gefährlich</value>
</data>
<data name="Category_Color_Default" xml:space="preserve">
<value>Standard</value>
</data>
<data name="Category_Color_Extra" xml:space="preserve">
<value>Zusatz</value>
</data>
<data name="Category_Color_Important" xml:space="preserve">
<value>Wichtig</value>
</data>
<data name="Category_Color_Informative" xml:space="preserve">
<value>Informativ</value>
</data>
<data name="Category_Color_Primary" xml:space="preserve">
<value>Primär</value>
</data>
<data name="Category_Color_Secondary" xml:space="preserve">
<value>Sekundär</value>
</data>
</root>

View file

@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 1.3
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">1.3</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1">this is my long string</data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
[base64 mime encoded serialized .NET Framework object]
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
[base64 mime encoded string representing a byte array form of the .NET Framework object]
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View file

@ -0,0 +1,134 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 1.3
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">1.3</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1">this is my long string</data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
[base64 mime encoded serialized .NET Framework object]
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
[base64 mime encoded string representing a byte array form of the .NET Framework object]
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Title" xml:space="preserve">
<value>Manage Categories</value>
</data>
<data name="Category_Label" xml:space="preserve">
<value>Add Category</value>
</data>
<data name="Category_Name_Placeholder" xml:space="preserve">
<value>Cooking</value>
</data>
<data name="Category_Submit" xml:space="preserve">
<value>Add</value>
</data>
<data name="Category_Color_Default" xml:space="preserve">
<value>Default</value>
</data>
<data name="Category_Color_Dangerous" xml:space="preserve">
<value>Dangerous</value>
</data>
<data name="Category_Color_Important" xml:space="preserve">
<value>Imporant</value>
</data>
<data name="Category_Color_Informative" xml:space="preserve">
<value>Informative</value>
</data>
<data name="Category_Color_Secondary" xml:space="preserve">
<value>Secondary</value>
</data>
<data name="Category_Color_Extra" xml:space="preserve">
<value>Extra</value>
</data>
<data name="Category_Color_Primary" xml:space="preserve">
<value>Primary</value>
</data>
</root>

View file

@ -0,0 +1,18 @@
using Wave.Data;
namespace Wave.Utilities;
public static class CategoryUtilities {
public static string GetCssClassPostfixForColor(CategoryColors color) {
return color switch {
CategoryColors.Primary => "primary",
CategoryColors.Dangerous => "error",
CategoryColors.Important => "warning",
CategoryColors.Informative => "info",
CategoryColors.Secondary => "secondary",
CategoryColors.Default => "",
CategoryColors.Extra => "accent",
_ => throw new ArgumentOutOfRangeException(nameof(color), color, null)
};
}
}

File diff suppressed because one or more lines are too long