示例#1
0
        // todo: check if this call could be replaced with the normal ContentTypeController.Get to prevent redundant code
        public IEnumerable <object> GetContentTypesWithStatus()
        {
            // 2016-09-08 2dm - changed to use all templates, because of https://github.com/2sic/2sxc/issues/831
            var availableTemplates = GetAllTemplates().ToList();// GetVisibleTemplates();
            var visTemplates       = availableTemplates.Where(t => !t.IsHidden).ToList();
            var mdCache            = TemplateDataSource().Cache;
            var ctc = new ContentTypeController();
            var ser = new Serializer();

            return(GetAvailableContentTypes(Settings.AttributeSetScope)
                   .Where(p => availableTemplates.Any(t => t.ContentTypeStaticName == p.StaticName)) // must exist in at least 1 template
                   .OrderBy(p => p.Name)
                   .Select(p => new
            {
                p.StaticName,
                p.Name,
                IsHidden = !(visTemplates.Any(t => t.ContentTypeStaticName == p.StaticName)),     // must check if *any* template is visible, otherise tell the UI that it's hidden
                Metadata = ser.Prepare(ctc.GetMetadata(p, mdCache))
            }));
        }
示例#2
0
        // todo: check if this call could be replaced with the normal ContentTypeController.Get to prevent redundant code
        public IEnumerable <ContentTypeUiInfo> GetContentTypesWithStatus()
        {
            var templates  = GetAllTemplates().ToList();
            var visible    = templates.Where(t => !t.IsHidden).ToList();
            var mdCache    = TemplateDataSource().Cache;
            var ctc        = new ContentTypeController();
            var serializer = new Serializer();

            return(new AppRuntime(ZoneId, AppId).ContentTypes.FromScope(Settings.AttributeSetScope)
                   .Where(ct => templates.Any(t => t.ContentTypeStaticName == ct.StaticName)) // must exist in at least 1 template
                   .OrderBy(ct => ct.Name)
                   .Select(ct =>
            {
                var metadata = ctc.GetMetadata((ContentType)ct, mdCache);
                return new ContentTypeUiInfo {
                    StaticName = ct.StaticName,
                    Name = ct.Name,
                    IsHidden = visible.All(t => t.ContentTypeStaticName != ct.StaticName),       // must check if *any* template is visible, otherise tell the UI that it's hidden
                    Thumbnail = metadata?.GetBestValue(AppConstants.TemplateIcon, true)?.ToString(),
                    Metadata = serializer.Prepare(metadata)
                };
            }));
        }