Beispiel #1
0
        private void _initTreeFromViewRecursive(CswNbtViewNode ViewNode, RadTreeNodeCollection Nodes, ViewTreeSelectType SelectType)
        {
            RadTreeNode newNode = null;

            newNode = _CreateNode(ViewNode, SelectType);
            Nodes.Add(newNode);

            // Recurse
            if (ViewNode is CswNbtViewRoot)
            {
                foreach (CswNbtViewRelationship Child in ((CswNbtViewRoot)ViewNode).ChildRelationships)
                {
                    _initTreeFromViewRecursive(Child, newNode.Nodes, SelectType);
                }
            }
            else if (ViewNode is CswNbtViewRelationship)
            {
                foreach (CswNbtViewProperty Child in ((CswNbtViewRelationship)ViewNode).Properties)
                {
                    _initTreeFromViewRecursive(Child, newNode.Nodes, SelectType);
                }
                foreach (CswNbtViewRelationship Child in ((CswNbtViewRelationship)ViewNode).ChildRelationships)
                {
                    _initTreeFromViewRecursive(Child, newNode.Nodes, SelectType);
                }
            }
            else if (ViewNode is CswNbtViewProperty)
            {
                foreach (CswNbtViewPropertyFilter Child in ((CswNbtViewProperty)ViewNode).Filters)
                {
                    _initTreeFromViewRecursive(Child, newNode.Nodes, SelectType);
                }
            }
        }
Beispiel #2
0
        private void _removeProp(ICswNbtMetaDataProp prop)
        {
            if (null != prop)
            {
                CurrentView.removeViewProperty(prop);

                Collection <string> doomedRels = new Collection <string>();
                CswNbtViewRoot.forEachRelationship eachRelationship = relationship =>
                {
                    if (relationship.Properties.Count == 0 && relationship.ChildRelationships.Count == 0)
                    {
                        doomedRels.Add(relationship.ArbitraryId);
                    }
                };
                CurrentView.Root.eachRelationship(eachRelationship, null);

                foreach (string doomedRelId in doomedRels)
                {
                    CswNbtViewRelationship doomedRel = (CswNbtViewRelationship)CurrentView.FindViewNodeByArbitraryId(doomedRelId);
                    if (null != doomedRel)
                    {
                        CswNbtViewNode doomedRelsParent = CurrentView.FindViewNodeByArbitraryId(doomedRel.ParentArbitraryId);
                        if (doomedRelsParent is CswNbtViewRelationship)
                        {
                            CswNbtViewRelationship AsRelationship = (CswNbtViewRelationship)doomedRelsParent;
                            AsRelationship.removeChildRelationship(doomedRel);
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public void reinitTreeFromView(CswNbtView View, CswNbtViewNode ViewNodeToSelect, CswNbtViewNode DefaultNodeToSelect, ViewTreeSelectType SelectType)
        {
            EnsureChildControls();

            // Setup tree and selected node
            string PriorSelectedNodeValue = string.Empty;

            if (_Tree.SelectedNode != null)
            {
                PriorSelectedNodeValue = _Tree.SelectedNode.Value;
            }

            _Tree.Nodes.Clear();
            _initTreeFromViewRecursive(View.Root, _Tree.Nodes, SelectType);

            if (PriorSelectedNodeValue != string.Empty)
            {
                RadTreeNode PotentialNodeMatch = _Tree.FindNodeByValue(PriorSelectedNodeValue);
                if (PotentialNodeMatch != null)
                {
                    PotentialNodeMatch.Selected = true;
                }
            }
            if (ViewNodeToSelect != null)
            {
                RadTreeNode PotentialNodeMatch = _Tree.FindNodeByValue(ViewNodeToSelect.ArbitraryId);
                if (PotentialNodeMatch != null)
                {
                    PotentialNodeMatch.Selected = true;
                }
            }
            if (_Tree.SelectedNode == null && DefaultNodeToSelect != null)
            {
                _Tree.FindNodeByValue(DefaultNodeToSelect.ArbitraryId).Selected = true;
            }

            if (_Tree.SelectedNode == null && IsRootSelectable)
            {
                _Tree.FindNodeByValue(View.Root.ArbitraryId).Selected = true;
            }

            _Tree.ExpandAllNodes();
        }
Beispiel #4
0
        private RadTreeNode _CreateNode(CswNbtViewNode ViewNode, ViewTreeSelectType SelectType)
        {
            RadTreeNode node = new RadTreeNode();

            node.ImageUrl = ViewNode.IconFileName;
            node.Text     = ViewNode.TextLabel;

            if (SelectableNodeTextPrefix != string.Empty || SelectableNodeTextSuffix != string.Empty)
            {
                if ((SelectType == ViewTreeSelectType.Relationship && ViewNode is CswNbtViewRelationship &&
                     (IsFirstLevelRemovable || ViewNode.Parent is CswNbtViewRelationship)) ||                    // BZ 9203
                    (SelectType == ViewTreeSelectType.Property && ViewNode is CswNbtViewProperty) ||
                    (SelectType == ViewTreeSelectType.Filter && ViewNode is CswNbtViewPropertyFilter))
                {
                    {
                        node.Text = node.Text + SelectableNodeTextPrefix;
                        node.Text = node.Text + CswTools.SafeJavascriptParam(ViewNode.ArbitraryId);
                        node.Text = node.Text + SelectableNodeTextSuffix;
                    }
                }
            }
            node.Expanded = true;

            if (SelectType != ViewTreeSelectType.None)
            {
                node.Enabled = false;
                if ((SelectType == ViewTreeSelectType.Relationship && ((ViewNode is CswNbtViewRoot && IsRootSelectable) || ViewNode is CswNbtViewRelationship)) ||
                    (SelectType == ViewTreeSelectType.Property && (ViewNode is CswNbtViewRelationship || ViewNode is CswNbtViewProperty)) ||
                    (SelectType == ViewTreeSelectType.Filter && (ViewNode is CswNbtViewProperty || ViewNode is CswNbtViewPropertyFilter)))
                {
                    node.Enabled = true;
                }
            }

            node.CssClass         = "TreeNode";
            node.SelectedCssClass = "SelectedTreeNode";
            node.Value            = ViewNode.ArbitraryId;
            return(node);
        }
Beispiel #5
0
        private void _getDefaultContentRecursive(JObject ParentObj, CswNbtViewNode ViewNode)
        {
            Collection <CswNbtViewNode.CswNbtViewAddNodeTypeEntry> Entries = ViewNode.AllowedChildNodeTypes(true);

            if (Entries.Count > 0)
            {
                ParentObj["entries"] = new JObject();
                foreach (CswNbtViewNode.CswNbtViewAddNodeTypeEntry Entry in Entries)
                {
                    ParentObj["entries"][Entry.NodeType.NodeTypeName] = CswNbtWebServiceMainMenu.makeAddMenuItem(Entry.NodeType, new CswPrimaryKey(), string.Empty);
                }
            }
            JObject ChildObj = new JObject();

            ParentObj["children"] = ChildObj;

            // recurse
            foreach (CswNbtViewRelationship ChildViewRel in ViewNode.GetChildrenOfType(CswEnumNbtViewNodeType.CswNbtViewRelationship))
            {
                _getDefaultContentRecursive(ChildObj, ChildViewRel);
            }
        } // _getDefaultContentRecursive()
        public override CswNbtViewEditorData HandleAction()
        {
            CswNbtViewEditorData Return = new CswNbtViewEditorData();

            if (Request.Action == "Click")
            {
                CswNbtViewNode foundNode = Request.CurrentView.FindViewNodeByArbitraryId(Request.ArbitraryId);
                if (null != foundNode)
                {
                    CswNbtView TempView = _CswNbtResources.ViewSelect.restoreView(CurrentView.ToString());
                    if (foundNode is CswNbtViewPropertyFilter)
                    {
                        Return.Step6.FilterNode = (CswNbtViewPropertyFilter)foundNode;
                    }
                    else if (foundNode is CswNbtViewRelationship)
                    {
                        CswNbtViewRelationship asRelationship = (CswNbtViewRelationship)foundNode;

                        if (asRelationship.SecondType == CswEnumNbtViewRelatedIdType.NodeTypeId)
                        {
                            CswNbtMetaDataNodeType NodeType = _CswNbtResources.MetaData.getNodeType(asRelationship.SecondId);
                            foreach (CswNbtViewProperty prop in _getProps(NodeType, TempView, new HashSet <string>(), asRelationship))
                            {
                                if (((CswEnumNbtViewRenderingMode.Tree == Request.CurrentView.ViewMode || CswEnumNbtViewRenderingMode.List == Request.CurrentView.ViewMode) && CswEnumNbtFieldType.Button != prop.FieldType) ||
                                    CswEnumNbtViewRenderingMode.Grid == Request.CurrentView.ViewMode || CswEnumNbtViewRenderingMode.Table == Request.CurrentView.ViewMode)
                                {
                                    Return.Step6.Properties.Add(prop);
                                }
                            }
                        }
                        else if (asRelationship.SecondType == CswEnumNbtViewRelatedIdType.ObjectClassId)
                        {
                            CswNbtMetaDataObjectClass ObjClass = _CswNbtResources.MetaData.getObjectClass(asRelationship.SecondId);
                            foreach (CswNbtViewProperty prop in _getProps(ObjClass, TempView, new HashSet <string>(), asRelationship))
                            {
                                if (((CswEnumNbtViewRenderingMode.Tree == Request.CurrentView.ViewMode || CswEnumNbtViewRenderingMode.List == Request.CurrentView.ViewMode) && CswEnumNbtFieldType.Button != prop.FieldType) ||
                                    CswEnumNbtViewRenderingMode.Grid == Request.CurrentView.ViewMode || CswEnumNbtViewRenderingMode.Table == Request.CurrentView.ViewMode)
                                {
                                    Return.Step6.Properties.Add(prop);
                                }
                            }
                        }
                        else
                        {
                            CswNbtMetaDataPropertySet PropSet   = _CswNbtResources.MetaData.getPropertySet(asRelationship.SecondId);
                            HashSet <string>          seenProps = new HashSet <string>();
                            foreach (CswNbtMetaDataObjectClass ObjClass in PropSet.getObjectClasses())
                            {
                                foreach (CswNbtViewProperty prop in _getProps(ObjClass, TempView, seenProps, asRelationship).OrderBy(prop => prop.TextLabel))
                                {
                                    if (((CswEnumNbtViewRenderingMode.Tree == Request.CurrentView.ViewMode || CswEnumNbtViewRenderingMode.List == Request.CurrentView.ViewMode) && CswEnumNbtFieldType.Button != prop.FieldType) ||
                                        CswEnumNbtViewRenderingMode.Grid == Request.CurrentView.ViewMode || CswEnumNbtViewRenderingMode.Table == Request.CurrentView.ViewMode)
                                    {
                                        Return.Step6.Properties.Add(prop);
                                    }
                                }
                            }
                        }

                        Return.Step6.Relationships = getViewChildRelationshipOptions(CurrentView, asRelationship.ArbitraryId);

                        Return.Step6.RelationshipNode = asRelationship;
                    }
                    else if (foundNode is CswNbtViewRoot && CurrentView.Visibility != CswEnumNbtViewVisibility.Property)  //can't add to view root on Prop view
                    {
                        TempView.Root.ChildRelationships.Clear();
                        foreach (CswNbtMetaDataNodeType NodeType in _CswNbtResources.MetaData.getNodeTypes().OrderBy(NT => NT.NodeTypeName))
                        {
                            Return.Step6.Relationships.Add(TempView.AddViewRelationship(NodeType, false));
                        }
                        foreach (CswNbtMetaDataObjectClass ObjClass in _CswNbtResources.MetaData.getObjectClasses().OrderBy(OC => OC.ObjectClass.Value))
                        {
                            Return.Step6.Relationships.Add(TempView.AddViewRelationship(ObjClass, false));
                        }
                        foreach (CswNbtMetaDataPropertySet PropSet in _CswNbtResources.MetaData.getPropertySets().OrderBy(PS => PS.Name))
                        {
                            Return.Step6.Relationships.Add(TempView.AddViewRelationship(PropSet, false));
                        }
                        Return.Step6.RootNode = (CswNbtViewRoot)foundNode;
                    }
                    else if (foundNode is CswNbtViewProperty && CswEnumNbtFieldType.Button != ((CswNbtViewProperty)foundNode).FieldType)
                    {
                        Return.Step6.PropertyNode = (CswNbtViewProperty)foundNode;
                        Request.Relationship      = (CswNbtViewRelationship)foundNode.Parent; //getFilterProps needs Request.Relationship to be populated
                        _getFilterProps(Return);
                    }
                }
            }
            else if (Request.Action == "AddProp")
            {
                ICswNbtMetaDataProp prop = null;
                if (Request.Property.Type == CswEnumNbtViewPropType.NodeTypePropId)
                {
                    prop = _CswNbtResources.MetaData.getNodeTypeProp(Request.Property.NodeTypePropId);
                }
                else
                {
                    prop = _CswNbtResources.MetaData.getObjectClassProp(Request.Property.ObjectClassPropId);
                }
                CswNbtViewRelationship relToAddTo = (CswNbtViewRelationship)CurrentView.FindViewNodeByArbitraryId(Request.Relationship.ArbitraryId);
                CurrentView.AddViewProperty(relToAddTo, prop, CurrentView.getOrderedViewProps(false).Count + 1);
            }
            else if (Request.Action == "AddRelationship")
            {
                CswNbtViewRelationship relToAddTo = (CswNbtViewRelationship)CurrentView.FindViewNodeByArbitraryId(Request.ArbitraryId);
                ICswNbtMetaDataProp    prop       = null;
                if (Request.Relationship.PropType == CswEnumNbtViewPropIdType.NodeTypePropId)
                {
                    prop = _CswNbtResources.MetaData.getNodeTypeProp(Request.Relationship.PropId);
                }
                else
                {
                    prop = _CswNbtResources.MetaData.getObjectClassProp(Request.Relationship.PropId);
                }
                CurrentView.AddViewRelationship(relToAddTo, Request.Relationship.PropOwner, prop, true);
            }
            else if (Request.Action == "AddFilter")
            {
                CswNbtViewProperty propNode = (CswNbtViewProperty)CurrentView.FindViewNodeByArbitraryId(Request.PropArbId);
                if (false == _hasFilter(propNode))
                {
                    CurrentView.AddViewPropertyFilter(propNode,
                                                      Conjunction: (CswEnumNbtFilterConjunction)Request.FilterConjunction,
                                                      SubFieldName: (CswEnumNbtSubFieldName)Request.FilterSubfield,
                                                      FilterMode: (CswEnumNbtFilterMode)Request.FilterMode,
                                                      Value: Request.FilterValue
                                                      );
                }
                Return.Step6.PropertyNode = propNode;
            }
            else if (Request.Action == "RemoveNode")
            {
                CswNbtViewNode nodeToRemove = CurrentView.FindViewNodeByArbitraryId(Request.ArbitraryId);
                CswNbtViewNode parent       = nodeToRemove.Parent;
                parent.RemoveChild(nodeToRemove);

                if (parent.ViewNodeType == CswEnumNbtViewNodeType.CswNbtViewProperty)
                {
                    Return.Step6.PropertyNode = (CswNbtViewProperty)parent;
                }
                else if (parent.ViewNodeType == CswEnumNbtViewNodeType.CswNbtViewRelationship)
                {
                    Return.Step6.RelationshipNode = (CswNbtViewRelationship)parent;
                }
                else if (parent.ViewNodeType == CswEnumNbtViewNodeType.CswNbtViewRoot)
                {
                    Return.Step6.RootNode = (CswNbtViewRoot)parent;
                }
            }
            else if (Request.Action == "UpdateView")
            {
                string grp = string.Empty;
                if (null != Request.Property)
                {
                    CswNbtViewRelationship selectedPropsParent = (CswNbtViewRelationship)CurrentView.FindViewNodeByArbitraryId(Request.Property.ParentArbitraryId);
                    Request.Property.Parent = selectedPropsParent;
                    CswNbtViewProperty rel = (CswNbtViewProperty)CurrentView.FindViewNodeByArbitraryId(Request.Property.ArbitraryId);
                    if (null == rel)
                    {
                        CswNbtViewRelationship parent = (CswNbtViewRelationship)CurrentView.FindViewNodeByArbitraryId(Request.Property.ParentArbitraryId);
                        ICswNbtMetaDataProp    prop   = null;
                        if (Request.Property.Type == CswEnumNbtViewPropType.NodeTypePropId)
                        {
                            prop = _CswNbtResources.MetaData.getNodeTypeProp(Request.Property.NodeTypePropId);
                        }
                        else
                        {
                            prop = _CswNbtResources.MetaData.getObjectClassProp(Request.Property.ObjectClassPropId);
                        }
                        rel = CurrentView.AddViewProperty(parent, prop);
                    }
                    grp = rel.TextLabel;
                }

                CurrentView.GridGroupByCol = grp;
            }

            base.Finalize(Return);
            return(Return);
        }
Beispiel #7
0
        } // _runTreeNodesRecursive()

        /// <summary>
        /// Generate a JObject for the tree's current node
        /// </summary>
        private CswExtTree.TreeNode _getTreeNode(ICswNbtTree Tree, CswExtTree.TreeNode Parent, CswNbtSdTrees.Contract.Request Request)
        {
            CswExtTree.TreeNode Ret;
            if (null != Request && Request.UseCheckboxes)
            {
                Ret = new CswExtTree.TreeNodeWithCheckbox();
            }
            else
            {
                Ret = new CswExtTree.TreeNode();
            }

            CswNbtNodeKey ThisNodeKey       = Tree.getNodeKeyForCurrentPosition();
            string        ThisNodeName      = Tree.getNodeNameForCurrentPosition();
            string        ThisNodeIcon      = "";
            string        ThisNodeKeyString = ThisNodeKey.ToString();
            string        ThisNodeId        = "";
            int           ThisNodeTypeId    = int.MinValue;
            int           ThisObjectClassId = int.MinValue;

            bool ThisNodeLocked   = false;
            bool ThisNodeDisabled = false;
            bool ThisNodeFavorite = false;
            CswNbtMetaDataNodeType ThisNodeType = _CswNbtResources.MetaData.getNodeType(ThisNodeKey.NodeTypeId);

            switch (ThisNodeKey.NodeSpecies)
            {
            case CswEnumNbtNodeSpecies.Plain:
                ThisNodeId        = ThisNodeKey.NodeId.ToString();
                ThisNodeName      = Tree.getNodeNameForCurrentPosition();
                ThisNodeTypeId    = ThisNodeType.FirstVersionNodeTypeId;
                ThisObjectClassId = ThisNodeType.ObjectClassId;
                ThisNodeLocked    = Tree.getNodeLockedForCurrentPosition();
                ThisNodeDisabled  = (false == Tree.getNodeIncludedForCurrentPosition());
                ThisNodeFavorite  = Tree.getNodeFavoritedForCurrentPosition();
                if (ThisNodeFavorite)
                {
                    ThisNodeIcon = CswNbtMetaDataObjectClass.IconPrefix16 + "starsolid.png";
                }
                else
                {
                    ThisNodeIcon = CswNbtMetaDataObjectClass.IconPrefix16 + Tree.getNodeIconForCurrentPosition();
                }
                break;

            case CswEnumNbtNodeSpecies.Group:
                Ret.CssClass = "folder";
                break;
            }

            CswNbtViewNode ThisNodeViewNode = _View.FindViewNodeByUniqueId(ThisNodeKey.ViewNodeUniqueId);

            string ThisNodeState = "closed";

            if (ThisNodeKey.NodeSpecies == CswEnumNbtNodeSpecies.More ||
                _View.ViewMode == CswEnumNbtViewRenderingMode.List ||
                (Tree.IsFullyPopulated && Tree.getChildNodeCount() == 0) ||
                (ThisNodeViewNode != null && ThisNodeViewNode.GetChildrenOfType(CswEnumNbtViewNodeType.CswNbtViewRelationship).Count == 0))
            {
                ThisNodeState = "leaf";
            }

            Ret.Name = ThisNodeName;
            Ret.Icon = ThisNodeIcon;
            Ret.Id   = ThisNodeKeyString;
            switch (ThisNodeState)
            {
            case "closed":
                Ret.Expanded = false;
                break;

            case "leaf":
                Ret.IsLeaf = true;
                break;
            }

            if (null != Request)
            {
                Ret.Expanded = Request.ExpandAll;
            }

            if (int.MinValue != ThisNodeTypeId)
            {
                Ret.NodeTypeId = ThisNodeTypeId.ToString();
            }
            if (int.MinValue != ThisObjectClassId)
            {
                Ret.ObjectClassId = ThisObjectClassId.ToString();
            }

            Ret.NodeSpecies = ThisNodeKey.NodeSpecies.ToString();
            Ret.NodeId      = ThisNodeId;
            Ret.IsLocked    = ThisNodeLocked;
            if (ThisNodeDisabled)
            {
                Ret.IsDisabled = true;
                Ret.CssClass   = "disabled";
            }
            Ret.IsFavorite = ThisNodeFavorite;

            if (null != Parent && false == string.IsNullOrEmpty(Parent.Path))
            {
                Ret.Path = Parent.Path;
            }
            else
            {
                Ret.ParentId = "root";
                Ret.Path     = "|root";
            }
            if (false == Tree.isCurrentPositionRoot())
            {
                CswNbtNodeKey ParentKey = Tree.getNodeKeyForParentOfCurrentPosition();
                if (ParentKey.NodeSpecies != CswEnumNbtNodeSpecies.Root)
                {
                    Ret.ParentId = ParentKey.ToString();
                }
            }

            Ret.Path += "|" + Ret.Id;

            if (Tree.getChildNodeCount() > 0)
            {
                Ret.Children = new Collection <CswExtTree.TreeNode>();
            }
            else
            {
                Ret.Children = null;
            }

            Collection <CswNbtTreeNodeProp> ThisNodeProps = Tree.getChildNodePropsOfNode();

            CswNbtViewRoot.forEachProperty EachNodeProp = (ViewProp) =>
            {
                foreach (CswNbtTreeNodeProp NodeProp in ThisNodeProps)
                {
                    if (NodeProp.PropName.ToLower().Trim() == ViewProp.Name.ToLower().Trim())
                    {
                        Ret.data[new CswExtJsGridDataIndex(_View.ViewName, ViewProp.Name.ToLower().Trim())] = NodeProp.Gestalt;
                    }
                }
            };

            _View.Root.eachRelationship(relationshipCallBack: null, propertyCallBack: EachNodeProp);

            //ThisNodeObj["childcnt"] = Tree.getChildNodeCount().ToString();


            return(Ret);
        } // _treeNodeJObject()
Beispiel #8
0
        public JObject getMenu(CswNbtView View, string SafeNodeKey, Int32 NodeTypeId, string PropIdAttr, bool ReadOnly, string NodeId)
        {
            CswTimer MainMenuTimer = new CswTimer();

            JObject Ret = new JObject();

            CswPrimaryKey RelatedNodeId   = new CswPrimaryKey();
            string        RelatedNodeName = string.Empty;
            CswNbtNode    Node            = null;

            if (false == String.IsNullOrEmpty(SafeNodeKey))
            {
                CswNbtNodeKey NbtNodeKey = new CswNbtNodeKey(SafeNodeKey);
                Node = _CswNbtResources.Nodes[NbtNodeKey];
            }
            else if (false == String.IsNullOrEmpty(NodeId))
            {
                CswPrimaryKey NodePk = CswConvert.ToPrimaryKey(NodeId);
                Node = _CswNbtResources.Nodes[NodePk];
            }
            if (null != Node)
            {
                RelatedNodeId   = Node.NodeId;
                RelatedNodeName = Node.NodeName;
            }

            // MORE
            if (_MenuItems.Contains("More"))
            {
                JObject MoreObj = new JObject();

                if (null == View && Int32.MinValue != NodeTypeId)
                {
                    // ADD for Searches
                    if (_MenuItems.Contains("Add") && false == ReadOnly)
                    {
                        JObject AddObj = new JObject();

                        CswNbtMetaDataNodeType NodeType = _CswNbtResources.MetaData.getNodeType(NodeTypeId);
                        if (null != NodeType && _CswNbtResources.Permit.canNodeType(CswEnumNbtNodeTypePermission.Create, NodeType) && NodeType.getObjectClass().CanAdd)
                        {
                            AddObj[NodeType.NodeTypeName] = makeAddMenuItem(NodeType, RelatedNodeId, RelatedNodeName);
                            AddObj["haschildren"]         = true;
                            Ret["Add"] = AddObj;
                        }
                    } // if( _MenuItems.Contains( "Add" ) && false == ReadOnly )
                }     // if( null == View && Int32.MinValue != NodeTypeId )
                if (null != View)
                {
                    // ADD for Views
                    if (_MenuItems.Contains("Add") && false == ReadOnly)
                    {
                        JObject AddObj = new JObject();

                        // case 21672
                        CswNbtViewNode ParentNode = View.Root;
                        bool           LimitToFirstLevelRelationships = (View.ViewMode == CswEnumNbtViewRenderingMode.Grid);
                        if (LimitToFirstLevelRelationships && View.Visibility == CswEnumNbtViewVisibility.Property)
                        {
                            if (null == Node)
                            {
                                ICswNbtTree Tree = _CswNbtResources.Trees.getTreeFromView(View, false, false, false);
                                if (Tree.getChildNodeCount() > 0)
                                {
                                    Tree.goToNthChild(0);
                                    CswNbtNodeKey NodeKey = Tree.getNodeKeyForCurrentPosition();
                                    Node = _CswNbtResources.Nodes[NodeKey];
                                    if (null != Node)
                                    {
                                        RelatedNodeId   = Node.NodeId;
                                        RelatedNodeName = Node.NodeName;
                                    }
                                }
                            }
                            if (View.Root.ChildRelationships.Count > 0)
                            {
                                ParentNode = View.Root.ChildRelationships[0];
                            }
                        }
                        foreach (JProperty AddNodeType in ParentNode.AllowedChildNodeTypes(LimitToFirstLevelRelationships)
                                 .Select(Entry => new JProperty(Entry.NodeType.NodeTypeName,
                                                                makeAddMenuItem(Entry.NodeType, RelatedNodeId, RelatedNodeName))))
                        {
                            AddObj.Add(AddNodeType);
                        }

                        if (AddObj.HasValues)
                        {
                            AddObj["haschildren"] = true;
                            Ret["Add"]            = AddObj;
                        }
                    }

                    // COPY
                    if (
                        _MenuItems.Contains("Copy") &&
                        false == ReadOnly &&
                        null != Node && Node.NodeSpecies == CswEnumNbtNodeSpecies.Plain &&
                        View.ViewMode != CswEnumNbtViewRenderingMode.Grid &&
                        _CswNbtResources.Permit.canNodeType(CswEnumNbtNodeTypePermission.Create, Node.getNodeType()) &&
                        Node.getObjectClass().CanAdd //If you can't Add the node, you can't Copy it either
                        )
                    {
                        MoreObj["Copy"]               = new JObject();
                        MoreObj["Copy"]["copytype"]   = _getActionType(Node.getNodeType());
                        MoreObj["Copy"]["action"]     = CswEnumNbtMainMenuActions.CopyNode.ToString();
                        MoreObj["Copy"]["nodeid"]     = Node.NodeId.ToString();
                        MoreObj["Copy"]["nodename"]   = Node.NodeName;
                        MoreObj["Copy"]["nodetypeid"] = Node.NodeTypeId.ToString();
                    }

                    // DELETE
                    if (_MenuItems.Contains("Delete") &&
                        false == ReadOnly &&
                        false == string.IsNullOrEmpty(SafeNodeKey) &&
                        null != Node &&
                        View.ViewMode != CswEnumNbtViewRenderingMode.Grid &&
                        Node.NodeSpecies == CswEnumNbtNodeSpecies.Plain &&
                        _CswNbtResources.Permit.isNodeWritable(CswEnumNbtNodeTypePermission.Delete, Node.getNodeType(), Node.NodeId))
                    {
                        MoreObj["Delete"]             = new JObject();
                        MoreObj["Delete"]["action"]   = CswEnumNbtMainMenuActions.DeleteNode.ToString();
                        MoreObj["Delete"]["nodeid"]   = Node.NodeId.ToString();
                        MoreObj["Delete"]["nodename"] = Node.NodeName;
                    }

                    // SAVE VIEW AS
                    if (_MenuItems.Contains("Save View As") &&
                        false == View.ViewId.isSet() &&
                        _CswNbtResources.Permit.can(_CswNbtResources.Actions[CswEnumNbtActionName.Edit_View]))
                    {
                        View.SaveToCache(false);
                        MoreObj["Save View As"]             = new JObject();
                        MoreObj["Save View As"]["action"]   = CswEnumNbtMainMenuActions.SaveViewAs.ToString();
                        MoreObj["Save View As"]["viewid"]   = View.SessionViewId.ToString();
                        MoreObj["Save View As"]["viewmode"] = View.ViewMode.ToString();
                    }

                    JObject PrintObj = null;

                    // PRINT LABEL

                    bool ValidForTreePrint = (false == string.IsNullOrEmpty(SafeNodeKey) &&
                                              View.ViewMode != CswEnumNbtViewRenderingMode.Grid &&
                                              null != Node &&
                                              null != Node.getNodeType() &&
                                              Node.getNodeType().HasLabel);

                    bool  ValidForGridPrint    = false;
                    bool  TryValidForGridPrint = (View.ViewMode == CswEnumNbtViewRenderingMode.Grid);
                    Int32 MultiPrintNodeTypeId = Int32.MinValue;
                    if (TryValidForGridPrint)
                    {
                        CswNbtViewRelationship TryRel = null;
                        if (View.Visibility != CswEnumNbtViewVisibility.Property && View.Root.ChildRelationships.Count == 1)
                        {
                            TryRel = View.Root.ChildRelationships[0];
                        }
                        else if (View.Visibility == CswEnumNbtViewVisibility.Property &&
                                 View.Root.ChildRelationships.Count == 1 &&
                                 View.Root.ChildRelationships[0].ChildRelationships.Count == 1)
                        {
                            TryRel = View.Root.ChildRelationships[0].ChildRelationships[0];
                        }

                        if (null != TryRel)
                        {
                            ICswNbtMetaDataDefinitionObject MdDef = TryRel.SecondMetaDataDefinitionObject();
                            if (null != MdDef)
                            {
                                if (MdDef.HasLabel)
                                {
                                    //This assumes that only NodeTypes will implement this property
                                    MultiPrintNodeTypeId = MdDef.UniqueId;
                                    ValidForGridPrint    = true;
                                }
                            }
                        }
                    }

                    if (_MenuItems.Contains("Print") &&
                        (ValidForTreePrint || ValidForGridPrint))
                    {
                        PrintObj = PrintObj ?? new JObject(new JProperty("haschildren", true));
                        PrintObj["Print Label"]           = new JObject();
                        PrintObj["Print Label"]["action"] = CswEnumNbtMainMenuActions.PrintLabel.ToString();

                        if (ValidForTreePrint)
                        {
                            PrintObj["Print Label"]["nodeid"]     = Node.NodeId.ToString();
                            PrintObj["Print Label"]["nodetypeid"] = Node.NodeTypeId;
                            PrintObj["Print Label"]["nodename"]   = Node.NodeName;
                        }
                        else if (ValidForGridPrint)
                        {
                            PrintObj["Print Label"]["nodetypeid"] = MultiPrintNodeTypeId;
                        }
                    }
                    // PRINT
                    if (_MenuItems.Contains("Print") &&
                        View.ViewMode == CswEnumNbtViewRenderingMode.Grid)
                    {
                        View.SaveToCache(false);
                        PrintObj = PrintObj ?? new JObject(new JProperty("haschildren", true));
                        PrintObj["Print View"]           = new JObject();
                        PrintObj["Print View"]["action"] = CswEnumNbtMainMenuActions.PrintView.ToString();
                    }

                    if (null != PrintObj)
                    {
                        MoreObj["Print"] = PrintObj;
                    }

                    // EXPORT
                    if (_MenuItems.Contains("Export"))
                    {
                        if (CswEnumNbtViewRenderingMode.Grid == View.ViewMode)
                        {
                            JObject ExportObj = new JObject();
                            MoreObj["Export"] = ExportObj;

                            View.SaveToCache(false);
                            ExportObj["CSV"] = new JObject();
                            string ExportLink = "wsNBT.asmx/gridExportCSV?ViewId=" + View.SessionViewId + "&SafeNodeKey='";
                            if (CswEnumNbtViewVisibility.Property == View.Visibility)
                            {
                                ExportLink += SafeNodeKey;
                            }
                            ExportLink += "'";

                            ExportObj["CSV"]["popup"] = ExportLink;

                            ExportObj["haschildren"] = true;
                        }
                    }
                } // if( null != View )

                // EDIT VIEW
                if (_MenuItems.Contains("Edit View") &&
                    _CswNbtResources.Permit.can(CswEnumNbtActionName.Edit_View) &&
                    (null == View || (false == View.IsSystem || CswNbtObjClassUser.ChemSWAdminUsername == _CswNbtResources.CurrentNbtUser.Username)))
                {
                    MoreObj["Edit View"]           = new JObject();
                    MoreObj["Edit View"]["action"] = CswEnumNbtMainMenuActions.editview.ToString();
                }

                if (_MenuItems.Contains("Multi-Edit") &&
                    false == ReadOnly &&
                    null != View &&
                    _CswNbtResources.Permit.can(CswEnumNbtActionName.Multi_Edit) &&
                    // Per discussion with David, for the short term eliminate the need to validate the selection of nodes across different nodetypes in Grid views.
                    // Case 21701: for Grid Properties, we need to look one level deeper
                    // Case 29032: furthermore (for Grids), we need to exclude ObjectClass relationships (which can also produce the multi-nodetype no-no
                    (View.ViewMode != CswEnumNbtViewRenderingMode.Grid ||
                     ((View.Root.ChildRelationships.Count == 1 && View.Root.ChildRelationships[0].SecondType == CswEnumNbtViewRelatedIdType.NodeTypeId) &&
                      (View.Visibility != CswEnumNbtViewVisibility.Property || (View.Root.ChildRelationships[0].ChildRelationships.Count == 1 && View.Root.ChildRelationships[0].ChildRelationships[0].SecondType == CswEnumNbtViewRelatedIdType.NodeTypeId))))
                    )
                {
                    MoreObj["Multi-Edit"]           = new JObject();
                    MoreObj["Multi-Edit"]["action"] = CswEnumNbtMainMenuActions.multiedit.ToString();
                }
                if (_MenuItems.Contains("Bulk Edit") &&
                    false == ReadOnly &&
                    null != View &&
                    _CswNbtResources.Permit.can(CswEnumNbtActionName.Bulk_Edit))
                {
                    MoreObj["Bulk Edit"]           = new JObject();
                    MoreObj["Bulk Edit"]["action"] = CswEnumNbtMainMenuActions.bulkedit.ToString();
                }

                if (MoreObj.Count > 0)
                {
                    MoreObj["haschildren"] = true;
                    Ret["More"]            = MoreObj;
                }
            } // if( _MenuItems.Contains( "More" ) )

            _CswNbtResources.logTimerResult("CswNbtWebServiceMainMenu.getMenu()", MainMenuTimer.ElapsedDurationInSecondsAsString);


            return(Ret);
        } // getMenu()
        public Collection <CswNbtViewRelationship> getViewChildRelationshipOptions(CswNbtView View, string ArbitraryId)
        {
            Collection <CswNbtViewRelationship> ret = new Collection <CswNbtViewRelationship>();

            if (View.ViewId != null)
            {
                CswNbtViewNode SelectedViewNode = View.FindViewNodeByArbitraryId(ArbitraryId);
                if (View.ViewMode != CswEnumNbtViewRenderingMode.Unknown || View.Root.ChildRelationships.Count == 0)
                {
                    if (SelectedViewNode is CswNbtViewRelationship)
                    {
                        CswNbtViewRelationship CurrentRelationship = (CswNbtViewRelationship)SelectedViewNode;
                        Int32          CurrentLevel = 0;
                        CswNbtViewNode Parent       = CurrentRelationship;
                        while (!(Parent is CswNbtViewRoot))
                        {
                            CurrentLevel++;
                            Parent = Parent.Parent;
                        }

                        // Child options are all relations to this nodetype
                        Int32 CurrentId = CurrentRelationship.SecondId;

                        Collection <CswNbtViewRelationship> Relationships = null;
                        if (CurrentRelationship.SecondType == CswEnumNbtViewRelatedIdType.PropertySetId)
                        {
                            Relationships = getPropertySetRelated(CurrentId, View, CurrentLevel);
                        }
                        else if (CurrentRelationship.SecondType == CswEnumNbtViewRelatedIdType.ObjectClassId)
                        {
                            Relationships = getObjectClassRelated(CurrentId, View, CurrentLevel);
                        }
                        else if (CurrentRelationship.SecondType == CswEnumNbtViewRelatedIdType.NodeTypeId)
                        {
                            Relationships = getNodeTypeRelated(CurrentId, View, CurrentLevel);
                        }

                        foreach (CswNbtViewRelationship R in from CswNbtViewRelationship _R in Relationships orderby _R.SecondName select _R)
                        {
                            R.Parent = CurrentRelationship;

                            string Label = String.Empty;
                            if (R.PropOwner == CswEnumNbtViewPropOwnerType.First)
                            {
                                Label = R.SecondName + " (by " + R.PropName + ")";
                            }
                            else if (R.PropOwner == CswEnumNbtViewPropOwnerType.Second)
                            {
                                Label = R.SecondName + " (by " + R.SecondName + "'s " + R.PropName + ")";
                            }
                            R.TextLabel = Label;

                            bool contains = ret.Any(existingRel => existingRel.TextLabel == R.TextLabel);    //no dupes
                            if (false == contains)
                            {
                                ret.Add(R);
                            }
                        } // foreach( CswNbtViewRelationship R in Relationships )
                    }
                }
            }
            return(ret);
        } // getViewChildOptions()
Beispiel #10
0
        } // _runTreeNodesRecursive()

        /// <summary>
        /// Generate a JObject for the tree's current node
        /// </summary>
        private JObject _treeNodeJObject(ICswNbtTree Tree)
        {
            JObject ThisNodeObj = new JObject();

            CswNbtNodeKey ThisNodeKey       = Tree.getNodeKeyForCurrentPosition();
            string        ThisNodeName      = Tree.getNodeNameForCurrentPosition();
            string        ThisNodeIcon      = "";
            string        ThisNodeKeyString = ThisNodeKey.ToString();
            string        ThisNodeId        = "";

            string ThisNodeRel                  = "";
            bool   ThisNodeLocked               = false;
            bool   ThisNodeDisabled             = false;
            CswNbtMetaDataNodeType ThisNodeType = _CswNbtResources.MetaData.getNodeType(ThisNodeKey.NodeTypeId);

            switch (ThisNodeKey.NodeSpecies)
            {
            //case NodeSpecies.More:
            //    ThisNodeId = ThisNodeKey.NodeId.ToString();
            //    ThisNodeName = NodeSpecies.More.ToString() + "...";
            //    ThisNodeIcon = "Images/icons/triangle_blueS.gif";
            //    ThisNodeRel = "nt_" + ThisNodeType.FirstVersionNodeTypeId;
            //    break;
            case CswEnumNbtNodeSpecies.Plain:
                ThisNodeId       = ThisNodeKey.NodeId.ToString();
                ThisNodeName     = Tree.getNodeNameForCurrentPosition();
                ThisNodeRel      = "nt_" + ThisNodeType.FirstVersionNodeTypeId;
                ThisNodeLocked   = Tree.getNodeLockedForCurrentPosition();
                ThisNodeDisabled = (false == Tree.getNodeIncludedForCurrentPosition());
                if (false == string.IsNullOrEmpty(ThisNodeType.IconFileName))
                {
                    ThisNodeIcon = CswNbtMetaDataObjectClass.IconPrefix16 + ThisNodeType.IconFileName;
                }
                break;

            case CswEnumNbtNodeSpecies.Group:
                ThisNodeRel = "group";
                break;
            }

            CswNbtViewNode ThisNodeViewNode = _View.FindViewNodeByUniqueId(ThisNodeKey.ViewNodeUniqueId);

            string ThisNodeState = "closed";

            if (ThisNodeKey.NodeSpecies == CswEnumNbtNodeSpecies.More ||
                _View.ViewMode == CswEnumNbtViewRenderingMode.List ||
                (Tree.IsFullyPopulated && Tree.getChildNodeCount() == 0) ||
                (ThisNodeViewNode != null && ThisNodeViewNode.GetChildrenOfType(CswEnumNbtViewNodeType.CswNbtViewRelationship).Count == 0))
            {
                ThisNodeState = "leaf";
            }

            ThisNodeObj["data"]       = ThisNodeName;
            ThisNodeObj["icon"]       = ThisNodeIcon;
            ThisNodeObj["attr"]       = new JObject();
            ThisNodeObj["attr"]["id"] = _IdPrefix + ThisNodeKeyString;   // This is the only unique string for this node in this tree
            //ThisNodeObj["attr"]["id"] = _IdPrefix + ThisNodeId;
            ThisNodeObj["attr"]["rel"]     = ThisNodeRel;
            ThisNodeObj["attr"]["state"]   = ThisNodeState;
            ThisNodeObj["attr"]["species"] = ThisNodeKey.NodeSpecies.ToString();
            ThisNodeObj["attr"]["nodeid"]  = ThisNodeId;
            ThisNodeObj["attr"]["nodekey"] = ThisNodeKeyString;
            ThisNodeObj["attr"]["locked"]  = ThisNodeLocked.ToString().ToLower();
            if (ThisNodeDisabled)
            {
                ThisNodeObj["attr"]["disabled"] = ThisNodeDisabled.ToString().ToLower();
            }
            CswNbtNodeKey ParentKey = Tree.getNodeKeyForParentOfCurrentPosition();

            if (ParentKey.NodeSpecies != CswEnumNbtNodeSpecies.Root)
            {
                ThisNodeObj["attr"]["parentkey"] = ParentKey.ToString();
            }

            //if( "leaf" != ThisNodeState && Tree.getChildNodeCount() > 0 )
            //{
            ThisNodeObj["state"]    = ThisNodeState;
            ThisNodeObj["children"] = new JArray();
            ThisNodeObj["childcnt"] = Tree.getChildNodeCount().ToString();
            //}
            return(ThisNodeObj);
        } // _treeNodeJObject()