Skip to content

Commit

Permalink
Merge branch 'master' into jaredg-viewer-design-update
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed May 19, 2023
2 parents 6a87a29 + 68dfc56 commit 1909925
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 53 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ To avoid injection attacks, ASP.NET Core defaults to only accepting forwarded he
- Data for Remotely will be saved in `/var/www/remotely/` within two files: appsettings.json and Remotely.db.
- These files will persist through teardown and setup of new Remotely containers.
- If upgrading from a non-Docker version of Remotely, overwrite these files with the ones from your previous installation.
- In that case, please note that you may need to change _SQLite_ parameter in your non-Docker appsettings.json. You may have something like:
```
"SQLite": "DataSource=Remotely.db",
```
but this should be changed to reflect the new Remotely.db location (relative to the container):
```
"SQLite": "DataSource=/remotely-data/Remotely.db",
```
- Use Caddy as a reverse proxy if you want to expose the site to the internet.
- If this is the first run, create your account by clicking the `Register` button on the main page.
- This account will be both the server admin and organization admin.
Expand Down
3 changes: 2 additions & 1 deletion Server/API/RemoteControlController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ await _serviceHub.Clients.Client(serviceConnectionId).SendAsync("RemoteControl",
accessKey,
HttpContext.Connection.Id,
string.Empty,
orgName);
orgName,
orgID);

var waitResult = await session.WaitForSessionReady(TimeSpan.FromSeconds(30));
if (!waitResult)
Expand Down
2 changes: 1 addition & 1 deletion Server/Components/Scripts/RunScript.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion Server/Components/Scripts/SavedScripts.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion Server/Components/Scripts/ScriptSchedules.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions Server/Components/Scripts/ScriptTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ScriptTreeNode
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; }
}
Expand Down
105 changes: 58 additions & 47 deletions Server/Pages/ScriptsPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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;
}
}

Expand All @@ -85,31 +77,9 @@

public async Task RefreshScripts()
{
TreeNodes.Clear();
_filteredScriptNodes = null;

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.Clear();

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()
Expand All @@ -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]);
Expand All @@ -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);
});
}
}
4 changes: 2 additions & 2 deletions Server/Services/DataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -655,12 +655,12 @@ public async Task ClearLogs(string currentUserName)
{
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();
Expand Down

0 comments on commit 1909925

Please sign in to comment.