public ContainerPartHandler(
            IRepository<ContainerPartRecord> repository, 
            IContentDefinitionManager contentDefinitionManager, 
            IListViewService listViewService, 
            IContainerService containerService) {

            _contentDefinitionManager = contentDefinitionManager;
            _listViewService = listViewService;
            _containerService = containerService;
            Filters.Add(StorageFilter.For(repository));
            OnInitializing<ContainerPart>((context, part) => {
                part.Record.ItemsShown = part.Settings.GetModel<ContainerTypePartSettings>().ItemsShownDefault
                                        ?? part.PartDefinition.Settings.GetModel<ContainerPartSettings>().ItemsShownDefault;
                part.Record.PageSize = part.Settings.GetModel<ContainerTypePartSettings>().PageSizeDefault
                                        ?? part.PartDefinition.Settings.GetModel<ContainerPartSettings>().PageSizeDefault;
                part.Record.Paginated = part.Settings.GetModel<ContainerTypePartSettings>().PaginatedDefault
                                        ?? part.PartDefinition.Settings.GetModel<ContainerPartSettings>().PaginatedDefault;

            });

            OnGetContentItemMetadata<ContainerPart>((context, part) => {
                    context.Metadata.DisplayRouteValues = new RouteValueDictionary {
                    {"Area", "Containers"},
                    {"Controller", "Item"},
                    {"Action", "Display"},
                    {"id", context.ContentItem.Id}
                };
            });

            OnActivated<ContainerPart>((context, part) => {
                part.ContainerSettingsField.Loader(() => part.Settings.GetModel<ContainerTypePartSettings>());

                part.ItemContentTypesField.Loader(() => {
                    var settings = part.ContainerSettings;
                    var types = settings.RestrictItemContentTypes ? settings.RestrictedItemContentTypes : part.Record.ItemContentTypes;
                    return _contentDefinitionManager.ParseContentTypeDefinitions(types);
                });

                part.ItemContentTypesField.Setter(value => {
                    part.Record.ItemContentTypes = _contentDefinitionManager.JoinContentTypeDefinitions(value);
                    return value;
                });

                part.AdminListViewField.Loader(() => {
                    var providers = _listViewService.Providers.ToList();
                    var listViewProviderName = !String.IsNullOrWhiteSpace(part.Record.AdminListViewName)
                        ? part.Record.AdminListViewName
                        : !String.IsNullOrWhiteSpace(part.ContainerSettings.AdminListViewName)
                            ? part.ContainerSettings.AdminListViewName
                            : providers.Any() ? providers.First().Name : null;

                    return _listViewService.GetProvider(listViewProviderName) ?? _listViewService.GetDefaultProvider();
                });
            });

            OnPublished<ContainerPart>((context, part) => _containerService.UpdateItemCount(part));
        }
        public ContainerPartHandler(
            IRepository <ContainerPartRecord> repository,
            IContentDefinitionManager contentDefinitionManager,
            IListViewService listViewService,
            IContainerService containerService)
        {
            _contentDefinitionManager = contentDefinitionManager;
            _listViewService          = listViewService;
            _containerService         = containerService;
            Filters.Add(StorageFilter.For(repository));
            OnInitializing <ContainerPart>((context, part) => {
                part.Record.ItemsShown = part.Settings.GetModel <ContainerTypePartSettings>().ItemsShownDefault
                                         ?? part.PartDefinition.Settings.GetModel <ContainerPartSettings>().ItemsShownDefault;
                part.Record.PageSize = part.Settings.GetModel <ContainerTypePartSettings>().PageSizeDefault
                                       ?? part.PartDefinition.Settings.GetModel <ContainerPartSettings>().PageSizeDefault;
                part.Record.Paginated = part.Settings.GetModel <ContainerTypePartSettings>().PaginatedDefault
                                        ?? part.PartDefinition.Settings.GetModel <ContainerPartSettings>().PaginatedDefault;
            });

            OnGetContentItemMetadata <ContainerPart>((context, part) => {
                context.Metadata.DisplayRouteValues = new RouteValueDictionary {
                    { "Area", "Containers" },
                    { "Controller", "Item" },
                    { "Action", "Display" },
                    { "id", context.ContentItem.Id }
                };
            });

            OnActivated <ContainerPart>((context, part) => {
                part.ContainerSettingsField.Loader(() => part.Settings.GetModel <ContainerTypePartSettings>());

                part.ItemContentTypesField.Loader(() => {
                    var settings = part.ContainerSettings;
                    var types    = settings.RestrictItemContentTypes ? settings.RestrictedItemContentTypes : part.Record.ItemContentTypes;
                    return(_contentDefinitionManager.ParseContentTypeDefinitions(types));
                });

                part.ItemContentTypesField.Setter(value => {
                    part.Record.ItemContentTypes = _contentDefinitionManager.JoinContentTypeDefinitions(value);
                    return(value);
                });

                part.AdminListViewField.Loader(() => {
                    var providers            = _listViewService.Providers.ToList();
                    var listViewProviderName = !String.IsNullOrWhiteSpace(part.Record.AdminListViewName)
                        ? part.Record.AdminListViewName
                        : !String.IsNullOrWhiteSpace(part.ContainerSettings.AdminListViewName)
                            ? part.ContainerSettings.AdminListViewName
                            : providers.Any() ? providers.First().Name : null;

                    return(_listViewService.GetProvider(listViewProviderName) ?? _listViewService.GetDefaultProvider());
                });
            });

            OnPublished <ContainerPart>((context, part) => _containerService.UpdateItemCount(part));
        }
Beispiel #3
0
        public override IDisplayResult Display(ListPart listPart, BuildPartDisplayContext context)
        {
            var settings = context.TypePartDefinition.GetSettings <ListPartSettings>();
            var renderItemsInFrontEnd = settings.RenderItemsInFrontEnd;
            var renderItemsInBackEnd  = settings.RenderItemsInBackEnd;

            return
                (Combine(
                     Initialize <ListPartViewModel>(
                         renderItemsInFrontEnd ? GetDisplayShapeType(context) : "ListPart_Empty", async model =>
            {
                //this is called from front end

                if (settings.RenderItemsInFrontEnd)
                {
                    var pager = await GetPagerSlimAsync(context);
                    //this is for backend only
                    model.ListViewProviders = _listViewService.Providers.ToList();
                    // model.ListViewProvider = GetListViewProvider(settings.FrontEndListViewName);
                    model.ListViewProviderFrontEnd = GetListViewProvider(settings.FrontEndListViewName);
                    model.ListMode = GetListViewListMode();

                    // model.AllowUserToSwitchListViews = settings.AllowUserToSwitchListViews;
                    model.AllowUserToSwitchListViewsFrontEnd =
                        settings.AllowUserToSwitchListViewsFrontEnd;
                    model.UseTemplatesOnCreatingNewListItem =
                        settings.UseTemplatesOnCreatingNewListItem;
                    model.ShowSearchAndFilterOptions = settings.ShowSearchAndFilterOptions;
                    model.FrontEndListViews = settings.FrontEndListViews;
                    model.AllowUserToAddChildItemsFrontEnd = settings.AllowUserToAddChildItems;
                    model.ShowLatestVersion = settings.ShowLatestVersion;

                    if (settings.AllowUserToSwitchListViewsFrontEnd)
                    {
                        if (!String.IsNullOrEmpty(settings.FrontEndListViews))
                        {
                            IEnumerable <string> rawTypes = settings.FrontEndListViews
                                                            .Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
                                                            .ToList();
                            model.FrontEndListViewProviders = rawTypes.Select(listviewType =>
                                                                              _listViewService.GetProvider(listviewType));
                        }
                        else
                        {
                            //if FrontEndListViews is empty than show all available providers in front end
                            model.FrontEndListViewProviders = _listViewService.Providers.ToList();
                        }
                    }
                    //========

                    model.ListPart = listPart;

                    //  var pager = await GetPagerSlimAsync(context);


                    model.PageOfContentItems =
                        (await _containerService.QueryContainedItemsAsync(
                             listPart.ContentItem.ContentItemId, settings.EnableOrdering, pager, false))
                        .ToArray();
                    // model.PageOfContentItems = (await QueryListItemsAsync(listPart, pager,  !model.ShowLatestVersion, pager.GetType().Name == "Pager")).ToArray();


                    if (settings.AllowOverrideDataFillModePerInstance)
                    {
                        //get settings from instance not part definition settings
                        model.DataFillMode = listPart.DataFillMode;

                        if (model.DataFillMode == DataFillMode.ContentTypes)
                        {
                            model.ContainedContentTypeDefinitions =
                                GetContainedContentTypes(listPart.ContainedContentTypes);
                        }
                        else if (model.DataFillMode == DataFillMode.WorkMaps)
                        {
                            model.SelectedWorkMapContentItemIds =
                                listPart.SelectedWorkMapContentItemIds;
                            if (model.SelectedWorkMapContentItemIds?.Length > 0)
                            {
                                //get selected content items
                                model.SelectedWorkMapContentItems =
                                    await _contentManager.GetAsync(model.SelectedWorkMapContentItemIds,
                                                                   true);
                            }
                        }
                    }
                    else                 //get from settings
                    {
                        model.DataFillMode = settings.DataFillMode;
                        if (model.DataFillMode == DataFillMode.ContentTypes)
                        {
                            model.ContainedContentTypeDefinitions =
                                GetContainedContentTypes(settings.ContainedContentTypes);
                        }
                        else if (model.DataFillMode == DataFillMode.WorkMaps)
                        {
                            model.SelectedWorkMapContentItemIds =
                                settings.SelectedWorkMapContentItemIds;
                            if (model.SelectedWorkMapContentItemIds?.Length > 0)
                            {
                                //get selected content items
                                model.SelectedWorkMapContentItems =
                                    await _contentManager.GetAsync(model.SelectedWorkMapContentItemIds,
                                                                   true);
                            }
                        }
                    }

                    //PopulateListPartSearchOptions(model);


                    model.Context = context;

                    model.Pager = (await context.New.PagerSlim(pager)).UrlParams(pager.UrlParams);


                    var displayContext = new BuildListDisplayContext()
                    {
                        ContentItem = listPart.ContentItem,
                        PageOfContentItems = model.PageOfContentItems,
                        EnableOrdering = settings.EnableOrdering,
                        EnableDetaching = settings.EnableDetaching,
                        EnableMoving = settings.EnableMoving,
                        EnableAttaching = settings.EnableAttaching,
                        Pager = model.Pager,
                        PartDisplayContext = context,
                        AdminListViewName = settings.AdminListViewName,
                        FrontEndListViewName = settings.FrontEndListViewName,
                        FrontEndListViews = settings.FrontEndListViews,
                        IsInAdminView = false                 //isInAdmView
                        ,
                        UseInfiniteScroll = settings.UseInfiniteScroll,
                        InfiniteAjaxScrollPartSettings = settings.InfiniteAjaxScrollPartSettings
                    };

                    var currentListViewProvider = GetListViewProvider(settings.FrontEndListViewName);
                    model.ListMode = GetListViewListMode();
                    model.ListViewShape =
                        await currentListViewProvider.BuildDisplayAsync(displayContext);
                }
            })
                     .Location("Detail", "Content:10"),
                     Initialize <ListPartViewModel>(renderItemsInBackEnd ? "ListPart" : "ListPart_Empty", async model =>
            {
                //this is called from back end


                //var settings = context.TypePartDefinition.GetSettings<ListPartSettings>();

                if (settings.RenderItemsInBackEnd)
                {
                    var pager = await GetPagerSlimAsync(context);
                    model.ListViewProviders = _listViewService.Providers.ToList();
                    model.ListViewProvider = GetListViewProvider(settings.AdminListViewName);
                    model.ListViewProviderFrontEnd = GetListViewProvider(settings.FrontEndListViewName);
                    model.ListMode = GetListViewListMode();
                    model.AllowUserToSwitchListViews = settings.AllowUserToSwitchListViews;
                    model.AllowUserToSwitchListViewsFrontEnd = settings.AllowUserToSwitchListViewsFrontEnd;
                    model.UseTemplatesOnCreatingNewListItem = settings.UseTemplatesOnCreatingNewListItem;
                    model.ShowSearchAndFilterOptions = settings.ShowSearchAndFilterOptions;
                    model.FrontEndListViews = settings.FrontEndListViews;
                    model.AllowUserToAddChildItemsFrontEnd = settings.AllowUserToAddChildItems;
                    model.ShowLatestVersion = settings.ShowLatestVersion;
                    //========
                    model.ListPart = listPart;
                    model.PageOfContentItems =
                        (await _containerService.QueryContainedItemsAsync(
                             listPart.ContentItem.ContentItemId, settings.EnableOrdering, (PagerSlim)pager,
                             false)).ToArray();


                    if (settings.AllowOverrideDataFillModePerInstance == true)
                    {
                        model.DataFillMode = listPart.DataFillMode;

                        if (model.DataFillMode == DataFillMode.ContentTypes)
                        {
                            model.ContainedContentTypeDefinitions =
                                GetContainedContentTypes(listPart.ContainedContentTypes);
                        }
                        else if (model.DataFillMode == DataFillMode.WorkMaps)
                        {
                            model.SelectedWorkMapContentItemIds = listPart.SelectedWorkMapContentItemIds;
                            if (model.SelectedWorkMapContentItemIds?.Length > 0)
                            {
                                //get selected content items
                                model.SelectedWorkMapContentItems =
                                    await _contentManager.GetAsync(model.SelectedWorkMapContentItemIds,
                                                                   true);
                            }
                        }
                    }
                    else             //get from settings
                    {
                        model.DataFillMode = settings.DataFillMode;
                        if (model.DataFillMode == DataFillMode.ContentTypes)
                        {
                            model.ContainedContentTypeDefinitions =
                                GetContainedContentTypes(settings.ContainedContentTypes);
                        }
                        else if (model.DataFillMode == DataFillMode.WorkMaps)
                        {
                            model.SelectedWorkMapContentItemIds = settings.SelectedWorkMapContentItemIds;
                            if (model.SelectedWorkMapContentItemIds?.Length > 0)
                            {
                                //get selected content items
                                model.SelectedWorkMapContentItems =
                                    await _contentManager.GetAsync(model.SelectedWorkMapContentItemIds,
                                                                   true);
                            }
                        }
                    }


                    model.Context = context;


                    model.EnableOrdering = settings.EnableOrdering;
                    model.EnableDetaching = settings.EnableDetaching;
                    model.EnableMoving = settings.EnableMoving;
                    model.EnableAttaching = settings.EnableAttaching;
                    //  model.Pager = await context.New.PagerSlim(pager);
                    model.Pager =
                        await context.New
                        .PagerSlim(
                            pager);                 //await GetViewModelPagerShapeAsync(context, pager, listPart, false);
                    var displayContext = new BuildListDisplayContext()
                    {
                        ContentItem = listPart.ContentItem,
                        PageOfContentItems = model.PageOfContentItems,
                        EnableOrdering = settings.EnableOrdering,
                        EnableDetaching = settings.EnableDetaching,
                        EnableMoving = settings.EnableMoving,
                        EnableAttaching = settings.EnableAttaching,
                        Pager = model.Pager,
                        PartDisplayContext = context,
                        AdminListViewName = settings.AdminListViewName,
                        FrontEndListViewName = settings.FrontEndListViewName,
                        FrontEndListViews = settings.FrontEndListViews,
                        IsInAdminView = true             //isInAdmView
                        ,
                        UseInfiniteScroll = settings.UseInfiniteScroll,
                        InfiniteAjaxScrollPartSettings = settings.InfiniteAjaxScrollPartSettings
                    };
                    var currenListViewProvider = GetListViewProvider(settings.AdminListViewName);
                    model.ListMode = GetListViewListMode();
                    model.ListViewShape = await currenListViewProvider.BuildDisplayAsync(displayContext);
                }
            })
                     .Location("DetailAdmin", "Content:10")
                     ));
        }
Beispiel #4
0
        public override IDisplayResult Display(CrossReferencePart part, BuildPartDisplayContext context)
        {
            return
                (Combine(
                     Initialize <CrossReferencePartViewModel>("CrossReferencePart", async model =>
            {
                //this is called from front end
                // var pager = await GetPagerAsync(context.Updater, listPart);
                var pager = await GetPagerObjectAsync(context.Updater, part, context.TypePartDefinition.Name);
                //giannis
                var settings = GetSettings(part, context.TypePartDefinition.Name);
                //this is for backend only
                model.ListViewProviders = _listViewService.Providers.ToList();
                // model.ListViewProvider = GetListViewProvider(settings.FrontEndListViewName);
                model.ListViewProviderFrontEnd = GetListViewProvider(settings.FrontEndListViewName);
                // model.AllowUserToSwitchListViews = settings.AllowUserToSwitchListViews;
                model.AllowUserToSwitchListViewsFrontEnd = settings.AllowUserToSwitchListViewsFrontEnd;
                model.FrontEndListViews = settings.FrontEndListViews;
                model.Relation = settings.Relation;
                model.AllowUserToAddChildItemsFrontEnd = settings.AllowUserToAddChildItems;
                model.ShowLatestVersion = settings.ShowLatestVersion;

                if (settings.AllowUserToSwitchListViewsFrontEnd)
                {
                    if (!String.IsNullOrEmpty(settings.FrontEndListViews))
                    {
                        IEnumerable <string> rawTypes = settings.FrontEndListViews.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                        model.FrontEndListViewProviders = rawTypes.Select(listviewType => _listViewService.GetProvider(listviewType));
                    }
                    else
                    {
                        //if FrontEndListViews is empty than show all available providers in front end
                        model.FrontEndListViewProviders = _listViewService.Providers.ToList();
                    }
                }
                //========

                model.Part = part;
                //  model.ContentItems = (await QueryListItemsAsync(listPart, pager, true)).ToArray();
                //  model.PageOfContentItems = (await QueryListItemsAsync(listPart, pager, !model.ShowLatestVersion)).ToArray();
                model.PageOfContentItems = (await QueryListItemsAsync(part, pager, !model.ShowLatestVersion, settings.Relation)).ToArray();
                model.ContainedContentTypeDefinitions = GetContainedContentTypes(part, context.TypePartDefinition.Name);
                model.Context = context;
                // model.Pager = await context.New.PagerSlim(pager);
                model.Pager = await GetViewModelPagerAsync(context, pager, part, false, settings.Relation);
                //   bool isInAdmView = AdminAttribute.IsApplied(_httpContextAccessor.HttpContext);
                var displayContext = new BuildListDisplayContext()
                {
                    ContentItem = part.ContentItem,
                    PageOfContentItems = model.PageOfContentItems,
                    //EnablePositioning = settings.EnablePositioning,

                    Pager = model.Pager,
                    PartDisplayContext = context,
                    AdminListViewName = settings.AdminListViewName,
                    FrontEndListViewName = settings.FrontEndListViewName,
                    FrontEndListViews = settings.FrontEndListViews,
                    IsInAdminView = false       //isInAdmView
                };

                var currentListViewProvider = GetListViewProvider(settings.FrontEndListViewName);
                //todo why is it that when placing await in fron of currenListViewProvider i get a null reference in view
                model.ListViewShape = await currentListViewProvider.BuildDisplayAsync(displayContext);
            })
                     .Location("Detail", "Content:10"),

                     Initialize <CrossReferencePartViewModel>("CrossReferencePart", async model =>
            {
                //this is called from back end
                //var pager = await GetPagerAsync(context.Updater, listPart);
                var pager = await GetPagerObjectAsync(context.Updater, part, context.TypePartDefinition.Name);
                //giannis
                var settings = GetSettings(part, context.TypePartDefinition.Name);

                model.ListViewProviders = _listViewService.Providers.ToList();
                model.ListViewProvider = GetListViewProvider(settings.AdminListViewName);
                model.ListViewProviderFrontEnd = GetListViewProvider(settings.FrontEndListViewName);
                model.AllowUserToSwitchListViews = settings.AllowUserToSwitchListViews;
                model.AllowUserToSwitchListViewsFrontEnd = settings.AllowUserToSwitchListViewsFrontEnd;
                model.FrontEndListViews = settings.FrontEndListViews;
                model.Relation = settings.Relation;
                model.AllowUserToAddChildItemsFrontEnd = settings.AllowUserToAddChildItems;
                model.ShowLatestVersion = settings.ShowLatestVersion;
                //========
                model.Part = part;
                // model.ContentItems = (await QueryListItemsAsync(listPart, pager, false)).ToArray();
                //  model.PageOfContentItems = (await QueryListItemsAsync(listPart, pager, !model.ShowLatestVersion)).ToArray();
                model.PageOfContentItems = (await QueryListItemsAsync(part, pager, !model.ShowLatestVersion, settings.Relation)).ToArray();
                model.ContainedContentTypeDefinitions = GetContainedContentTypes(part, context.TypePartDefinition.Name);
                model.Context = context;
                //  model.Pager = await context.New.PagerSlim(pager);
                model.Pager = await GetViewModelPagerAsync(context, pager, part, false, settings.Relation);
                var displayContext = new BuildListDisplayContext()
                {
                    ContentItem = part.ContentItem,
                    PageOfContentItems = model.PageOfContentItems,
                    // EnablePositioning = settings.EnablePositioning,

                    Pager = model.Pager,
                    PartDisplayContext = context,
                    AdminListViewName = settings.AdminListViewName,
                    FrontEndListViewName = settings.FrontEndListViewName,
                    FrontEndListViews = settings.FrontEndListViews,
                    IsInAdminView = true       //isInAdmView
                };
                var currenListViewProvider = GetListViewProvider(settings.AdminListViewName);
                //todo why is it that when placing await in fron of currenListViewProvider i get a null reference in view
                model.ListViewShape = await currenListViewProvider.BuildDisplayAsync(displayContext);
                //
            })
                     .Location("DetailAdmin", "Content:10")
                     ));
        }