Beispiel #1
0
        public JsonResult IsNodeSelectable(HiveId dataTypeId, HiveId nodeId, Guid treeId)
        {
            var ds = BackOfficeRequestContext.RegisteredComponents.TreeControllers.GetNodeSelectorDataSource(treeId);

            try
            {
                return(Json(new
                {
                    result = CSharpExpressionsUtility.GetNodeFilterResult(BackOfficeRequestContext, dataTypeId, ds, nodeId),
                    success = true
                }));
            }
            catch (Exception ex)
            {
                var errorMsg = "NodeSelector filter error (see rebel log for full details): " + ex.Message;
                LogHelper.Error <NodeSelectorUtilityController>("The filter executed on the node caused an error", ex);
                Notifications.Add(new NotificationMessage(errorMsg, "Compilation error", NotificationType.Error));
                return(new CustomJsonResult(new
                {
                    success = false,
                    notifications = Notifications,
                    errorMsg
                }.ToJsonString));
            }
        }
        /// <summary>
        /// Creates the editor model
        /// </summary>
        /// <param name="preValues"></param>
        /// <returns></returns>
        public override NodeSelectorEditorModel CreateEditorModel(NodeSelectorPreValueModel preValues)
        {
            var docType       = GetContentPropertyValue(x => x.DocTypeProperty, null);
            var dataTypeId    = HiveId.Empty;
            var currentNodeId = GetContentModelValue(x => x.Id, HiveId.Empty);

            if (docType != null)
            {
                dataTypeId = docType.DataTypeId;
            }

            var model = new NodeSelectorEditorModel(
                preValues,
                BackOfficeRequestContext,
                GetContentModelValue(x => x.Id, HiveId.Empty),
                GetContentPropertyValue(x => x.Alias, ""),
                dataTypeId);

            //not sure what else to do here, but need a UrlHelper which requires a RequestContext
            var urlHelper = DependencyResolver.Current.GetService <UrlHelper>();

            //give the HtmlId of the tree being rendered a unique but consistent Id across the editor
            var htmlId = "ns_" + GetContentPropertyValue(x => x.Id, HiveId.Empty).GetHtmlId();

            //create the custom tree parameters that will be passed up in query string
            var treeparams = urlHelper.CreateTreeParams(
                true,                                                  //it is dialog
                "Rebel.PropertyEditors.NodeSelector.nodeClickHandler", //the node click handler
                new Dictionary <string, object>
            {
                //we want to render the node requested, not its children
                { TreeQueryStringParameters.RenderParent, true }
            });

            var startNodeId = HiveId.Empty;

            if (preValues.SelectedTree == default(Guid))
            {
                model.ErrorMessage = string.Format("No tree type has been selected for the NodeSelector");
                //exit now as we cannot continue
                return(model);
            }

            //we need to get the start node id based on the query
            var ds = BackOfficeRequestContext.RegisteredComponents.TreeControllers.GetNodeSelectorDataSource(preValues.SelectedTree);

            if (preValues.StartNodeSelectionType == StartNodeSelectionType.UsePicker)
            {
                if (!preValues.StartNodeId.IsNullValueOrEmpty())
                {
                    model.StartNode = ds.GetEntity(preValues.StartNodeId);
                    if (model.StartNode == null)
                    {
                        model.ErrorMessage = string.Format("Could not find a start node with Id: {0} to render", preValues.StartNodeId.ToFriendlyString());
                        //exit now as we cannot continue
                        return(model);
                    }
                }
                else
                {
                    model.ErrorMessage = string.Format("No start node id assigned to the NodeSelector");
                    //exit now as we cannot continue
                    return(model);
                }

                startNodeId = preValues.StartNodeId;
            }
            else
            {
                if (dataTypeId != HiveId.Empty && currentNodeId != HiveId.Empty)
                {
                    //TODO: Error check this nicely !!
                    startNodeId = CSharpExpressionsUtility.GetStartNodeQueryResult(BackOfficeRequestContext, dataTypeId, ds, currentNodeId);
                }
            }

            model.TreeModel = new TreeRenderModel(
                urlHelper.GetTreeUrl(startNodeId, preValues.SelectedTree, treeparams))
            {
                TreeHtmlElementId = htmlId,
                ShowContextMenu   = false
            };

            return(model);
        }