public static void GetSearchImageLink(ICswResources CswResources, CswNbtLayoutDataReturn Ret, string Req) { CswNbtResources NbtResources = (CswNbtResources)CswResources; CswPrimaryKey NodeId = CswConvert.ToPrimaryKey(Req); CswNbtNode Node = NbtResources.Nodes.GetNode(NodeId); CswNbtMetaDataNodeType NodeType = NbtResources.MetaData.getNodeType(Node.NodeTypeId); foreach (CswNbtNodePropWrapper Prop in Node.Properties) { if (CswEnumNbtFieldType.Image == Prop.getFieldTypeValue()) { Ret.Data.ImageLink = CswNbtNodePropImage.getLink(Prop.JctNodePropId, NodeId); } if (CswEnumNbtFieldType.MOL == Prop.getFieldTypeValue()) { Ret.Data.ImageLink = CswNbtNodePropMol.getLink(Prop.JctNodePropId, NodeId); } } if (string.Empty == Ret.Data.ImageLink) { if (NodeType.IconFileName != string.Empty) { Ret.Data.ImageLink = CswNbtMetaDataObjectClass.IconPrefix100 + NodeType.IconFileName; } else { Ret.Data.ImageLink = "Images/icons/300/_placeholder.gif"; } } }
/// <summary> /// Gets a collection of all images for a property /// </summary> public Collection <CswNbtBlob> GetImages(CswPrimaryKey NodeId, Int32 JctNodePropId, string Date = "") { Collection <CswNbtBlob> images = new Collection <CswNbtBlob>(); DataTable blobDataTbl = null; if (string.IsNullOrEmpty(Date)) { CswTableSelect blobDataTS = _CswNbtResources.makeCswTableSelect("NodePropImage.getFileNames", "blob_data"); blobDataTbl = blobDataTS.getTable("where jctnodepropid = " + JctNodePropId); } else //fetch blob content { CswArbitrarySelect blobDataAuditTS = GetBlobAuditSelect(_CswNbtResources, Date, JctNodePropId); blobDataTbl = blobDataAuditTS.getTable(); } foreach (DataRow row in blobDataTbl.Rows) { Int32 BlobDataId = CswConvert.ToInt32(row["blobdataid"]); CswNbtBlob img = new CswNbtBlob() { FileName = row["filename"].ToString(), ContentType = row["contenttype"].ToString(), BlobDataId = BlobDataId, BlobUrl = CswNbtNodePropImage.getLink(JctNodePropId, NodeId, BlobDataId), Caption = row["caption"].ToString() }; images.Add(img); } if (images.Count == 0) //add default placeholder { CswNbtBlob placeHolderImg = new CswNbtBlob() { FileName = "empty.jpg", ContentType = "image/gif", BlobDataId = Int32.MinValue, BlobUrl = CswNbtNodePropImage.getLink(JctNodePropId, NodeId) }; images.Add(placeHolderImg); } return(images); }
} // TreeToJson() private void _TreeNodeToGrid(CswNbtView View, ICswNbtTree Tree, CswExtJsGrid grid, CswExtJsGridRow gridrow) { string gridUniquePrefix = _getUniquePrefix(View); Collection <CswNbtTreeNodeProp> ChildProps = Tree.getChildNodePropsOfNode(); foreach (CswNbtTreeNodeProp Prop in ChildProps) { // Potential bug here! // If the view defines the property by objectclass propname, but the nodetype propname differs, this might break CswExtJsGridDataIndex dataIndex = new CswExtJsGridDataIndex(gridUniquePrefix, Prop.PropName); bool IsHidden = Prop.Hidden; bool IsLocked = Tree.getNodeLockedForCurrentPosition(); string newValue = string.Empty; if (false == IsHidden) { CswPrimaryKey NodeId = Tree.getNodeIdForCurrentPosition(); CswNbtMetaDataNodeTypeProp MetaDataProp = _CswNbtResources.MetaData.getNodeTypeProp(Prop.NodeTypePropId); string oldValue = Prop.Gestalt; if (string.IsNullOrEmpty(oldValue)) { oldValue = null; } switch (Prop.FieldType) { case CswEnumNbtFieldType.Button: if (false == IsLocked) { CswNbtFieldTypeRuleButton buttonFTR = (CswNbtFieldTypeRuleButton)MetaDataProp.getFieldTypeRule(); grid.rowData.btns.Add(new CswExtJsGridButton { DataIndex = dataIndex.ToString(), RowNo = gridrow.RowNo, MenuOptions = Prop[buttonFTR.MenuOptionsSubField.Column], SelectedText = oldValue ?? Prop.PropName, PropAttr = new CswPropIdAttr(NodeId, Prop.NodeTypePropId).ToString(), Mode = String.IsNullOrEmpty(MetaDataProp.DesignNode.getAttributeValueByColumn(CswEnumNbtPropertyAttributeColumn.Extended)) ? "button" : MetaDataProp.DesignNode.getAttributeValueByColumn(CswEnumNbtPropertyAttributeColumn.Extended) }); } break; case CswEnumNbtFieldType.File: string LinkUrl = CswNbtNodePropBlob.getLink(Prop.JctNodePropId, NodeId); if (false == string.IsNullOrEmpty(LinkUrl) && false == string.IsNullOrEmpty(oldValue)) { newValue = "<a target=\"blank\" href=\"" + LinkUrl + "\">" + (oldValue) + "</a>"; } break; case CswEnumNbtFieldType.Image: string ImageUrl = CswNbtNodePropImage.getLink(Prop.JctNodePropId, NodeId); if (false == string.IsNullOrEmpty(ImageUrl)) { newValue = "<a target=\"blank\" href=\"" + ImageUrl + "\">" + (oldValue ?? "Image") + "</a>"; } break; case CswEnumNbtFieldType.Link: //string Href = CswNbtNodePropLink.GetFullURL( MetaDataProp.Attribute1, Prop.Field1_Big, MetaDataProp.Attribute2 ); string Href = CswNbtNodePropLink.GetFullURL(MetaDataProp.DesignNode.getAttributeValueByColumn(CswEnumNbtPropertyAttributeColumn.Attribute1), Prop.Field1_Big, MetaDataProp.DesignNode.getAttributeValueByColumn(CswEnumNbtPropertyAttributeColumn.Attribute2)); if (false == string.IsNullOrEmpty(Href)) { newValue = "<a target=\"blank\" href=\"" + Href + "\">" + (oldValue ?? "Link") + "</a>"; } break; case CswEnumNbtFieldType.Logical: newValue = CswConvert.ToDisplayString(CswConvert.ToTristate(oldValue)); break; case CswEnumNbtFieldType.MOL: string molUrl = CswNbtNodePropMol.getLink(Prop.JctNodePropId, NodeId); if (false == string.IsNullOrEmpty(molUrl)) { newValue = "<a target=\"blank\" href=\"" + molUrl + "\">" + "Structure.jpg" + "</a>"; } break; default: newValue = oldValue; break; } } gridrow.data[dataIndex] = newValue; } // foreach( JObject Prop in ChildProps ) // Recurse, but add properties of child nodes to the same gridrow for (Int32 c = 0; c < Tree.getChildNodeCount(); c++) { Tree.goToNthChild(c); _TreeNodeToGrid(View, Tree, grid, gridrow); Tree.goToParentNode(); } } // _TreeNodeToGrid()
private Int32 _populateDictionary( ICswNbtTree Tree, Collection<Int32> PropsToHide, Int32 Page = 0, Int32 PageLimit = 0 ) { Int32 results = 0; for( Int32 c = Math.Max( 0, ( Page - 1 ) * PageLimit ); ( c < Tree.getChildNodeCount() && ( PageLimit < 1 || results < PageLimit ) ); c++ ) { Tree.goToNthChild( c ); TableNode thisNode = new TableNode(); thisNode.NodeKey = Tree.getNodeKeyForCurrentPosition(); // Note on FilterToNodeTypeId: // It would be better to filter inside the view, // but it's also much more work, and I'm not even sure this feature will be used. if( null != thisNode.NodeKey && ( Int32.MinValue == _FilterToNodeTypeId || _FilterToNodeTypeId == thisNode.NodeKey.NodeTypeId ) ) { thisNode.NodeType = _CswNbtResources.MetaData.getNodeType( thisNode.NodeKey.NodeTypeId ); if( null != thisNode.NodeType ) { thisNode.NodeId = Tree.getNodeIdForCurrentPosition(); thisNode.NodeName = Tree.getNodeNameForCurrentPosition(); thisNode.Locked = Tree.getNodeLockedForCurrentPosition(); thisNode.Disabled = ( false == Tree.getNodeIncludedForCurrentPosition() ); thisNode.IsFavorite = Tree.getNodeFavoritedForCurrentPosition(); thisNode.ThumbnailUrl = _getThumbnailUrl( Tree.getNodeIconForCurrentPosition() ); thisNode.AllowView = _CswNbtResources.Permit.canAnyTab( Security.CswEnumNbtNodeTypePermission.View, thisNode.NodeType ); thisNode.AllowEdit = _CswNbtResources.Permit.canAnyTab( Security.CswEnumNbtNodeTypePermission.Edit, thisNode.NodeType ); thisNode.AllowDelete = _CswNbtResources.Permit.canNodeType( Security.CswEnumNbtNodeTypePermission.Delete, thisNode.NodeType ); // Properties SortedSet<CswNbtSearchPropOrder.SearchOrder> orderDict = _CswNbtSearchPropOrder.getPropOrderDict( thisNode.NodeKey, _View ); foreach( CswNbtTreeNodeProp PropElm in Tree.getChildNodePropsOfNode() ) { TableProp thisProp = new TableProp(); if( false == PropElm.Hidden ) { thisProp.NodeTypePropId = PropElm.NodeTypePropId; thisProp.ObjectClassPropId = PropElm.ObjectClassPropId; if( PropsToHide == null || false == PropsToHide.Contains( thisProp.NodeTypePropId ) ) { thisProp.PropId = new CswPropIdAttr( thisNode.NodeId, thisProp.NodeTypePropId ); thisProp.FieldType = PropElm.FieldType; thisProp.PropName = PropElm.PropName; thisProp.Gestalt = _Truncate( PropElm.Gestalt ); thisProp.JctNodePropId = PropElm.JctNodePropId; // Special case: Image becomes thumbnail if( thisProp.FieldType == CswEnumNbtFieldType.Image ) { thisNode.ThumbnailUrl = CswNbtNodePropImage.getLink( thisProp.JctNodePropId, thisNode.NodeId ); } if( thisProp.FieldType == CswEnumNbtFieldType.MOL ) { thisNode.ThumbnailUrl = CswNbtNodePropMol.getLink( thisProp.JctNodePropId, thisNode.NodeId ); } else { CswNbtSearchPropOrder.SearchOrder thisOrder = orderDict.FirstOrDefault( Order => Order.NodeTypePropId == thisProp.NodeTypePropId || ( thisProp.ObjectClassPropId != Int32.MinValue && Order.ObjectClassPropId == thisProp.ObjectClassPropId ) ); if( null != thisOrder ) { thisProp.Source = thisOrder.Source; if( thisProp.FieldType == CswEnumNbtFieldType.Button ) { // Include full info for rendering the button // This was done in such a way as to prevent instancing the CswNbtNode object, // which we don't need for Buttons. CswNbtMetaDataNodeTypeProp NodeTypeProp = _CswNbtResources.MetaData.getNodeTypeProp( thisProp.NodeTypePropId ); CswNbtWebServiceTabsAndProps ws = new CswNbtWebServiceTabsAndProps( _CswNbtResources, _CswNbtStatisticsEvents ); Int32 TabId = Int32.MaxValue; if( null != NodeTypeProp.FirstEditLayout ) { TabId = NodeTypeProp.FirstEditLayout.TabId; } JProperty JpPropData = ws.makePropJson( thisNode.NodeId, TabId, NodeTypeProp, null, Int32.MinValue, Int32.MinValue, string.Empty, thisNode.Locked ); thisProp.PropData = (JObject) JpPropData.Value; JObject PropValues = new JObject(); CswNbtNodePropButton.AsJSON( NodeTypeProp, PropValues, PropElm.Field2, PropElm.Field1 ); thisProp.PropData["values"] = PropValues; } if( false == thisNode.Props.ContainsKey( thisOrder.Order ) && false == thisNode.Props.ContainsValue( thisProp ) ) { thisNode.Props.Add( thisOrder.Order, thisProp ); } else { throw new CswDniException( CswEnumErrorType.Error, "A search result with the same value and position already exists in the result set.", "{" + thisNode.NodeType.NodeTypeName + "} entity {" + thisNode.NodeName + "}, Id: {" + thisNode.NodeId + ", has a duplicate {" + thisProp.FieldType + "} property record for {" + thisProp.PropName + "} PropId: {" + thisProp.NodeTypePropId + "}" ); } } } } // if( false == PropsToHide.Contains( NodeTypePropId ) ) } //if (false == CswConvert.ToBoolean(PropElm["hidden"])) } // foreach( XElement PropElm in NodeElm.Elements() ) if( false == _TableDict.ContainsKey( thisNode.NodeType ) ) { _TableDict.Add( thisNode.NodeType, new Collection<TableNode>() ); } _TableDict[thisNode.NodeType].Add( thisNode ); results++; } // if( thisNode.NodeType != null ) } // if(null != thisNode.NodeKey && ( Int32.MinValue == _FilterToNodeTypeId || _FilterToNodeTypeId == thisNode.NodeKey.NodeTypeId ) ) Tree.goToParentNode(); } // for( Int32 c = 0; c < Tree.getChildNodeCount(); c++ ) return results; } // _populateDictionary()