Try our conversational search powered by Generative AI!

Howto create a block with custom property of a class

Vote:
 

We have a need to create a custom property for a project we are working on. We are creating a shared block that is going to show a graph. The editor can set title and type of (chart, donut etc.) the graph, these are ordinary string properties.

Next the editor need to create data for each part of the chart, example is that the editor is going to create three columns holidng data for a Basic Column Chart.

Each part of the column chart is holding three values and we manage this properies in a class called GraphPart

int value; string color; string description;

What we want to create is a custom property that the user easily can create as many as they like to the block graph. Something similiar as the LinkItemCollection property works.

What are the best practise and how should we implement this? All suggestions and tips/guides are welcome.

Example of code below:

[ContentType(
        DisplayName = "Graf",
        Description = "Block med graf",
        AvailableInEditMode = true)]
    [ImageUrl("~/Content/icons/block-type-graf-stapel.jpg")]
    public class GraphBlock : BlockData
    {
        [Display(
           Name = "Diagramtyp",
           Description = "Välj vilken diagramtyp som ",
           GroupName = SystemTabNames.Content,
           Order = 0)]
        [UIHint(SiteUIHints.GraphTypes)]
        public virtual string Typ { get; set; }

        [Display(
            Name = "Title",
            Description = "Beskrivande titel kan anges",
            GroupName = SystemTabNames.Content,
            Order = 1)]
        public virtual string MainTitle { get; set; }

        [Display(
            Name = "Diagrambitar",
            Description = "För varje bit av diagram måste en diagrambit med tre värden anges.",
            GroupName = SystemTabNames.Content,
            Order = 2)]
        public virtual IEnumerable<GraphParts> GraphParts { get; set; }
    }

    public class GraphPart
    {
        public int Value { get; set; }
        public string Title { get; set; }
        public string Color { get; set; }
    }
#86859
Jun 03, 2014 15:15
Vote:
 

As I'm heading on home I'll go for the quick option. ;)

I would steal Peter Löfmans code and change the key/value part to use your GraphPart instead.

#86860
Jun 03, 2014 15:29
Vote:
 

I followed the guide that Peter Löfman wrote, and everything seems to compile and run fine. After some struggle with preview controller missing and location of Scripts/Editors/ files it seems like it is working. Now i can try to modify the custom propery for our needs.

#86971
Edited, Jun 05, 2014 12:32
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.