Ejemplo n.º 1
0
        public ActionResult Add(int id)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageQueries, T("Not authorized to manage queries")))
            {
                return(new HttpUnauthorizedResult());
            }

            var viewModel = new LayoutAddViewModel {
                Id = id, Layouts = _projectionManager.DescribeLayouts()
            };

            return(View(viewModel));
        }
        protected override DriverResult Editor(HighlightsGroupPart part, dynamic shapeHelper)
        {
            var HighlightsItems = _HighlightsService.GetHighlightsItemsByGroupId(part.Id);
            // populating the list of queries and layouts
            var layouts            = _projectionManager.DescribeLayouts().SelectMany(x => x.Descriptors).ToList();
            var queryRecordEntries = _orchardServices.ContentManager.Query <QueryPart>().Join <TitlePartRecord>().OrderBy(x => x.Title).List()
                                     .Select(x => new QueryRecordEntry {
                Id   = x.Id,
                Name = x.Name,
            });

            var group = new HighlightsGroup {
                Id                   = part.Id,
                ContentId            = (part.ContentItem != null) ? part.ContentItem.Id : 0,
                DisplayPlugin        = part.DisplayPlugin,
                DisplayTemplate      = part.DisplayTemplate,
                HighlightsItems      = HighlightsItems.ToList(),
                HighlightsItemsOrder = String.Join(",", HighlightsItems.Select(s => s.Id).ToArray()),
                ItemsSourceType      = part.ItemsSourceType,
                Query_Id             = part.Query_Id,
                QueryRecordEntries   = queryRecordEntries,
            };

            return(ContentShape(
                       "Parts_HighlightsGroup_Edit",
                       () => shapeHelper.EditorTemplate(
                           TemplateName: "Parts/HighlightsGroup_Edit",
                           Model: group,
                           Prefix: Prefix)));
        }
Ejemplo n.º 3
0
        protected override DriverResult Editor(CalendarPart part, dynamic shapeHelper)
        {
            return(ContentShape("Parts_Calendar_Edit",
                                () =>
            {
                var model = new CalendarEditViewModel
                {
                    DisplayPager = part.DisplayPager,
                    ItemsPerPage = part.ItemsPerPage,
                    CalendarShape = part.CalendarShape,
                    PagerSuffix = part.PagerSuffix,
                    StartDate = part.StartDate,
                    NumDays = part.NumDays,
                    QueryLayoutRecordId = "-1",
                };

                // concatenated Query and Layout ids for the view
                if (part.QueryPartRecord != null)
                {
                    model.QueryLayoutRecordId = part.QueryPartRecord.Id + ";";
                }

                if (part.LayoutRecord != null)
                {
                    model.QueryLayoutRecordId += part.LayoutRecord.Id.ToString();
                }
                else
                {
                    model.QueryLayoutRecordId += "-1";
                }

                // populating the list of queries and layouts
                var layouts = _projectionManager.DescribeLayouts().SelectMany(x => x.Descriptors).ToList();
                model.QueryRecordEntries = _orchardServices.ContentManager.Query <QueryPart>().Join <TitlePartRecord>()
                                           .OrderBy(x => x.Title)
                                           .List()
                                           .Select(x => new QueryRecordEntry
                {
                    Id = x.Id,
                    Name = x.Name,
                    LayoutRecordEntries = x.Layouts.Select(l => new LayoutRecordEntry
                    {
                        Id = l.Id,
                        Description = GetLayoutDescription(layouts, l)
                    })
                });


                return shapeHelper.EditorTemplate(TemplateName: "Parts/Calendar", Model: model, Prefix: Prefix);
            }));
        }
Ejemplo n.º 4
0
        public ActionResult Edit(int id)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageQueries, T("Not authorized to edit queries")))
            {
                return(new HttpUnauthorizedResult());
            }

            var query     = _queryService.GetQuery(id);
            var viewModel = new AdminEditViewModel {
                Id   = query.Id,
                Name = query.Name
            };

            #region Load Filters
            var filterGroupEntries = new List <FilterGroupEntry>();
            var allFilters         = _projectionManager.DescribeFilters().SelectMany(x => x.Descriptors).ToList();

            foreach (var group in query.FilterGroups)
            {
                var filterEntries = new List <FilterEntry>();

                foreach (var filter in group.Filters)
                {
                    var category = filter.Category;
                    var type     = filter.Type;

                    var f = allFilters.FirstOrDefault(x => category == x.Category && type == x.Type);
                    if (f != null)
                    {
                        filterEntries.Add(
                            new FilterEntry {
                            Category       = f.Category,
                            Type           = f.Type,
                            FilterRecordId = filter.Id,
                            DisplayText    = String.IsNullOrWhiteSpace(filter.Description) ? f.Display(new FilterContext {
                                State = FormParametersHelper.ToDynamic(filter.State)
                            }).Text : filter.Description
                        });
                    }
                }

                filterGroupEntries.Add(new FilterGroupEntry {
                    Id = group.Id, Filters = filterEntries
                });
            }

            viewModel.FilterGroups = filterGroupEntries;

            #endregion

            #region Load Sort criterias
            var sortCriterionEntries = new List <SortCriterionEntry>();
            var allSortCriteria      = _projectionManager.DescribeSortCriteria().SelectMany(x => x.Descriptors).ToList();

            foreach (var sortCriterion in query.SortCriteria.OrderBy(s => s.Position))
            {
                var category = sortCriterion.Category;
                var type     = sortCriterion.Type;

                var f = allSortCriteria.FirstOrDefault(x => category == x.Category && type == x.Type);
                if (f != null)
                {
                    sortCriterionEntries.Add(
                        new SortCriterionEntry {
                        Category = f.Category,
                        Type     = f.Type,
                        SortCriterionRecordId = sortCriterion.Id,
                        DisplayText           = String.IsNullOrWhiteSpace(sortCriterion.Description) ? f.Display(new SortCriterionContext {
                            State = FormParametersHelper.ToDynamic(sortCriterion.State)
                        }).Text : sortCriterion.Description
                    });
                }
            }

            viewModel.SortCriteria = sortCriterionEntries;

            #endregion

            #region Load Layouts
            var layoutEntries = new List <LayoutEntry>();
            var allLayouts    = _projectionManager.DescribeLayouts().SelectMany(x => x.Descriptors).ToList();

            foreach (var layout in query.Layouts)
            {
                var category = layout.Category;
                var type     = layout.Type;

                var f = allLayouts.FirstOrDefault(x => category == x.Category && type == x.Type);
                if (f != null)
                {
                    layoutEntries.Add(
                        new LayoutEntry {
                        Category       = f.Category,
                        Type           = f.Type,
                        LayoutRecordId = layout.Id,
                        DisplayText    = String.IsNullOrWhiteSpace(layout.Description) ? f.Display(new LayoutContext {
                            State = FormParametersHelper.ToDynamic(layout.State)
                        }).Text : layout.Description
                    });
                }
            }

            viewModel.Layouts = layoutEntries;

            #endregion

            return(View(viewModel));
        }