public IEnumerable <FieldResponse> GetAllForForm(string id)
        {
            var result = new List <FieldResponse>();

            foreach (var field in FieldProvider.GetAllFor(id))
            {
                if (!field.AutoGenerate)
                {
                    continue;
                }

                var control        = ControlMatcher.GetFor(field.Type, field.UIHints);
                var embeddedFormId = FormProvider.GetAll().FirstOrDefault(f => f.Type == field.Type);

                if (control == null && embeddedFormId == null)
                {
                    continue;
                }

                result.Add(new FieldResponse
                {
                    Id             = field.Id,
                    Label          = field.Label ?? Humanizer.Humanize(field.Id),
                    CamelCaseId    = CamelCaseNamingStrategy.GetPropertyName(field.Id, false),
                    Control        = control,
                    EmbeddedFormId = embeddedFormId?.Id,
                    IsSortable     = field.IsSortable,
                    Group          = field.Group,
                });
            }

            return(result);
        }
Exemple #2
0
        public IEnumerable <FieldResponse> GetAllForForm(string id)
        {
            var result = new List <FieldResponse>();

            foreach (var field in FieldProvider.GetAllFor(id))
            {
                if (!field.AutoGenerate)
                {
                    continue;
                }

                var control        = ControlMatcher.GetFor(field.Type, field.UIHints);
                var embeddedFormId = FormProvider.GetAll().FirstOrDefault(f => f.Type == field.Type);

                if (control == null && embeddedFormId == null)
                {
                    Logger.LogInformation($"Could not find control for {id} {field.Id}");
                    continue;
                }

                var label = field.Label;

                if (label == null)
                {
                    label = field.Id;
                    label = Humanizer.Humanize(field.Id);

                    if (label.EndsWith(" ids"))
                    {
                        label = label.Substring(0, label.Length - " ids".Length);
                        label = Pluralizer.Pluralize(label);
                    }
                    else if (label.EndsWith(" id"))
                    {
                        label = label.Substring(0, label.Length - " id".Length);
                    }
                }

                var singularLabel = Singularizer.Singularize(label);

                result.Add(new FieldResponse
                {
                    Id             = field.Id,
                    Label          = label,
                    SingularLabel  = singularLabel,
                    CamelCaseId    = CamelCaseNamingStrategy.GetPropertyName(field.Id, false),
                    Control        = control,
                    EmbeddedFormId = embeddedFormId?.Id,
                    IsSortable     = field.IsSortable,
                    Group          = field.Group,
                });
            }

            return(result);
        }