Update: Plugin UI Extensions
Add additional Results; Implemented UI Extensions on Device, Job and User Controllers
This commit is contained in:
@@ -12,14 +12,16 @@ namespace Disco.Services.Plugins.Features.UIExtension.Results
|
||||
{
|
||||
private string _content;
|
||||
|
||||
public LiteralResult(PluginFeatureManifest Source, string Content) : base(Source)
|
||||
public LiteralResult(PluginFeatureManifest Source, string Content)
|
||||
: base(Source)
|
||||
{
|
||||
this._content = Content;
|
||||
}
|
||||
|
||||
public override void ExecuteResult<T>(WebViewPage<T> page)
|
||||
{
|
||||
page.Write(new HtmlString(_content));
|
||||
if (!string.IsNullOrEmpty(_content))
|
||||
page.Write(new HtmlString(_content));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Disco.Services.Plugins.Features.UIExtension.Results
|
||||
{
|
||||
public class MultipleResult : UIExtensionResult
|
||||
{
|
||||
private IEnumerable<UIExtensionResult> results;
|
||||
|
||||
public MultipleResult(PluginFeatureManifest Source, params UIExtensionResult[] Results) : base(Source)
|
||||
{
|
||||
if (Results == null || Results.Length == 0)
|
||||
throw new ArgumentException("At least one result is required", "Results");
|
||||
|
||||
this.results = Results;
|
||||
}
|
||||
|
||||
public override void ExecuteResult<T>(System.Web.Mvc.WebViewPage<T> page)
|
||||
{
|
||||
foreach (var result in this.results)
|
||||
{
|
||||
result.ExecuteResult(page);
|
||||
page.WriteLiteral("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
|
||||
namespace Disco.Services.Plugins.Features.UIExtension.Results
|
||||
{
|
||||
public class PluginResourceCssResult : UIExtensionResult
|
||||
{
|
||||
private string _resource;
|
||||
private HtmlString _resourceUrl;
|
||||
|
||||
public PluginResourceCssResult(PluginFeatureManifest Source, string Resource)
|
||||
: base(Source)
|
||||
{
|
||||
this._resource = Resource;
|
||||
this._resourceUrl = HttpContext.Current.Request.RequestContext.DiscoPluginResourceUrl(Resource, false, Source.PluginManifest);
|
||||
|
||||
var deferredBundles = HttpContext.Current.Items["Bundles.UIExtensionCss"] as List<HtmlString>;
|
||||
if (deferredBundles == null)
|
||||
{
|
||||
deferredBundles = new List<HtmlString>();
|
||||
HttpContext.Current.Items["Bundles.UIExtensionCss"] = deferredBundles;
|
||||
}
|
||||
if (!deferredBundles.Contains(this._resourceUrl))
|
||||
deferredBundles.Add(this._resourceUrl);
|
||||
}
|
||||
|
||||
public override void ExecuteResult<T>(System.Web.Mvc.WebViewPage<T> page)
|
||||
{
|
||||
// Nothing Done
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,23 +3,44 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
|
||||
namespace Disco.Services.Plugins.Features.UIExtension.Results
|
||||
{
|
||||
public class PluginResourceScriptResult : UIExtensionResult
|
||||
{
|
||||
private string _resource;
|
||||
private HtmlString _resourceUrl;
|
||||
private bool _placeInPageHead;
|
||||
|
||||
public PluginResourceScriptResult(PluginFeatureManifest Source, string Resource) : base(Source)
|
||||
public PluginResourceScriptResult(PluginFeatureManifest Source, string Resource, bool PlaceInPageHead)
|
||||
: base(Source)
|
||||
{
|
||||
this._resource = Resource;
|
||||
this._resourceUrl = HttpContext.Current.Request.RequestContext.DiscoPluginResourceUrl(Resource, false, Source.PluginManifest);
|
||||
this._placeInPageHead = PlaceInPageHead;
|
||||
|
||||
if (this._placeInPageHead)
|
||||
{
|
||||
var deferredBundles = HttpContext.Current.Items["Bundles.UIExtensionScripts"] as List<HtmlString>;
|
||||
if (deferredBundles == null)
|
||||
{
|
||||
deferredBundles = new List<HtmlString>();
|
||||
HttpContext.Current.Items["Bundles.UIExtensionScripts"] = deferredBundles;
|
||||
}
|
||||
if (!deferredBundles.Contains(this._resourceUrl))
|
||||
deferredBundles.Add(this._resourceUrl);
|
||||
}
|
||||
}
|
||||
|
||||
public override void ExecuteResult<T>(System.Web.Mvc.WebViewPage<T> page)
|
||||
{
|
||||
page.WriteLiteral("<script src=\"");
|
||||
page.WriteLiteral(page.DiscoPluginResourceUrl(_resource, false, this.Source.PluginManifest));
|
||||
page.WriteLiteral("\" type=\"text/javascript\"></script>");
|
||||
if (!this._placeInPageHead)
|
||||
{
|
||||
page.WriteLiteral("<script src=\"");
|
||||
page.WriteLiteral(_resourceUrl);
|
||||
page.WriteLiteral("\" type=\"text/javascript\"></script>");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.WebPages;
|
||||
|
||||
namespace Disco.Services.Plugins.Features.UIExtension.Results
|
||||
{
|
||||
public class PrecompiledPartialViewResult : UIExtensionResult
|
||||
{
|
||||
private Type viewType;
|
||||
private object model;
|
||||
|
||||
public PrecompiledPartialViewResult(PluginFeatureManifest Source, Type ViewType, object Model = null)
|
||||
: base(Source)
|
||||
{
|
||||
if (!typeof(WebViewPage).IsAssignableFrom(ViewType))
|
||||
throw new ArgumentException("The View Type must inherit from WebViewPage", "ViewType");
|
||||
|
||||
this.viewType = ViewType;
|
||||
this.model = Model;
|
||||
}
|
||||
|
||||
public override void ExecuteResult<T>(System.Web.Mvc.WebViewPage<T> page)
|
||||
{
|
||||
WebViewPage partialView = Activator.CreateInstance(viewType) as WebViewPage;
|
||||
if (partialView == null)
|
||||
throw new InvalidOperationException("Invalid View Type");
|
||||
partialView.ViewContext = page.ViewContext;
|
||||
partialView.ViewData = new ViewDataDictionary(this.model);
|
||||
partialView.InitHelpers();
|
||||
partialView.ExecutePageHierarchy(new WebPageContext(page.ViewContext.HttpContext, null, model), page.ViewContext.Writer, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user