Giter Site home page Giter Site logo

abjerner / limbo.umbraco.multinodetreepicker Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 788 KB

Custom multinode treepicker for Umbraco.

Home Page: https://packages.limbo.works/limbo.umbraco.multinodetreepicker/

License: MIT License

Batchfile 0.56% C# 86.69% HTML 6.28% JavaScript 4.95% CSS 0.77% Less 0.75%
limbo skybrud umbraco umbraco-package mntp multi-node-tree-picker umbraco-v11 umbracov10 umbravo-v9

limbo.umbraco.multinodetreepicker's Introduction

Limbo Multinode Treepicker

GitHub license NuGet NuGet Limbo.Umbraco.MultiNodeTreePicker at packages.limbo.works Umbraco Marketplace

Limbo.Umbraco.MultiNodeTreePicker adds a special multinode treepicker to the Umbraco backoffice in which developers can select a custom item converter.

The purpose of an item converter is to control the C# type returned by the .Value() method or the corresponding property in a ModelsBuilder generated model. This is particular useful in a SPA/Headless Umbraco implementation, where the ModelsBuilder model can then be returned directly via a WebAPI endpoint.

License: MIT License
Umbraco: Umbraco 10, 11 and 12
Target Framework: .NET 6



Installation

The package targets Umbraco 10 and is only available via NuGet. To install the package, you can use either .NET CLI

dotnet add package Limbo.Umbraco.MultiNodeTreePicker --version 1.0.6

or the NuGet Package Manager:

Install-Package Limbo.Umbraco.MultiNodeTreePicker -Version 1.0.6

Note
This package replaces our older Skybrud.Umbraco.MultiNodeTreePicker package. See this package for older versions of Umbraco.



Examples

At @limbo-works we typically use Umbraco as a headless CMS, and being able to control the generated models therefore makes a lot of sense. If a given page has some related content, it doesn't make sense for us to return the full model of a related model, so we instead have an item class with the needed properties - this class could be called TestItem.

Normally the property with the related content would return the full model for each page, but with the special multinode treepicker from this package, we can implement a custom item converter.

We can do this by implementing the IMntpItemConverter interface, but to get going a bit quicker, the package also contains the abstract MntpGenericItemConverter class we can use instead:

public class TestMntpItemConverter : MntpGenericItemConverter<TestItem> {

    public TestMntpItemConverter() : base("Default item converter", x => new TestItem(x)) { }

}
public class TestItem {
        
        public Guid Key { get; }

        public string Name { get; }

        public string Url { get; }
        
        public TestItem(IPublishedContent content) {
            Key = content.Key;
            Name = content.Name;
            Url = content.Url;
        }

    }

The MntpGenericItemConverter class requires us to specify a name for the converter, and then a callback function that will be used for converting each IPublishedContent to the desired type.

image

When the data type is configured to use our item converter (see screenshot above), properties of this type will now return List<TestItem> instead of List<IPublishedContent>.

With this special multinode treepicker, it's the datatype of the individual property, that determines the returned value. Another property could for instance be for selecting contact persons where we'd need a bit more information than what's available from the TestItem class, so we can create another item converter:

  public class TestMntpPersonItemConverter : MntpGenericItemConverter<TestPersonItem> {

      public TestMntpPersonItemConverter() : base("Person item converter", x => new TestPersonItem(x)) { }

  }
  public class TestPersonItem : TestItem {

      public string Phone { get; }

      public string Email { get; }

      public TestPersonItem(IPublishedContent content) : base(content) {
          Phone = content.Value<string>("phone");
          Email = content.Value<string>("email");
      }

  }

image



Documentation



Inspiration

The item converters in this package was inspired by a similar concept in the Contentment package. Thanks for creating and sharing this with us @leekelleher ๐Ÿ‘

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.