Fix scripts page "Creator" display field and public filter.

This commit is contained in:
Jared Goodwin 2023-05-02 12:21:44 -07:00
parent 9ee51e9da4
commit e2e92e9ab4
9 changed files with 49 additions and 21 deletions

View File

@ -15,7 +15,7 @@
<span class="align-top">Show only mine</span>
</div>
</div>
<TreeView DataSource="ParentPage.TreeNodes"
<TreeView DataSource="ParentPage.FilteredScriptNodes"
ItemTypeSelector="x => x.ItemType"
ItemHeaderSelector="x => x.Name"
ItemSelected="ScriptSelected"

View File

@ -149,7 +149,7 @@
<span class="align-top">Show only mine</span>
</div>
</div>
<TreeView DataSource="ParentPage.TreeNodes"
<TreeView DataSource="ParentPage.FilteredScriptNodes"
ItemTypeSelector="x => x.ItemType"
ItemHeaderSelector="x => x.Name"
ItemSelected="ScriptSelected"

View File

@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.CodeAnalysis.Scripting;
using Remotely.Server.Pages;
using Remotely.Server.Services;
using Remotely.Shared.Models;
@ -36,8 +37,7 @@ namespace Remotely.Server.Components.Scripts
public IModalService ModalService { get; set; }
private bool CanModifyScript => _selectedScript.Id == Guid.Empty ||
_selectedScript.CreatorId == User.Id ||
User.IsAdministrator;
_selectedScript.CreatorId == User.Id || User.IsAdministrator;
private bool CanDeleteScript => !string.IsNullOrWhiteSpace(_selectedScript.CreatorId) &&
(_selectedScript.CreatorId == User.Id || User.IsAdministrator);

View File

@ -71,7 +71,7 @@
<input type="checkbox" @bind="ParentPage.ShowOnlyMyScripts" />
<span class="align-top">Show only mine</span>
</div>
<TreeView DataSource="ParentPage.TreeNodes"
<TreeView DataSource="ParentPage.FilteredScriptNodes"
ItemTypeSelector="x => x.ItemType"
ItemHeaderSelector="x => x.Name"
ItemSelected="ScriptSelected"

View File

@ -9,7 +9,7 @@ namespace Remotely.Server.Components.TreeView
public partial class TreeView<T> : ComponentBase
{
[Parameter]
public List<T> DataSource { get; set; }
public IEnumerable<T> DataSource { get; set; }
[Parameter]
public Func<T, List<T>> ChildItemSelector { get; set; }

View File

@ -188,7 +188,7 @@
</div>
</div>
<div class="input-group-append">
<button type="submit" class="btn btn-secondary" @onclick="SendInvite">Add</button>
<button type="submit" class="btn btn-primary" @onclick="SendInvite">Add</button>
</div>
</div>
</div>

View File

@ -32,14 +32,47 @@
@code {
private IEnumerable<ScriptTreeNode>? _filteredScriptNodes;
private bool _showOnlyMyScripts = true;
[Parameter]
public string ActiveTab { get; set; }
public bool ShowOnlyMyScripts { get; set; } = true;
public bool ShowOnlyMyScripts
{
get => _showOnlyMyScripts;
set
{
_filteredScriptNodes = null;
_showOnlyMyScripts = value;
}
}
public List<ScriptTreeNode> TreeNodes { get; } = new();
public IEnumerable<ScriptTreeNode> FilteredScriptNodes
{
get
{
if (_filteredScriptNodes?.Any() == true)
{
return _filteredScriptNodes;
}
if (ShowOnlyMyScripts)
{
_filteredScriptNodes = TreeNodes.Where(x =>
x.Script.CreatorId == User.Id);
}
else
{
_filteredScriptNodes = TreeNodes.Where(x =>
x.Script.IsPublic || x.Script.CreatorId == User.Id);
}
return _filteredScriptNodes;
}
}
public string GetItemIconCss(ScriptTreeNode viewModel)
{
@ -53,18 +86,12 @@
public async Task RefreshScripts()
{
TreeNodes.Clear();
_filteredScriptNodes = null;
var allScripts = await DataService.GetSavedScriptsWithoutContent(User.Id, User.OrganizationID);
foreach (var script in allScripts)
{
if (ShowOnlyMyScripts &&
script.CreatorId != User.Id &&
!script.IsPublic)
{
continue;
}
var root = BuildFolderPath(script.FolderPath);
root.Add(new ScriptTreeNode()
{

View File

@ -268,7 +268,7 @@ using (var scope = app.Services.CreateScope())
context.Database.Migrate();
}
dataService.SetAllDevicesNotOnline();
await dataService.SetAllDevicesNotOnline();
dataService.CleanupOldRecords();
loggerFactory.AddProvider(new DbLoggerProvider(app.Environment, app.Services));

View File

@ -190,7 +190,7 @@ namespace Remotely.Server.Services
Task ResetBranding(string organizationId);
void SetAllDevicesNotOnline();
Task SetAllDevicesNotOnline();
Task SetDisplayName(RemotelyUser user, string displayName);
@ -1467,6 +1467,7 @@ namespace Remotely.Server.Services
using var dbContext = _appDbFactory.GetContext();
return await dbContext.SavedScripts
.Include(x => x.Creator)
.FirstOrDefaultAsync(x =>
x.Id == scriptId &&
(x.IsPublic || x.CreatorId == userId));
@ -1714,15 +1715,15 @@ namespace Remotely.Server.Services
await dbContext.SaveChangesAsync();
}
public void SetAllDevicesNotOnline()
public async Task SetAllDevicesNotOnline()
{
using var dbContext = _appDbFactory.GetContext();
dbContext.Devices.ForEachAsync(x =>
await dbContext.Devices.ForEachAsync(x =>
{
x.IsOnline = false;
}).Wait();
dbContext.SaveChanges();
});
await dbContext.SaveChangesAsync();
}
public async Task SetDisplayName(RemotelyUser user, string displayName)