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);
if (loginResult.IsSuccess) Result loginResult = await AuthenticationService.LoginUserAsync(username, password);
{
NavigationManager.NavigateTo("/", true); if (loginResult.IsSuccess)
} {
else NavigationManager.NavigateTo("/", true);
{ }
color = Color.Danger; else
disabled = false; {
} color = Color.Danger;
} 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" <Div Display="Display.Flex.Row.OnDesktop" Margin=" Margin.Is3.FromBottom" Width="Width.Is100">
Border="Border.Is1.RoundedTop"> <Column ColumnSize="ColumnSize.Is5.OnDesktop.Is12.OnMobile">
<BarBrand> <Bar Breakpoint="Breakpoint.Desktop"
<Column ColumnSize="ColumnSize.Is12"> Background="Background.White"
Users ThemeContrast="ThemeContrast.None"
</Column> Shadow="Shadow.Remove"
<Column ColumnSize="ColumnSize.Is12.Is11.WithOffset.OnDesktop.IsAuto.OnMobile"> Border="Border.Is1.RoundedTop">
<Button Clicked="@ShowModalAddUser" TextAlignment="TextAlignment.End" Shadow="Shadow.Remove"> <BarBrand>
<BarIcon IconName="IconName.Add"></BarIcon> <Column ColumnSize="ColumnSize.Is12">
</Button> Users
</Column>
</BarBrand>
</Bar>
<ListView TItem="User"
Data="@users"
TextField="@((_)=>(""))"
ValueField="@((_)=>(""))"
Style="border-radius: 0px 0px"
Height="100%"
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>
</BarBrand>
</Bar>
<ListView TItem="User"
Data="@users"
TextField="@((_)=>(""))"
ValueField="@((_)=>(""))"
Style="border-radius: 0px 0px"
Height="100%"
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 ColumnSize="ColumnSize.Is4.OnDesktop.Is7.OnMobile">
<Button @onclick="() => Delete(context.Item)" class="btn1" Position="Position.Absolute.Top.Is50.Start.Is50.Translate.Middle" Color="Color.Dark" Outline>
<BarIcon IconName="IconName.Delete" />
</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>
<br />
<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>
</Column>
<Column ColumnSize="ColumnSize.Is6.OnDesktop.Is12.OnMobile" Margin="Margin.Is3.FromTop.OnMobile" Padding="Padding.Is4.FromStart.OnMobile">
@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 />
<br /> <br />
<Row> <Validation @ref="updateValidation" Validator="ValidationRule.IsEmail">
<Column ColumnSize="ColumnSize.Is1.OnDesktop"> <Field>
<Button @onclick="() => Toggle(context.Item)" Position="Position.Absolute.Top.Is50.Start.Is100.Translate.Middle" Color="Color.Dark" Outline> <FieldLabel>
<BarIcon IconName="IconName.Pen" /> <h5>
</Button> E-Mail
</Column> </h5>
</Row> <Paragraph>
Here you can change the E-Mail of a User
</Row> </Paragraph>
</ListGroupItem> </FieldLabel>
</ItemTemplate> <TextEdit @ref="updateEmail" @bind-Text="@SelectedUser.Email" Placeholder="Enter new email" />
</ListView> </Field>
</Column> </Validation>
<Column ColumnSize="ColumnSize.Is6.OnDesktop.Is12.OnMobile" Margin="Margin.Is3.FromTop.OnMobile" Padding="Padding.Is4.FromStart.OnMobile"> <br />
@if (SelectedUser is not null) <br />
{ <Validation @ref="updateValidation" Validator="ValidationRule.IsNotEmpty">
<Div hidden="@hideButtonSettings"> <Field>
<Field> <FieldLabel>
<FieldLabel> <h5>
<h2> Password
User Settings </h5>
</h2> <Paragraph>
</FieldLabel> Here you can change the password of a User
</Field> </Paragraph>
<Validation @ref="updateValidation" Validator="ValidationRule.IsNotEmpty"> </FieldLabel>
<Field> <TextEdit @ref="updatePW" Placeholder="Enter new password" />
<FieldLabel> </Field>
<h5> </Validation>
User Name <br />
</h5> <br />
<Paragraph> <Field>
Here you can change the name of the User <FieldLabel>
</Paragraph> <h5>
</FieldLabel> Select Role
<TextEdit @ref="updateName" @bind-Text="@SelectedUser.Name" Placeholder="Enter User Name" /> </h5>
</Field> <Paragraph>
</Validation> Here you select or change the role of to User or Admin
<br /> </Paragraph>
<br /> </FieldLabel>
<Validation @ref="updateValidation" Validator="ValidationRule.IsEmail"> <br />
<Field> <Dropdown Display="Display.InlineBlock">
<FieldLabel> <DropdownToggle Color="Color.Primary" Width="Width.Is100">Roles</DropdownToggle>
<h5> <DropdownMenu>
E-Mail <DropdownItem @onclick="() => SetRoleAdmin()">Admin</DropdownItem>
</h5> <DropdownDivider />
<Paragraph> <DropdownItem @onclick="() => SetRoleUser()">User</DropdownItem>
Here you can change the E-Mail of a User </DropdownMenu>
</Paragraph> </Dropdown>
</FieldLabel> </Field>
<TextEdit @ref="updateEmail" @bind-Text="@SelectedUser.Email" Placeholder="Enter new email" /> <Column ColumnSize="ColumnSize.IsFull" TextAlignment="TextAlignment.End">
</Field> <Button @onclick="OnSave" Color="Color.Primary">Save</Button>
</Validation> </Column>
<br /> </Div>
<br /> }
<Validation @ref="updateValidation" Validator="ValidatePW"> </Column>
<Field> </Div>
<FieldLabel> </Row>
<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> </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;
}
}
} }