private SearchDocument FromData(IData data, CultureInfo culture) { using (new DataScope(culture)) { string label = data.GetLabel(); if (string.IsNullOrEmpty(label)) { // Having a label is a requirement for a data item to be searchable return(null); } var docBuilder = new SearchDocumentBuilder(); docBuilder.SetDataType(_interfaceType); string documentId = GetDocumentId(data); if (InternalUrls.DataTypeSupported(_interfaceType) && (!_isPublishable || data.DataSourceId.PublicationScope == PublicationScope.Published)) { docBuilder.Url = InternalUrls.TryBuildInternalUrl(data.ToDataReference()); } docBuilder.CrawlData(data); var entityToken = GetConsoleEntityToken(data); if (entityToken == null) { Log.LogWarning(LogTitle, $"Failed to obtain an entity token for a data item of type '{data.DataSourceId.InterfaceType}'"); return(null); } return(docBuilder.BuildDocument(Name, documentId, label, null, entityToken)); } }
private Element CreateElement(IData data) { string label = data.GetLabel(); var element = new Element(_elementProviderContext.CreateElementHandle(data.GetDataEntityToken())) { VisualData = new ElementVisualizedData { Label = label, ToolTip = label, HasChildren = false, Icon = data is IPublishControlled publishedControlled ? DataIconLookup[publishedControlled.PublicationStatus] : DataIconFacade.DataPublishedIcon } }; AddEditAssociatedDataAction(element); AddDeleteAssociatedDataAction(element); AddDuplicateAssociatedDataAction(element); if (InternalUrls.DataTypeSupported(data.DataSourceId.InterfaceType)) { var dataReference = data.ToDataReference(); if (DataUrls.CanBuildUrlForData(dataReference)) { string internalUrl = InternalUrls.TryBuildInternalUrl(dataReference); if (internalUrl != null) { element.PropertyBag.Add("Uri", internalUrl); } } } return(element); }
private Element BuildElement(IData data, DynamicValuesHelperReplaceContext replaceContext, TreeNodeDynamicContext dynamicContext, bool localizationEnabled, List <object> itemKeys, ref IEnumerable <object> keysJoinedByParentFilters, EntityToken parentEntityToken ) { replaceContext.CurrentDataItem = data; object keyValue = this.KeyPropertyInfo.GetValue(data, null); bool itemLocalizationEnabledAndForeign = localizationEnabled && !data.DataSourceId.LocaleScope.Equals(UserSettings.ActiveLocaleCultureInfo); if (itemLocalizationEnabledAndForeign && itemKeys.Contains(keyValue)) { return(null); } var currentEntityToken = data.GetDataEntityToken(); var element = new Element(new ElementHandle ( dynamicContext.ElementProviderName, currentEntityToken, dynamicContext.Piggybag.PreparePiggybag(this.ParentNode, parentEntityToken) )); bool hasChildren; bool isDisabled = false; ResourceHandle icon, openedIcon; if (itemLocalizationEnabledAndForeign) { hasChildren = false; isDisabled = !data.IsTranslatable(); if (this.Icon != null) { icon = this.Icon; openedIcon = this.OpenedIcon; } else { icon = data.GetForeignIcon(); openedIcon = icon; } } else { if (this.Display != LeafDisplayMode.Auto) { hasChildren = ChildNodes.Any(); } else { hasChildren = ChildNodes.OfType <SimpleElementTreeNode>().Any(); if (!hasChildren) { if (keysJoinedByParentFilters != null) { keysJoinedByParentFilters = keysJoinedByParentFilters.Evaluate(); hasChildren = keysJoinedByParentFilters.Contains(keyValue); } } // Checking children filtered by FunctionFilters if (!hasChildren) { foreach (var childNode in this.ChildNodes.OfType <DataElementsTreeNode>() .Where(n => n.FilterNodes.OfType <FunctionFilterNode>().Any())) { var newDynamicContext = new TreeNodeDynamicContext(TreeNodeDynamicContextDirection.Down) { ElementProviderName = dynamicContext.ElementProviderName, Piggybag = dynamicContext.Piggybag.PreparePiggybag(this.ParentNode, parentEntityToken), CurrentEntityToken = currentEntityToken }; if (childNode.GetDataset(newDynamicContext, false).DataItems.Any()) { hasChildren = true; break; } } } } if (this.Icon != null) { icon = this.Icon; openedIcon = this.OpenedIcon; } else { openedIcon = icon = data.GetIcon(); } } string label = this.Label.IsNullOrEmpty() ? data.GetLabel() : this.LabelDynamicValuesHelper.ReplaceValues(replaceContext); string toolTip = this.ToolTip.IsNullOrEmpty() ? label : this.ToolTipDynamicValuesHelper.ReplaceValues(replaceContext); if (itemLocalizationEnabledAndForeign) { label = string.Format("{0} ({1})", label, DataLocalizationFacade.GetCultureTitle(UserSettings.ForeignLocaleCultureInfo)); if (!data.IsTranslatable()) { toolTip = StringResourceSystemFacade.GetString("Composite.C1Console.Trees", "LocalizeDataWorkflow.DisabledData"); } else { toolTip = string.Format("{0} ({1})", toolTip, DataLocalizationFacade.GetCultureTitle(UserSettings.ForeignLocaleCultureInfo)); } } element.VisualData = new ElementVisualizedData { Label = label, ToolTip = toolTip, HasChildren = hasChildren, Icon = icon, OpenedIcon = openedIcon, IsDisabled = isDisabled }; if (InternalUrls.DataTypeSupported(data.DataSourceId.InterfaceType)) { var dataReference = data.ToDataReference(); if (DataUrls.CanBuildUrlForData(dataReference)) { string internalUrl = InternalUrls.TryBuildInternalUrl(dataReference); if (internalUrl != null) { element.PropertyBag.Add("Uri", internalUrl); } } } if (itemLocalizationEnabledAndForeign) { var actionToken = new WorkflowActionToken( WorkflowFacade.GetWorkflowType("Composite.C1Console.Trees.Workflows.LocalizeDataWorkflow"), LocalizeDataPermissionTypes); element.AddAction(new ElementAction(new ActionHandle(actionToken)) { VisualData = new ActionVisualizedData { Label = StringResourceSystemFacade.GetString("Composite.C1Console.Trees", "LocalizeDataWorkflow.LocalizeDataLabel"), ToolTip = StringResourceSystemFacade.GetString("Composite.C1Console.Trees", "LocalizeDataWorkflow.LocalizeDataToolTip"), Icon = LocalizeDataTypeIcon, Disabled = false, ActionLocation = ActionLocation.OtherPrimaryActionLocation } }); } return(element); }
private static IEnumerable <SearchResultEntry> SearchInType <T>(string[] keywords, bool currentWebsiteOnly) where T : class, IData { var stringFields = typeof(T).GetPropertiesRecursively() .Where(p => p.PropertyType == typeof(string) && p.ReflectedType != typeof(IPublishControlled) && p.ReflectedType != typeof(ILocalizedControlled) && p.ReflectedType != typeof(IPageMetaData) && !p.GetCustomAttributes <ForeignKeyAttribute>().Any()).ToList(); if (stringFields.Count == 0) { return(null); } Expression searchExpr = null; var parameter = Expression.Parameter(typeof(T), "p"); foreach (string keyword in keywords) { Expression keywordSearchExpr = null; foreach (var stringField in stringFields) { // Building the following expression: // p => (p.{stringField} != null && p.{stringField}.ToLower().Contains(keyword)) var propertyExpression = Expression.Property(parameter, stringField); var notNullExpression = Expression.NotEqual(propertyExpression, Expression.Constant(null, typeof(string))); var toLowerExpression = Expression.Call(propertyExpression, String_ToLower); var containsExpression = Expression.Call(toLowerExpression, String_Contains, new Expression[] { Expression.Constant(keyword) }); var andExpression = Expression.AndAlso(notNullExpression, containsExpression); keywordSearchExpr = keywordSearchExpr.OrElse(andExpression); } searchExpr = searchExpr.AndAlso(keywordSearchExpr); } if (searchExpr == null) { return(null); } var searchPredicate = Expression.Lambda <Func <T, bool> >(searchExpr, parameter); HashSet <Guid> pagesIdsOfCurrentSite = null; if (currentWebsiteOnly) { using (var c = new DataConnection()) { pagesIdsOfCurrentSite = new HashSet <Guid>(c.SitemapNavigator.CurrentPageNode .GetPageIds(SitemapScope.Level1AndDescendants)); } } var result = new List <SearchResultEntry>(); foreach (var data in DataFacade.GetData(searchPredicate)) { if (currentWebsiteOnly && data is IPageRelatedData && !pagesIdsOfCurrentSite.Contains((data as IPageRelatedData).PageId)) { continue; } var dataReference = data.ToDataReference(); string url; if (currentWebsiteOnly && !(data is IPageRelatedData)) { // Getting public url data to see if it is pointing to the website var pageUrlData = DataUrls.TryGetPageUrlData(dataReference); if (pageUrlData == null || !pagesIdsOfCurrentSite.Contains(pageUrlData.PageId)) { continue; } url = PageUrls.BuildUrl(pageUrlData); } else { url = InternalUrls.TryBuildInternalUrl(dataReference); } if (url == null) { continue; } string label = data.GetLabel(); // TODO: support for current website only for global data types result.Add(new SearchResultEntry { Url = url, Title = label }); } return(result); }