public IActionResult CreateNode([FromQuery] string tree, [FromQuery] string type, [FromQuery] string view, [FromQuery] string parent, [FromQuery] int index) { var zone = GetZoneContextFromQuery(Request.Query); // TODO: Move validation logic to service if (tree == null || type == null || zone == null) { return(BadRequest("Invalid node operation")); } var widget = _widgetProvider.Create(type); if (view == null) { view = _widgetProvider.GetWidgetConfig(type).Views.First().Id; } var node = new ContentNode() { ContentTreeId = tree, ParentId = parent, WidgetType = type, WidgetId = widget?.Id, ViewId = view, Zone = zone.Name, Index = index, }; _contentManager.CreateContentNode(node).Wait(); InitTreeContext(node, zone); return(ViewComponent("ContentNode", new { node = node })); }
public async Task EnsureContentNodeModel(ContentNode node) { if (node.WidgetId == null) { // HACK: Having to intialize "null" models here because of // Several widgets who's models can't be exported / imported // due to dependency on SiteContext. // TODO: Update all widgets so can be exported / imported properly if (_widgetProvider.GetWidgetConfig(node.WidgetType).ModelType != null) { node.WidgetId = _widgetProvider.Create(node.WidgetType).Id; await UpdateContentNode(node); } } }
private async Task <Models.ContentNode> CreateNodeFromDefaultModel(string treeId, string containerName, string widgetType, string modelName, string viewId) { var widgetConfig = _widgetProvider.GetWidgetConfig(widgetType); IWidgetModel widgetModel; // Create an instance of the widget using based on default or named model if (string.IsNullOrEmpty(modelName)) { widgetModel = _widgetProvider.Create(widgetType); } else { widgetModel = _widgetProvider.Create(widgetType, modelName); } // Map the widget to the ContentTree var node = new Models.ContentNode() { ContentTreeId = treeId, WidgetType = widgetType, WidgetId = widgetModel?.Id, Zone = containerName }; // Verify ViewId if (viewId == null || !widgetConfig.Views.Any(x => x.Id == viewId)) { node.ViewId = widgetConfig.GetDefaultViewId(); } else { node.ViewId = viewId; } await _contentManager.CreateContentNode(node); return(node); }
public async Task <IViewComponentResult> InvokeAsync(string type, string id = null) { var widgetInfo = _widgetProvider.GetWidgetConfig(type); // If multiple forms are present, use the view that creates tab items // automatically (eg, the old method) var viewPath = "/UI/Views/Rendering/WidgetSettingsModal-V1.cshtml"; // Otherwise use the new form // NOTE: All widgets will eventually use the new form if (widgetInfo.Forms.Count() == 1) { viewPath = "/UI/Views/Rendering/WidgetSettingsModal-V2.cshtml"; } // Sending id via ViewData to avoid creating a custom view model ViewData["WidgetId"] = id; // The underlying modal layout will add to modal's css if set ViewData["ModalCssClass"] = "widget-form-modal"; return(await Task.Run(() => View(viewPath, widgetInfo))); }