Example #1
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public async Task <string> RenderContainerAsync(GridRecordData model)
        {
            ScriptBuilder sb = new ScriptBuilder();

            GridDictionaryInfo.ReadGridDictionaryInfo dictInfo = await GridDictionaryInfo.LoadGridColumnDefinitionsAsync(model.GridDef);

            // render record
            string tr = await GridDisplayComponent.RenderRecordHTMLAsync(HtmlHelper, model.GridDef, dictInfo, model.FieldPrefix, model.Data, 0, 0, false);

            GridRecordResult result = new GridRecordResult {
                TR         = tr,
                StaticData = model.Data,
            };

            sb.Append(Utility.JsonSerialize(result));

            return(sb.ToString());
        }
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public async Task <string> RenderContainerAsync(GridPartialData model)
        {
            ScriptBuilder sb = new ScriptBuilder();

            GridDictionaryInfo.ReadGridDictionaryInfo dictInfo = await GridDictionaryInfo.LoadGridColumnDefinitionsAsync(model.GridDef);

            // render all records
            string data = await GridDisplayComponent.RenderTableHTML(HtmlHelper, model.GridDef, model.Data, model.StaticData, dictInfo, model.FieldPrefix, true, model.Skip, model.Take);

            data += Manager.ScriptManager.RenderEndofPageScripts();// portions generated by components

            int pages    = 0;
            int page     = 0;
            int pageSize = model.Take;

            if (model.Data.Total > 0)
            {
                if (model.Take == 0)
                {
                    pages    = 1;
                    pageSize = 0;
                }
                else
                {
                    pages = Math.Max(1, model.Data.Total / model.Take + (model.Data.Total % model.Take == 0 ? 0 : 1));
                    page  = Math.Max(model.Skip / model.Take, 0);
                }
            }

            GridPartialResult result = new GridPartialResult {
                Records  = model.Data.Total,
                TBody    = data,
                Pages    = pages,
                Page     = page,
                PageSize = pageSize,
            };

            sb.Append(Utility.JsonSerialize(result));

            return(sb.ToString());
        }
Example #3
0
        /// <summary>
        /// Loads the grid column definitions for a grid.
        /// </summary>
        /// <param name="recordType">The record type for which grid column definitions are to be loaded.</param>
        /// <returns>A GridDictionaryInfo.ReadGridDictionaryInfo object describing the grid.</returns>
        /// <remarks>This method is not used by applications. It is reserved for component implementation.</remarks>
        private static async Task <GridDictionaryInfo.ReadGridDictionaryInfo> LoadGridColumnDefinitionsAsync(Type recordType)
        {
            Dictionary <string, GridColumnInfo> dict = new Dictionary <string, GridColumnInfo>();
            string className = recordType.FullName.Split(new char[] { '.' }).Last();

            string[] s   = className.Split(new char[] { '+' });
            int      len = s.Length;

            if (len != 2)
            {
                throw new InternalError("Unexpected class {0} in record type {1}", className, recordType.FullName);
            }
            string  controller = s[0];
            string  model      = s[1];
            string  file       = controller + "." + model;
            Package package    = Package.GetPackageFromType(recordType);
            string  predefUrl  = VersionManager.GetAddOnPackageUrl(package.AreaName) + "Grids/" + file;
            string  customUrl  = VersionManager.GetCustomUrlFromUrl(predefUrl);

            GridDictionaryInfo.ReadGridDictionaryInfo info;
            GridDictionaryInfo.ReadGridDictionaryInfo predefInfo = await GridDictionaryInfo.ReadGridDictionaryAsync(package, recordType, Utility.UrlToPhysical(predefUrl));

            if (!predefInfo.Success)
            {
                throw new InternalError("No grid definition exists for {0}", file);
            }
            info = predefInfo;
            GridDictionaryInfo.ReadGridDictionaryInfo customInfo = await GridDictionaryInfo.ReadGridDictionaryAsync(package, recordType, Utility.UrlToPhysical(customUrl));

            if (customInfo.Success)
            {
                info = customInfo;
            }
            if (info.ColumnInfo.Count == 0)
            {
                throw new InternalError("No grid definition exists for {0}", file);
            }
            return(info);
        }
Example #4
0
        public static async Task SaveSettingsAsync(GridPartialData gridData)
        {
            // save the current sort order and page size
            if (gridData.GridDef.SettingsModuleGuid != null && gridData.GridDef.SettingsModuleGuid != Guid.Empty)
            {
                GridLoadSave.GridSavedSettings gridSavedSettings = GridLoadSave.LoadModuleSettings((Guid)gridData.GridDef.SettingsModuleGuid);
                gridSavedSettings.PageSize = gridData.Take;
                if (gridData.Take == 0)
                {
                    gridSavedSettings.CurrentPage = 1;
                }
                else
                {
                    gridSavedSettings.CurrentPage = Math.Max(1, gridData.Skip / gridData.Take + 1);
                }
                foreach (GridDefinition.ColumnInfo col in gridSavedSettings.Columns.Values)
                {
                    col.Sort = GridDefinition.SortBy.NotSpecified;
                }
                if (gridData.Sorts != null)
                {
                    foreach (var sortCol in gridData.Sorts)
                    {
                        GridDefinition.SortBy sortDir = (sortCol.Order == DataProviderSortInfo.SortDirection.Ascending) ? GridDefinition.SortBy.Ascending : GridDefinition.SortBy.Descending;
                        if (gridSavedSettings.Columns.ContainsKey(sortCol.Field))
                        {
                            gridSavedSettings.Columns[sortCol.Field].Sort = sortDir;
                        }
                        else
                        {
                            gridSavedSettings.Columns.Add(sortCol.Field, new GridDefinition.ColumnInfo {
                                Sort = sortDir
                            });
                        }
                    }
                }
                GridDictionaryInfo.ReadGridDictionaryInfo dictInfo = await GridDictionaryInfo.LoadGridColumnDefinitionsAsync(gridData.GridDef);

                foreach (GridDefinition.ColumnInfo col in gridSavedSettings.Columns.Values)
                {
                    col.FilterOperator = null;
                    col.FilterValue    = null;
                }
                if (gridData.Filters != null && dictInfo.SaveColumnFilters != false)
                {
                    foreach (var filterCol in gridData.Filters)
                    {
                        if (gridSavedSettings.Columns.ContainsKey(filterCol.Field))
                        {
                            gridSavedSettings.Columns[filterCol.Field].FilterOperator = filterCol.Operator;
                            gridSavedSettings.Columns[filterCol.Field].FilterValue    = filterCol.ValueAsString;
                        }
                        else
                        {
                            gridSavedSettings.Columns.Add(filterCol.Field, new GridDefinition.ColumnInfo {
                                FilterOperator = filterCol.Operator,
                                FilterValue    = filterCol.ValueAsString,
                            });
                        }
                    }
                }
                GridLoadSave.SaveModuleSettings((Guid)gridData.GridDef.SettingsModuleGuid, gridSavedSettings);
            }
        }