Skip to content
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
155 changes: 2 additions & 153 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,162 +16,11 @@ This packages aims to help developers quickly put together Umbraco Trees using C
- Easy to define section permissions
- ✨ Custom Entity Actions!

> [!IMPORTANT]
> Version 15 will only receive security updates and no new features.
> [!WARNING]
> Version 15 is no longer supported and is End of Life (EOL).

> Please review the [security policy](https://github.com/jcdcdev/Umbraco.Community.SimpleTrees?tab=security-ov-file#supported-versions) for more information.

## Quick Start

### Install Package

```csharp
dotnet add package Umbraco.Community.SimpleTrees
```

### Register Tree

By default, this will display in the content section.

```csharp title="ExampleTree.cs"
using Umbraco.Cms.Core.Models;
using Umbraco.Community.SimpleTrees.Core.Models;

namespace Umbraco.Community.SimpleTrees.TestSite.Trees;

public class MyTree : SimpleTree
{
public override Task<PagedModel<ISimpleTreeItem>> GetTreeRootAsync(int skip, int take, bool foldersOnly)
{
var data = new List<ISimpleTreeItem>
{
CreateRootItem("James", Guid.NewGuid().ToString(), "icon-user"),
CreateRootItem("Tim", Guid.NewGuid().ToString(), "icon-user"),
};

return Task.FromResult(new PagedModel<ISimpleTreeItem>(data.Count, data));
}

public override Task<PagedModel<ISimpleTreeItem>> GetTreeChildrenAsync(string entityType, string parentUnique, int skip, int take, bool foldersOnly) => Task.FromResult(EmptyResult());

public override string Name => "My Tree";
}
```

### Create Views

- Your views **must** go in `/Views/Trees`
- You views **must** be the name of your tree entities
- For example: `MyTree.cs` => `/Views/Trees/MyItem.cshtml` & `/Views/Trees/MyRoot.cshtml`

```csharp title="Views/Trees/MyItem.cshtml"
@inherits Umbraco.Community.SimpleTrees.Web.SimpleTreeViewPage

<uui-box headline="This is a custom tree item">
<div>
<table>
<thead>
<tr>
<th>Entity Type</th>
<th>Unique</th>
</tr>
</thead>
<tbody>
<tr>
<td>@Model.EntityType</td>
<td>@Model.Unique</td>
</tr>
</table>
</div>
</uui-box>
```


## Extending

### Entity Actions

It is possible to implement two Entity Actions

#### Url Actions

When clicked, the user will be taken to the specific URL.

```csharp title="NuGetPackageItemEntityUrlAction.cs"
using Umbraco.Community.SimpleTrees.Core.Models;

namespace Umbraco.Community.SimpleTrees.TestSite.Trees;

public class NuGetPackageItemEntityUrlAction : SimpleEntityUrlAction
{
public override string Icon => "icon-link";
public override string Name => "Go to Package";
public override Type[] ForTreeItems => [typeof(NuGetPackageTree)];
public override Type[] ForSimpleEntityTypes => [typeof(NuGetPackageVersionEntityType)];

public override Task<Uri> GetUrlAsync(string unique, string entityType)
{
var uri = new Uri("https://www.nuget.org/packages/" + unique);
return Task.FromResult(uri);
}
}
```

#### Execute Actions

When clicked, you custom logic will be executed. You can also return a helpful response to the user.

```csharp title="NuGetPackageItemEntityExecuteAction"
using System.Net.Http.Headers;
using Umbraco.Community.SimpleTrees.Core.Models;
using Umbraco.Community.SimpleTrees.Web.Models;

namespace Umbraco.Community.SimpleTrees.TestSite.Trees;

public class NuGetPackageItemEntityExecuteAction : SimpleEntityExecuteAction
{
private readonly HttpClient _client;

public NuGetPackageItemEntityExecuteAction(HttpClient client)
{
var url = "https://functions.marketplace.umbraco.com/api/";
client.BaseAddress = new Uri(url);
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Umbraco.Community.SimpleTrees.TestSite", "1.0"));
_client = client;
}

public override string Icon => "icon-refresh";
public override string Name => "Sync Package";
public override Type[] ForTreeItems => [typeof(NuGetPackageTree)];

public override async Task<SimpleEntityActionExecuteResponse> ExecuteAsync(string unique, string entityType)
{
try
{
var split = unique.Split('_');
var packageId = split[0];
var model = new MarketplaceRequest
{
PackageId = packageId,
};

var result = await _client.PostAsJsonAsync("InitiateSinglePackageSyncFunction", model);
if (!result.IsSuccessStatusCode)
{
return SimpleEntityActionExecuteResponse.Error("Failed to initiate package update", $"Status Code: {result.StatusCode}, Reason: {result.ReasonPhrase}");
}

var message = $"Package {packageId} update has been initiated. You can check the progress in the Umbraco Marketplace.";
return SimpleEntityActionExecuteResponse.Success("Package update initiated successfully", message);
}
catch (Exception ex)
{
return SimpleEntityActionExecuteResponse.Error("An error occurred while initiating the package update", ex.Message);
}
}
}
```

## Contributing

Contributions to this package are most welcome! Please visit the [Contributing](https://github.com/jcdcdev/Umbraco.Community.SimpleTrees/contribute) page.
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Build
uses: jcdcdev/jcdcdev.Umbraco.Github.Build@main
uses: jcdcdev/jcdcdev.Umbraco.GitHub.Build@v0
with:
project-name: Umbraco.Community.SimpleTrees
project-path: src/Umbraco.Community.SimpleTrees/Umbraco.Community.SimpleTrees.csproj
npm-working-dir: src/Umbraco.Community.SimpleTrees.Client
npm-enabled: true
umbraco-version: 15
dotnet-version: "9"
npm-version: "22.x"
npm-version: "22.x"
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: 🚀 Release
on:
workflow_dispatch:
pull_request:
types: [ closed ]
types: [closed]
jobs:
release:
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
Expand All @@ -13,7 +13,7 @@ jobs:
steps:
- name: Build
id: build
uses: jcdcdev/jcdcdev.Umbraco.GitHub.Build@main
uses: jcdcdev/jcdcdev.Umbraco.GitHub.Build@v0
with:
project-name: Umbraco.Community.SimpleTrees
project-path: src/Umbraco.Community.SimpleTrees/Umbraco.Community.SimpleTrees.csproj
Expand All @@ -23,9 +23,9 @@ jobs:
umbraco-version: 15
dotnet-version: "9"
- name: Release
uses: jcdcdev/jcdcdev.Umbraco.GitHub.Release@main
uses: jcdcdev/jcdcdev.Umbraco.GitHub.Release@v0
with:
artifact-name: ${{ steps.build.outputs.artifact-name }}
version: ${{ steps.build.outputs.version }}
nuget-api-key: ${{ secrets.NUGET_API_KEY }}
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
Loading