|
1 | 1 | # Umbraco.Community.SimpleTrees |
2 | 2 |
|
| 3 | +[](https://github.com/jcdcdev/Umbraco.Community.SimpleTrees#quick-start) |
| 4 | +[](https://marketplace.umbraco.com/package/Umbraco.Community.SimpleTrees) |
| 5 | +[](https://github.com/jcdcdev/Umbraco.Community.SimpleTrees?tab=MIT-1-ov-file) |
| 6 | +[](https://www.nuget.org/packages/Umbraco.Community.SimpleTrees) |
| 7 | +[](https://jcdc.dev/umbraco-packages/simple-trees) |
| 8 | + |
| 9 | + |
| 10 | +This packages aims to help developers quickly put together Umbraco Trees using C#. |
| 11 | + |
| 12 | +## Features |
| 13 | + |
| 14 | +- C# custom tree creation |
| 15 | +- No javascript or umbraco-package.json files required |
| 16 | +- Supports both Views & View Components |
| 17 | +- Easy to define section permissions |
| 18 | + |
| 19 | +## Quick Start |
| 20 | + |
| 21 | +### Install Package |
| 22 | + |
| 23 | +```csharp |
| 24 | +dotnet add package Umbraco.Community.SimpleTrees |
| 25 | +``` |
| 26 | + |
| 27 | +### Register Tree |
| 28 | + |
| 29 | +By default, this will display in the content section. |
| 30 | + |
| 31 | +```csharp title="ExampleTree.cs" |
| 32 | +using Umbraco.Cms.Core.Models; |
| 33 | +using Umbraco.Community.SimpleTrees.Models; |
| 34 | + |
| 35 | +namespace Umbraco.Community.SimpleTrees.TestSite.Trees; |
| 36 | + |
| 37 | +public class MyTree : SimpleTree |
| 38 | +{ |
| 39 | + public override Task<PagedModel<ISimpleTreeItem>> GetTreeRootAsync(int skip, int take, bool foldersOnly) |
| 40 | + { |
| 41 | + var data = new List<ISimpleTreeItem> |
| 42 | + { |
| 43 | + CreateRootItem("James", Guid.NewGuid().ToString(), "icon-user"), |
| 44 | + CreateRootItem("Tim", Guid.NewGuid().ToString(), "icon-user"), |
| 45 | + }; |
| 46 | + |
| 47 | + return Task.FromResult(new PagedModel<ISimpleTreeItem>(data.Count, data)); |
| 48 | + } |
| 49 | + |
| 50 | + public override Task<PagedModel<ISimpleTreeItem>> GetTreeChildrenAsync(string entityType, string parentUnique, int skip, int take, bool foldersOnly) => Task.FromResult(EmptyResult()); |
| 51 | + |
| 52 | + public override string Name => "My Tree"; |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +### Create Views |
| 57 | + |
| 58 | +- Your views **must** go in `/Views/Trees` |
| 59 | +- You views **must** be the name of your tree entities |
| 60 | + - For example: `MyTree.cs` => `/Views/Trees/MyItem.cshtml` & `/Views/Trees/MyRoot.cshtml` |
| 61 | + |
| 62 | +```csharp title="Views/Trees/MyItem.cshtml" |
| 63 | +@inherits Umbraco.Community.SimpleTrees.Web.SimpleTreeViewPage |
| 64 | + |
| 65 | +<uui-box headline="This is a custom tree item"> |
| 66 | + <div> |
| 67 | + <table> |
| 68 | + <thead> |
| 69 | + <tr> |
| 70 | + <th>Entity Type</th> |
| 71 | + <th>Unique</th> |
| 72 | + </tr> |
| 73 | + </thead> |
| 74 | + <tbody> |
| 75 | + <tr> |
| 76 | + <td>@Model.EntityType</td> |
| 77 | + <td>@Model.Unique</td> |
| 78 | + </tr> |
| 79 | + </table> |
| 80 | + </div> |
| 81 | +</uui-box> |
| 82 | +``` |
| 83 | + |
| 84 | + |
| 85 | +## Contributing |
| 86 | + |
| 87 | +Contributions to this package are most welcome! Please visit the [Contributing](https://github.com/jcdcdev/Umbraco.Community.SimpleTrees/contribute) page. |
| 88 | +
|
| 89 | +## Acknowledgements (Thanks) |
| 90 | + |
| 91 | +- LottePitcher - [opinionated-package-starter](https://github.com/LottePitcher/opinionated-package-starter) |
| 92 | +
|
3 | 93 |
|
4 | 94 |
|
0 commit comments