예제 #1
0
 private void InitializeWebsitePageView()
 {
     WebsitePageModelsView        = WebsitePageModels.ToListCollectionView();
     WebsitePageModelsView.Filter = (item) =>
     {
         var wpm = item as WebsitePageModel;
         return
             (DoPropertyFilter(wpm) &&
              DoPageTypeFilter(wpm) &&
              DoAudienceFilter(wpm));
     };
 }
예제 #2
0
        private void ComputeWebsitePageList()
        {
            if (CurrentWebsite == null)
            {
                return;
            }
            //	Start with the loaded 'modified' WebsitePages.
            //	- Care has to be taken that:
            //		A) (for Static Pages,) Pages with the same name get added to the same WebsitePageModel. or
            //		B) (for Report Pages,) Pages with the same Report get added to the same WebsitePageModel
            //	- ^^ (A) happens because in DB, pages are considered unique per Audience.
            //	- ^^ (B) happens because we currently allow Headers/Footers, to be edited at the Report (per Audience) level.
            WebsitePageModels.Clear();
            CurrentWebsite.WebsitePages.ForEach(wp =>
            {
                //var model = WebsitePageModels.FirstOrDefault(wpm => wpm.WebsitePageName == wp.Name);
                var model = WebsitePageModels.FirstOrDefault(wpm =>
                {
                    if (wpm.PageType == WebsitePageTypeEnum.Static)
                    {
                        return(wpm.WebsitePageName == wp.Name);
                    }
                    else if (wpm.PageType == WebsitePageTypeEnum.Report)
                    {
                        return(wpm.ReportName == wp.ReportName);
                    }
                    else
                    {
                        return(false);
                    }
                });
                if (model == null)
                {
                    model = new WebsitePageModel(); WebsitePageModels.Add(model);
                }

                model.WebsitePages.Add(new WebsitePage(wp));
                model.IsModified = true;
            });

            //	Insert any missing/unmodified WebsitePages from Available List (BaseData).
            foreach (var aWebsitePageModel in ManageViewModel.AllAvailableWebsitePages)
            {
                //var oWebsitePageModel = WebsitePageModels.FirstOrDefault(wpm => wpm.WebsitePageName == aWebsitePageModel.WebsitePageName);
                var oWebsitePageModel = WebsitePageModels.FirstOrDefault(wpm =>
                {
                    if (wpm.PageType == WebsitePageTypeEnum.Static)
                    {
                        return(wpm.WebsitePageName == aWebsitePageModel.WebsitePageName);
                    }
                    else if (wpm.PageType == WebsitePageTypeEnum.Report)
                    {
                        return(wpm.ReportName == aWebsitePageModel.ReportName);
                    }
                    else
                    {
                        return(false);
                    }
                });
                if (oWebsitePageModel == null)
                {
                    oWebsitePageModel = new WebsitePageModel(aWebsitePageModel);
                    WebsitePageModels.Add(oWebsitePageModel);
                    continue;                           //  We're adding the entire PageModel from BaseData, thus we have all the Pages(by audience) and their zones also.
                }

                foreach (var aPage in aWebsitePageModel.WebsitePages)
                {
                    var oWebsitePage = oWebsitePageModel.WebsitePages.FirstOrDefault(wp => wp.Audience == aPage.Audience && wp.Name == aPage.Name);

                    if (oWebsitePage == null)
                    {
                        oWebsitePage = new WebsitePage(aPage);
                        oWebsitePageModel.WebsitePages.Add(oWebsitePage);
                    }

                    foreach (var aZone in aPage.Zones)
                    {
                        var oZone = oWebsitePage.Zones.FirstOrDefault(c => c.Name == aZone.Name);
                        if (oZone == null)
                        {
                            oZone = new WebsitePageZone(aZone);
                            oWebsitePage.Zones.Add(oZone);
                        }
                    }
                }
            }

            //	Filter out:
            //		Any Pages that are not associated with one of this websites selected Audiences.
            //		Any (Report) Pages that are not associated with one of the websites selected Reports.
            //		Any Model that does not have at least one Editable Page.
            WebsitePageModels = WebsitePageModels.Where(wpm =>
            {
                return
                (CurrentWebsite.Audiences.ContainsAny(wpm.Audiences) &&
                 (wpm.WebsitePages[0].PageType == WebsitePageTypeEnum.Static ||
                  wpm.WebsitePages[0].PageType == WebsitePageTypeEnum.Report &&
                  CurrentWebsite.Reports.Any(r =>
                {
                    //	We are forced to check Report.Datasets here because CurrentWebsite.Reports are not kept up to date;
                    //	 particularly on Dataset delete.
                    return
                    wpm.WebsitePages[0].ReportName == r.Report.Name &&
                    CurrentWebsite.Datasets.AnyIn(r.Report.Datasets, (cwd, rd) => cwd.Dataset.ContentType.Name == rd);
                })
                 ) &&
                 wpm.WebsitePages.Any(wp => wp.IsEditable));

                //return
                //	CurrentWebsite.Audiences.Any(a => wpm.WebsitePage.Audiences.Contains(a)) &&
                //	CurrentWebsite.Reports.Any(r =>
                //	{
                //		return
                //							wpm.WebsitePage.PageType == WebsitePageTypeEnum.Static ||
                //							wpm.WebsitePage.ReportName == r.Report.Name;
                //	});
            }).ToList();

            InitializeWebsitePageView();
        }