<commit_before>﻿using jQueryApi;
using jQueryApi.UI.Widgets;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

namespace Serenity.Reporting
{
    public class ReportDialog : TemplatedDialog<ReportDialogOptions>
    {
        private List<PropertyItem> propertyItems;
        private PropertyGrid propertyGrid;
        private ReportDesignPanel designPanel;
        private string reportKey;

        public ReportDialog(ReportDialogOptions opt)
            : base(opt)
        {
            designPanel = new ReportDesignPanel(
                J("<div/>")
                    .AddClass("design-panel")
                    .PrependTo(this.ById("Toolbar").Find(".tool-buttons")),
                new ReportDesignPanelOptions
            {
            });

            if (opt.ReportKey != null)
                LoadReport(opt.ReportKey);
        }

        protected void CreatePropertyGrid()
        {
            if (propertyGrid != null)
            {
                this.ById("PropertyGrid").Html("").Attribute("class", "");
                propertyGrid = null;
            }

            propertyGrid = new PropertyGrid(this.ById("PropertyGrid"), new PropertyGridOptions
            {
                IdPrefix = this.IdPrefix,
                UseCategories = true,
                Items = propertyItems
            });
        }

        public void LoadReport(string reportKey)
        {
            Q.ServiceCall(new ServiceCallOptions<ReportRetrieveResponse>
            {
                Service = "Report/Retrieve",
                Request = new ReportRetrieveRequest
                {
                    ReportKey = reportKey
                },
                OnSuccess = response =>
                {
                    this.reportKey = response.ReportKey ?? reportKey;
                    this.propertyItems = response.Properties ?? new List<PropertyItem>();
                    this.designPanel.ReportKey = this.reportKey;
                    this.Element.Dialog().Title = response.Title;
                    this.designPanel.SetDesignList(response.Designs);
                    CreatePropertyGrid();
                    propertyGrid.Load(response.InitialSettings ?? new object());

                    this.toolbar.FindButton("print-preview-button").Toggle(!response.IsDataOnlyReport);
                    this.toolbar.FindButton("export-pdf-button").Toggle(!response.IsDataOnlyReport);
                    this.toolbar.FindButton("export-docx-button").Toggle(!response.IsDataOnlyReport);

                    this.DialogOpen();
                }
            });
        }

        protected void ExecuteReport(string targetFrame, string exportType)
        {
            var designId = designPanel.SelectedDesignId;
            if (designId == null)
            {
                Q.Alert("Lütfen bir rapor dizaynı seçiniz");
                return;
            }

            if (!ValidateForm())
                return;

            var parameters = new object();
            propertyGrid.Save(parameters);

            Q.Externals.PostToService(new PostToServiceOptions
            {
                Service = "Report/Execute",
                Request = new ReportExecuteRequest
                {
                    ReportKey = reportKey,
                    DesignId = designId,
                    ExportType = exportType,<commit_msg>report dialog remove design chooser<commit_after>﻿using jQueryApi;
using jQueryApi.UI.Widgets;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

namespace Serenity.Reporting
{
    public class ReportDialog : TemplatedDialog<ReportDialogOptions>
    {
        private List<PropertyItem> propertyItems;
        private PropertyGrid propertyGrid;
        private string reportKey;

        public ReportDialog(ReportDialogOptions opt)
            : base(opt)
        {
            if (opt.ReportKey != null)
                LoadReport(opt.ReportKey);
        }

        protected void CreatePropertyGrid()
        {
            if (propertyGrid != null)
            {
                this.ById("PropertyGrid").Html("").Attribute("class", "");
                propertyGrid = null;
            }

            propertyGrid = new PropertyGrid(this.ById("PropertyGrid"), new PropertyGridOptions
            {
                IdPrefix = this.IdPrefix,
                UseCategories = true,
                Items = propertyItems
            });
        }

        public void LoadReport(string reportKey)
        {
            Q.ServiceCall(new ServiceCallOptions<ReportRetrieveResponse>
            {
                Service = "Report/Retrieve",
                Request = new ReportRetrieveRequest
                {
                    ReportKey = reportKey
                },
                OnSuccess = response =>
                {
                    this.reportKey = response.ReportKey ?? reportKey;
                    this.propertyItems = response.Properties ?? new List<PropertyItem>();
                    this.Element.Dialog().Title = response.Title;
                    CreatePropertyGrid();
                    propertyGrid.Load(response.InitialSettings ?? new object());

                    this.toolbar.FindButton("print-preview-button").Toggle(!response.IsDataOnlyReport);
                    this.toolbar.FindButton("export-pdf-button").Toggle(!response.IsDataOnlyReport);
                    this.toolbar.FindButton("export-docx-button").Toggle(!response.IsDataOnlyReport);

                    this.DialogOpen();
                }
            });
        }

        protected void ExecuteReport(string targetFrame, string exportType)
        {
            if (!ValidateForm())
                return;

            var parameters = new object();
            propertyGrid.Save(parameters);

            Q.Externals.PostToService(new PostToServiceOptions
            {
                Service = "Report/Execute",
                Request = new ReportExecuteRequest
                {
                    ReportKey = reportKey,
                    DesignId = "Default",
                    ExportType = exportType,
{'fraction_non_alphanumeric': 0.08697772719882946, 'fraction_numerical': 0.0, 'mean_word_length': 1.5453040959867606, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5385575', 'n_tokens_mistral': 1435, 'n_tokens_neox': 1344, 'n_words': 253}