Feature: Plugin UI Extensions

Initially available for 'Job Show' action
This commit is contained in:
Gary Sharp
2013-02-21 18:28:24 +11:00
parent e8e141c9af
commit 69c61a9b7d
23 changed files with 1847 additions and 1537 deletions
+12
View File
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Disco.Models.UI
{
public interface BaseUIModel
{
}
}
+15
View File
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Disco.Models.UI.Job
{
public interface JobShowModel : BaseUIModel
{
Repository.Job Job { get; set; }
List<Repository.DocumentTemplate> AvailableDocumentTemplates { get; set; }
List<Repository.JobSubType> UpdatableJobSubTypes { get; set; }
}
}
+6 -1
View File
@@ -101,6 +101,10 @@
<Compile Include="Logging\Targets\LogPersistContext.cs" /> <Compile Include="Logging\Targets\LogPersistContext.cs" />
<Compile Include="Logging\Utilities.cs" /> <Compile Include="Logging\Utilities.cs" />
<Compile Include="Plugins\CommunityInterop\PluginLibraryUpdateTask.cs" /> <Compile Include="Plugins\CommunityInterop\PluginLibraryUpdateTask.cs" />
<Compile Include="Plugins\Features\UIExtension\Results\LiteralResult.cs" />
<Compile Include="Plugins\Features\UIExtension\Results\PluginResourceScriptResult.cs" />
<Compile Include="Plugins\Features\UIExtension\UIExtensionResult.cs" />
<Compile Include="Plugins\Features\UIExtension\UIExtensionFeature.cs" />
<Compile Include="Plugins\UpdatePluginsAfterDiscoUpdateTask.cs" /> <Compile Include="Plugins\UpdatePluginsAfterDiscoUpdateTask.cs" />
<Compile Include="Plugins\UpdatePluginTask.cs" /> <Compile Include="Plugins\UpdatePluginTask.cs" />
<Compile Include="Plugins\InstallPluginTask.cs" /> <Compile Include="Plugins\InstallPluginTask.cs" />
@@ -133,6 +137,7 @@
<Compile Include="Tasks\ScheduledTaskStatus.cs" /> <Compile Include="Tasks\ScheduledTaskStatus.cs" />
<Compile Include="Tasks\ScheduledTasksLiveStatusService.cs" /> <Compile Include="Tasks\ScheduledTasksLiveStatusService.cs" />
<Compile Include="Tasks\ScheduledTaskStatusLive.cs" /> <Compile Include="Tasks\ScheduledTaskStatusLive.cs" />
<Compile Include="UIExtensions\UIExtensions.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Disco.Data\Disco.Data.csproj"> <ProjectReference Include="..\Disco.Data\Disco.Data.csproj">
@@ -152,7 +157,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions> <ProjectExtensions>
<VisualStudio> <VisualStudio>
<UserProperties BuildVersion_StartDate="2001/1/1" BuildVersion_BuildAction="ReBuild" BuildVersion_DetectChanges="False" BuildVersion_UseGlobalSettings="True" /> <UserProperties BuildVersion_UseGlobalSettings="True" BuildVersion_DetectChanges="False" BuildVersion_BuildAction="ReBuild" BuildVersion_StartDate="2001/1/1" />
</VisualStudio> </VisualStudio>
</ProjectExtensions> </ProjectExtensions>
<PropertyGroup> <PropertyGroup>
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
namespace Disco.Services.Plugins.Features.UIExtension.Results
{
public class LiteralResult : UIExtensionResult
{
private string _content;
public LiteralResult(PluginFeatureManifest Source, string Content) : base(Source)
{
this._content = Content;
}
public override void ExecuteResult<T>(WebViewPage<T> page)
{
page.Write(new HtmlString(_content));
}
}
}
@@ -0,0 +1,25 @@
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 PluginResourceScriptResult : UIExtensionResult
{
private string _resource;
public PluginResourceScriptResult(PluginFeatureManifest Source, string Resource) : base(Source)
{
this._resource = Resource;
}
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>");
}
}
}
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using Disco.Models.UI;
using Disco.Services.Plugins.Features.UIExtension.Results;
namespace Disco.Services.Plugins.Features.UIExtension
{
[PluginFeatureCategory(DisplayName = "User Interface Extensions")]
public abstract class UIExtensionFeature<UIModel> : PluginFeature where UIModel : BaseUIModel
{
public abstract UIExtensionResult ExecuteAction(ControllerContext context, UIModel model);
#region ActionResults
protected LiteralResult Literal(string Content)
{
return new LiteralResult(this.Manifest, Content);
}
protected PluginResourceScriptResult ScriptResource(string Resource)
{
return new PluginResourceScriptResult(this.Manifest, Resource);
}
#endregion
#region Registration
public bool Register()
{
return UIExtensions.UIExtensions.RegisterExtension(this);
}
public bool Unregister()
{
return UIExtensions.UIExtensions.UnregisterExtension(this);
}
public bool IsRegistered
{
get
{
return UIExtensions.UIExtensions.ExtensionRegistered(this);
}
}
#endregion
}
}
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
namespace Disco.Services.Plugins.Features.UIExtension
{
public abstract class UIExtensionResult
{
public PluginFeatureManifest Source { get; private set; }
public UIExtensionResult(PluginFeatureManifest Source)
{
this.Source = Source;
}
public abstract void ExecuteResult<T>(WebViewPage<T> page);
}
}
@@ -93,6 +93,10 @@ namespace Disco.Services.Plugins
var pageAssembly = pageType.Assembly; var pageAssembly = pageType.Assembly;
var manifest = Plugins.GetPlugin(pageAssembly); var manifest = Plugins.GetPlugin(pageAssembly);
return ViewPage.DiscoPluginResourceUrl(Resource, false, manifest);
}
public static HtmlString DiscoPluginResourceUrl<T>(this WebViewPage<T> ViewPage, string Resource, bool Download, PluginManifest manifest)
{
var resourcePath = manifest.WebResourcePath(Resource); var resourcePath = manifest.WebResourcePath(Resource);
var routeValues = new RouteValueDictionary(new { PluginId = manifest.Id, res = Resource }); var routeValues = new RouteValueDictionary(new { PluginId = manifest.Id, res = Resource });
@@ -115,6 +119,10 @@ namespace Disco.Services.Plugins
var pageAssembly = pageType.Assembly; var pageAssembly = pageType.Assembly;
var manifest = Plugins.GetPlugin(pageAssembly); var manifest = Plugins.GetPlugin(pageAssembly);
return ViewPage.DiscoPluginActionUrl(PluginAction, manifest);
}
public static HtmlString DiscoPluginActionUrl<T>(this WebViewPage<T> ViewPage, string PluginAction, PluginManifest manifest)
{
var routeValues = new RouteValueDictionary(new { PluginId = manifest.Id, PluginAction = PluginAction }); 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, ViewPage.ViewContext.RequestContext, false);
return new HtmlString(pluginActionUrl); return new HtmlString(pluginActionUrl);
@@ -126,6 +134,10 @@ namespace Disco.Services.Plugins
var pageAssembly = pageType.Assembly; var pageAssembly = pageType.Assembly;
var manifest = Plugins.GetPlugin(pageAssembly); var manifest = Plugins.GetPlugin(pageAssembly);
return ViewPage.DiscoPluginConfigureUrl(manifest);
}
public static HtmlString DiscoPluginConfigureUrl<T>(this WebViewPage<T> ViewPage, PluginManifest manifest)
{
var routeValues = new RouteValueDictionary(new { PluginId = manifest.Id }); var routeValues = new RouteValueDictionary(new { PluginId = manifest.Id });
string pluginActionUrl = UrlHelper.GenerateUrl("Config_Plugins_Configure", null, null, routeValues, RouteTable.Routes, ViewPage.ViewContext.RequestContext, false); string pluginActionUrl = UrlHelper.GenerateUrl("Config_Plugins_Configure", null, null, routeValues, RouteTable.Routes, ViewPage.ViewContext.RequestContext, false);
return new HtmlString(pluginActionUrl); return new HtmlString(pluginActionUrl);
+2 -2
View File
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0219.1854")] [assembly: AssemblyVersion("1.2.0221.1820")]
[assembly: AssemblyFileVersion("1.2.0219.1854")] [assembly: AssemblyFileVersion("1.2.0221.1820")]
+115
View File
@@ -0,0 +1,115 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using Disco.Models.UI;
using Disco.Services.Plugins;
using Disco.Services.Plugins.Features.UIExtension;
namespace Disco.Services.UIExtensions
{
public static class UIExtensions
{
private const string ViewDataKey = "___DiscoUIExtensionResults";
// Warning: No type-safety, validate types before updating
private static Dictionary<Type, List<PluginFeatureManifest>> _registrations = new Dictionary<Type, List<PluginFeatureManifest>>();
private static List<PluginFeatureManifest> GetUIModelRegistrations<UIModel>() where UIModel : BaseUIModel
{
Type uiModelType = typeof(UIModel);
List<PluginFeatureManifest> modelRegistrations;
if (!_registrations.TryGetValue(uiModelType, out modelRegistrations))
{
lock (_registrations)
{
if (!_registrations.TryGetValue(uiModelType, out modelRegistrations))
{
modelRegistrations = new List<PluginFeatureManifest>();
_registrations.Add(uiModelType, modelRegistrations);
}
}
}
return modelRegistrations;
}
public static void ExecuteExtensions<UIModel>(ControllerContext context, UIModel model) where UIModel : BaseUIModel
{
var uiExts = UIExtensions.GetRegisteredExtensions<UIModel>();
Queue<UIExtensionResult> uiExtResults = new Queue<UIExtensionResult>();
foreach (var uiExt in uiExts)
{
using (var uiExtInstance = uiExt.CreateInstance<UIExtensionFeature<UIModel>>())
{
uiExtResults.Enqueue(uiExtInstance.ExecuteAction(context, model));
}
}
context.Controller.ViewData[ViewDataKey] = uiExtResults;
}
public static void ExecuteExtensionResult<UIModel>(WebViewPage<UIModel> page)
{
Queue<UIExtensionResult> uiExtResults = page.ViewData[ViewDataKey] as Queue<UIExtensionResult>;
if (uiExtResults != null && uiExtResults.Count > 0)
{
page.WriteLiteral("<!-- BEGIN: Disco UI Extensions -->");
page.WriteLiteral("\n<div id=\"layout_uiExtensions\">");
foreach (var uiExtResult in uiExtResults)
{
string extensionDescription = HttpUtility.HtmlEncode(string.Format("{0} @ {1} v{2}", uiExtResult.Source.Id, uiExtResult.Source.PluginManifest.Id, uiExtResult.Source.PluginManifest.Version.ToString(4)));
page.WriteLiteral(string.Format("\n<!-- BEGIN UI EXTENSION: {0} -->\n", extensionDescription));
uiExtResult.ExecuteResult(page);
page.WriteLiteral(string.Format("\n<!-- END UI EXTENSION: {0} -->", extensionDescription));
}
page.WriteLiteral("\n</div>");
page.WriteLiteral("\n<!-- END: Disco UI Extensions -->");
}
}
public static ReadOnlyCollection<PluginFeatureManifest> GetRegisteredExtensions<UIModel>() where UIModel : BaseUIModel
{
List<PluginFeatureManifest> modelRegistrations = GetUIModelRegistrations<UIModel>();
return new ReadOnlyCollection<PluginFeatureManifest>(modelRegistrations);
}
internal static bool ExtensionRegistered<UIModel>(UIExtensionFeature<UIModel> Extension) where UIModel : BaseUIModel
{
List<PluginFeatureManifest> modelRegistrations = GetUIModelRegistrations<UIModel>();
return modelRegistrations.Contains(Extension.Manifest);
}
internal static bool RegisterExtension<UIModel>(UIExtensionFeature<UIModel> Extension) where UIModel : BaseUIModel
{
List<PluginFeatureManifest> modelRegistrations = GetUIModelRegistrations<UIModel>();
lock (modelRegistrations)
{
if (!modelRegistrations.Contains(Extension.Manifest))
{
modelRegistrations.Add(Extension.Manifest);
return true;
}
}
return false;
}
internal static bool UnregisterExtension<UIModel>(UIExtensionFeature<UIModel> Extension) where UIModel : BaseUIModel
{
List<PluginFeatureManifest> modelRegistrations = GetUIModelRegistrations<UIModel>();
lock (modelRegistrations)
{
if (modelRegistrations.Contains(Extension.Manifest))
{
modelRegistrations.Remove(Extension.Manifest);
return true;
}
}
return false;
}
}
}
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0219.1854")] [assembly: AssemblyVersion("1.2.0221.1820")]
[assembly: AssemblyFileVersion("1.2.0219.1854")] [assembly: AssemblyFileVersion("1.2.0221.1820")]
@@ -1448,6 +1448,9 @@ header .watermark,
-webkit-border-radius: 0 0 6px 6px; -webkit-border-radius: 0 0 6px 6px;
border-radius: 0 0 6px 6px; border-radius: 0 0 6px 6px;
} }
#layout_uiExtensions {
display: none;
}
footer, footer,
#footer { #footer {
color: #777; color: #777;
File diff suppressed because one or more lines are too long
+3
View File
@@ -270,6 +270,9 @@ header .watermark,
-webkit-border-radius: 0 0 6px 6px; -webkit-border-radius: 0 0 6px 6px;
border-radius: 0 0 6px 6px; border-radius: 0 0 6px 6px;
} }
#layout_uiExtensions {
display: none;
}
footer, footer,
#footer { #footer {
color: #777; color: #777;
+4
View File
@@ -238,6 +238,10 @@ header, #header
.border-radius4(0, 0, 6px, 6px); .border-radius4(0, 0, 6px, 6px);
} }
#layout_uiExtensions {
display: none;
}
footer, #footer footer, #footer
{ {
color: #777; color: #777;
File diff suppressed because one or more lines are too long
+6 -1
View File
@@ -10,6 +10,8 @@ using Disco.Models.Repository;
using System.Web.Script.Serialization; using System.Web.Script.Serialization;
using Disco.Services.Plugins.Features.WarrantyProvider; using Disco.Services.Plugins.Features.WarrantyProvider;
using Disco.Services.Plugins; using Disco.Services.Plugins;
using Disco.Services.UIExtensions;
using Disco.Models.UI.Job;
namespace Disco.Web.Controllers namespace Disco.Web.Controllers
{ {
@@ -211,7 +213,10 @@ namespace Disco.Web.Controllers
m.UpdatableJobSubTypes = m.Job.JobType.JobSubTypes.OrderBy(jst => jst.Description).ToList(); m.UpdatableJobSubTypes = m.Job.JobType.JobSubTypes.OrderBy(jst => jst.Description).ToList();
m.DocumentTemplates = m.Job.AvailableDocumentTemplates(dbContext, DiscoApplication.CurrentUser, DateTime.Now); m.AvailableDocumentTemplates = m.Job.AvailableDocumentTemplates(dbContext, DiscoApplication.CurrentUser, DateTime.Now);
// UI Extensions
UIExtensions.ExecuteExtensions<JobShowModel>(this.ControllerContext, m);
return View(m); return View(m);
} }
+4 -3
View File
@@ -4,15 +4,16 @@ using System.Linq;
using System.Web; using System.Web;
using System.Web.Mvc; using System.Web.Mvc;
using Disco.BI.Extensions; using Disco.BI.Extensions;
using Disco.Models.UI.Job;
using Disco.Web.Extensions; using Disco.Web.Extensions;
namespace Disco.Web.Models.Job namespace Disco.Web.Models.Job
{ {
public class ShowModel public class ShowModel : JobShowModel
{ {
public Disco.Models.Repository.Job Job { get; set; } public Disco.Models.Repository.Job Job { get; set; }
public List<Disco.Models.Repository.DocumentTemplate> DocumentTemplates { get; set; } public List<Disco.Models.Repository.DocumentTemplate> AvailableDocumentTemplates { get; set; }
public List<Disco.Models.Repository.JobSubType> UpdatableJobSubTypes { get; set; } public List<Disco.Models.Repository.JobSubType> UpdatableJobSubTypes { get; set; }
public List<SelectListItem> DocumentTemplatesSelectListItems public List<SelectListItem> DocumentTemplatesSelectListItems
@@ -21,7 +22,7 @@ namespace Disco.Web.Models.Job
{ {
var list = new List<SelectListItem>(); var list = new List<SelectListItem>();
list.Add(new SelectListItem() { Selected = true, Value = string.Empty, Text = "Generate Document" }); list.Add(new SelectListItem() { Selected = true, Value = string.Empty, Text = "Generate Document" });
list.AddRange(this.DocumentTemplates.ToSelectListItems()); list.AddRange(this.AvailableDocumentTemplates.ToSelectListItems());
return list; return list;
} }
} }
+2 -2
View File
@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// //
// You can specify all the values or you can default the Revision and Build Numbers // You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("1.2.0219.1854")] [assembly: AssemblyVersion("1.2.0221.1820")]
[assembly: AssemblyFileVersion("1.2.0219.1854")] [assembly: AssemblyFileVersion("1.2.0221.1820")]
+1 -1
View File
@@ -184,7 +184,7 @@ WriteLiteral(" ");
#line default #line default
#line hidden #line hidden
WriteLiteral("\r\n </div>\r\n</div>\r\n"); WriteLiteral("\r\n </div>\r\n</div>");
} }
} }
+1
View File
@@ -104,5 +104,6 @@
href="http://discoict.com.au/" target="_blank">discoict.com.au</a> | @Html.ActionLink("Credits", MVC.Public.Public.Credits()) | @Html.ActionLink("Licence", MVC.Public.Public.Licence()) href="http://discoict.com.au/" target="_blank">discoict.com.au</a> | @Html.ActionLink("Credits", MVC.Public.Public.Credits()) | @Html.ActionLink("Licence", MVC.Public.Public.Licence())
</footer> </footer>
</div> </div>
@{ Disco.Services.UIExtensions.UIExtensions.ExecuteExtensionResult(this); }
</body> </body>
</html> </html>
+15 -1
View File
@@ -478,7 +478,21 @@ WriteLiteral(" | ");
#line default #line default
#line hidden #line hidden
WriteLiteral("\r\n </footer>\r\n </div>\r\n</body>\r\n</html>\r\n"); WriteLiteral("\r\n </footer>\r\n </div>\r\n");
#line 107 "..\..\Views\Shared\_Layout.cshtml"
#line default
#line hidden
#line 107 "..\..\Views\Shared\_Layout.cshtml"
Disco.Services.UIExtensions.UIExtensions.ExecuteExtensionResult(this);
#line default
#line hidden
WriteLiteral("\r\n</body>\r\n</html>\r\n");
} }
} }