Ejemplo n.º 1
0
 protected void _addViewNodeViews(CswNbtView View)
 {
     CswNbtViewRoot.forEachProperty eachProperty = property =>
     {
         property.SetViewRootView(View);
         foreach (CswNbtViewPropertyFilter filter in property.Filters)
         {
             filter.Parent = property;
             filter.SetViewRootView(View);
         }
     };
     CswNbtViewRoot.forEachRelationship eachRelationship = relationship =>
     {
         if (null == relationship.Parent)
         {
             relationship.Parent = View.Root;
         }
         relationship.SetViewRootView(View);
         foreach (CswNbtViewRelationship childRel in relationship.ChildRelationships)
         {
             if (null == childRel.Parent)
             {
                 childRel.Parent = relationship;
             }
         }
         foreach (CswNbtViewProperty viewProp in relationship.Properties)
         {
             if (null == viewProp.Parent)
             {
                 viewProp.Parent = relationship;
             }
         }
     };
     View.Root.eachRelationship(eachRelationship, eachProperty);
 }
        private void _getFilters(CswNbtViewEditorData Return, CswNbtView View)
        {
            HashSet <string> seenFilters = new HashSet <string>();

            CswNbtViewRoot.forEachProperty eachProp = property =>
            {
                foreach (CswNbtViewPropertyFilter filter in property.Filters)
                {
                    string parentName = _getRelationshipOwnerName((CswNbtViewRelationship)property.Parent);
                    string fullLabel  = parentName + " " + property.TextLabel + " " + filter.TextLabel;
                    if (false == seenFilters.Contains(fullLabel))
                    {
                        Return.Step4.Filters.Add(filter);
                        seenFilters.Add(fullLabel);
                    }
                }
            };
            View.Root.eachRelationship(null, eachProp);
        }
Ejemplo n.º 3
0
        }//searchLocations()

        private CswNbtView _getLocationsView(string ViewId, string FullPathFilter = "")
        {
            CswNbtView Ret = new CswNbtView();

            if (string.IsNullOrEmpty(ViewId))
            {
                Ret = CswNbtNodePropLocation.LocationPropertyView(_CswNbtResources, null, ResultMode: CswEnumNbtFilterResultMode.Disabled, FullPathFilter: FullPathFilter);
                Ret.SaveToCache(false);
                ViewId = Ret.SessionViewId.ToString();
            }

            CswNbtSessionDataId SessionViewId = new CswNbtSessionDataId(ViewId);

            if (SessionViewId.isSet())
            {
                Ret = _CswNbtResources.ViewSelect.getSessionView(SessionViewId);
                CswNbtMetaDataObjectClass     LocationOC          = _CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.LocationClass);
                CswNbtMetaDataObjectClassProp LocationFullPathOCP = LocationOC.getObjectClassProp(CswNbtObjClassLocation.PropertyName.FullPath);
                if (false == string.IsNullOrEmpty(FullPathFilter))
                {
                    CswNbtViewRoot.forEachProperty forEachPropDelegate = delegate(CswNbtViewProperty ViewProp)
                    {
                        if (ViewProp.ObjectClassPropId == LocationFullPathOCP.PropId)
                        {
                            Ret.AddViewPropertyFilter(ViewProp,
                                                      Conjunction: CswEnumNbtFilterConjunction.And,
                                                      FilterMode: CswEnumNbtFilterMode.Contains,
                                                      SubFieldName: CswEnumNbtSubFieldName.Value,
                                                      Value: FullPathFilter);
                        }
                    };
                    Ret.Root.eachRelationship(null, forEachPropDelegate);
                }
            }

            return(Ret);
        }//_getLocationsView()
        private void _removeFilter(CswNbtViewEditorData Return)
        {
            Dictionary <string, CswNbtViewPropertyFilter> filtersToRemove = new Dictionary <string, CswNbtViewPropertyFilter>();
            Collection <ICswNbtMetaDataProp> propsToRemove = new Collection <ICswNbtMetaDataProp>();

            CswNbtViewRoot.forEachProperty eachProperty = prop =>
            {
                foreach (CswNbtViewPropertyFilter filter in prop.Filters)
                {
                    if (filter.TextLabel == Request.FilterToRemove.TextLabel)
                    {
                        if (prop.ShowInGrid || prop.Filters.Count > 1)  //if ShowInGrid == true, just remove the filter
                        {
                            filtersToRemove.Add(prop.UniqueId, filter);
                        }
                        else //otherwise, remove the property as well
                        {
                            ICswNbtMetaDataProp propToRemove;
                            if (prop.Type.Equals(CswEnumNbtViewPropType.ObjectClassPropId))
                            {
                                propToRemove = _CswNbtResources.MetaData.getObjectClassProp(prop.ObjectClassPropId);
                            }
                            else
                            {
                                propToRemove = _CswNbtResources.MetaData.getNodeTypeProp(prop.NodeTypePropId);
                            }

                            if (null != propToRemove)
                            {
                                propsToRemove.Add(propToRemove);
                            }
                        }
                    }
                }
            };
            CurrentView.Root.eachRelationship(null, eachProperty);

            foreach (var propAndFilter in filtersToRemove)
            {
                CswNbtViewProperty prop = (CswNbtViewProperty)CurrentView.FindViewNodeByUniqueId(propAndFilter.Key);
                prop.removeFilter(propAndFilter.Value);
            }
            foreach (ICswNbtMetaDataProp propToRemove in propsToRemove)
            {
                CurrentView.removeViewProperty(propToRemove);
            }

            _getFilters(Return, CurrentView);

            HashSet <string> seenRels = new HashSet <string>();

            CswNbtViewRoot.forEachRelationship eachRelationship = relationship =>
            {
                if (false == seenRels.Contains(relationship.TextLabel))
                {
                    seenRels.Add(relationship.TextLabel);
                    Return.Step4.Relationships.Add(relationship);
                }
            };
            CurrentView.Root.eachRelationship(eachRelationship, null);

            Return.Step4.ViewJson = CswConvert.ToString(CurrentView.ToJson());
        }
Ejemplo n.º 5
0
        } // _treeNodeJObject()

        public void runTree(Contract.Response.ResponseData ResponseData, Contract.Request Request, Int32 PerLevelNodeLimit = Int32.MinValue, Int32 TotalNodeLimit = Int32.MinValue)
        {
            ResponseData.Tree = ResponseData.Tree ?? new Collection <CswExtTree.TreeNode>();
            ICswNbtTree Tree     = null;
            string      RootName = string.Empty;

            if (null != _View)
            {
                Tree = _CswNbtResources.Trees.getTreeFromView(_View, Request.RequireViewPermissions, false, false, PerLevelNodeLimit: PerLevelNodeLimit);
                _View.SaveToCache(Request.IncludeInQuickLaunch);
                RootName = _View.ViewName;
            }

            CswPrimaryKey IncludeNodeId     = null;
            CswNbtNodeKey SelectKey         = null;
            Int32         IncludeNodeTypeId = Int32.MinValue;

            if (null != Request.IncludeNodeKey)
            {
                IncludeNodeId     = Request.IncludeNodeKey.NodeId;
                IncludeNodeTypeId = Request.IncludeNodeKey.NodeTypeId;
                if (null != Tree)
                {
                    Tree.makeNodeCurrent(Request.IncludeNodeKey);
                    if (Tree.isCurrentNodeDefined())
                    {
                        SelectKey = Request.IncludeNodeKey;
                    }
                }
            }
            else if (CswTools.IsPrimaryKey(Request.IncludeNodeId))
            {
                IncludeNodeId = Request.IncludeNodeId;
                CswNbtNode IncludeNode = _CswNbtResources.Nodes[IncludeNodeId];
                if (null != IncludeNode)
                {
                    IncludeNodeTypeId = IncludeNode.NodeTypeId;
                }
                if (null != Tree)
                {
                    SelectKey = Tree.getNodeKeyByNodeId(IncludeNodeId);
                }
            }

            if ((CswTools.IsPrimaryKey(IncludeNodeId) && IncludeNodeTypeId != Int32.MinValue) &&
                (Tree == null ||
                 (Request.IncludeNodeRequired && SelectKey == null)))
            {
                CswNbtMetaDataNodeType IncludeNodeType = _CswNbtResources.MetaData.getNodeType(IncludeNodeTypeId);
                if (null != IncludeNodeType)
                {
                    _View          = IncludeNodeType.CreateDefaultView(false);
                    _View.ViewName = IncludeNodeType.NodeTypeName;
                    _View.Root.ChildRelationships[0].NodeIdsToFilterIn.Add(IncludeNodeId);
                    _View.SaveToCache(Request.IncludeInQuickLaunch);   // case 22713
                    RootName = _View.ViewName;

                    Tree = _CswNbtResources.Trees.getTreeFromView(_View, false, false, false);
                }
            }

            bool HasResults = false;

            if (null != Tree)
            {
                Tree.goToRoot();
                HasResults = (Tree.getChildNodeCount() > 0);
                //ReturnObj["result"] = HasResults.ToString().ToLower();
                //ReturnObj["types"] = getTypes();
                ResponseData.PageSize = _CswNbtResources.CurrentNbtUser.PageSize;

                ResponseData.SelectedNodeKey = null;
                if (HasResults)
                {
                    // Determine the default selected node:
                    // If the requested node to select is on the tree, return it.
                    // If the requested node to select is not on the tree, return the first child of the root.
                    if (SelectKey != null)
                    {
                        Tree.makeNodeCurrent(SelectKey);
                        if (Tree.isCurrentNodeDefined())
                        {
                            ResponseData.SelectedNodeKey = SelectKey;
                        }
                    }
                    if (ResponseData.SelectedNodeKey == null)
                    {
                        switch (Request.DefaultSelect)
                        {
                        case "none":
                            break;

                        case "root":
                            break;

                        case "firstchild":
                            Tree.goToRoot();
                            CswNbtNodeKey CurrentKey = Tree.getNodeKeyForCurrentPosition();
                            while (CurrentKey != null &&
                                   CurrentKey.NodeSpecies != CswEnumNbtNodeSpecies.Plain &&
                                   Tree.getChildNodeCount() > 0)
                            {
                                Tree.goToNthChild(0);
                                CurrentKey = Tree.getNodeKeyForCurrentPosition();
                            }
                            if (CurrentKey != null && CurrentKey.NodeSpecies == CswEnumNbtNodeSpecies.Plain)
                            {
                                ResponseData.SelectedNodeKey = CurrentKey;
                            }
                            break;
                        } // switch( DefaultSelect )
                    }     // if( ReturnObj["selectid"] == null )
                }         // if( HasResults )
                else
                {
                    Request.DefaultSelect = "root";
                }

                Tree.goToRoot();
            }
            //Build the Response:

            ResponseData.Name = RootName;

            //#1: the Root node
            CswExtTree.TreeNode RootNode = new CswExtTree.TreeNode();
            ResponseData.Tree.Add(RootNode);

            RootNode.Name     = RootName;
            RootNode.IsRoot   = true;
            RootNode.Expanded = true;
            RootNode.Path     = "|root";
            RootNode.Id       = "root";
            RootNode.Icon     = "Images/view/viewtree.gif";

            //#2: the columns for the Tree Grid
            ResponseData.Columns.Add(new CswExtJsGridColumn
            {
                dataIndex    = new CswExtJsGridDataIndex(_View.ViewName, "text"),
                xtype        = CswEnumExtJsXType.treecolumn,
                MenuDisabled = true,
                width        = 269,
                header       = "Tree",
                resizable    = false,
            });
            ResponseData.Columns.Add(new CswExtJsGridColumn
            {
                dataIndex    = new CswExtJsGridDataIndex(_View.ViewName, "nodetypeid"),
                header       = "NodeTypeId",
                hidden       = true,
                resizable    = false,
                width        = 0,
                xtype        = CswEnumExtJsXType.gridcolumn,
                MenuDisabled = false
            });
            ResponseData.Columns.Add(new CswExtJsGridColumn
            {
                dataIndex    = new CswExtJsGridDataIndex(_View.ViewName, "objectclassid"),
                header       = "ObjectClassId",
                hidden       = true,
                resizable    = false,
                width        = 0,
                xtype        = CswEnumExtJsXType.gridcolumn,
                MenuDisabled = false
            });
            ResponseData.Columns.Add(new CswExtJsGridColumn
            {
                dataIndex    = new CswExtJsGridDataIndex(_View.ViewName, "nodeid"),
                header       = "NodeId",
                hidden       = true,
                resizable    = false,
                width        = 0,
                xtype        = CswEnumExtJsXType.gridcolumn,
                MenuDisabled = false
            });
            ResponseData.Columns.Add(new CswExtJsGridColumn
            {
                dataIndex    = new CswExtJsGridDataIndex(_View.ViewName, "disabled"),
                header       = "Disabled",
                hidden       = true,
                resizable    = false,
                width        = 0,
                xtype        = CswEnumExtJsXType.booleancolumn,
                MenuDisabled = false
            });


            //#3: The fields to map the columns to the data store
            ResponseData.Fields.Add(new CswExtJsGridField {
                name = "text", type = "string"
            });
            ResponseData.Fields.Add(new CswExtJsGridField {
                name = "nodetypeid", type = "string"
            });
            ResponseData.Fields.Add(new CswExtJsGridField {
                name = "objectclassid", type = "string"
            });
            ResponseData.Fields.Add(new CswExtJsGridField {
                name = "nodeid", type = "string"
            });
            ResponseData.Fields.Add(new CswExtJsGridField {
                name = "disabled", type = "bool"
            });

            //#4: View Properties are columns now too
            Collection <string> UniqueColumnNames = new Collection <string>()
            {
                "text", "nodetypeid", "objectclassid", "nodeid", "disabled"
            };

            CswNbtViewRoot.forEachProperty AddProp = (ViewProperty) =>
            {
                string PropName = ViewProperty.Name.ToLower().Trim();
                bool   HideProp = (null != Request.PropsToShow && false == Request.PropsToShow.Contains(PropName));
                if (false == UniqueColumnNames.Contains(PropName))
                {
                    UniqueColumnNames.Add(PropName);

                    CswExtJsGridColumn Col = new CswExtJsGridColumn
                    {
                        dataIndex    = new CswExtJsGridDataIndex(_View.ViewName, PropName),
                        header       = ViewProperty.Name,
                        hidden       = HideProp,
                        resizable    = false,
                        width        = ViewProperty.Width * 7,
                        xtype        = CswEnumExtJsXType.gridcolumn,
                        MenuDisabled = false
                    };
                    CswExtJsGridField Fld = new CswExtJsGridField {
                        name = PropName, type = "string"
                    };
                    Fld.dataIndex = Col.dataIndex;

                    ResponseData.Columns.Add(Col);
                    ResponseData.Fields.Add(Fld);
                }
            };
            _View.Root.eachRelationship(relationshipCallBack: null, propertyCallBack: AddProp);


            //#5: the tree
            RootNode.Children = new Collection <CswExtTree.TreeNode>();
            if (HasResults)
            {
                Tree.goToRoot();
                int count = 0;
                _runTreeNodesRecursive(Tree, RootNode.Children, RootNode, Request, TotalNodeLimit, ref count);

                if (Int32.MinValue != TotalNodeLimit && count >= TotalNodeLimit && RootNode.Children[0].Name != "Results Truncated")
                {
                    CswExtTree.TreeNode TruncatedTreeNode = _getTreeNode(Tree, RootNode, null);
                    TruncatedTreeNode.Name   = "Results Truncated";
                    TruncatedTreeNode.IsLeaf = true;
                    TruncatedTreeNode.Icon   = "Images/icons/truncated.gif";
                    TruncatedTreeNode.Id     = TruncatedTreeNode.Id + "_truncated";
                    TruncatedTreeNode.NodeId = "";
                    RootNode.Children.Insert(0, TruncatedTreeNode);
                }
            }
            else
            {
                CswExtTree.TreeNode EmptyNode = new CswExtTree.TreeNode();
                EmptyNode.Name     = "No Results";
                EmptyNode.IsLeaf   = true;
                EmptyNode.Selected = true;
                EmptyNode.Id       = "empty";
                EmptyNode.ParentId = RootNode.Id;
                EmptyNode.Path     = RootNode.Path + "|empty";
                RootNode.Children.Add(EmptyNode);
            }
            //}
        } // runTree()
Ejemplo n.º 6
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()