private dynamic ContentTypeForJson(IContentType t, ICache cache) { var metadata = GetMetadata(t, cache); var nameOverride = metadata?.GetBestValue(Constants.ContentTypeMetadataLabel).ToString(); if (string.IsNullOrEmpty(nameOverride)) nameOverride = t.Name; var ser = new Serializer(); var jsonReady = new { Id = t.AttributeSetId, t.Name, Label = nameOverride, t.StaticName, t.Scope, t.Description, UsesSharedDef = t.UsesConfigurationOfAttributeSet != null, SharedDefId = t.UsesConfigurationOfAttributeSet, Items = cache.LightList.Count(i => i.Type == t), Fields = ((ContentType)t).AttributeDefinitions.Count, Metadata = ser.Prepare(metadata) }; return jsonReady; }
public IEnumerable<dynamic> GetFields(int appId, string staticName) { SetAppIdAndUser(appId); var fields = CurrentContext.ContentType.GetContentTypeConfiguration(staticName) .OrderBy(ct => ((AttributeBase)ct.Item1).SortOrder); var appDef = new BetaFullApi(null, appId, CurrentContext); var appInputTypes = appDef.GetInputTypes(true).ToList(); var noTitleCount = 0; string fldName = ""; // assemble a list of all input-types (like "string-default", "string-wysiwyg..." Dictionary<string, IEntity> inputTypesDic; try { inputTypesDic = appInputTypes.ToDictionary( a => (fldName = a.GetBestValue("EntityTitle")?.ToString() ?? "error-no-title" + noTitleCount++), a => a); } catch (Exception ex) { throw new Exception("Error on " + fldName + "; note: noTitleCount " + noTitleCount, ex); } var ser = new Serializer(); return fields.Select(a => { var inputtype = findInputType(a.Item2); return new { Id = a.Item1.AttributeId, ((AttributeBase)a.Item1).SortOrder, a.Item1.Type, InputType = inputtype, StaticName = a.Item1.Name, a.Item1.IsTitle, a.Item1.AttributeId, Metadata = a.Item2.ToDictionary(e => e.Key, e => ser.Prepare(e.Value)), InputTypeConfig = inputTypesDic.ContainsKey(inputtype) ? ser.Prepare(inputTypesDic[inputtype]) : null }; }); }
// 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)) }); }