Example #1
0
        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));
            }
        }
Example #2
0
        public static Tuple <string, string>[] GetSearchableDataTypeOptions()
        {
            var result = new List <Tuple <string, string> >();

            var dataTypes = DataFacade.GetAllInterfaces().Where(type =>
                                                                type.GetCustomAttributes(typeof(SearchableTypeAttribute), false).Length > 0 &&
                                                                InternalUrls.DataTypeSupported(type)).ToList();

            dataTypes.Add(typeof(IPage));
            dataTypes.Add(typeof(IMediaFile));

            foreach (var dataType in dataTypes)
            {
                var descriptor = DynamicTypeManager.GetDataTypeDescriptor(dataType);
                result.Add(new Tuple <string, string>(
                               dataType.FullName,
                               descriptor.Title ?? dataType.Name));
            }

            return(result.OrderBy(r => r.Item2).ToArray());
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }