IDocumentView
The IDocumentView interface allows you to implement your own "views" on top of documents in the documents system in Veva. The documents system includes one standard view, called the Generic HTTP View. It has various settings to control which documents to expose, such as filtering and paging. It allows the user to assign endpoints which are implementations of the IDocumentViewEndpoint interface - those control how the data is formatted and returned.
By implementing the IDocumentView interface, you can create your own view, even though the Generic HTTP View, along with the appropriate endpoints should be sufficient for most use cases.
Interface declaration
public interface IDocumentView { string Alias { get; set; } IEnumerable<IDocumentViewEndpoint> Endpoints { get; set; } Task<DocumentQueryResult> GetData(Guid modelId, DocumentViewContext context); }
Example
This example shows the implementation of the Generic HTTP View which comes as standard with the documents system in Veva.
[DisplayName("Generic HTTP View")] [Description("Sets up a view for documents which can be queried using HTTP. The defined endpoints dictate how this view returns data.")] public class GenericHTTPDocumentView : IDocumentView { private readonly IDocumentQueryService _queryService; private readonly IStringFormatService _stringFormatService; [EditorBrowsable] [DisplayName("Alias")] [Description("This is the name which will be a part of the URL which is used to call this view. Avoid using special and/or language specific characters.")] public string Alias { get; set; } [EditorBrowsable] [Category("Filtering")] [DisplayName("Filters")] public IEnumerable<IDocumentFilterProvider> Filters { get; set; } [EditorBrowsable] [Category("Filtering")] [DisplayName("Restrict to user")] [Description("If this is checked, the list of documents will be restricted to those documents created by the currently logged on user. If the user is anonymou public bool RestrictDocumentsToCurrentUser { get; set; } [EditorBrowsable] [Category("Filtering")] [DisplayName("Count")] [Description("Number of documents to display")] public int? Count { get; set; } [EditorBrowsable] [Category("Filtering")] [DisplayName("Skip")] [Description("Number of documents to skip")] [DefaultValue(0)] public int Skip { get; set; } = 0; [EditorBrowsable] [Category("Sorting")] [DisplayName("Sort by")] [Description("Which field in the list to sort by")] [Editor(PropertyEditors.SortFieldSelector, "")] public string SortByField { get; set; } [EditorBrowsable] [Category("Sorting")] [DisplayName("Descending")] [Description("Wether to sort in descending order")] public bool SortDescending { get; set; } [EditorBrowsable] [Category("Endpoints")] [DisplayName("Endpoints")] [Description("The configured endpoints which return data from this view")] public IEnumerable<IDocumentViewEndpoint> Endpoints { get; set; } public GenericHTTPDocumentView(IDocumentQueryService queryService, IStringFormatService stringFormatService) { _queryService = queryService; _stringFormatService = stringFormatService; } public async Task<DocumentQueryResult> GetData(Guid modelId, DocumentViewContext context) { Paging paging = new Paging { Skip = Skip, Count = Count }; OrderBy orderBy = new OrderBy() { Column = SortByField, Descending = SortDescending }; QueryFilter fieldFilter = new QueryFilter(); fieldFilter.SetOperator = FieldFilterSetOperator.All; if (Filters != null) { foreach (var filter in Filters) { var filterResult = filter.GetFilter(new FilterContext() { }); if (filterResult != null) { fieldFilter.Filters.Add(filterResult); } } } var userId = (Guid?)null; if (RestrictDocumentsToCurrentUser) { if (context.CurrentUser.Identity.IsAuthenticated) { userId = context.CurrentUser.GetUserId(); } else { userId = Guid.Empty; } } return await _queryService.GetDocuments(modelId, paging, orderBy, fieldFilter, true, userId); } }
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<IDocumentView, GenericHTTPDocumentView>(); }
Usage
To use document views, you need to open up the designer for the model, go to the "Views" tab and from the list of available views, add the view you want to add. You need to have give the view an alias, which will become part of the URL to call. Then you need to add at least one endpoint. In this case we added the RSS endpoint which will generate an XML feed based on the RSS specification. You also need to specifcy an alias for the endpoint, which will also become a part of the URL. The URL will be shown at the top of the view settings.