Пример #1
0
        public ExecuteChartResult Execute(ChartRequest request)
        {
            var resultTable = ChartLogic.ExecuteChart(request);

            var chartTable = ChartUtils.DataJson(request, resultTable);

            return new ExecuteChartResult { resultTable = resultTable, chartTable = chartTable };
        }
Пример #2
0
        public HttpResponseMessage ToPlainExcel(ChartRequest request)
        {
            var resultTable = ChartLogic.ExecuteChart(request);

            byte[] binaryFile = PlainExcelGenerator.WritePlainExcel(resultTable, QueryUtils.GetNiceName(request.QueryName));

            var fileName = request.ChartScript.ToString() + " " + QueryUtils.GetKey(request.QueryName) + TimeZoneManager.Now.ToString("yyyyMMdd-HHmmss") + ".xlsx";

            return FilesController.GetHttpReponseMessage(new MemoryStream(binaryFile), fileName);
        }
Пример #3
0
        internal static void FixParameters(ChartRequest chartRequest, ChartColumnEmbedded chartColumn)
        {
            int index = chartRequest.Columns.IndexOf(chartColumn);

            foreach (var p in chartRequest.Parameters.Where(p => p.ScriptParameter.ColumnIndex == index))
            {
                if (p.PropertyCheck(() => p.Value).HasText())
                {
                    p.Value = p.ScriptParameter.DefaultValue(chartColumn.Token?.Token);
                }
            }
        }
Пример #4
0
        //Manual Json printer for performance and pretty print
        public static object DataJson(ChartRequest request, ResultTable resultTable)
        {
            int index = 0;
            var cols  = request.Columns.Select((c, i) => new
            {
                name        = "c" + i,
                displayName = c.ScriptColumn.DisplayName,
                title       = c.GetTitle(),
                token       = c.Token?.Token.FullKey(),
                type        = c.Token?.Token.GetChartColumnType().ToString(),
                isGroupKey  = c.IsGroupKey,
                converter   = c.Token == null ? null : c.Converter(index++)
            }).ToList();

            if (!request.GroupResults)
            {
                cols.Insert(0, new
                {
                    name        = "entity",
                    displayName = "Entity",
                    title       = "",
                    token       = ChartColumnType.Lite.ToString(),
                    type        = "entity",
                    isGroupKey  = (bool?)true,
                    converter   = new Func <ResultRow, object>(r => r.Entity.Key())
                });
            }

            var parameters = request.Parameters.ToDictionary(p => p.Name, p => p.Value);

            return(new
            {
                columns = cols.ToDictionary(a => a.name, a => new
                {
                    a.title,
                    a.displayName,
                    a.token,
                    a.isGroupKey,
                    a.type,
                }),
                parameters = request.ChartScript.Parameters.ToDictionary(a => a.Name, a => parameters.TryGetC(a.Name) ?? a.DefaultValue(a.GetToken(request))),
                rows = resultTable.Rows.Select(r => cols.ToDictionary(a => a.name, a => a.converter == null ? null : a.converter(r))).ToList()
            });
        }
        public ActionResult Index(FindOptions findOptions)
        {
            ChartPermission.ViewCharting.AssertAuthorized();

            if (!Finder.IsFindable(findOptions.QueryName))
                throw new UnauthorizedAccessException(ChartMessage.Chart_Query0IsNotAllowed.NiceToString().FormatWith(findOptions.QueryName));

            QueryDescription queryDescription = DynamicQueryManager.Current.QueryDescription(findOptions.QueryName);

            FilterOption.SetFilterTokens(findOptions.FilterOptions, queryDescription, false);

            var request = new ChartRequest(findOptions.QueryName)
            {
                ChartScript = ChartScriptLogic.Scripts.Value.Values.FirstEx(() => "No ChartScript loaded in the database"),
                Filters = findOptions.FilterOptions.Select(fo => fo.ToFilter()).ToList()
            };

            return OpenChartRequest(request, null);
        }
Пример #6
0
        public static UserChartEntity ToUserChart(this ChartRequest request)
        {
            var result = new UserChartEntity
            {
                Owner = UserQueryUtils.DefaultOwner(),

                QueryName = request.QueryName,

                GroupResults = request.GroupResults,
                ChartScript  = request.ChartScript,

                Filters = request.Filters.Select(f => new QueryFilterEmbedded
                {
                    Token       = new QueryTokenEmbedded(f.Token),
                    Operation   = f.Operation,
                    ValueString = FilterValueConverter.ToString(f.Value, f.Token.Type),
                }).ToMList(),

                Orders = request.Orders.Select(o => new QueryOrderEmbedded
                {
                    Token     = new QueryTokenEmbedded(o.Token),
                    OrderType = o.OrderType
                }).ToMList()
            };

            result.Columns.ZipForeach(request.Columns, (u, r) =>
            {
                u.Token       = r.Token;
                u.DisplayName = r.DisplayName;
            });

            result.Parameters.ForEach(u =>
            {
                u.Value = request.Parameters.FirstOrDefault(r => r.Name == u.Name).Value;
            });

            return(result);
        }
Пример #7
0
        public static ChartRequest ToRequest(this UserChartEntity uq)
        {
            var result = new ChartRequest(uq.QueryName)
            {
                GroupResults = uq.GroupResults,
                ChartScript  = uq.ChartScript,
                Filters      = uq.Filters.Select(qf => new Filter(qf.Token.Token, qf.Operation,
                                                                  FilterValueConverter.Parse(qf.ValueString, qf.Token.Token.Type, qf.Operation.IsList()))).ToList(),
                Orders = uq.Orders.Select(o => new Order(o.Token.Token, o.OrderType)).ToList(),
            };

            result.Columns.ZipForeach(uq.Columns, (r, u) =>
            {
                r.Token       = u.Token;
                r.DisplayName = u.DisplayName;
            });

            result.Parameters.ForEach(r =>
            {
                r.Value = uq.Parameters.FirstOrDefault(u => u.Name == r.Name)?.Value ?? r.ScriptParameter.DefaultValue(r.ScriptParameter.GetToken(uq));
            });
            return(result);
        }
Пример #8
0
 public UserChartEntity FromQueryRequest(ChartRequest request)
 {
     return request.ToUserChart();
 }
Пример #9
0
        internal static void OpenChartRequest(ChartRequest chartRequest, UserChartEntity uc, Entity currentEntity)
        {
            Navigator.OpenIndependentWindow(() => 
            {
                var crw = new ChartRequestWindow()
                {
                    DataContext = chartRequest,
                    Title = ChartMessage.ChartOf0.NiceToString().FormatWith(QueryUtils.GetNiceName(chartRequest.QueryName)),
                    Icon = Finder.Manager.GetFindIcon(chartRequest.QueryName, false) ?? ExtensionsImageLoader.GetImageSortName("chartIcon.png")
                };

                if (uc != null)
                    SetUserChart(crw, uc);

                if (currentEntity != null)
                    UserAssetsClient.SetCurrentEntity(crw, currentEntity);

                return crw; 
            });
        }
Пример #10
0
        static MenuItem SearchControl_GetCustomMenuItems(SearchControl sc)
        {
            if (!ChartPermission.ViewCharting.IsAuthorized())
                return null;

            var miResult = new MenuItem
            {
                Header = ChartMessage.Chart.NiceToString(),
                Icon = ExtensionsImageLoader.GetImageSortName("chartIcon.png").ToSmallImage()
            };

            miResult.Click += delegate
            {
                var cr = new ChartRequest(sc.QueryName)
                {
                    Filters = sc.FilterOptions.Select(fo => fo.ToFilter()).ToList(),
                };

                ChartClient.OpenChartRequest(cr, null, null);
            };

            return miResult;
        }
Пример #11
0
 public ResultTable ExecuteChart(ChartRequest request)
 {
     return Return(MethodInfo.GetCurrentMethod(),
        () => ChartLogic.ExecuteChart(request));
 }
        ViewResult OpenChartRequest(ChartRequest request, Lite<UserChartEntity> currentUserChart)
        {
            ViewData[ViewDataKeys.Title] = QueryUtils.GetNiceName(request.QueryName);
            ViewData[ViewDataKeys.QueryDescription] = DynamicQueryManager.Current.QueryDescription(request.QueryName); ;
            ViewData[ViewDataKeys.FilterOptions] =  request.Filters.Select(f => new FilterOption { Token = f.Token, Operation = f.Operation, Value = f.Value }).ToList();
            ViewData["UserChart"] = currentUserChart;

            return View(ChartClient.ChartRequestView, new TypeContext<ChartRequest>(request, ""));
        }
        public MappingContext<ChartRequest> ExtractChartRequestCtx(int? lastTokenChanged)
        {
            var ctx = new ChartRequest(Finder.ResolveQueryName(Request.Params["webQueryName"]))
                .ApplyChanges(this, ChartClient.MappingChartRequest, inputs: Request.Params.ToSortedList(this.Prefix()));

            ctx.Value.CleanOrderColumns();

            ChartRequest chart = ctx.Value;
            if (lastTokenChanged != null)
            {
                if (lastTokenChanged == -1)
                    chart.ChartScript.SyncronizeColumns(chart); 
                else
                    chart.Columns[lastTokenChanged.Value].TokenChanged();
            }

            return ctx;
        }
Пример #14
0
        internal static void FixParameters(ChartRequest chartRequest, ChartColumnEntity chartColumn)
        {
            int index = chartRequest.Columns.IndexOf(chartColumn);

            foreach (var p in chartRequest.Parameters.Where(p => p.ScriptParameter.ColumnIndex == index))
	        {
                if (p.PropertyCheck(() => p.Value).HasText())
                    p.Value = p.ScriptParameter.DefaultValue(chartColumn.Token.Try(t => t.Token));
	        }
        }
Пример #15
0
        //Manual Json printer for performance and pretty print
        public static object DataJson(ChartRequest request, ResultTable resultTable)
        {
            int index = 0;
            var cols = request.Columns.Select((c, i) => new
            {
                name = "c" + i,
                displayName = request.Columns[i].ScriptColumn.DisplayName,
                title = c.GetTitle(),
                token = c.Token == null ? null : c.Token.Token.FullKey(),
                type = c.Token == null ? null : c.Token.Token.GetChartColumnType().ToString(),               
                isGroupKey = c.IsGroupKey,
                converter = c.Token == null ? null : c.Converter(index++)
            }).ToList();

            if (!request.GroupResults)
            {
                cols.Insert(0, new
                {
                    name = "entity",
                    displayName = "Entity",
                    title = "",
                    token = ChartColumnType.Lite.ToString(),
                    type = "entity",
                    isGroupKey = (bool?)true,
                    converter = new Func<ResultRow, object>(r => r.Entity.Key())
                });
            }

            var parameters = request.Parameters.ToDictionary(p=> p.Name, p => p.Value);

            return new
            {
                columns = cols.ToDictionary(a => a.name, a => new
                {
                    a.title,
                    a.displayName,
                    a.token,
                    a.isGroupKey,
                    a.type,
                }),
                parameters = request.ChartScript.Parameters.ToDictionary(a => a.Name, a => parameters.TryGetC(a.Name) ?? a.DefaultValue(a.GetToken(request))),
                rows = resultTable.Rows.Select(r => cols.ToDictionary(a => a.name, a => a.converter == null ? null : a.converter(r))).ToList()
            };
        }
Пример #16
0
        public static ChartRequest ToRequest(this UserChartEntity uq)
        {
            var result = new ChartRequest(uq.QueryName)
            {
                GroupResults = uq.GroupResults,
                ChartScript = uq.ChartScript,
                Filters = uq.Filters.Select(qf => new Filter(qf.Token.Token, qf.Operation,
                    FilterValueConverter.Parse(qf.ValueString, qf.Token.Token.Type, qf.Operation == FilterOperation.IsIn))).ToList(),
                Orders = uq.Orders.Select(o => new Order(o.Token.Token, o.OrderType)).ToList(),
            };

            result.Columns.ZipForeach(uq.Columns, (r, u) =>
            {
                r.Token = u.Token;
                r.DisplayName = u.DisplayName;
            });

            result.Parameters.ForEach(r =>
            {
                r.Value = uq.Parameters.FirstOrDefault(u => u.Name == r.Name).Try(a => a.Value) ?? r.ScriptParameter.DefaultValue(r.ScriptParameter.GetToken(uq));
            });
            return result;
        }