GithubHelp home page GithubHelp logo

skybrud / skybrud.umbraco.griddata.dtge Goto Github PK

View Code? Open in Web Editor NEW
0.0 5.0 2.0 504 KB

Doc Type GridEditor add-on for Skybrud.Umbraco.GridData.

License: MIT License

C# 98.11% Batchfile 1.89%
skybrud limbo umbraco umbraco-package umbraco-packages umbraco-v8 umbraco-v9 grid dtge doc-type-grid-editor

skybrud.umbraco.griddata.dtge's Introduction

Skybrud.Umbraco.GridData.Dtge

Add-on for Skybrud.Umbraco.GridData that adds support for Doc Type Grid Editor.



Installation

The package is only available via NuGet. To install the package, you can use either .NET CLI:

dotnet add package Skybrud.Umbraco.GridData.Dtge --version 4.0.3

or the NuGet Package Manager in Visual Studio:

Install-Package Skybrud.Umbraco.GridData.Dtge -Version 4.0.3



Usage

Skybrud.Umbraco.GridData works by having a list of grid converters. The package contains a default grid converter which handles the editors that is installed with Umbraco, but also allows developers and other packages to add their own conveters to handle custom grid editors.

This package builds on top of that by introducing a DtgeGridConverter, that will then handle DTGE grid controls. Also utilizing the generic improvements made in Skybrud.Umbraco.GridData v3.0.2, there are now a few different ways to working with strongly typed DTE based gird controls.

For instance in the example below, we can iterate through all the controls in a grid model. control.Value is defined as an instance of IGridControlValue, but given that this is an interface, it has a more specific type that depends on the underlying grid editor. For DTGE based grid controls, the value will be an instance if GridControlDtgeValue, which we can check for in an if statement.

GridControlDtgeValue then specifies the element value of the control. The type of the GridControlDtgeValue.Element property is IPublishedElement, but when using tools like ModelsBuilder, it may have an even more specific type, which we in a similar way can check for in a new if statement or switch case statement (DtgeTest is my test element type):

@foreach (GridControl control in grid.GetAllControls()) {
    <div style="padding: 50px;">
        <table class="table details">
            @if (control.Value is GridControlDtgeValue dtge) {
                <tr>
                    <th>ID</th>
                    <td>@dtge.Id</td>
                </tr>
                <tr>
                    <th>Alias</th>
                    <td>@dtge.DtgeContentTypeAlias</td>
                </tr>
                <tr>
                    <th>Element</th>
                    <td>@dtge.Element</td>
                </tr>
                switch (dtge.Element) {
                    case DtgeTest test:
                        <tr>
                            <th>DTGE Test</th>
                            <td>@test.Title</td>
                        </tr>
                        break;
                }
            }  
            <tr>
                <th>Value</th>
                <td>@(control.Value?.GetType().ToString() ?? "NULL")</td>
            </tr>
            <tr>
                <th>Control</th>
                <td>@(control.GetType())</td>
            </tr>
        </table>
    </div>
}

Indexing DTGE grid controls

Normally when using the Skybrud.Umbraco.GridData package for indexing grid content, it will work by asking the individual models implementing IGridControlValue to return a textual representation of the value of a given grid control (via the GetSearchableText method). But duye to the nature of DTGE based controls, this package can't know how to return a textual representation for models that it does not know about.

So to still allow this concept for DTGE based grid controls, GridConverterBase now contains a virtual TryGetSearchableText method that you can override in your own custom grid converter.

The method could be implemented with a switch case statement like en the example below, which then checks for the element types that it should handle - eg. my DtgeTest model.

If the method encounters an element type it does know how to handle, it should return false. This ensures that the Skybrud.Umbraco.GridData will ask the next grid converter in the list of grid converters.

using System;
using Skybrud.Umbraco.GridData.Converters;
using Umbraco.Core.Models.PublishedContent;
using WebApplication11.Models.Umbraco.Elements;

namespace WebApplication11.Grid {

    public class MyGridConverter : GridConverterBase {

        public override bool TryGetSearchableText(IPublishedElement element, out string text) {

            switch (element) {
                
                case DtgeTest dtge:
                    text = dtge.Title + Environment.NewLine;
                    return true;

                default:
                    text = null;
                    return false;

            }

        }

    }

}

skybrud.umbraco.griddata.dtge's People

Contributors

abjerner avatar lumimario avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

skybrud.umbraco.griddata.dtge's Issues

Indexing custom components

Hi, I can't find any updated documentation about how to index my custom grid components.

I have tried creating a new GridConverter that uses new models for GridControleDtageValue but it getting really complicated and I wonder if there's a simpler way of doing this.

On your docs you talk about GridConverterBase now contains a virtual TryGetSearchableText but it doesn't.

Can you please let me know the best solution for this? Thanks!

Duplicating first instance of content for each Doc Type

Thanks for putting this online, I can see this issue you are having with the control ID in the GridControlDtgeValue line 65
Content = DocTypeGridEditorHelper.ConvertValueToContent("0", docTypeAlias, contentValue);
The hardcode 0 value will just duplicate the first instance of the doctype as Doc Type Grid Editor caches on this id. Without adding a GUID to the control in GridData itself, I have an alternative solution. I have hashed the value to create a unique id for the content.

        public string GetControlId(string input)
        {
            using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
            {
                return BitConverter.ToString(
                  md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(input))
                ).Replace("-", String.Empty);
            }
        }

Can't think of an easier way to do it atm

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.