protected async Task ReloadSectionsAsync(IEnumerable <string> reloadEntityIds)
        {
            if (UIResolver == null || Sections == null)
            {
                return;
            }

            var newSections = await Sections.ToListAsync(async x =>
            {
                if (reloadEntityIds.Contains(x.editContext.Entity.Id))
                {
                    var reloadedEditContext = await PresentationService.GetEntityAsync(new GetEntityRequestModel
                    {
                        CollectionAlias = x.editContext.CollectionAlias,
                        Id         = x.editContext.Entity.Id,
                        ParentPath = x.editContext.Parent?.GetParentPath(),
                        UsageType  = x.editContext.UsageType
                    });

                    return(reloadedEditContext, await UIResolver.GetSectionsForEditContextAsync(reloadedEditContext));
                }
                else
                {
                    return(x);
                }
            });

            Sections = newSections;
        }
        protected async Task LoadCollectionDataAsync(IEnumerable <string>?reloadEntityIds = null)
        {
            try
            {
                if (CurrentState == null)
                {
                    throw new InvalidOperationException();
                }

                if (reloadEntityIds?.Any() == true)
                {
                    await ReloadSectionsAsync(reloadEntityIds);
                }
                else
                {
                    UIResolver = await UIResolverFactory.GetListUIResolverAsync(CurrentState.UsageType, CurrentState.CollectionAlias);

                    ListUI = UIResolver.GetListDetails();

                    var listContext = await LoadSectionsAsync();

                    var buttons = await UIResolver.GetButtonsForEditContextAsync(listContext.ProtoEditContext);

                    var tabs = await UIResolver.GetTabsAsync(listContext.ProtoEditContext);

                    Buttons     = buttons;
                    Tabs        = tabs;
                    ListContext = listContext;
                    Sections?.ForEach(x => x.editContext.OnFieldChanged += (s, a) => StateHasChanged());

                    PageContents = null;
                }

                StateHasChanged();
            }
            catch
            {
                ListContext = null;
                Sections    = null;
                ListUI      = null;

                throw;
            }
        }
Ejemplo n.º 3
0
        private async Task SetSectionsAsync(ListContext listContext)
        {
            if (UIResolver == null)
            {
                return;
            }

            Sections = await listContext.EditContexts.ToListAsync(async editContext => (editContext, await UIResolver.GetSectionsForEditContextAsync(editContext)));
        }