Fix some stuff (❁´◡`❁)

This commit is contained in:
Stone_Red
2023-06-14 00:06:23 +02:00
parent 32fc8c9e94
commit 9f99c4f72c
2 changed files with 213 additions and 251 deletions
@@ -6,37 +6,37 @@
@inherits LayoutComponentBase @inherits LayoutComponentBase
<Image Source="logo.png" Width="Width.Is50" Height="Height.Is50"> </Image> <Image Source="logo.png" Width="Width.Is50" Height="Height.Is50"> </Image>
<Card Width="Width.Is50" Position="Position.Absolute.Top.Is50.Start.Is50.Translate.Middle" Padding="Padding.Is5"> <Card Width="Width.Is50" Position="Position.Absolute.Top.Is50.Start.Is50.Translate.Middle" Padding="Padding.Is2.OnX.Is4.OnMobile.OnY.OnMobile.Is5.OnDesktop">
<Column ColumnSize="ColumnSize.Is6.OnDesktop.Is3.WithOffset.OnDesktop.Is12.OnMobile"> <Column ColumnSize="ColumnSize.Is6.OnDesktop.Is3.WithOffset.OnDesktop.Is12.OnMobile">
<Field Position="Position.Relative.Top.Is50.Start.Is50.Translate.Middle" Width="Width.Auto"> <Field Position="Position.Relative.Top.Is50.Start.Is50.Translate.Middle" Width="Width.Auto">
<TextEdit @bind-Text="username" Placeholder="Username" Size="Size.Small"/> <TextEdit @bind-Text="username" Placeholder="Username" Size="Size.Small" />
</Field> </Field>
<Field Position="Position.Relative.Top.Is50.Start.Is50.Translate.Middle" Width="Width.Auto"> <Field Position="Position.Relative.Top.Is50.Start.Is50.Translate.Middle" Width="Width.Auto">
<TextEdit @bind-Text="password" Role="TextRole.Password" Placeholder="Password" Size="Size.Small" /> <TextEdit @bind-Text="password" Role="TextRole.Password" Placeholder="Password" Size="Size.Small" />
</Field> </Field>
<Button Width="Width.Is25" Disabled="disabled" Color="color" Clicked="Clicked" Position="Position.Relative.Bottom.Is50.Start.Is50.Translate.MiddleX">Login</Button> <Button Width="Width.Is25" Disabled="disabled" Color="color" Clicked="Clicked" Position="Position.Relative.Bottom.Is50.Start.Is50.Translate.MiddleX">Login</Button>
</Column> </Column>
</Card> </Card>
@code { @code {
private string username = string.Empty; private string username = string.Empty;
private string password = string.Empty; private string password = string.Empty;
private Color color = Color.Primary; private Color color = Color.Primary;
private bool disabled; private bool disabled;
private async Task Clicked() private async Task Clicked()
{ {
color = Color.Primary; color = Color.Primary;
disabled = true; disabled = true;
Result loginResult = await AuthenticationService.LoginUserAsync(username, password); Result loginResult = await AuthenticationService.LoginUserAsync(username, password);
if (loginResult.IsSuccess) if (loginResult.IsSuccess)
{ {
NavigationManager.NavigateTo("/", true); NavigationManager.NavigateTo("/", true);
} }
else else
{ {
color = Color.Danger; color = Color.Danger;
disabled = false; disabled = false;
} }
} }
} }
@@ -14,196 +14,203 @@
@inject IAuthenticationService AuthenthicationService; @inject IAuthenticationService AuthenthicationService;
@inject NavigationManager NavigationManager; @inject NavigationManager NavigationManager;
@inject MainDatabaseContext MainDatabaseContext; @inject MainDatabaseContext MainDatabaseContext;
<Div>
<Row Style="width: 100%; height: 100%" Margin="Margin.Is3.FromTop.OnMobile" Padding="Padding.Is4.FromStart.OnMobile">
<Div Display="Display.Flex.Row.OnDesktop" Margin=" Margin.Is3.FromBottom" Width="Width.Is100"> <Protected RequiredRole="Role.Admin">
<Column ColumnSize="ColumnSize.Is5.OnDesktop.Is12.OnMobile"> <Authorized>
<Bar Breakpoint="Breakpoint.Desktop" <Div>
Background="Background.White" <Row Style="width: 100%; height: 100%" Margin="Margin.Is3.FromTop.OnMobile" Padding="Padding.Is4.FromStart.OnMobile">
ThemeContrast="ThemeContrast.None"
Shadow="Shadow.Remove"
Border="Border.Is1.RoundedTop">
<BarBrand>
<Column ColumnSize="ColumnSize.Is12">
Users
</Column>
<Column ColumnSize="ColumnSize.Is12.Is11.WithOffset.OnDesktop.IsAuto.OnMobile">
<Button Clicked="@ShowModalAddUser" TextAlignment="TextAlignment.End" Shadow="Shadow.Remove">
<BarIcon IconName="IconName.Add"></BarIcon>
</Button>
</Column>
</BarBrand>
<Div Display="Display.Flex.Row.OnDesktop" Margin=" Margin.Is3.FromBottom" Width="Width.Is100">
<Column ColumnSize="ColumnSize.Is5.OnDesktop.Is12.OnMobile">
<Bar Breakpoint="Breakpoint.Desktop"
</Bar> Background="Background.White"
<ListView TItem="User" ThemeContrast="ThemeContrast.None"
Data="@users" Shadow="Shadow.Remove"
TextField="@((_)=>(""))" Border="Border.Is1.RoundedTop">
ValueField="@((_)=>(""))" <BarBrand>
Style="border-radius: 0px 0px" <Column ColumnSize="ColumnSize.Is12">
Height="100%" Users
MaxHeight="90%">
<ItemTemplate>
<ListGroupItem Border="Border.OnBottom">
<Row>
<Column ColumnSize="ColumnSize.Is6">
<Row>
<Column ColumnSize="ColumnSize.Is7">
<Heading Size="HeadingSize.Is6" Margin="Margin.Is1.FromBottom">@context.Item.Name</Heading>
</Column>
</Row>
<Row>
<Column>
<Small>Name: @context.Item.Name</Small>
<br />
<Small>Rolle: @context.Item.Role</Small>
<br />
<Small>E-Mail: @context.Item.Email</Small>
</Column>
</Row>
</Column> </Column>
<Column ColumnSize="ColumnSize.Is12.Is11.WithOffset.OnDesktop.IsAuto.OnMobile">
<Column ColumnSize="ColumnSize.Is4.OnDesktop.Is7.OnMobile"> <Button Clicked="@ShowModalAddUser" TextAlignment="TextAlignment.End" Shadow="Shadow.Remove">
<Button @onclick="() => Delete(context.Item)" class="btn1" Position="Position.Absolute.Top.Is50.Start.Is50.Translate.Middle" Color="Color.Dark" Outline> <BarIcon IconName="IconName.Add"></BarIcon>
<BarIcon IconName="IconName.Delete" />
</Button> </Button>
<style>
.btn1:hover {
background: #E50000;
}
</style>
<Modal @ref="modalRefAddUser">
<ModalContent Centered>
<ModalHeader>
<ModalTitle>Add User</ModalTitle>
<CloseButton />
</ModalHeader>
<ModalBody>
<Field>
<FieldLabel>User Name</FieldLabel>
<TextEdit @ref="modalAddUserName" Placeholder="Enter new name..." />
</Field>
<Field>
<FieldLabel>User E-Mail</FieldLabel>
<TextEdit @ref="modalAddUserEmail" Placeholder="Enter new E-mail..." />
</Field>
<Field>
<FieldLabel>User Password</FieldLabel>
<TextEdit @ref="modalAddUserPW" Placeholder="Enter new password..." />
</Field>
</ModalBody>
<ModalFooter>
<Button Color="Color.Secondary" style="border-bottom-left-radius: 3px; border-bottom-right-radius: 3px" Clicked="@HideModalAddUser">Close</Button>
<Button Color="Color.Primary" style="border-bottom-left-radius: 3px; border-bottom-right-radius: 3px" Clicked="@AddButtonPressed">Add</Button>
</ModalFooter>
</ModalContent>
</Modal>
</Column> </Column>
<br /> </BarBrand>
<br />
<Row>
<Column ColumnSize="ColumnSize.Is1.OnDesktop">
<Button @onclick="() => Toggle(context.Item)" Position="Position.Absolute.Top.Is50.Start.Is100.Translate.Middle" Color="Color.Dark" Outline>
<BarIcon IconName="IconName.Pen" />
</Button>
</Column>
</Row>
</Row>
</ListGroupItem>
</ItemTemplate>
</ListView> </Bar>
</Column> <ListView TItem="User"
<Column ColumnSize="ColumnSize.Is6.OnDesktop.Is12.OnMobile" Margin="Margin.Is3.FromTop.OnMobile" Padding="Padding.Is4.FromStart.OnMobile"> Data="@users"
@if (SelectedUser is not null) TextField="@((_)=>(""))"
{ ValueField="@((_)=>(""))"
<Div hidden="@hideButtonSettings"> Style="border-radius: 0px 0px"
<Field> Height="100%"
<FieldLabel> MaxHeight="90%">
<h2> <ItemTemplate>
User Settings <ListGroupItem Border="Border.OnBottom">
</h2> <Row>
</FieldLabel>
</Field> <Column ColumnSize="ColumnSize.Is6">
<Validation @ref="updateValidation" Validator="ValidationRule.IsNotEmpty"> <Row>
<Field> <Column ColumnSize="ColumnSize.Is7">
<FieldLabel> <Heading Size="HeadingSize.Is6" Margin="Margin.Is1.FromBottom">@context.Item.Name</Heading>
<h5> </Column>
User Name </Row>
</h5> <Row>
<Paragraph> <Column>
Here you can change the name of the User <Small>Name: @context.Item.Name</Small>
</Paragraph> <br />
</FieldLabel> <Small>Rolle: @context.Item.Role</Small>
<TextEdit @ref="updateName" @bind-Text="@SelectedUser.Name" Placeholder="Enter User Name" /> <br />
</Field> <Small>E-Mail: @context.Item.Email</Small>
</Validation> </Column>
<br /> </Row>
<br /> </Column>
<Validation @ref="updateValidation" Validator="ValidationRule.IsEmail">
<Field> <Column ColumnSize="ColumnSize.Is4.OnDesktop.Is7.OnMobile">
<FieldLabel> <Button @onclick="() => Delete(context.Item)" class="btn1" Position="Position.Absolute.Top.Is50.Start.Is50.Translate.Middle" Color="Color.Dark" Outline>
<h5> <BarIcon IconName="IconName.Delete" />
E-Mail </Button>
</h5> <style>
<Paragraph> .btn1:hover {
Here you can change the E-Mail of a User background: #E50000;
</Paragraph> }
</FieldLabel> </style>
<TextEdit @ref="updateEmail" @bind-Text="@SelectedUser.Email" Placeholder="Enter new email" />
</Field> <Modal @ref="modalRefAddUser">
</Validation> <ModalContent Centered>
<br /> <ModalHeader>
<br /> <ModalTitle>Add User</ModalTitle>
<Validation @ref="updateValidation" Validator="ValidatePW"> <CloseButton />
<Field> </ModalHeader>
<FieldLabel> <ModalBody>
<h5> <Field>
Password <FieldLabel>User Name</FieldLabel>
</h5> <TextEdit @ref="modalAddUserName" Placeholder="Enter new name..." />
<Paragraph> </Field>
Here you can change the password of a User <Field>
</Paragraph> <FieldLabel>User E-Mail</FieldLabel>
</FieldLabel> <TextEdit @ref="modalAddUserEmail" Placeholder="Enter new E-mail..." />
<TextEdit @ref="updatePW" Placeholder="Enter new password" /> </Field>
</Field> <Field>
</Validation> <FieldLabel>User Password</FieldLabel>
<br /> <TextEdit @ref="modalAddUserPW" Placeholder="Enter new password..." />
<br /> </Field>
<Field> </ModalBody>
<FieldLabel> <ModalFooter>
<h5> <Button Color="Color.Secondary" style="border-bottom-left-radius: 3px; border-bottom-right-radius: 3px" Clicked="@HideModalAddUser">Close</Button>
Select Role <Button Color="Color.Primary" style="border-bottom-left-radius: 3px; border-bottom-right-radius: 3px" Clicked="@AddButtonPressed">Add</Button>
</h5> </ModalFooter>
<Paragraph> </ModalContent>
Here you select or change the role of to User or Admin </Modal>
</Paragraph> </Column>
</FieldLabel> <br />
<br /> <br />
<Dropdown Display="Display.InlineBlock"> <Row>
<DropdownToggle Color="Color.Primary" Width="Width.Is100">Roles</DropdownToggle> <Column ColumnSize="ColumnSize.Is1.OnDesktop">
<DropdownMenu> <Button @onclick="() => Toggle(context.Item)" Position="Position.Absolute.Top.Is50.Start.Is100.Translate.Middle" Color="Color.Dark" Outline>
<DropdownItem @onclick="() => SetRoleAdmin()">Admin</DropdownItem> <BarIcon IconName="IconName.Pen" />
<DropdownDivider /> </Button>
<DropdownItem @onclick="() => SetRoleUser()">User</DropdownItem> </Column>
</DropdownMenu> </Row>
</Dropdown>
</Field> </Row>
<Column ColumnSize="ColumnSize.IsFull" TextAlignment="TextAlignment.End"> </ListGroupItem>
<Button @onclick="OnSave" Color="Color.Primary">Save</Button> </ItemTemplate>
</Column> </ListView>
</Div> </Column>
} <Column ColumnSize="ColumnSize.Is6.OnDesktop.Is12.OnMobile" Margin="Margin.Is3.FromTop.OnMobile" Padding="Padding.Is4.FromStart.OnMobile">
</Column> @if (SelectedUser is not null)
{
<Div hidden="@hideButtonSettings">
<Field>
<FieldLabel>
<h2>
User Settings
</h2>
</FieldLabel>
</Field>
<Validation @ref="updateValidation" Validator="ValidationRule.IsNotEmpty">
<Field>
<FieldLabel>
<h5>
User Name
</h5>
<Paragraph>
Here you can change the name of the User
</Paragraph>
</FieldLabel>
<TextEdit @ref="updateName" @bind-Text="@SelectedUser.Name" Placeholder="Enter User Name" />
</Field>
</Validation>
<br />
<br />
<Validation @ref="updateValidation" Validator="ValidationRule.IsEmail">
<Field>
<FieldLabel>
<h5>
E-Mail
</h5>
<Paragraph>
Here you can change the E-Mail of a User
</Paragraph>
</FieldLabel>
<TextEdit @ref="updateEmail" @bind-Text="@SelectedUser.Email" Placeholder="Enter new email" />
</Field>
</Validation>
<br />
<br />
<Validation @ref="updateValidation" Validator="ValidationRule.IsNotEmpty">
<Field>
<FieldLabel>
<h5>
Password
</h5>
<Paragraph>
Here you can change the password of a User
</Paragraph>
</FieldLabel>
<TextEdit @ref="updatePW" Placeholder="Enter new password" />
</Field>
</Validation>
<br />
<br />
<Field>
<FieldLabel>
<h5>
Select Role
</h5>
<Paragraph>
Here you select or change the role of to User or Admin
</Paragraph>
</FieldLabel>
<br />
<Dropdown Display="Display.InlineBlock">
<DropdownToggle Color="Color.Primary" Width="Width.Is100">Roles</DropdownToggle>
<DropdownMenu>
<DropdownItem @onclick="() => SetRoleAdmin()">Admin</DropdownItem>
<DropdownDivider />
<DropdownItem @onclick="() => SetRoleUser()">User</DropdownItem>
</DropdownMenu>
</Dropdown>
</Field>
<Column ColumnSize="ColumnSize.IsFull" TextAlignment="TextAlignment.End">
<Button @onclick="OnSave" Color="Color.Primary">Save</Button>
</Column>
</Div>
}
</Column>
</Div>
</Row>
</Div> </Div>
</Row> </Authorized>
</Div> <NotAuthorized>
Bro no! this page is only for admins! 😠
</NotAuthorized>
</Protected>
@code { @code {
List<User> users = new List<User>(); List<User> users = new List<User>();
@@ -334,49 +341,4 @@
{ {
admin = false; admin = false;
} }
public void ValidateName(ValidatorEventArgs e)
{
string? input = Convert.ToString(e.Value);
if (string.IsNullOrWhiteSpace(input))
{
e.Status = ValidationStatus.None;
return;
}
else
{
e.Status = ValidationStatus.Success;
return;
}
}
public void ValidateEmail(ValidatorEventArgs e)
{
string? input = Convert.ToString(e.Value);
if (string.IsNullOrWhiteSpace(input))
{
e.Status = ValidationStatus.None;
return;
}
else
{
e.Status = ValidationStatus.Success;
return;
}
}
public void ValidatePW(ValidatorEventArgs e)
{
string? input = Convert.ToString(e.Value);
if (string.IsNullOrWhiteSpace(input))
{
e.Status = ValidationStatus.None;
return;
}
else
{
e.Status = ValidationStatus.Success;
return;
}
}
} }