IModelTemplate
The IModelTemplate interface allows you to define Model templates for the Document system, in code. The only method you need to implement is a read only property called JsonData. It needs to return a JSON Model definition, just like the JSON that can be viewed in the model designer in the Document system backend in Veva.
Interface declaration
public interface IModelTemplate { string JsonData { get; } }
Example
In this example, we are defining a simple employee list. Instead of returning a manually built JSON as a string, we are leveraging the model Export classes in Veva, which allows us to define the model by defining class instances, which we then simply serialize to the required JSON string.
Model templates can have configuration options, simply by defining public properties marked with the [EditorBrowsable] attribute. In this example, the user has the option to include photos, just by checking the boolean property called IncludePhoto. This property will be shown in the Veva backend UI when the user decides to create a model based on this model template.
[DisplayName("Employee list")] [Description("A simple list of employees")] public class EmployeeListModelTemplate : IModelTemplate { public string JsonData => JsonConvert.SerializeObject(GetModelDefinition()); [EditorBrowsable] [DisplayName("Employee photos")] [Description("If checked, the model will include a field for employee photos")] public bool IncludePhoto { get; set; } private ExportRoot GetModelDefinition() { var root = new ExportRoot(); root.Folder = new ModelFolder() { IsModule = false, IsShared = false, ModuleName = "Employees", Name = "Employees", ModuleIcon = "fas fa-users" }; root.Models = new List<ExportModel>(); var fields = new List<ModelField>(); fields.Add(new ModelField() { Name = "name", Title = "Name", Display = true, RequiresValue = true, Type = "String" }); fields.Add(new ModelField() { Name = "email", Title = "E-mail", Display = true, RequiresValue = true, Type = "Email" }); fields.Add(new ModelField() { Name = "mobile", Title = "Mobile", Display = true, Type = "String" }); fields.Add(new ModelField() { Name = "jobtitle", Title = "Job title", Display = true, Type = "String" }); fields.Add(new ModelField() { Name = "department", Title = "Department", Display = true, Type = "String" }); if (IncludePhoto) { fields.Add(new ModelField() { Name = "photo", Title = "Photo", Display = true, Type = "Asset" }); } root.Models.Add(new ExportModel() { Model = new DocumentModel() { Alias = "employees", Name = "Employees", TitleField = "name" }, Fields = fields }); return root; } }
Registration
This is how the implementation is registered into the DI container in Veva, this should be done in your module config file (The class which implements IModule).
public void ConfigureServices(IServiceCollection services, IConfiguration configuration) { services.AddNamed<IModelTemplate, EmployeeListModelTemplate>(); }