Examples of Code portlets
In ELMA you can create custom portlets by writing their content in Razor.
Razor markup language combines C# and HTML and allows working with system objects.
To create such a portlet, add a Code type portlet to a page. Click on the edit icon. In the opened portlet settings window, click Open markup editor, which will open the editor in a new tab.
To add a C# code line, use the @ character. For example:
<p>
Current time :@DateTime.Now
</p>
To add a C# code block, use the @{…} structure. Example:
@{
if(condition)
{
code
}
}
For more information, follow this link: http://msdn.microsoft.com/en-us/VS2010TrainingCourse_ASPNETMVC3Razor
Consider examples of Code type portlets.
Example 1. Approval tasks
In this example, the portlet will display approval tasks, in which the current user is the approver.
Script with PublicAPI
@using EleWise.ELMA.API
@using EleWise.ELMA.Tasks.Models
@{
//create variables that store static links
//for document approval
var DocRef = "/Docflow/Approvement/Execute/";
//for tasks
var TaskRef = "/Tasks/Task/Approve/";
//get the current user
var CurUser = PublicAPI.Portal.Security.User.GetCurrentUser();
//get active approval tasks
var ActiveApprove = PublicAPI.Portal.Objects.Tasks.ApprovalTask.Filter().Statuses(TaskBaseExtensions.ActiveTaskStatuses.ToList()).Query("Harmonizator=" + CurUser).Find();
//get active document approval tasks
var ActiveDocumentApprove = PublicAPI.Docflow.Objects.Tasks.DocumentApprovementTask.Filter().Statuses(TaskBaseExtensions.ActiveTaskStatuses.ToList()).Query("Harmonizator=" + CurUser).Find();
}
@{
foreach(var item in ActiveDocumentApprove)
{
//generate a link based on the created variables and ids of the found tasks
<p><a href=@DocRef@item.Id>Согласование документа - @item.Subject</a></p>
}
}
@{
foreach(var item in ActiveApprove)
{
<p><a href=@TaskRef@item.Id>@item.Subject</a></p>
}
}
Script without PublicAPI
@using EleWise.ELMA.Security.Models
@using EleWise.ELMA.Security.Services
@using EleWise.ELMA.Tasks.Models
@using EleWise.ELMA.Model.Services;
@using EleWise.ELMA.Model.Managers
@using EleWise.ELMA.Tasks.Managers;
@using EleWise.ELMA.Documents.Models.Tasks
@{
//create variables for storing static links
//For document approval
var DocRef = "/Docflow/Approvement/Execute/";
//for tasks
var TaskRef = "/Tasks/Task/Approve/";
//identify the current user
var CurUser = (User)AuthenticationService.GetCurrentUser<EleWise.ELMA.Security.Models.IUser>();
//create a filter for an approval task
var TaskFilter = InterfaceActivator.Create<ApprovalTaskFilter>();
//specify the statuses of the active tasks
TaskFilter.Statuses=TaskBaseExtensions.ActiveTaskStatuses.ToList();
// foreach(var t in TaskBaseExtensions.ActiveTaskStatuses)
// {TaskFilter.Statuses.Add(t);}
//specify the current user as the approver
TaskFilter.Query = "Harmonizator="+CurUser;
//select data by filter
var ActiveApprove = ApprovalTaskManager.Instance.Find(TaskFilter, null);
//create a filter for a document approval task
var DocumentTaskFilter = InterfaceActivator.Create<DocumentApprovementTaskFilter>();
DocumentTaskFilter.Statuses=TaskBaseExtensions.ActiveTaskStatuses.ToList();
//specify the statuses of the active tasks
// foreach(var w in TaskBaseExtensions.ActiveTaskStatuses)
// {DocumentTaskFilter.Statuses.Add(w);}
//specify the current user as the approver
DocumentTaskFilter.Query = "Harmonizator="+CurUser;
//select data by the filter
var ActiveDocumentApprove = EntityManager<DocumentApprovementTask>.Instance.Find(DocumentTaskFilter, null);
}
@{
foreach(var item in ActiveDocumentApprove)
{
//generate a link from the created variables and IDs of the found tasks
<p><a href=@DocRef@item.Id>Document approval - @item.Subject</a></p>
}
}
@{
foreach(var item in ActiveApprove)
{
<p><a href=@TaskRef@item.Id>@item.Subject</a></p>
}
}
Example 2. My contractors
The portlet will display the contractors, for which the current user is responsible and all the contractors created for the current day, regardless of the responsible user.
Script with PublicAPI
@using EleWise.ELMA.API;
@using EleWise.ELMA.Model.Ranges;
<h1>My Contractors</h1>
@{
//generate a link, search the required objects
var KontrRef = "/CRM/ContractorLegal/Details/";
var CurUser = PublicAPI.Portal.Security.User.GetCurrentUser();
//find contractor by filter, select the current user as the responsible in the filter
var MyKontr = PublicAPI.CRM.Contractor.Filter().Responsible(CurUser).Find();
foreach(var item in MyKontr)
{
<p><a href=@KontrRef@item.Id>@item.Name</a></p>
}
<h1>New Contractors</h1>
//only contractors, created today (regardless of the responsible user)
var createdate = new DateTimeRange();
createdate.From = DateTime.Now.Date;
var NewKontr = PublicAPI.CRM.Contractor.Filter().CreationDate(createdate).Find();
foreach(var item in NewKontr)
{
<p><a href=@KontrRef@item.Id>@item.Name</a></p>
}
}
Script without PublicAPI
@using EleWise.ELMA.Security.Models;
@using EleWise.ELMA.Security.Services;
@using EleWise.ELMA.CRM.Managers;
@using EleWise.ELMA.CRM.Models;
@using EleWise.ELMA.Model.Services;
@using EleWise.ELMA.Model.Managers;
@using EleWise.ELMA.Model.Ranges;
<h1>My contractors</h1>
@{
//generate a link, find the required objects
var KontrRef = "/CRM/ContractorLegal/Details/";
var CurUser = (User)AuthenticationService.GetCurrentUser<EleWise.ELMA.Security.Models.IUser>();
//create a filter for a contractor
var contractorFilter = InterfaceActivator.Create<ContractorFilter>();
//specify the current user as the responsible in the filter
contractorFilter.Responsible = CurUser;
//find contractors by filter
var MyKontr = ContractorManager.Instance.Find(contractorFilter, null);
foreach(var item in MyKontr)
{
<p><a href=@KontrRef@item.Id>@item.Name</a></p>
}
<h1>New contractors</h1>
//only contractors, created on the current day (regardless of the responsible user)
var conCreateTodayFilter = InterfaceActivator.Create<ContractorFilter>();
var createdate = new DateTimeRange();
createdate.From = DateTime.Now.Date;
conCreateTodayFilter.CreationDate = createdate;
var NewKontr = ContractorManager.Instance.Find(conCreateTodayFilter, null);
foreach(var item in NewKontr)
{
<p><a href=@KontrRef@item.Id>@item.Name</a></p>
}
}
Example 3. Portlet for managers: Task execution control
This portlet will display the tasks that the executor has not opened for more than 24 hours. The tasks are divided into process and user tasks, the result is displayed in a table.
Script with PublicAPI
@using EleWise.ELMA.API
@{
var TaskRef = "/Tasks/Task/Execute/";
var FreshNewTasks = PublicAPI.Portal.TaskBase.Task.Filter().Status(PublicAPI.Enums.Tasks.TaskBaseStatus.NewOrder).Query("CreationDate in RelativeDateTime(’’,’0d’)").Find();
}
<TABLE border="1" ALIGN=TOP WIDTH=100% >
<UL>
<TR>
<TD width="250" VALIGN=TOP><H3>Tasks without activity for more than one day</H3>
</TD>
<TD width="250" VALIGN=TOP>
@{
foreach(var item in FreshNewTasks)
{
<li><a href=@TaskRef@item.Id>@item.Subject</a></li>
}
}
@{
//if there are no tasks, show the respective comment
if(FreshNewTasks.Count <= 0)
{
<p align="center">No tasks with the New status</p>
}}
</TD>
<TD width="250" VALIGN=TOP>
@{
foreach(var item in FreshNewTasks)
{
<li>@item.CreationDate.Value.ToString().Substring(0,16)</li>
}
}
</TD>
</UL>
</TR>
@{
var WTRef = "/Workflow/WorkflowTask/Execute/";
var FreshNewWT = PublicAPI.Processes.WorkflowTaskBase.WorkflowTask.Filter().Status(PublicAPI.Enums.Tasks.TaskBaseStatus.NewOrder).Query("CreationDate in RelativeDateTime(’’,’0d’)").Find();
}
<UL>
<TR>
<TD width="250" VALIGN=TOP> <H3>Process tasks without activitiy for more than one day</H3></TD>
<TD width="250" VALIGN=TOP>
@{
foreach(var item in FreshNewWT)
{
<li> <a href=@WTRef@item.Id>@item.Subject</a></li>
}
}
@{
if(FreshNewWT.Count <= 0)
{
<p align="center">No tasks with the New status</p>
}
}
</TD>
<TD width="250" VALIGN=TOP>
@{
foreach(var item in FreshNewWT)
{
<li>@item.CreationDate.Value.ToString().Substring(0, 16)</li>
}
}
</TD>
</UL>
</TR>
</TABLE>
Script without PublicAPI
@using EleWise.ELMA.Model.Managers;
@using EleWise.ELMA.Tasks.Models;
@using EleWise.ELMA.Model.Services;
@using EleWise.ELMA.Workflow.Managers;
@using EleWise.ELMA.Tasks.Managers;
@using EleWise.ELMA.Workflow.Models;
@{
var TaskRef = "/Tasks/Task/Execute/";
var taskFilter = InterfaceActivator.Create<TaskFilter>();
taskFilter.Status = TaskBaseStatus.NewOrder;
taskFilter.Query="CreationDate in RelativeDateTime(’’,’0d’) ";
var FreshNewTasks = TaskManager.Instance.Find(taskFilter, null);
}
<TABLE border="1" ALIGN=TOP WIDTH=100% >
<UL>
<TR>
<TD width="250" VALIGN=TOP><H3>Tasks without activity for more than one day</H3>
</TD>
<TD width="250" VALIGN=TOP>
@{
foreach(var item in FreshNewTasks)
{
<li><a href=@TaskRef@item.Id>@item.Subject</a></li>
}
}
@{
//If there aren't required tasks, add the respective comment
if(FreshNewTasks.Count <= 0)
{
<p align="center">No tasks with the "New" status</p>
}}
</TD>
<TD width="250" VALIGN=TOP>
@{
foreach(var item in FreshNewTasks)
{
<li>@item.CreationDate.Value.ToString().Substring(0,16)</li>
}
}
</TD>
</UL>
</TR>
@{
var WTRef = "/Workflow/WorkflowTask/Execute/";
var wftaskFilter = InterfaceActivator.Create<WorkflowTaskFilter>();
wftaskFilter.Status = TaskBaseStatus.NewOrder;
wftaskFilter.Query="CreationDate in RelativeDateTime(’’,’0d’) ";
var FreshNewWT = WorkflowTaskManager.Instance.Find(wftaskFilter, null);
}
<UL>
<TR>
<TD width="250" VALIGN=TOP> <H3> Process tasks without activity for more than one day</H3></TD>
<TD width="250" VALIGN=TOP>
@{
foreach(var item in FreshNewWT)
{
<li> <a href=@WTRef@item.Id>@item.Subject</a></li>
}
}
@{
if(FreshNewWT.Count <= 0)
{
<p align="center">No tasks with the "New" status</p>
}
}
</TD>
<TD width="250" VALIGN=TOP>
@{
foreach(var item in FreshNewWT)
{
<li>@item.CreationDate.Value.ToString().Substring(0, 16)</li>
}
}
</TD>
</UL>
</TR>
</TABLE>