Ejemplo n.º 1
0
    private static IEnumerable <ToolbarResponse>?ToResponse(TranslatableElement <ToolbarElementEmbedded> transElement)
    {
        var element = transElement.Value;

        IContentConfig?config = null;

        if (element.Content != null)
        {
            config = ContentCondigDictionary.GetOrThrow(element.Content.EntityType);
            if (!config.IsAuhorized(element.Content))
            {
                return(null);
            }

            var customResponse = config.CustomResponses(element.Content);
            if (customResponse != null)
            {
                return(customResponse);
            }
        }

        var result = new ToolbarResponse
        {
            type              = element.Type,
            content           = element.Content,
            url               = element.Url,
            label             = transElement.TranslatedElement(a => a.Label !).DefaultText(null) ?? config?.DefaultLabel(element.Content !),
            iconName          = element.IconName,
            iconColor         = element.IconColor,
            autoRefreshPeriod = element.AutoRefreshPeriod,
            openInPopup       = element.OpenInPopup,
        };

        if (element.Content is Lite <ToolbarMenuEntity> )
        {
            var tme = ToolbarMenus.Value.GetOrThrow((Lite <ToolbarMenuEntity>)element.Content);
            result.elements = ToResponseList(TranslatedInstanceLogic.TranslatedMList(tme, t => t.Elements).ToList());
            if (result.elements.Count == 0)
            {
                return(null);
            }
        }

        if (element.Content is Lite <ToolbarEntity> )
        {
            var tme = Toolbars.Value.GetOrThrow((Lite <ToolbarEntity>)element.Content);
            var res = ToResponseList(TranslatedInstanceLogic.TranslatedMList(tme, t => t.Elements).ToList());
            if (res.Count == 0)
            {
                return(null);
            }

            return(res);
        }

        return(new[] { result });
    }
Ejemplo n.º 2
0
 public static ContentConfig <T> GetContentConfig <T>() where T : Entity
 {
     return((ContentConfig <T>)ContentCondigDictionary.GetOrThrow(typeof(T)));
 }