public async Task <IResolvedSetup <ListSetup> > ResolveSetupAsync(ListConfig config, CollectionSetup?collection = default) { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } if (config is IIsConventionBased isConventionBasedConfig) { config = await _conventionListConfigResolver.ResolveByConventionAsync(config.BaseType, isConventionBasedConfig.GetFeatures(), collection); } var cacheable = true; var panes = (await _paneSetupResolver.ResolveSetupAsync(config.Panes, collection)).CheckIfCachable(ref cacheable).ToList(); var buttons = (await _buttonSetupResolver.ResolveSetupAsync(config.Buttons, collection)).CheckIfCachable(ref cacheable).ToList(); return(new ResolvedSetup <ListSetup>(new ListSetup( config.PageSize, config.SearchBarVisible, config.ReorderingAllowed, config.ListEditorType, config.EmptyVariantColumnVisibility, panes, buttons), cacheable)); }
public Task <IResolvedSetup <IEnumerable <TreeElementSetup> > > ResolveSetupAsync(IEnumerable <ITreeElementConfig> config, CollectionSetup?collection = default) { return(Task.FromResult <IResolvedSetup <IEnumerable <TreeElementSetup> > >( new ResolvedSetup <IEnumerable <TreeElementSetup> >( config.Select(corp => { var type = corp switch { IPageConfig page => PageType.Page, _ => PageType.Collection }; return new TreeElementSetup(corp.Alias, corp.Name, type) { RootVisibility = (corp as CollectionConfig)?.TreeView?.RootVisibility ?? default }; }) ?? Enumerable.Empty <TreeElementSetup>(), true))); }
public Task <NodeConfig> ResolveByConventionAsync(Type subject, Features features, CollectionSetup?collection) { var result = new NodeConfig(subject); if (features.HasFlag(Features.CanView) || features.HasFlag(Features.CanEdit)) { result.Buttons.Add(new DefaultButtonConfig { ButtonType = DefaultButtonType.Up }); result.Panes = new List <PaneConfig> { new PaneConfig(subject) { FieldIndex = 1, Fields = _fieldConfigResolver.GetFields(subject, features).ToList(), VariantType = subject } }; } if (features.HasFlag(Features.CanEdit)) { result.Buttons.AddRange(new[] { new DefaultButtonConfig { ButtonType = DefaultButtonType.SaveExisting }, new DefaultButtonConfig { ButtonType = DefaultButtonType.SaveNew }, new DefaultButtonConfig { ButtonType = DefaultButtonType.Delete } }); } if (collection?.Collections.Any() ?? false) { foreach (var subCollection in collection.Collections) { result.Panes.Add(new PaneConfig(subject) { IsVisible = (entity, state) => state == EntityState.IsExisting, SubCollectionLists = new List <CollectionListConfig> { new ReferencedCollectionListConfig(subCollection.Alias) } }); } } return(Task.FromResult(result)); }
protected async Task <UsageType> GetUsageTypeAsync(CollectionListConfig config, CollectionSetup?collection) { if (config is ReferencedCollectionListConfig referencedCollectionList) { if (referencedCollectionList.CollectionAlias == collection?.Alias) { return((collection.ListEditor != null ? UsageType.Edit : 0) | (collection.ListView != null ? UsageType.View : 0)); } else { // TODO: this can trigger infinite loops / stack overflows.. var resolver = _setupResolver.Value; var referencedCollection = await resolver.ResolveSetupAsync(referencedCollectionList.CollectionAlias); return((referencedCollection?.ListEditor != null ? UsageType.Edit : 0) | (referencedCollection?.ListView != null ? UsageType.View : 0)); } } else { return((config?.ListEditor != null ? UsageType.Edit : 0) | (config?.ListView != null ? UsageType.View : 0)); } }
public async Task <IResolvedSetup <NodeSetup> > ResolveSetupAsync(NodeConfig config, CollectionSetup?collection = default) { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } if (config is IIsConventionBased isConventionBasedConfig) { config = await _conventionNodeConfigResolver.ResolveByConventionAsync(config.BaseType, isConventionBasedConfig.GetFeatures(), collection); } var cacheable = true; var panes = (await _paneSetupResolver.ResolveSetupAsync(config.Panes, collection)).CheckIfCachable(ref cacheable).ToList(); var buttons = (await _buttonSetupResolver.ResolveSetupAsync(config.Buttons, collection)).CheckIfCachable(ref cacheable).ToList(); return(new ResolvedSetup <NodeSetup>(new NodeSetup( config.BaseType, panes, buttons), cacheable)); }
public async Task <IResolvedSetup <IEnumerable <TreeElementSetup> > > ResolveSetupAsync(IPlugin config, CollectionSetup?collection = null) { return(new ResolvedSetup <IEnumerable <TreeElementSetup> >(await config.GetTreeElementsAsync(), false)); }
public async Task <IResolvedSetup <SubCollectionListSetup> > ResolveSetupAsync(CollectionListConfig config, CollectionSetup?collection = default) { var usageType = await GetUsageTypeAsync(config, collection); return(new ResolvedSetup <SubCollectionListSetup>( new SubCollectionListSetup(config !.Index, config.CollectionAlias) { SupportsUsageType = usageType }, true));
public Task <ListConfig> ResolveByConventionAsync(Type subject, Features features, CollectionSetup?collection) { var listButtons = new List <ButtonConfig>(); if (features.HasFlag(Features.CanEdit) || features.HasFlag(Features.CanGoToEdit)) { listButtons.Add(new DefaultButtonConfig { ButtonType = DefaultButtonType.New, Label = !(collection?.SubEntityVariants?.Any() ?? false) ? null : _languageResolver.ResolveText("New {0}") }); listButtons.Add(new DefaultButtonConfig { ButtonType = DefaultButtonType.Return }); listButtons.Add(new DefaultButtonConfig { ButtonType = DefaultButtonType.SaveExisting, Label = _languageResolver.ResolveText("Update all") }); } ; var paneButtons = new List <ButtonConfig>(); if (features.HasFlag(Features.CanGoToView)) { paneButtons.Add(new DefaultButtonConfig { ButtonType = DefaultButtonType.View }); } if (features.HasFlag(Features.CanGoToEdit)) { paneButtons.Add(new DefaultButtonConfig { ButtonType = DefaultButtonType.Edit }); } if (features.HasFlag(Features.CanEdit)) { paneButtons.Add(new DefaultButtonConfig { ButtonType = DefaultButtonType.SaveExisting }); paneButtons.Add(new DefaultButtonConfig { ButtonType = DefaultButtonType.SaveNew }); paneButtons.Add(new DefaultButtonConfig { ButtonType = DefaultButtonType.Delete }); } var result = new ListConfig(subject) { PageSize = 25, Buttons = listButtons, ListEditorType = features.HasFlag(Features.IsBlockList) ? ListType.Block : ListType.Table, Panes = new List <PaneConfig> { new PaneConfig(subject) { Buttons = paneButtons, FieldIndex = 1, Fields = _fieldConfigResolver.GetFields(subject, features).ToList(), VariantType = subject } }, ReorderingAllowed = false, SearchBarVisible = true }; return(Task.FromResult(result)); }
public Task <IResolvedSetup <TypeRegistrationSetup> > ResolveSetupAsync(CustomTypeRegistrationConfig config, CollectionSetup?collection = default) { return(Task.FromResult <IResolvedSetup <TypeRegistrationSetup> >( new ResolvedSetup <TypeRegistrationSetup>( new TypeRegistrationSetup { Type = config.Type == typeof(CollectionConfig) ? typeof(CollectionSetup) : config.Type, Alias = config.Alias, Parameters = config.Parameters }, true))); }
public Task <IResolvedSetup <TreeViewSetup> > ResolveSetupAsync(TreeViewConfig config, CollectionSetup?collection = default) { return(Task.FromResult <IResolvedSetup <TreeViewSetup> >(new ResolvedSetup <TreeViewSetup>(new TreeViewSetup( config.EntityVisibilty, config.RootVisibility, config.DefaultOpenEntities, config.DefaultOpenCollections, config.Name), true))); }
public Task <IResolvedSetup <ButtonSetup> > ResolveSetupAsync(ButtonConfig config, CollectionSetup?collection = default) { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } var @default = (config as DefaultButtonConfig)?.ButtonType.GetCustomAttribute <DefaultIconLabelAttribute>(); var button = new ButtonSetup { Buttons = Enumerable.Empty <ButtonSetup>(), Label = _languageResolver.ResolveText(config.Label ?? @default?.Label ?? "Button"), Icon = config.Icon ?? @default?.Icon ?? "", IsPrimary = config.IsPrimary, IsVisible = config.IsVisible, ButtonId = config.Id ?? throw new ArgumentNullException(nameof(config.Id)), EntityVariant = collection.EntityVariant }; if (config is DefaultButtonConfig defaultButton) { if (defaultButton.ButtonType == DefaultButtonType.OpenPane) { throw new InvalidOperationException($"An {DefaultButtonType.OpenPane} button is not allowed to be used by DefaultButton"); } button.DefaultButtonType = defaultButton.ButtonType; button.ButtonHandlerType = typeof(DefaultButtonActionHandler); if (defaultButton.ButtonType == DefaultButtonType.New && collection.SubEntityVariants != null) { button.Buttons = collection.SubEntityVariants.ToList(variant => new ButtonSetup { Label = _languageResolver.ResolveText(string.Format(button.Label ?? variant.Name, variant.Name)), Icon = variant.Icon ?? @default?.Icon ?? "", IsPrimary = config.IsPrimary, ButtonId = $"{config.Id}-{variant.Alias}", EntityVariant = variant, DefaultButtonType = DefaultButtonType.New, ButtonHandlerType = typeof(DefaultButtonActionHandler), Buttons = Enumerable.Empty <ButtonSetup>() }); } } else if (config is CustomButtonConfig customButton) { button.CustomType = customButton.CustomType; button.ButtonHandlerType = customButton.ActionHandler; } else if (config is PaneButtonConfig paneButton) { button.DefaultButtonType = DefaultButtonType.OpenPane; button.ButtonHandlerType = typeof(OpenPaneButtonActionHandler <>).MakeGenericType(paneButton.PaneType); } else if (config is NavigationButtonConfig navigationButton) { button.DefaultButtonType = DefaultButtonType.Navigate; button.ButtonHandlerType = typeof(NavigateButtonActionHandler <>).MakeGenericType(navigationButton.HandlerType); } else { throw new InvalidOperationException(); } return(Task.FromResult <IResolvedSetup <ButtonSetup> >(new ResolvedSetup <ButtonSetup>(button, true))); } }
public Task <IResolvedSetup <EntityVariantSetup> > ResolveSetupAsync(EntityVariantConfig config, CollectionSetup?collection = default) { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } if (config == default) { return(Task.FromResult <IResolvedSetup <EntityVariantSetup> >(new ResolvedSetup <EntityVariantSetup>(EntityVariantSetup.Undefined, true))); } else { return(Task.FromResult <IResolvedSetup <EntityVariantSetup> >(new ResolvedSetup <EntityVariantSetup>( new EntityVariantSetup(config.Name, config.Icon, config.Type, AliasHelper.GetEntityVariantAlias(config.Type)), true))); } }
public static async Task <IResolvedSetup <IEnumerable <TSetup> > > ResolveSetupAsync <TSetup, TConfig>(this ISetupResolver <TSetup, TConfig> resolver, IEnumerable <TConfig> configs, CollectionSetup?collection = default) where TConfig : notnull { var allCachable = true; return(new ResolvedSetup <IEnumerable <TSetup> >( await configs.ToListAsync(async config => (await resolver.ResolveSetupAsync(config, collection)).CheckIfCachable(ref allCachable)), allCachable)); }
public Task <IResolvedSetup <ElementSetup> > ResolveSetupAsync(ElementConfig config, CollectionSetup?collection = default) { return(Task.FromResult <IResolvedSetup <ElementSetup> >(new ResolvedSetup <ElementSetup>(new ElementSetup( config.IdProperty, config.DisplayProperties), true))); }
public async Task <NodeSetup> ResolveByConventionAsync(Type subject, Features features, CollectionSetup?collection) { var node = await _nodeResolver.ResolveByConventionAsync(subject, features, collection); var pane = await _nodeSetupResolver.ResolveSetupAsync(node, collection); return(pane.Setup); }
public Task <IResolvedSetup <FieldSetup> > ResolveSetupAsync(FieldConfig config, CollectionSetup?collection = default) { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } var setup = config switch { _ when config.EditorType == EditorType.Custom && config.Property != null => (FieldSetup) new CustomPropertyFieldSetup(config, config.CustomType !), _ when config.EditorType != EditorType.None && config.Property != null => (FieldSetup) new PropertyFieldSetup(config), _ when config.DisplayType != DisplayType.None && config.Property != null => (FieldSetup) new ExpressionFieldSetup(config, config.Property), _ when config.DisplayType == DisplayType.Custom && config.Expression != null => (FieldSetup) new CustomExpressionFieldSetup(config, config.Expression, config.CustomType !), _ when config.DisplayType != DisplayType.None && config.Expression != null => (FieldSetup) new ExpressionFieldSetup(config, config.Expression), _ => throw new InvalidOperationException() }; if (config.Relation != null && setup is PropertyFieldSetup propertySetup) { propertySetup.Relation = config.Relation switch { RepositoryRelationConfig collectionConfig => (RelationSetup) new RepositoryRelationSetup( collectionConfig.RepositoryType == null ? null : _repositoryTypeResolver.GetAlias(collectionConfig.RepositoryType), collectionConfig.CollectionAlias, collectionConfig.RelatedEntityType !, collectionConfig.IdProperty, collectionConfig.DisplayProperties, collectionConfig.IsRelationToMany) { RepositoryParentSelector = collectionConfig.RepositoryParentProperty, EntityAsParent = collectionConfig.EntityAsParent, RelatedElementsGetter = collectionConfig.RelatedElementsGetter },
public async Task <IResolvedSetup <PaneSetup> > ResolveSetupAsync(PaneConfig config, CollectionSetup?collection = default) { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } var cacheable = true; var buttons = (await _buttonSetupResolver.ResolveSetupAsync(config.Buttons, collection)).CheckIfCachable(ref cacheable).ToList(); var fields = (await _fieldSetupResolver.ResolveSetupAsync(config.Fields, collection)).CheckIfCachable(ref cacheable).ToList(); var subCollectionLists = (await _subCollectionSetupResolver.ResolveSetupAsync(config.SubCollectionLists, collection)).CheckIfCachable(ref cacheable).ToList(); var relatedCollectionLists = (await _relatedCollectionSetupResolver.ResolveSetupAsync(config.RelatedCollectionLists, collection)).CheckIfCachable(ref cacheable).ToList(); return(new ResolvedSetup <PaneSetup>(new PaneSetup( config.CustomType, config.Label, config.IsVisible, config.VariantType, buttons, fields, subCollectionLists, relatedCollectionLists), cacheable)); }