예제 #1
0
        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 }));
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
                }
            }
        }