Integrate as a tab into antony's flexobjectview
TL;DR
You can find the repository of this sample within out Bitbucket https://bitbucket.org/diegroupware/antony.demo.trainee.desktop/src
Write an antony registry ( Howto write an antony registry )
Provide an
IAttachedFlexObjectView
Use
IAttachedFlexObjectInfoService
to get and set some informations within the flexobjects view
General
Welcome to our first developer howto. In this article you will see how you can create a custom View and attach it as a Tab into the flexobjectview. The result is illustrated in the two images below. In the first image you see the additional tab “Trainee” with a beautiful tree icon in front of it. This is defined by our module.
In the second one you see the content of the page, after the user activated it.
As you can see the page is able to access the data of the flexobject. In additional you are able to search for values with specific contentType
. As the last feature you are able to write some content to the flexobject. These data are only written to the UI itself, so the user needs to save them.
IAttachedFlexObjectView
This interface is the main actor in our project. As you can see in the registry below we registered a MyAttachedFlexObjectView
within the DI container. It provides the name and an image of the tab. Additional a selector and a method to generate the view.
using antony.Demo.Trainee.Desktop;
using antony.Groupware.ExtensionInterfaces.ExtensibilityStarter;
using antony.Groupware.ExtensionInterfaces.FlexObjects.UI;
using Microsoft.Extensions.DependencyInjection;
[assembly: AntonyModule(typeof(TraineeModuleAntonyRegistry),
RegistryGroup = "de.die_groupware.trainee")]
namespace antony.Demo.Trainee.Desktop
{
public class TraineeModuleAntonyRegistry
{
[AntonyServiceRegistry()]
public void Register(IServiceCollection services)
{
services.AddTransient<IAttachedFlexObjectView, MyAttachedFlexObjectView>();
}
}
}
Selector
The selector of this ExtensionPoint provides the whole FlexObject and its data. Using the selector you can hide the tab within specific situations. For example you are able to show a tab only within a specific flexobject type or it the current user is within a specific user-group.
CreateView
This method is called by antony to create the view, which should be displayed. As a returntype `AntonyView`
is defined. You can pass a WPF-Element or Winforms-Control here.
As a parameter you’ll receive the flexObjectId
, the flexObjectSetId
and the data of the flexObject given by a dictionary. In the example we simply put them into a ViewItem and push them into the returned view.
public object CreateView(long foId, int foSetId, Dictionary<string, object> customFields)
{
var curFields = new List<CustomFieldViewItem>();
foreach (var item in customFields)
curFields.Add(new CustomFieldViewItem(_infoService)
{
FieldName = _infoService.GetFieldInfo(item.Key)?.FieldName,
Value = item.Value,
PropertyName = item.Key
});
var view = new TraineePageView();
var viewModel = new TraineePageViewModel(_infoService, curFields);
view.DataContext = viewModel;
return AntonyView.FromWpfFrameworkElement(view);
}
Access additional information
As you might noticed you cannot implement much usecases with the defined interfaces above. To let you access some further information from the flexobject you can inject a service of the type IAttachedFlexObjectInfoService
.
With this service you are able to access fields of the flexobject by a contentType you provide. As an example you can retrieve all links by getting the fields of contentType “www”. Therefore call the method GetFirstFieldByContentType(”www”)
within your module.
Finally you can also set data to the UI by using the method SetCustomFieldValue
and pass the field to set (by its propertyName) and the new value. As a result you get a “Success” or some error code nested within the result class of the call.
You are also able to access client wide interfaces like the IUserService
, IClientMailService
or IClientAppointmentService
by injecting it.
Conclusion
As you saw it is quite simple to integrate yourself into antony’s DI container and into the flexobjects' view. Suggestenions and enhancements are welcome. Let us now and write to info(at)die-groupware.de.