WIP
This commit is contained in:
parent
4e829ad27e
commit
430e62628c
|
|
@ -0,0 +1,20 @@
|
|||
using Flowsharp.Models;
|
||||
|
||||
namespace Flowsharp.Web.Abstractions.Drivers
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for activity drivers.
|
||||
/// </summary>
|
||||
public abstract class TypedActivityDisplayDriver<TActivity> : ActivityDisplayDriver where TActivity : class, IActivity
|
||||
{
|
||||
public override bool CanHandleModel(IActivity model) => model.Name == typeof(TActivity).Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Base class for activity drivers using a strongly typed view model.
|
||||
/// </summary>
|
||||
public abstract class TypedActivityDisplayDriver<TActivity, TEditViewModel> : ActivityDisplayDriver<TEditViewModel> where TActivity : class, IActivity where TEditViewModel : class, new()
|
||||
{
|
||||
public override bool CanHandleModel(IActivity model) => model.Name == typeof(TActivity).Name;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
using Flowsharp.Models;
|
||||
using OrchardCore.DisplayManagement;
|
||||
|
||||
namespace Flowsharp.Web.Abstractions.Services
|
||||
{
|
||||
public interface IActivityDisplayManager : IDisplayManager<IActivity>
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
using Flowsharp.Models;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using OrchardCore.DisplayManagement.Views;
|
||||
|
||||
namespace Flowsharp.Web.Abstractions.ViewModels
|
||||
{
|
||||
public class ActivityViewModel : ShapeViewModel
|
||||
{
|
||||
public ActivityViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public ActivityViewModel(IActivity activity)
|
||||
{
|
||||
Activity = activity;
|
||||
}
|
||||
|
||||
[BindNever]
|
||||
public IActivity Activity { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
///<reference path='../../../node_modules/@types/jquery/index.d.ts' />
|
||||
///<reference path='../../../node_modules/@types/bootstrap/index.d.ts' />
|
||||
|
||||
namespace Flowsharp {
|
||||
|
||||
export class ActivityEditor {
|
||||
public show = () => this.containerElement.modal('show');
|
||||
public hide = () => this.containerElement.modal('hide');
|
||||
public display = (activityName: string) => $.ajax({
|
||||
type: 'POST',
|
||||
url: `/activity/display/${activityName}`,
|
||||
data: {},
|
||||
contentType: 'application/json',
|
||||
dataType: 'json'
|
||||
}).done(this.displayActivity);
|
||||
private baseUrl: string;
|
||||
private containerElement: JQuery<HTMLElement>;
|
||||
private titleElement: JQuery<HTMLElement>;
|
||||
private contentElement: JQuery<HTMLElement>;
|
||||
private displayActivity = (data: any) => {
|
||||
const html = <string>data;
|
||||
this.contentElement.html(html);
|
||||
};
|
||||
|
||||
constructor(container: HTMLElement) {
|
||||
this.containerElement = $(container);
|
||||
this.titleElement = this.containerElement.find('.modal-title');
|
||||
this.contentElement = this.containerElement.find('.modal-body');
|
||||
this.baseUrl = this.containerElement.data('base-url');
|
||||
}
|
||||
|
||||
public get title(): string {
|
||||
return this.titleElement.text();
|
||||
}
|
||||
|
||||
public set title(value: string) {
|
||||
this.titleElement.text(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Flowsharp.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OrchardCore.DisplayManagement;
|
||||
using OrchardCore.DisplayManagement.ModelBinding;
|
||||
|
||||
namespace Flowsharp.Web.ViewComponents.Controllers
|
||||
{
|
||||
[Route("[controller]")]
|
||||
[IgnoreAntiforgeryToken]
|
||||
public class ActivityController : Controller, IUpdateModel
|
||||
{
|
||||
private readonly IDisplayManager<Flowsharp.Models.ActivityDescriptor> displayManager;
|
||||
private readonly IActivityLibrary activityLibrary;
|
||||
|
||||
public ActivityController(IDisplayManager<Flowsharp.Models.ActivityDescriptor> displayManager, IActivityLibrary activityLibrary)
|
||||
{
|
||||
this.displayManager = displayManager;
|
||||
this.activityLibrary = activityLibrary;
|
||||
}
|
||||
|
||||
[HttpPost("display/{activityName}")]
|
||||
public async Task<IActionResult> Display(string activityName, [FromBody] JToken json, CancellationToken cancellationToken)
|
||||
{
|
||||
var activity = await activityLibrary.GetActivityByNameAsync(activityName, cancellationToken);
|
||||
var editorShape = await displayManager.BuildEditorAsync(activity, this, true);
|
||||
return View(editorShape);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
using System.Collections.Generic;
|
||||
using Flowsharp.Models;
|
||||
using Flowsharp.Web.Abstractions.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OrchardCore.DisplayManagement;
|
||||
using OrchardCore.DisplayManagement.Descriptors;
|
||||
using OrchardCore.DisplayManagement.Handlers;
|
||||
using OrchardCore.DisplayManagement.Layout;
|
||||
using OrchardCore.DisplayManagement.Theming;
|
||||
|
||||
namespace Flowsharp.Web.ViewComponents.Services
|
||||
{
|
||||
public class ActivityDisplayManager : DisplayManager<IActivity>, IActivityDisplayManager
|
||||
{
|
||||
public ActivityDisplayManager(
|
||||
IEnumerable<IDisplayDriver<IActivity>> drivers,
|
||||
IShapeTableManager shapeTableManager,
|
||||
IShapeFactory shapeFactory,
|
||||
IThemeManager themeManager,
|
||||
ILogger<DisplayManager<IActivity>> logger,
|
||||
ILayoutAccessor layoutAccessor) : base(drivers, shapeTableManager, shapeFactory, themeManager, logger, layoutAccessor)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
@model dynamic
|
||||
@await DisplayAsync(Model)
|
||||
Loading…
Reference in a new issue