Update: Plugin UI Extensions
Add additional Results; Implemented UI Extensions on Device, Job and User Controllers
This commit is contained in:
@@ -102,7 +102,10 @@
|
||||
<Compile Include="Logging\Utilities.cs" />
|
||||
<Compile Include="Plugins\CommunityInterop\PluginLibraryUpdateTask.cs" />
|
||||
<Compile Include="Plugins\Features\UIExtension\Results\LiteralResult.cs" />
|
||||
<Compile Include="Plugins\Features\UIExtension\Results\MultipleResult.cs" />
|
||||
<Compile Include="Plugins\Features\UIExtension\Results\PluginResourceCssResult.cs" />
|
||||
<Compile Include="Plugins\Features\UIExtension\Results\PluginResourceScriptResult.cs" />
|
||||
<Compile Include="Plugins\Features\UIExtension\Results\PrecompiledPartialViewResult.cs" />
|
||||
<Compile Include="Plugins\Features\UIExtension\UIExtensionResult.cs" />
|
||||
<Compile Include="Plugins\Features\UIExtension\UIExtensionFeature.cs" />
|
||||
<Compile Include="Plugins\UpdatePluginsAfterDiscoUpdateTask.cs" />
|
||||
@@ -137,7 +140,7 @@
|
||||
<Compile Include="Tasks\ScheduledTaskStatus.cs" />
|
||||
<Compile Include="Tasks\ScheduledTasksLiveStatusService.cs" />
|
||||
<Compile Include="Tasks\ScheduledTaskStatusLive.cs" />
|
||||
<Compile Include="UIExtensions\UIExtensions.cs" />
|
||||
<Compile Include="Plugins\Features\UIExtension\UIExtensions.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Disco.Data\Disco.Data.csproj">
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,9 +20,25 @@ namespace Disco.Services.Plugins.Features.UIExtension
|
||||
{
|
||||
return new LiteralResult(this.Manifest, Content);
|
||||
}
|
||||
protected PluginResourceScriptResult ScriptResource(string Resource)
|
||||
protected LiteralResult Nothing()
|
||||
{
|
||||
return new PluginResourceScriptResult(this.Manifest, Resource);
|
||||
return new LiteralResult(this.Manifest, null);
|
||||
}
|
||||
protected PluginResourceScriptResult ScriptResource(string Resource, bool PlaceInPageHead)
|
||||
{
|
||||
return new PluginResourceScriptResult(this.Manifest, Resource, PlaceInPageHead);
|
||||
}
|
||||
protected PluginResourceCssResult CssResource(string Resource)
|
||||
{
|
||||
return new PluginResourceCssResult(this.Manifest, Resource);
|
||||
}
|
||||
protected MultipleResult Multiple(params UIExtensionResult[] Results)
|
||||
{
|
||||
return new MultipleResult(this.Manifest, Results);
|
||||
}
|
||||
protected PrecompiledPartialViewResult Partial(Type PartialViewType, object Model = null)
|
||||
{
|
||||
return new PrecompiledPartialViewResult(this.Manifest, PartialViewType, Model);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -30,17 +46,17 @@ namespace Disco.Services.Plugins.Features.UIExtension
|
||||
#region Registration
|
||||
public bool Register()
|
||||
{
|
||||
return UIExtensions.UIExtensions.RegisterExtension(this);
|
||||
return UIExtensions.RegisterExtension(this);
|
||||
}
|
||||
public bool Unregister()
|
||||
{
|
||||
return UIExtensions.UIExtensions.UnregisterExtension(this);
|
||||
return UIExtensions.UnregisterExtension(this);
|
||||
}
|
||||
public bool IsRegistered
|
||||
{
|
||||
get
|
||||
{
|
||||
return UIExtensions.UIExtensions.ExtensionRegistered(this);
|
||||
return UIExtensions.ExtensionRegistered(this);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ using Disco.Models.UI;
|
||||
using Disco.Services.Plugins;
|
||||
using Disco.Services.Plugins.Features.UIExtension;
|
||||
|
||||
namespace Disco.Services.UIExtensions
|
||||
namespace Disco.Services.Plugins.Features.UIExtension
|
||||
{
|
||||
public static class UIExtensions
|
||||
{
|
||||
@@ -96,11 +96,15 @@ namespace Disco.Services.Plugins
|
||||
return ViewPage.DiscoPluginResourceUrl(Resource, false, manifest);
|
||||
}
|
||||
public static HtmlString DiscoPluginResourceUrl<T>(this WebViewPage<T> ViewPage, string Resource, bool Download, PluginManifest manifest)
|
||||
{
|
||||
return ViewPage.ViewContext.RequestContext.DiscoPluginResourceUrl(Resource, Download, manifest);
|
||||
}
|
||||
public static HtmlString DiscoPluginResourceUrl(this RequestContext RequestContext, string Resource, bool Download, PluginManifest manifest)
|
||||
{
|
||||
var resourcePath = manifest.WebResourcePath(Resource);
|
||||
|
||||
var routeValues = new RouteValueDictionary(new { PluginId = manifest.Id, res = Resource });
|
||||
string pluginActionUrl = UrlHelper.GenerateUrl("Plugin_Resources", null, null, routeValues, RouteTable.Routes, ViewPage.ViewContext.RequestContext, false);
|
||||
string pluginActionUrl = UrlHelper.GenerateUrl("Plugin_Resources", null, null, routeValues, RouteTable.Routes, RequestContext, false);
|
||||
|
||||
pluginActionUrl += string.Format("?v={0}", resourcePath.Item2);
|
||||
|
||||
@@ -122,9 +126,13 @@ namespace Disco.Services.Plugins
|
||||
return ViewPage.DiscoPluginActionUrl(PluginAction, manifest);
|
||||
}
|
||||
public static HtmlString DiscoPluginActionUrl<T>(this WebViewPage<T> ViewPage, string PluginAction, PluginManifest manifest)
|
||||
{
|
||||
return ViewPage.ViewContext.RequestContext.DiscoPluginActionUrl(PluginAction, manifest);
|
||||
}
|
||||
public static HtmlString DiscoPluginActionUrl(this RequestContext RequestContext, string PluginAction, PluginManifest manifest)
|
||||
{
|
||||
var routeValues = new RouteValueDictionary(new { PluginId = manifest.Id, PluginAction = PluginAction });
|
||||
string pluginActionUrl = UrlHelper.GenerateUrl("Plugin", null, null, routeValues, RouteTable.Routes, ViewPage.ViewContext.RequestContext, false);
|
||||
string pluginActionUrl = UrlHelper.GenerateUrl("Plugin", null, null, routeValues, RouteTable.Routes, RequestContext, false);
|
||||
return new HtmlString(pluginActionUrl);
|
||||
}
|
||||
public static HtmlString DiscoPluginConfigureUrl<T>(this WebViewPage<T> ViewPage)
|
||||
|
||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.2.0221.1820")]
|
||||
[assembly: AssemblyFileVersion("1.2.0221.1820")]
|
||||
[assembly: AssemblyVersion("1.2.0225.1951")]
|
||||
[assembly: AssemblyFileVersion("1.2.0225.1951")]
|
||||
|
||||
Reference in New Issue
Block a user