예제 #1
0
        public ActionResult UpdateColumnWidth(int reportId, string columnName, int width)
        {
            try
            {
                var userReport = GetUserReport(reportId, GetLoggedUserId());

                var outputConfig = new JavaScriptSerializer().Deserialize<List<ReportColumn>>(userReport.OutputConfiguration);

                var column = outputConfig.FirstOrDefault(col => col.Name == columnName);

                if (!column.IsNull())
                {
                    column.Width = width;

                    var updatedOutputConfig = new JavaScriptSerializer().Serialize(outputConfig);

                    UpdateUserReportOutPutConfig(reportId, GetLoggedUserId(), updatedOutputConfig);
                }

                return Json(true);
            }
            catch (Exception)
            {
                return null;
            }
        }
예제 #2
0
        private List<ReportColumn> GetReportColumns(UserReportViewModel userReport)
        {
            try
            {
                var userLogged = Session[Utils.UserKey] as UserModel;

                var userLevel = Utils.GetUserLevel(userLogged.UserCategory);

                var userReportOutPut = userReport.Output.Split(',').ToList();

                var reportDefaultOutput = userReport.DefaultOuput.Split(',').ToList();

                var userReportFilterableColumns = userReport.UserFilters.Split(',');

                var columnsConfig = new JavaScriptSerializer().Deserialize<List<ReportColumn>>(userReport.OutputConfiguration);

                var result = (from column in reportDefaultOutput
                    let columnConfig = columnsConfig.FirstOrDefault(col => col.Name == column)
                    select new ReportColumn
                    {
                        Name = column,
                        Level = columnConfig.IsNull() ? 0 : columnConfig.Level,
                        Selected = userReportOutPut.Contains(column) && userLevel >= (columnConfig.IsNull() ? 0 : columnConfig.Level),
                        Filterable = userReportFilterableColumns.Contains(column),
                        Width = columnConfig.IsNull() ? 120 : columnConfig.Width,
                        Index = columnConfig.IsNull() ? 0 : columnConfig.Index,
                        Label = Utils.GetColumnLabel(userReport.Labels, column)
                    }).ToList();

                result.Sort((a, b) => a.Index.CompareTo(b.Index));

                return result;
            }
            catch (Exception exception)
            {
                return null;
            }
        }
예제 #3
0
        public ActionResult UpdateColumnOrder(int reportId, string columnName, int oldIndex, int newIndex)
        {
            try
            {
                var userReport = GetUserReport(reportId, GetLoggedUserId());

                var currentOutput = userReport.Output;

                var outputConfig = new JavaScriptSerializer().Deserialize<List<ReportColumn>>(userReport.OutputConfiguration);

                var column = outputConfig.FirstOrDefault(col => col.Name == columnName);

                if (!column.IsNull())
                {
                    //Right offset
                    if (newIndex > oldIndex)
                    {
                        foreach (var col in outputConfig.Where(colum => colum.Index <= newIndex && colum.Index > oldIndex))
                            col.Index--;
                    }
                    else
                    {
                        //Left offset
                        foreach (var col in outputConfig.Where(colum => colum.Index >= newIndex && colum.Index < oldIndex))
                            col.Index++;
                    }

                    column.Index = newIndex;

                    var updatedOutputConfig = new JavaScriptSerializer().Serialize(outputConfig);

                    UpdateUserReportOutPutConfig(reportId, GetLoggedUserId(), updatedOutputConfig);
                }

                return Json(true);
            }
            catch (Exception)
            {
                return null;
            }
        }