Preview document template pdf
Renders document template pdfs to an image which is displayed in the configuration ui.
This commit is contained in:
@@ -11,6 +11,7 @@ using Disco.Services.Users;
|
||||
using Disco.Services.Web;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
@@ -36,10 +37,10 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
throw new ArgumentNullException("id");
|
||||
if (string.IsNullOrEmpty(key))
|
||||
throw new ArgumentNullException("key");
|
||||
|
||||
|
||||
ScheduledTaskStatus resultTask = null;
|
||||
var documentTemplate = Database.DocumentTemplates.Find(id);
|
||||
|
||||
|
||||
if (documentTemplate != null)
|
||||
{
|
||||
switch (key.ToLower())
|
||||
@@ -140,6 +141,29 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[DiscoAuthorize(Claims.Config.DocumentTemplate.Show), HttpGet]
|
||||
public virtual ActionResult TemplatePreview(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id))
|
||||
throw new ArgumentNullException("id");
|
||||
var documentTemplate = Database.DocumentTemplates.Find(id);
|
||||
if (documentTemplate == null)
|
||||
throw new ArgumentException("Invalid Document Template Id", "id");
|
||||
|
||||
var imageStream = new MemoryStream();
|
||||
using (var previewImage = documentTemplate.GenerateTemplatePreview(Database, 450, 8, true))
|
||||
{
|
||||
if (previewImage == null)
|
||||
{
|
||||
throw new InvalidOperationException("Template not found");
|
||||
}
|
||||
previewImage.SavePng(imageStream);
|
||||
}
|
||||
imageStream.Position = 0;
|
||||
|
||||
return File(imageStream, "image/png");
|
||||
}
|
||||
|
||||
#region Update Shortcut Methods
|
||||
[DiscoAuthorize(Claims.Config.DocumentTemplate.Configure)]
|
||||
public virtual ActionResult UpdateDescription(string id, string Description = null, bool redirect = false)
|
||||
@@ -265,7 +289,7 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
#endregion
|
||||
|
||||
#region Update Properties
|
||||
private void UpdateDescription(Disco.Models.Repository.DocumentTemplate documentTemplate, string Description)
|
||||
private void UpdateDescription(DocumentTemplate documentTemplate, string Description)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(Description))
|
||||
{
|
||||
@@ -275,9 +299,9 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
}
|
||||
throw new Exception("Invalid Description");
|
||||
}
|
||||
private ScheduledTaskStatus UpdateScope(Disco.Models.Repository.DocumentTemplate documentTemplate, string Scope)
|
||||
private ScheduledTaskStatus UpdateScope(DocumentTemplate documentTemplate, string Scope)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Scope) || !Disco.Models.Repository.DocumentTemplate.DocumentTemplateScopes.ToList().Contains(Scope))
|
||||
if (string.IsNullOrWhiteSpace(Scope) || !DocumentTemplate.DocumentTemplateScopes.ToList().Contains(Scope))
|
||||
throw new ArgumentException("Invalid Scope", "Scope");
|
||||
|
||||
Database.Configuration.LazyLoadingEnabled = true;
|
||||
@@ -287,7 +311,7 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
|
||||
documentTemplate.Scope = Scope;
|
||||
|
||||
if (documentTemplate.Scope != Disco.Models.Repository.DocumentTemplate.DocumentTemplateScopes.Job &&
|
||||
if (documentTemplate.Scope != DocumentTemplate.DocumentTemplateScopes.Job &&
|
||||
documentTemplate.JobSubTypes != null)
|
||||
{
|
||||
foreach (var st in documentTemplate.JobSubTypes.ToArray())
|
||||
@@ -308,7 +332,7 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
|
||||
return null;
|
||||
}
|
||||
private void UpdateFilterExpression(Disco.Models.Repository.DocumentTemplate documentTemplate, string FilterExpression)
|
||||
private void UpdateFilterExpression(DocumentTemplate documentTemplate, string FilterExpression)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(FilterExpression))
|
||||
{
|
||||
@@ -323,7 +347,7 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
|
||||
Database.SaveChanges();
|
||||
}
|
||||
private void UpdateOnGenerateExpression(Disco.Models.Repository.DocumentTemplate documentTemplate, string OnGenerateExpression)
|
||||
private void UpdateOnGenerateExpression(DocumentTemplate documentTemplate, string OnGenerateExpression)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(OnGenerateExpression))
|
||||
{
|
||||
@@ -338,7 +362,7 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
|
||||
Database.SaveChanges();
|
||||
}
|
||||
private void UpdateOnImportAttachmentExpression(Disco.Models.Repository.DocumentTemplate documentTemplate, string OnImportAttachmentExpression)
|
||||
private void UpdateOnImportAttachmentExpression(DocumentTemplate documentTemplate, string OnImportAttachmentExpression)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(OnImportAttachmentExpression))
|
||||
{
|
||||
@@ -353,7 +377,7 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
|
||||
Database.SaveChanges();
|
||||
}
|
||||
private void UpdateFlattenForm(Disco.Models.Repository.DocumentTemplate documentTemplate, string FlattenForm)
|
||||
private void UpdateFlattenForm(DocumentTemplate documentTemplate, string FlattenForm)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(FlattenForm))
|
||||
{
|
||||
@@ -370,7 +394,7 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
|
||||
Database.SaveChanges();
|
||||
}
|
||||
private void UpdateJobSubTypes(Disco.Models.Repository.DocumentTemplate documentTemplate, List<string> JobSubTypes)
|
||||
private void UpdateJobSubTypes(DocumentTemplate documentTemplate, List<string> JobSubTypes)
|
||||
{
|
||||
Database.Configuration.LazyLoadingEnabled = true;
|
||||
|
||||
@@ -384,7 +408,7 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
// Add New
|
||||
if (JobSubTypes != null && JobSubTypes.Count > 0)
|
||||
{
|
||||
var subTypes = new List<Disco.Models.Repository.JobSubType>();
|
||||
var subTypes = new List<JobSubType>();
|
||||
foreach (var stId in JobSubTypes)
|
||||
{
|
||||
var typeId = stId.Substring(0, stId.IndexOf("_"));
|
||||
|
||||
Reference in New Issue
Block a user