Adding link to object’s page

In ELMA, you can link to an object’s page.

This example shows an extension point for the IMyObject object created in a module containing the basic set of properties and one property of the “Drop-down list” type. Links to the object’s page are created from the table with a list of object’s items.

In ELMA, there are two extension points used to create links to an object, IEntityLink and IObjectLink. In this article, we shall review both of them.

Example of data display

Fig. 1. Link to object’s page from contractors’ table

Fig. 1. Link to object’s page from contractors’ table

Fig. 2. Object page

IEntityLink extension point (interface)

The IEntityLink extension point (interface) has the following methods:

/// <summary>
/// Entity type
/// </summary>
Type EntityType { get; }
 
/// <summary>
/// Entity type ID
/// </summary>
Guid TypeUid { get; }
 
/// <summary>
/// Area
/// </summary>
string Area(IEntity entity);
 
/// <summary>
/// Action
/// </summary>
string Action(IEntity entity);
 
/// <summary>
/// Controller
/// </summary>
string Controller(IEntity entity);
 
/// <summary>
/// Name of the id parameter in the method
/// </summary>
string IdParam { get; }
 
/// <summary>
/// Additional parameters
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
RouteValueDictionary GetParams(IEntity entity);
 
/// <summary>
/// Ready link
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
string Href(RequestContext html, IEntity entity);
 
/// <summary>
/// Load entity by TypeUid and Id if null
/// </summary>
bool LoadEntityIfNull { get; }

Example of extension point class

[Component]
public class EntityLinkExtension : IEntityLink
{
    public Type EntityType
    {
        get { return typeof(IMyObject); }
    }
 
    public Guid TypeUid
    {
        get { return Guid.Empty; }
    }
 
    public string Area(IEntity entity)
    {
        return null;
    }
 
    public string Action(IEntity entity)
    {
        return null;
    }
 
    public string Controller(IEntity entity)
    {
        return null;
    }
 
    public string IdParam
    {
        get { return null; }
    }
 
    public RouteValueDictionary GetParams(IEntity entity)
    {
        return null;
    }
 
    public string Href(RequestContext html, IEntity entity)
    {
        var urlHelper = new UrlHelper(html);
        return urlHelper.Action("Entity", "Home", new { area = EntityLink.Web.RouteProvider.AreaName, id = entity.GetId().ToString() }); 
    }
 
    public bool LoadEntityIfNull
    {
        get { return true; }
    }
 
}

It is best to use the IEntityLink extension point when managing ELMA objects, while IObjectLink is best used for external objects.  

The method returns a link to the object in the following form:

/Your_module/Controller_name/Action_in_controller/Object_ID

In our example, the link looks like this: /EntityLink.Web/Home/Entity/1

Controller´s code HomeController.cs :

public ActionResult Entity(long id)
{
     var model = EntityManager<IMyObject>.Instance.LoadOrNull(id);
     return View(model);
}

The first controller’s action returns the ViewItem.cshtml view with the IMyObject object model.

In this example, we used a table with a list of objects, where object names are links to their pages. The pages are displayed via ViewItem.cshtml.

Example of displaying an object page in ViewItem.cshtml:

@model IMyObject
@using EleWise.ELMA.Model.Services
@using EleWise.ELMA.Web.Mvc.ExtensionPoints
@using EleWise.ELMA;
@using EntityLink.Models
 
 
@{
    Html.Header(SR.T("Мой объект"));
}
@(Html.Toolbar("toolbar").Group("toolbar-group-1")
    .ToolbarLink(SR.Back, "#x32/Prev.png", "javascript:history.back(-1);", "toolbar-action-Back")
)
 
@using (Html.ElmaForm())
{
    @Html.TableFormStart()
    @Html.DisplayFor(m => m, "Object")
    @Html.TableFormEnd()
}

The main difference between IEntityLink and IObjectLink is that IEntityLink can be used for ELMA objects (entities) only, while IObjectLink can be used for almost any object (entity, enumeration, etc.).

Also, IEntityLink has more flexible settings than IObjectLink. In the example, for IObjectLink we will create a link for an IDelivery user event in the calendar. It would be impossible to create such a link with IEntityLink. For more information on creating your proper calendar events, read the next article.

Example of data display

Fig. 3. Generated link to a calendar event

Fig. 3. Generated link to a calendar event

IObjectLink extension point (interface)

The IObjectLink extension point (interface) has the following methods:

  1. public boolCheckType(Type type) – defines the object type for which the extension is intended, the object is passed as a parameter.
  2. public string Url(RequestContext contextobject obj) – returns the string that contains the address of the object.

Example of extension point class

[Component]
public class ObjectLinkExtension : IObjectLink
{
 public bool CheckType(Type type)
 {
  return type.IsInheritOrSame<DeliveryCalendarItem>();
 }
 
 public string Url(RequestContext context, object obj)
 {
  var urlHelper = new UrlHelper(context);
  return urlHelper.Action("ViewItem", "Catalogs", new
  {
   area = EleWise.ELMA.BPM.Web.Common.RouteProvider.AreaName,
   id = ((DeliveryCalendarItem)obj).Id,
   uid = InterfaceActivator.UID<IDelivery>()
  });
 }
}

The method returns a link to the object item. If needed, you can implement your own representation of the IDelivery object attributes.

Links to API elements

IObjectLink

IEntityLink