Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree View Optimizations #268

Merged
merged 4 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BLAZAM/BLAZAM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<ServerGarbageCollection>false</ServerGarbageCollection>
<AssemblyVersion>0.8.9</AssemblyVersion>
<Version>2024.03.20.2221</Version>
<Version>2024.03.23.1303</Version>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<RootNamespace>BLAZAM</RootNamespace>
<GenerateDocumentationFile>False</GenerateDocumentationFile>
Expand Down
4 changes: 2 additions & 2 deletions BLAZAM/Pages/Browse/ViewDirectoryEntry.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@inject IStringLocalizer<AppLocalization> AppLocalization
<CascadingValue Value="ChangeHistoryModal">
@switch (DirectoryEntry.ObjectType)
@switch (DirectoryEntry?.ObjectType)
{
case ActiveDirectoryObjectType.User:
<ViewUser DirectoryEntry="DirectoryEntry" />
Expand Down Expand Up @@ -31,5 +31,5 @@
[Parameter]
public IDirectoryEntryAdapter? DirectoryEntry { get; set; }

protected AppModal ChangeHistoryModal{ get; set; }
protected AppModal? ChangeHistoryModal{ get; set; }
}
12 changes: 6 additions & 6 deletions BLAZAM/Pages/Computers/ViewComputer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
OnResetPassword="@(()=>{ChangePasswordModal?.Show();})"
OnToggleEditMode="ToggleEditMode"
OnUnlock="@Unlock"
OnShowHistory="@(()=>{ChangeHistoryModal.Show();})"/>
OnShowHistory="@(()=>{ChangeHistoryModal?.Show();})"/>
<MudOverlay Visible="SavingChanges" DarkBackground="false" Absolute="true">

</MudOverlay>
Expand Down Expand Up @@ -252,15 +252,15 @@

async Task Unlock()
{
if (await MessageService.Confirm("Are you sure you want to unlock " + Computer?.CanonicalName + "?", "Unlock Computer"))
if (Computer!=null && await MessageService.Confirm("Are you sure you want to unlock " + Computer?.CanonicalName + "?", "Unlock Computer"))
{
Computer.LockedOut = false;
}

}
protected override async void DiscardChanges()
{
if (await MessageService.Confirm("Are you sure you want to discard your changes?", "Discard Changes"))
if (Computer != null && await MessageService.Confirm("Are you sure you want to discard your changes?", "Discard Changes"))
{
Computer.DiscardChanges();
EditMode = false;
Expand All @@ -271,7 +271,7 @@
}
async Task DeleteComputer()
{
if (await MessageService.Confirm("Are you sure you want to delete " + Computer?.CanonicalName + "?", "Delete Computer"))
if (Computer != null && await MessageService.Confirm("Are you sure you want to delete " + Computer?.CanonicalName + "?", "Delete Computer"))
{
try
{
Expand All @@ -290,7 +290,7 @@
}
async void SaveChanges()
{
if (await MessageService.Confirm("Are you sure you want to save the changes?"))
if (Computer != null && await MessageService.Confirm("Are you sure you want to save the changes?"))
{
var jobResults = await Computer.CommitChangesAsync();
if (jobResults.Result == JobResult.Passed)
Expand All @@ -305,7 +305,7 @@
}
else
{
jobResults.ShowJobDetailsDialog(MessageService);
await jobResults.ShowJobDetailsDialogAsync(MessageService);
}


Expand Down
4 changes: 2 additions & 2 deletions BLAZAM/Pages/Configure/AddFieldModalContent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
protected override void OnInitialized()
{
base.OnInitialized();
Modal.OnYes = Add;
Modal.YesText = AppLocalization["Add"];
Modal.SetOnYes(Add);
Modal.SetYesText(AppLocalization["Add"]);
foreach(var objectType in Enum.GetValues<ActiveDirectoryObjectType>().Where(ot=>ot!=ActiveDirectoryObjectType.All))
{
assignedObjectTypes.Add(objectType.ToString(), false);
Expand Down
7 changes: 5 additions & 2 deletions BLAZAM/Pages/Configure/Fields.razor
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@
{
LoadingData = true;
await InvokeAsync(StateHasChanged);
ADFields = await Context.CustomActiveDirectoryFields.Where(x => x.DeletedAt == null).ToListAsync();
if (Context != null)
{
ADFields = await Context.CustomActiveDirectoryFields.Where(x => x.DeletedAt == null).ToListAsync();
}
LoadingData = false;
var data = new GridData<CustomActiveDirectoryField>();
data.Items = ADFields;
Expand All @@ -104,7 +107,7 @@
if (await MessageService.Confirm("Are you sure you want to delete " + field.DisplayName + "?", "Delete " + field.DisplayName + "?"))
{
field.DeletedAt = DateTime.UtcNow;
if (await Context.SaveChangesAsync() > 0)
if (Context != null && await Context.SaveChangesAsync() > 0)
{
await fieldGrid?.ReloadServerData();

Expand Down
29 changes: 17 additions & 12 deletions BLAZAM/Pages/Configure/Templates.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
@inherits TemplateComponent
@attribute [Authorize(Roles = UserRoles.SuperAdmin)]

<AppPageTitle>Templates</AppPageTitle>
<AppPageTitle>@AppLocalization["Templates"]</AppPageTitle>

<SetHeader @ref=Header>


<MudStack Row=true>
<MudText Align="Align.Center">
Templates
@AppLocalization["Templates"]

</MudText>

Expand Down Expand Up @@ -86,7 +86,7 @@
{
<MudTooltip Text="@AppLocalization["Restore templates"]">

<MudIconButton OnClick=@(async()=>{RestoreModal.Show();})
<MudIconButton OnClick=@(async()=>{RestoreModal?.Show();})
Color="Color.Warning"
Icon="@Icons.Material.Filled.RestoreFromTrash" />
</MudTooltip>
Expand Down Expand Up @@ -173,22 +173,27 @@
async Task RenameSelectedCategory()
{
var temp = Context?.DirectoryTemplates.Where(t => t.Category == SelectedCategory).ToList();
foreach (var template in temp)
if (temp != null)
{
template.Category = newCategoryName;
foreach (var template in temp)
{
template.Category = newCategoryName;
}
}
if (SelectedTemplate.Category == SelectedCategory)
if (SelectedTemplate!=null && SelectedTemplate.Category == SelectedCategory)
SelectedTemplate.Category = newCategoryName;
Context?.SaveChanges();
if (Context != null && await Context.SaveChangesAsync() > 0)
{

SnackBarService.Success("Renamed category " + SelectedCategory + " to " + newCategoryName);
SelectedCategory = newCategoryName;
await FetchTemplates();
RenameModal?.Hide();
SnackBarService.Success(AppLocalization["Renamed category"] + ": " + SelectedCategory + " to " + newCategoryName);
SelectedCategory = newCategoryName;
await FetchTemplates();
RenameModal?.Hide();
}
await RefreshComponents();

}
private async void NewTemplate()
private void NewTemplate()
{
SelectedTemplate = new();
TemplateIdParameter = null;
Expand Down
8 changes: 4 additions & 4 deletions BLAZAM/Pages/Error/Oops.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
else
{
<h4>@Exception.GetType().Name</h4>
<p>@Exception.Message</p>
<p>@Exception.InnerException?.Message</p>
<p>@Exception.HelpLink</p>
<p>@Exception?.Message</p>
<p>@Exception?.InnerException?.Message</p>
<p>@Exception?.HelpLink</p>
}

<p>@Loc["Please report to"] your system administrator</p>
Expand All @@ -35,7 +35,7 @@
public static string? ErrorMessage { get; set; }
public static string? DetailsMessage { get; set; }
public static string? HelpMessage { get; set; }
public static Exception Exception { get; set; }
public static Exception? Exception { get; set; }
protected override void OnInitialized()
{
base.OnInitialized();
Expand Down
2 changes: 1 addition & 1 deletion BLAZAM/Pages/Error/UnhandledExceptionPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<MudPaper
Square
>
Error Message: @Error.Message
Error Message: @Error?.Message
</MudPaper Square>
<MudPaper Class="overflow-auto mud-typography-nowrap">
Stack Trace: <br>
Expand Down
2 changes: 1 addition & 1 deletion BLAZAM/Pages/Groups/CreateGroup.razor
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@



string newGroupName;
string newGroupName="";
List<DirectoryTemplate> templates;
IADOrganizationalUnit? parentOU;
IADGroup? newGroup;
Expand Down
4 changes: 2 additions & 2 deletions BLAZAM/Pages/Groups/ViewGroup.razor
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@



@if (Group.HasUnsavedChanges)
@if (Group.CanEdit && Group.HasUnsavedChanges)
{
<UnsavedChangesPrompt SaveChanges="SaveChanges" DiscardChanges="DiscardChanges" />
}
Expand Down Expand Up @@ -154,7 +154,7 @@
}
else
{
jobResults.ShowJobDetailsDialog(MessageService);
await jobResults.ShowJobDetailsDialogAsync(MessageService);
}


Expand Down
2 changes: 1 addition & 1 deletion BLAZAM/Pages/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
{
try
{
MOTD = (MarkupString)Context.AppSettings.FirstOrDefault().MOTD;
MOTD = (MarkupString)Context?.AppSettings.FirstOrDefault().MOTD;
}
catch
{
Expand Down
52 changes: 40 additions & 12 deletions BLAZAM/Pages/Login.razor
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,50 @@


<MudContainer Class="py-5">
<FullAppName/>
<FullAppName />



<form onsubmit="@(()=>{AttemptSignIn();})" class="login-form" method="post" action="/signin" id="login-form">
<MudContainer Style="max-width:300px;" Class="py-4">

<form onsubmit="@(()=>{AttemptSignIn();})"
class="login-form"
method="post"
action="/signin"
id="login-form">
<MudContainer Style="max-width:300px;"
Class="py-4">
@if (!ApplicationInfo.InDemoMode || DemoCustomLogin)
{



<MudTextField @ref=_usernameTextField Disabled=@attemptingSignIn Class="justify-center" AutoFocus Label="Username" name="Username" @bind-Value=LoginRequest.Username />
<MudTextField @ref=_usernameTextField
Disabled=@attemptingSignIn
Class="justify-center"
AutoFocus=true
Label=@AppLocalization["Username"]
name="Username"
@bind-Value=LoginRequest.Username />

<MudTextField @ref=_passwordTextField
Disabled=@attemptingSignIn
Class="justify-center"
Label=@AppLocalization["Password"]
name="Password"
InputType="InputType.Password"
@bind-Value=LoginRequest.Password />

<MudTextField Class="d-none"
name="ReturnUrl"
Value="@redirectUrl" />

<MudButton OnClick=@(()=>{attemptingSignIn=true;})
Class="my-5"
ButtonType=ButtonType.Submit
Color="Color.Primary">
@AppLocalization["Log In"]
</MudButton>

<MudTextField @ref=_passwordTextField Disabled=@attemptingSignIn Class="justify-center" Label="Password" name="Password" InputType="InputType.Password" @bind-Value=LoginRequest.Password />
<MudTextField Class="d-none" name="ReturnUrl" Value="@redirectUrl" />
<MudButton OnClick=@(()=>{attemptingSignIn=true;}) Class="my-5" ButtonType=ButtonType.Submit Color="Color.Primary">@AppLocalization["Log In"]</MudButton>



}
else if (ApplicationInfo.InDemoMode)
Expand All @@ -59,12 +85,14 @@

</MudContainer>

<MudOverlay Visible="attemptingSignIn" DarkBackground="true" Absolute="true">
<MudOverlay Visible="attemptingSignIn"
DarkBackground="true"
Absolute="true">
@*<MudProgressCircular Color="Color.Secondary" Indeterminate="true" />*@
</MudOverlay>
</form>
<MudElement Class="d-flex mud-width-full justify-end">
<Copyright Style="font-size:0.8em;"/>
<MudElement Class="d-flex mud-width-full justify-end">
<Copyright Style="font-size:0.8em;" />

</MudElement>
</MudContainer>
Expand Down
2 changes: 1 addition & 1 deletion BLAZAM/Pages/OU/ViewOU.razor
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</MudDataGrid>
}

@if (OU.HasUnsavedChanges)
@if (OU!=null && OU.CanEdit && OU.HasUnsavedChanges)
{
<UnsavedChangesPrompt SaveChanges="SaveChanges" DiscardChanges="DiscardChanges" />
}
Expand Down
2 changes: 1 addition & 1 deletion BLAZAM/Pages/SignIn.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public async Task<IActionResult> OnPost([FromFormAttribute]LoginRequest req)
await HttpContext.SignInAsync(result.AuthenticationState.User);
await AuditLogger.Logon.Login(result.AuthenticationState.User,req.IPAddress);
}
return new ObjectResult(result.Status);
return new ObjectResult(result?.Status);

}
catch (Exception ex)
Expand Down
2 changes: 1 addition & 1 deletion BLAZAM/Pages/Users/ViewUser.razor
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@
</CascadingValue>

</EditForm>
@if (User.HasUnsavedChanges && !User.NewEntry)
@if (User.CanEdit && User.HasUnsavedChanges && !User.NewEntry)
{
<UnsavedChangesPrompt SaveChanges="SaveChanges" DiscardChanges="DiscardChanges" />
}
Expand Down
9 changes: 0 additions & 9 deletions BLAZAM/RedirectToLogin.razor

This file was deleted.

21 changes: 18 additions & 3 deletions BLAZAMActiveDirectory/Adapters/DirectoryEntryAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,30 @@ public virtual bool IsDeleted
private set { _isDeleted = value; }

}
private bool? _cachedHasChildren;
public virtual bool HasChildren
{
get
{
if (CachedChildren == null)
{
EnsureDirectoryEntry();
var children = DirectoryEntry.Children;
CachedChildren = children.Encapsulate();
if (_cachedHasChildren == null)
{
EnsureDirectoryEntry();
_cachedHasChildren = DirectoryEntry?.Children.GetEnumerator().MoveNext();
}


return _cachedHasChildren==true;
//try{
// return cursor.Current != null;

//}
//catch (InvalidOperationException)
//{
// return false;
//}
//CachedChildren = children.Encapsulate();
}
var hasChildren = CachedChildren.Count() > 0;
return hasChildren;
Expand Down
2 changes: 1 addition & 1 deletion BLAZAMCommon/Data/LoginRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ public bool Valid
/// <summary>
/// The remote IP of the login attempt
/// </summary>
public IPAddress IPAddress { get; set; }
public IPAddress? IPAddress { get; set; }
}
}
Loading
Loading