private void AddReportsToModel(EditDataReportViewerViewModel model)
        {
            var reports = this.reportRepository.Table.ToList();

            model.Reports.AddRange(reports.Select(c => new SelectListItem
            {
                Value    = c.Id.ToString(CultureInfo.InvariantCulture),
                Text     = c.Title,
                Selected = model.ReportId.HasValue ? model.ReportId.Value == c.Id : false
            }));
        }
        public override IEnumerable <TemplateViewModel> TypePartEditor(ContentTypePartDefinition definition)
        {
            if (definition.PartDefinition.Name != "DataReportViewerPart")
            {
                yield break;
            }

            var settings = definition.Settings.GetModel <DataReportViewerPartSettings>();
            var model    = new EditDataReportViewerViewModel();

            model.ChartTagCssClass  = settings.ChartTagCssClass;
            model.ContainerCssClass = settings.ContainerTagCssClass;

            this.AddReportsToModel(model);
            yield return(DefinitionTemplate(model, "DataReportViewerPartSettings", "DataReportViewerPartSettings"));
        }
Exemplo n.º 3
0
        public override IEnumerable <TemplateViewModel> TypePartEditorUpdate(ContentTypePartDefinitionBuilder builder, IUpdateModel updateModel)
        {
            if (builder.Name != "DataReportViewerPart")
            {
                yield break;
            }
            var settings = new DataReportViewerPartSettings();
            var model    = new EditDataReportViewerViewModel();

            if (updateModel.TryUpdateModel(model, "DataReportViewerPartSettings", null, null))
            {
                settings.DefaultReportId      = model.ReportId;
                settings.ContainerTagCssClass = model.ContainerCssClass;
                settings.ChartTagCssClass     = model.ChartTagCssClass;
                settings.Build(builder);
            }

            this.AddReportsToModel(model);
            yield return(DefinitionTemplate(model, "DataReportViewerPartSettings", "DataReportViewerPartSettings"));
        }
Exemplo n.º 4
0
        protected override DriverResult Editor(DataReportViewerPart part, dynamic shapeHelper)
        {
            var model  = new EditDataReportViewerViewModel();
            var record = part.Record;

            // if it is called for creating a new item, then the default values from settings must be copied into the part
            if (record.Id == default(int))
            {
                var settings = part.TypePartDefinition.Settings.GetModel <DataReportViewerPartSettings>();
                model.ChartTagCssClass  = settings.ChartTagCssClass;
                model.ContainerCssClass = settings.ContainerTagCssClass;
                model.ReportId          = settings.DefaultReportId;
            }
            else
            {
                if (record.Report != null)
                {
                    model.ReportId = record.Report.Id;
                }
                model.ChartType         = (ChartTypes)(record.ChartType);
                model.ChartTagCssClass  = record.ChartTagCssClass;
                model.ContainerCssClass = record.ContainerTagCssClass;
                model.ColorStyle        = (ColorStyleValues)(record.ColorStyle);
                model.StartColor        = (ChartColorNames)(record.StartColor);
            }

            var reports = this.reportRepository.Table.ToList();

            model.Reports.AddRange(reports.Select(c => new SelectListItem
            {
                Value    = c.Id.ToString(CultureInfo.InvariantCulture),
                Text     = c.Title,
                Selected = model.ReportId.HasValue ? model.ReportId.Value == c.Id : false
            }));

            return(ContentShape("Parts_DataReportViewer_Edit",
                                () => shapeHelper.EditorTemplate(
                                    TemplateName: "Parts/DataReportViewer",
                                    Model: model,
                                    Prefix: Prefix)));
        }
        protected override DriverResult Editor(DataReportViewerPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            EditDataReportViewerViewModel model = new EditDataReportViewerViewModel();

            updater.TryUpdateModel(model, "DataReportViewerPart", null, null);

            if (model.ReportId == null)
            {
                updater.AddModelError("ReportId", T("Please select a Report"));
            }
            else
            {
                part.Record.Report = new ReportRecord {
                    Id = model.ReportId.Value
                };
                part.Record.ChartTagCssClass     = model.ChartTagCssClass;
                part.Record.ContainerTagCssClass = model.ContainerCssClass;
            }

            return(this.Editor(part, shapeHelper));
        }