Skip to content

IManuallyTriggeredHandler

IManuallyTriggeredHandler gives a model an action that an editor runs from the document list, such as an import, a sync or a link to a preview. It runs for the model as a whole, not for one document. Implement it, together with IDocumentHandler, and add the handler to the model.

Interface declaration

	namespace Veva.Modules.Documents.Domain.DocumentHandlers;

	public interface IManuallyTriggeredHandler
	{
		string ActionName { get; }
		string ActionDescription { get; }
		ActionTypeEnum ActionType { get; }
		bool ShowConfirmation { get; }
		ActionPlacement Placement => ActionPlacement.Menu;
		string RunButtonText => null;
		string Run(DocumentModel model);
	}

Example

This handler puts a Rebuild site button on the document list, which starts a build of a static site that reads the model. The build hook URL is a setting on the model; the branch is a setting too, but the editor can change it for one run in the run dialog.

	using System.ComponentModel;
	using Veva.Modules.Documents.Domain;
	using Veva.Modules.Documents.Domain.DocumentHandlers;
	using Veva.Modules.Documents.Domain.Enums;

	[DisplayName("Rebuild static site")]
	[Description("Adds a Rebuild site button that starts a build of the static site that reads this model")]
	public class RebuildSiteHandler : IDocumentHandler, IManuallyTriggeredHandler
	{
		private static readonly HttpClient Http = new();

		[EditorBrowsable]
		[DisplayName("Build hook URL")]
		[Description("The URL that starts a build")]
		public string BuildHookUrl { get; set; }

		[EditorBrowsable]
		[ActionOverridable]
		[DisplayName("Branch")]
		[Description("The branch to build. The run dialog shows it, so it can be changed for one run.")]
		[DefaultValue("main")]
		public string Branch { get; set; } = "main";

		public string ActionName => "Rebuild site";

		public string ActionDescription => "Starts a build of the static site with the content as it is now";

		public ActionTypeEnum ActionType => ActionTypeEnum.Action;

		public bool ShowConfirmation => true;

		public ActionPlacement Placement => ActionPlacement.Toolbar;

		public string RunButtonText => "Start build";

		public string Describe() => string.IsNullOrWhiteSpace(BuildHookUrl) ? "No build hook URL" : "Branch: " + Branch;

		public string Run(DocumentModel model)
		{
			if (string.IsNullOrWhiteSpace(BuildHookUrl))
			{
				// The document list shows the message in an error dialog.
				throw new InvalidOperationException("Set the build hook URL on the model's Handlers tab.");
			}

			var separator = BuildHookUrl.Contains('?') ? "&" : "?";
			var url = BuildHookUrl + separator + "branch=" + Uri.EscapeDataString(Branch ?? "main");

			// Run is not async and the editor waits for it: only start the build here.
			using var request = new HttpRequestMessage(HttpMethod.Post, url);
			using var response = Http.Send(request);
			response.EnsureSuccessStatusCode();

			// An Action's return value is not shown; an OpenUrl handler returns the URL to open.
			return string.Empty;
		}
	}

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).

	using Veva.Core.Application.DependencyInjection;
	using Veva.Modules.Documents.Domain.DocumentHandlers;

	public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
	{
		// Registered as IDocumentHandler, not IManuallyTriggeredHandler: Veva finds handlers there.
		// The key is the class name; the model stores it when the handler is added.
		services.AddNamed<IDocumentHandler, RebuildSiteHandler>(ServiceLifetime.Transient);
	}

Turning it on. The class must also implement IDocumentHandler and is registered as one. Add it to a model on the model designer's Handlers tab and fill in its settings, which are its [EditorBrowsable] properties. The action then shows in that model's document list. ActionType and Placement come from Veva.Modules.Documents.Domain.Enums.

Where it shows. With Placement Menu, the default, the action is an item in the list's Actions menu, with ActionDescription under ActionName. With Placement Toolbar it is a button on the list's toolbar, with ActionDescription as its tooltip. Editors who can see the model's documents see the action. Running it needs Update permission on the model.

What a click does. If the handler asks for inputs, a dialog shows them first, with RunButtonText on its button, or Run action when RunButtonText is null. If ShowConfirmation is true, the editor confirms next. Veva then creates the handler with the model's settings and calls Run with the model, inside the request, while the list shows a wait notice. ActionType says what the return value is for. With OpenUrl the browser opens the string Run returns in a new window. With Action the list reloads and the string is not shown. If Run throws, the list shows the error message in a dialog.

Inputs in the run dialog. Two attributes bring a property into the run dialog. [ActionInput] (Veva.Core.Domain.Attributes) asks for a value on every run: it is not a setting on the model and is never stored. [ActionOverridable] (this namespace) shows a stored setting, filled in with the model's value, so the editor can change it for one run. Do not use [ActionOverridable] for a secret: the value is sent to everyone who may run the action, and Veva leaves secret settings out of the dialog.

Keep it short. Run is not async, and the editor waits until it returns. Start long work, such as a big import, somewhere else and return.

One document. For an action on a single document, implement ISingleDocumentHandler, in the same namespace. It has the same members, except Task<string> Run(Document document), and its action shows in the document editor instead of the list.

Built-in examples. The Veva.Modules.Gatsby package from veva-integrations has two: Gatsby build trigger (TriggerPreviewHandler), an Action that posts to a build webhook, and Gatsby preview launcher (OpenPreviewUrlHandler), an OpenUrl action that returns the preview address.

Type to search the docs, components and API.

↑↓ to move ↵ to open Esc to close Search by Veva