Table of Contents

Class DashboardWidget

Namespace
Dynamicweb.Dashboard.Widgets
Assembly
Dynamicweb.Core.dll

The class DashboardWidget provides base dashboard widget

[AddInUseParameterOrdering(true)]
public abstract class DashboardWidget : ConfigurableAddIn, IParameterOptions
Inheritance
DashboardWidget
Implements
Derived
Inherited Members

Examples

using Dynamicweb.Dashboard.Widgets;
using Dynamicweb.Extensibility.AddIns;
using Dynamicweb.Extensibility.Editors;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Dynamicweb.Dashboard.Examples;

[AddInName("Date time widget")]
[AddInDescription("Show current date and time")]
[AddInIcon(Core.UI.Icons.KnownIcon.LocalHotel)]
public sealed class SimpleDateTimeWidget : DashboardWidget
{
    public SimpleDateTimeWidget()
    {
        Columns = 2;
        Title = "Current date and time";
    }

    [AddInLabel("Date time format"), AddInParameter("Format"), AddInParameterEditor(typeof(DropDownParameterEditor), "container=body;AllowSearch=true")]
    public string Format { get; set; } = "";

    public override IEnumerable<ParameterOption> GetParameterOptions(string dropdownName)
    {
        return dropdownName switch
        {
            "Format" => GetOptions(),
            _ => Enumerable.Empty<ParameterOption>()
        };

        ParameterOption[] GetOptions() => new ParameterOption[]
        {
            new("Short date time format", "Short"),
            new("Long date time format", "Long")
        };
    }

    public Dictionary<string, string> GetData()
    {
        DateTime dateTime = DateTime.Now;
        bool isShortFormat = Format.Equals("Short", StringComparison.OrdinalIgnoreCase);
        string currentDate = isShortFormat ? dateTime.ToShortDateString() : dateTime.ToLongDateString();
        string currentTime = isShortFormat ? dateTime.ToShortTimeString() : dateTime.ToLongTimeString();

        return new()
        {
            { "Date", currentDate },
            { "Time", currentTime }
        };
    }
}

Properties

Columns

Gets or sets widget size

[AddInLabel("Columns")]
[AddInParameter("CustomColumns")]
[AddInParameterOrder(0)]
[AddInParameterEditor(typeof(IntegerNumberParameterEditor), "")]
public virtual int Columns { get; set; }

Property Value

int

Remarks

The size set on widget via class name "col-md-" + Size

CreatedDate

Gets the created date and time.

public DateTime CreatedDate { get; }

Property Value

DateTime

Id

Gets widget Id

public int Id { get; }

Property Value

int

ModifiedDate

Gets the last modified date and time.

public DateTime ModifiedDate { get; }

Property Value

DateTime

Order

Gets or sets widget order

public int Order { get; set; }

Property Value

int

ShowTitle

Gets or sets value indicating whether to show widget title.

public bool ShowTitle { get; set; }

Property Value

bool

Title

Gets or sets widget title

[AddInLabel("Title")]
[AddInParameter("WidgetTitleEditor")]
[AddInParameterOrder(0)]
[AddInParameterEditor(typeof(TextParameterEditor), "")]
public virtual string Title { get; set; }

Property Value

string

Methods

GetParameterOptions(string)

Gets parameteroptions

public virtual IEnumerable<ParameterOption> GetParameterOptions(string parameterName)

Parameters

parameterName string

Returns

IEnumerable<ParameterOption>
To top