public override async Task <IViewComponentResult> InvokeAsync(EntityFieldDefinition fieldDefinition, object value)
    {
        if (value is not IEnumerable <string> typedValue)
        {
            throw new ArgumentException($"ViewComponent parameter ${value} must be of type {nameof(IEnumerable<string>)}", nameof(value));
        }

        var metadata = fieldDefinition.Using <CrudAdminEntityFieldFeature>();

        if (!metadata.EditorProperties.TryGetValue("DataSource", out var dataSourceDefinition))
        {
            throw new ArgumentNullException("DataSource");
        }

        var dataSource = dataSourceFactory.Create(dataSourceDefinition);
        var data       = await dataSourceReader.ReadFrom(dataSource);

        return(View(new MultiSelectFieldEditorViewModel
        {
            Id = fieldDefinition.Property.Name,
            FieldName = fieldDefinition.Property.Name,
            Label = fieldDefinition.DisplayName,
            Value = typedValue,
            Options = data.Select(x => new DropDownOptionViewModel
            {
                Value = x.Key,
                Label = x.Value,
            }),
        }));
    }
    public override async Task <IViewComponentResult> InvokeAsync(EntityFieldDefinition fieldDefinition, object value)
    {
        var metadata = fieldDefinition.Using <CrudAdminEntityFieldFeature>();

        if (!metadata.EditorProperties.TryGetValue("DataSource", out var dataSourceDefinition))
        {
            throw new ArgumentNullException("DataSource");
        }

        var dataSource = dataSourceFactory.Create(dataSourceDefinition);
        var data       = await dataSourceReader.ReadFrom(dataSource);

        return(View(new DropDownFieldEditorViewModel
        {
            Id = fieldDefinition.Property.Name,
            FieldName = fieldDefinition.Property.Name,
            Label = fieldDefinition.DisplayName,
            Value = value?.ToString() ?? string.Empty,
            Options = data.Select(x => new DropDownOptionViewModel
            {
                Value = x.Key,
                Label = x.Value,
            }),
        }));
    }
    public override void OnApplyingModule(EntityDefinition entity, EntityFieldDefinition field)
    {
        var metadata = field.Using <CrudAdminEntityFieldFeature>();

        if (field.Property.Name == nameof(IEntity.Id))
        {
            metadata.DisplayInEditor = false;
            metadata.DisplayOnSearch = false;
        }
    }
Beispiel #4
0
    private TableColumnViewModel BuildColumnViewModel(EntityFieldDefinition field)
    {
        var metadata = field.Using <CrudAdminEntityFieldFeature>();

        return(new TableColumnViewModel
        {
            DisplayName = field.DisplayName,
            Key = field.Property.Name,
            DisplayTemplate = metadata.DisplayTemplate,
            Properties = metadata.DisplayProperties,
        });
    }
    public override void OnApplyingFallbackDefaults(EntityDefinition entity, EntityFieldDefinition field)
    {
        var metadata = field.Using <CrudAdminEntityFieldFeature>();

        if (string.IsNullOrWhiteSpace(metadata.EditorViewComponentName))
        {
            metadata.EditorViewComponentName = nameof(InputFieldEditor);
        }

        if (string.IsNullOrWhiteSpace(metadata.DisplayTemplate))
        {
            metadata.DisplayTemplate = field.Property.PropertyType !.Name;
        }
    }
Beispiel #6
0
 /// <inheritdoc />
 protected internal override void ApplyToEntityFieldDefinition(EntityDefinition entity, EntityFieldDefinition field)
 {
     field.Using <JsonLdFieldFeature>().ExcludeFromLinkedData = true;
 }
Beispiel #7
0
    protected override void ApplyToEntityFieldDefinition(EntityDefinition entity, EntityFieldDefinition field)
    {
        var metadata = field.Using <CrudAdminEntityFieldFeature>();

        metadata.EditorProperties[Name] = Value;
    }
Beispiel #8
0
 protected internal override void ApplyToEntityFieldDefinition(EntityDefinition entity, EntityFieldDefinition field)
 {
     field.Using <JsonLdFieldFeature>().Iri = Iri;
 }
Beispiel #9
0
    public static IHtmlContent DisplayForDefinedField <TModel, TResult>(this IHtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TResult> > expression, EntityFieldDefinition definition)
    {
        var metadata = definition.Using <CrudAdminEntityFieldFeature>();

        return(htmlHelper.DisplayFor(expression, metadata.DisplayTemplate, definition.Property.Name, metadata.DisplayProperties));
    }
Beispiel #10
0
    protected override void ApplyToEntityFieldDefinition(EntityDefinition entity, EntityFieldDefinition field)
    {
        var metadata = field.Using <CrudAdminEntityFieldFeature>();

        metadata.EditorViewComponentName = ViewComponentName;
    }