Skip to content

Instantly share code, notes, and snippets.

View pawelel's full-sized avatar

Paweł Przytuła pawelel

  • Poland, Poznań
View GitHub Profile
@pawelel
pawelel / gist:0a448e8282f79b8442b5c6b8c80bb404
Created March 30, 2022 22:04
Mud nav menu - mini drawer and full text
//main
<MudPaper Class="mt-4" Height="400px" Style="overflow:hidden; position:relative;">
<MudDrawerContainer Class="mud-height-full">
<MudDrawer @bind-Open="@open" Fixed="true" DisableOverlay="true" Elevation="1" Variant="@DrawerVariant.Mini">
<NavMenu DrawerOpen="open" />
</MudDrawer>
<div class="d-flex justify-center align-center mud-height-full">
<MudButton OnClick="@ToggleDrawer" Color="Color.Primary">Toggle</MudButton>
</div>
</MudDrawerContainer>
@pawelel
pawelel / ObjectTranslator.cs
Last active January 10, 2022 17:37
Get string based on CurrentCulture
public static string GetString(object t, string property)
{
var language = CultureInfo.CurrentCulture.ToString();
if (language is not null and not "en")
{
foreach (var p in t.GetType().GetProperties().Where(p => p.Name.ToLower().Contains(property.ToLower() + language) && !string.IsNullOrWhiteSpace((string)p.GetValue(t))))
{
return (string)p.GetValue(t);
}
}
<MudLayout>
<MudAppBar Elevation="2" Dense="true" Style="@($"background:{Colors.Indigo.Darken2};")">
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="@ToggleDrawer"/>
<MudButtonGroup Color="Color.Primary" Variant="Variant.Filled">
<MudButton Size="Size.Small" Class="ma-0 rounded-pill">ScenarioTest</MudButton>
</MudButtonGroup>
</MudAppBar>
<MudDrawer @bind-Open="@open" Elevation="1" Style="@($"color:{Colors.Cyan.Lighten3}; background:{Colors.LightBlue.Darken3};")">
<MudDrawerHeader>
<MudText Typo="Typo.h5" Style="@($"color:{Colors.LightBlue.Lighten5};")">TestManager</MudText>
@inject IDialogService DialogService
<MudText Class="mt-1">This test page shows a 'bug' in Mud expansion panels...</MudText>
<MudText Class="mt-1">Click the add panels button (once). Several panels are created. Then, click on the top panel's pushpin to delete it. Once deleted, the panel below it auto-expands. This is <strong>undesired</strong> behaviour. </MudText>
<MudText Class="mt-1">Note: if you delete panels from bottom up, no panel get expanded. It appears only the panel directly below the delted on expands.</MudText>
<MudButton @onclick="AddPanels" Variant="Variant.Filled" Color="Color.Primary">
Add Panels
</MudButton>
<MudExpansionPanels>
@pawelel
pawelel / ConnectionString.sql
Created December 20, 2021 20:54
Connection String from SSMS
select
'data source=' + @@servername +
';initial catalog=' + db_name() +
case type_desc
when 'WINDOWS_LOGIN'
then ';trusted_connection=true'
else
';user id=' + suser_name()
end
from sys.server_principals
using Microsoft.AspNetCore.Components;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
public partial class LocationTable : ComponentBase
{
[Inject] private DataManager<Area, ApplicationDbContext> AreaManager { get; set; }
@pawelel
pawelel / RedirectToLogin.cs
Last active November 23, 2021 11:14
Get current user data without tracking by UserManager
[CascadingParameter] private Task<AuthenticationState> AuthSP { get; set; }
[Inject] private NavigationManager NavigationManager { get; set; }
string UserId;
ApplicationUser CurrentUser = new();
private async Task RedirectToLogin()
{
var user = (await AuthSP).User;
if (!user.Identity.IsAuthenticated)
{
NavigationManager.NavigateTo("Identity/Account/Login", true);
@pawelel
pawelel / ClearSearchOnEnter.razor
Created November 15, 2021 19:08
lowly tarnished frog shared code
<MudTextField @ref="field"
@bind-Value="_searchValue"
KeyUpPreventDefault="true"
OnKeyUp="OnKeyUp"/>
@code {
private string _searchValue = string.Empty;
MudTextField<string> field;
private void OnKeyUp(KeyboardEventArgs args)
public class ApplicationUser : IdentityUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
[NotMapped]
public string FullName => $"{LastName}, {FirstName}";
public DateTime? DateOfBirth { get; set; } = DateTime.Now;
@if (areas==null)
{
<p>wait</p>
}
else
{
<MudTable Items="@locations" T="AreaPlace" Dense="true" @bind-SelectedItem="selectedItem1" Filter="new Func<AreaPlace,bool>(FilterFunc1)">
<ToolBarContent>
<MudItem xs="12" md="5">