mirror of
https://github.com/immense/Remotely.git
synced 2025-10-26 11:27:15 +00:00
Merge pull request #632 from immense/jaredg-fix-scripts-page
Fix Scripts page.
This commit is contained in:
commit
2bd666ef1f
@ -15,7 +15,7 @@
|
||||
<span class="align-top">Show only mine</span>
|
||||
</div>
|
||||
</div>
|
||||
<TreeView DataSource="ParentPage.FilteredScriptNodes"
|
||||
<TreeView DataSource="ParentPage.TreeNodes"
|
||||
ItemTypeSelector="x => x.ItemType"
|
||||
ItemHeaderSelector="x => x.Name"
|
||||
ItemSelected="ScriptSelected"
|
||||
|
||||
@ -149,7 +149,7 @@
|
||||
<span class="align-top">Show only mine</span>
|
||||
</div>
|
||||
</div>
|
||||
<TreeView DataSource="ParentPage.FilteredScriptNodes"
|
||||
<TreeView DataSource="ParentPage.TreeNodes"
|
||||
ItemTypeSelector="x => x.ItemType"
|
||||
ItemHeaderSelector="x => x.Name"
|
||||
ItemSelected="ScriptSelected"
|
||||
|
||||
@ -71,7 +71,7 @@
|
||||
<input type="checkbox" @bind="ParentPage.ShowOnlyMyScripts" />
|
||||
<span class="align-top">Show only mine</span>
|
||||
</div>
|
||||
<TreeView DataSource="ParentPage.FilteredScriptNodes"
|
||||
<TreeView DataSource="ParentPage.TreeNodes"
|
||||
ItemTypeSelector="x => x.ItemType"
|
||||
ItemHeaderSelector="x => x.Name"
|
||||
ItemSelected="ScriptSelected"
|
||||
|
||||
@ -12,6 +12,7 @@ namespace Remotely.Server.Components.Scripts
|
||||
public string Id { get; } = Guid.NewGuid().ToString();
|
||||
public TreeItemType ItemType { get; set; }
|
||||
public string Name { get; init; }
|
||||
public ScriptTreeNode? ParentNode { get; set; }
|
||||
public List<ScriptTreeNode> ChildItems { get; } = new();
|
||||
public SavedScript Script { get; init; }
|
||||
}
|
||||
|
||||
@ -32,7 +32,9 @@
|
||||
|
||||
|
||||
@code {
|
||||
private IEnumerable<ScriptTreeNode>? _filteredScriptNodes;
|
||||
private readonly List<ScriptTreeNode> _treeNodes = new();
|
||||
private IEnumerable<SavedScript> _allScripts = Enumerable.Empty<SavedScript>();
|
||||
|
||||
private bool _showOnlyMyScripts = true;
|
||||
|
||||
[Parameter]
|
||||
@ -43,34 +45,24 @@
|
||||
get => _showOnlyMyScripts;
|
||||
set
|
||||
{
|
||||
_filteredScriptNodes = null;
|
||||
_showOnlyMyScripts = value;
|
||||
_treeNodes.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public List<ScriptTreeNode> TreeNodes { get; } = new();
|
||||
|
||||
public IEnumerable<ScriptTreeNode> FilteredScriptNodes
|
||||
public IEnumerable<ScriptTreeNode> TreeNodes
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_filteredScriptNodes?.Any() == true)
|
||||
if (_treeNodes?.Any() == true)
|
||||
{
|
||||
return _filteredScriptNodes;
|
||||
return _treeNodes;
|
||||
}
|
||||
|
||||
if (ShowOnlyMyScripts)
|
||||
{
|
||||
_filteredScriptNodes = TreeNodes.Where(x =>
|
||||
x.Script.CreatorId == User.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
_filteredScriptNodes = TreeNodes.Where(x =>
|
||||
x.Script.IsPublic || x.Script.CreatorId == User.Id);
|
||||
}
|
||||
RefreshTreeNodes();
|
||||
|
||||
return _filteredScriptNodes;
|
||||
return _treeNodes;
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,31 +77,9 @@
|
||||
|
||||
public async Task RefreshScripts()
|
||||
{
|
||||
TreeNodes.Clear();
|
||||
_filteredScriptNodes = null;
|
||||
_treeNodes.Clear();
|
||||
|
||||
var allScripts = await DataService.GetSavedScriptsWithoutContent(User.Id, User.OrganizationID);
|
||||
|
||||
foreach (var script in allScripts)
|
||||
{
|
||||
var root = BuildFolderPath(script.FolderPath);
|
||||
root.Add(new ScriptTreeNode()
|
||||
{
|
||||
Name = script.Name,
|
||||
Script = script,
|
||||
ItemType = TreeItemType.Item
|
||||
});
|
||||
}
|
||||
|
||||
TreeNodes.Sort((a, b) =>
|
||||
{
|
||||
if (a.ItemType != b.ItemType)
|
||||
{
|
||||
return Comparer.Default.Compare(a.ItemType, b.ItemType);
|
||||
}
|
||||
|
||||
return Comparer.Default.Compare(a.Name, b.Name);
|
||||
});
|
||||
_allScripts = await DataService.GetSavedScriptsWithoutContent(User.Id, User.OrganizationID);
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
@ -119,13 +89,14 @@
|
||||
}
|
||||
|
||||
|
||||
private List<ScriptTreeNode> BuildFolderPath(string folderPath)
|
||||
private void CreateTreeNode(SavedScript script)
|
||||
{
|
||||
var root = TreeNodes;
|
||||
var root = _treeNodes;
|
||||
ScriptTreeNode? targetParent = null;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(folderPath))
|
||||
if (!string.IsNullOrWhiteSpace(script.FolderPath))
|
||||
{
|
||||
var paths = folderPath.Split("/", StringSplitOptions.RemoveEmptyEntries);
|
||||
var paths = script.FolderPath.Split("/", StringSplitOptions.RemoveEmptyEntries);
|
||||
for (var i = 0; i < paths.Length; i++)
|
||||
{
|
||||
var existingParent = root.Find(x => x.Name == paths[i]);
|
||||
@ -135,18 +106,58 @@
|
||||
var newItem = new ScriptTreeNode()
|
||||
{
|
||||
Name = paths[i],
|
||||
ItemType = TreeItemType.Folder
|
||||
ItemType = TreeItemType.Folder,
|
||||
ParentNode = existingParent
|
||||
};
|
||||
root.Add(newItem);
|
||||
root = newItem.ChildItems;
|
||||
targetParent = newItem;
|
||||
}
|
||||
else
|
||||
{
|
||||
root = existingParent.ChildItems;
|
||||
targetParent = existingParent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return root;
|
||||
var scriptNode = new ScriptTreeNode()
|
||||
{
|
||||
Name = script.Name,
|
||||
Script = script,
|
||||
ItemType = TreeItemType.Item,
|
||||
ParentNode = targetParent
|
||||
};
|
||||
|
||||
root.Add(scriptNode);
|
||||
}
|
||||
|
||||
private void RefreshTreeNodes()
|
||||
{
|
||||
_treeNodes.Clear();
|
||||
|
||||
foreach (var script in _allScripts)
|
||||
{
|
||||
var showScript = ShowOnlyMyScripts ?
|
||||
script.CreatorId == User.Id :
|
||||
script.CreatorId == User.Id || script.IsPublic;
|
||||
|
||||
if (!showScript)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
CreateTreeNode(script);
|
||||
}
|
||||
|
||||
_treeNodes.Sort((a, b) =>
|
||||
{
|
||||
if (a.ItemType != b.ItemType)
|
||||
{
|
||||
return Comparer.Default.Compare(a.ItemType, b.ItemType);
|
||||
}
|
||||
|
||||
return Comparer.Default.Compare(a.Name, b.Name);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -655,12 +655,12 @@ namespace Remotely.Server.Services
|
||||
{
|
||||
if (currentUser.IsServerAdmin)
|
||||
{
|
||||
dbContext.EventLogs.RemoveRange(dbContext.EventLogs);
|
||||
await dbContext.EventLogs.ExecuteDeleteAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
var eventLogs = dbContext.EventLogs.Where(x => x.OrganizationID == currentUser.OrganizationID);
|
||||
dbContext.EventLogs.RemoveRange(eventLogs);
|
||||
await eventLogs.ExecuteDeleteAsync();
|
||||
}
|
||||
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user