internal async Task<string> RenderPropertyListTabbedAsync(object model, bool readOnly) { List<string> categories = GetCategories(model); if (categories.Count <= 1) // if there is only one category, show as regular property list return await RenderPropertyListAsync(model, readOnly); PropertyList.PropertyListSetup setup = await PropertyListComponentBase.GetPropertyListSetupAsync(model, categories); categories = setup.CategoryOrder; HtmlBuilder hb = new HtmlBuilder(); Type modelType = model.GetType(); ClassData classData = ObjectSupport.GetClassData(modelType); RenderHeader(hb, classData); string divId = Manager.UniqueId(); bool showVariables = YetaWF.Core.Localize.UserSettings.GetProperty<bool>("ShowVariables"); switch (setup.Style) { default: case PropertyList.PropertyListStyleEnum.Tabbed: UI ui = new UI { TabsDef = new TabsDefinition() }; int activeTab = 0; if (ObjectSupport.TryGetPropertyValue<int>(model, "_ActiveTab", out activeTab)) ui.TabsDef.ActiveTabIndex = activeTab; foreach (string category in categories) { string cat = category; if (classData.Categories.ContainsKey(cat)) cat = classData.Categories[cat]; ui.TabsDef.Tabs.Add(new TabEntry { Caption = cat, RenderPaneAsync = async (int tabIndex) => { return (await RenderListAsync(model, category, showVariables, readOnly)).ToString(); }, }); } hb.Append($@" <div id='{divId}' class='yt_propertylist t_tabbed {(readOnly ? "t_display" : "t_edit")}'> {await RenderHiddenAsync(model)} {await HtmlHelper.ForDisplayAsync(ui, nameof(ui.TabsDef), HtmlAttributes: new { __NoTemplate = true })} </div>"); break; case PropertyList.PropertyListStyleEnum.BoxedWithCategories: await Manager.AddOnManager.AddAddOnNamedAsync(AreaRegistration.CurrentPackage.AreaName, "masonry.desandro.com"); hb.Append($@" <div id='{divId}' class='yt_propertylist t_boxedcat {(readOnly ? "t_display" : "t_edit")}'> {await RenderHiddenAsync(model)}"); foreach (string category in categories) { string contents = await RenderListAsync(model, category, showVariables, readOnly); if (!string.IsNullOrWhiteSpace(contents)) { string stat = ""; if (setup.ExpandableList.Contains(category)) stat = (setup.InitialExpanded == category) ? " t_propexpandable t_propexpanded" : " t_propexpandable t_propcollapsed"; hb.Append($@" <div class='t_proptable{stat} t_cat t_boxpanel-{GetCategoryNormalized(category)}'> <div class='t_boxlabel'>{category}</div>"); if (setup.ExpandableList.Contains(category)) hb.Append(@$"<div class='t_boxexpcoll t_show'></div>"); hb.Append($@" {contents} </div>"); } } hb.Append($@" </div>"); break; case PropertyList.PropertyListStyleEnum.Boxed: await Manager.AddOnManager.AddAddOnNamedAsync(AreaRegistration.CurrentPackage.AreaName, "masonry.desandro.com"); hb.Append($@" <div id='{divId}' class='yt_propertylist t_boxed {(readOnly ? "t_display" : "t_edit")}'> {await RenderHiddenAsync(model)}"); foreach (string category in categories) { string contents = await RenderListAsync(model, category, showVariables, readOnly); if (!string.IsNullOrWhiteSpace(contents)) { string stat = ""; if (setup.ExpandableList.Contains(category)) stat = (setup.InitialExpanded == category) ? " t_propexpandable t_propexpanded" : " t_propexpandable t_propcollapsed"; hb.Append($@" <div class='t_proptable {stat} t_cat t_boxpanel-{GetCategoryNormalized(category)}'>"); if (setup.ExpandableList.Contains(category)) hb.Append($"<div class='t_boxexpcoll t_show'></div>"); hb.Append($@" {contents} </div>"); } } hb.Append($@" </div>"); break; } RenderFooter(hb, classData); ControlData cd = null; if (!readOnly) cd = GetControlSets(model, divId); if (setup.ExpandableList != null) { // normalize category names for javascript setup.ExpandableList = (from l in setup.ExpandableList select GetCategoryNormalized(l)).ToList(); } if (setup.InitialExpanded != null) setup.InitialExpanded = GetCategoryNormalized(setup.InitialExpanded); Manager.ScriptManager.AddLast($@"new YetaWF_ComponentsHTML.PropertyListComponent('{divId}', {Utility.JsonSerialize(setup)}, {Utility.JsonSerialize(cd)});"); return hb.ToString(); }
internal static async Task <PropertyList.PropertyListSetup> GetPropertyListSetupAsync(object obj, List <string> categories) { Type setupType = obj.GetType(); if (obj as ModuleDefinition != null) { setupType = typeof(ModuleDefinition); } Type objType = obj.GetType(); PropertyList.PropertyListSetup setup = await PropertyList.LoadPropertyListDefinitionsAsync(setupType); if (setup.ExplicitDefinitions) { // Invoke __PropertyListSetupAsync MethodInfo miAsync = objType.GetMethod("__PropertyListSetupAsync", new Type[] { typeof(PropertyList.PropertyListSetup) }); if (miAsync != null) { Task methRetvalTask = (Task)miAsync.Invoke(obj, new object[] { setup }); await methRetvalTask; } // sanity checking if (YetaWFManager.DiagnosticsMode) { // verify expandable list foreach (string cat in setup.ExpandableList) { if (!categories.Contains(cat)) { throw new InternalError($"Unknown category {cat} is used in {nameof(PropertyList.PropertyListSetup.ExpandableList)} for {objType.FullName}"); } } // verify initial expanded if (setup.InitialExpanded != null) { if (!categories.Contains(setup.InitialExpanded)) { throw new InternalError($"Unknown category {setup.InitialExpanded} is used in {nameof(PropertyList.PropertyListSetup.InitialExpanded)} for {objType.FullName}"); } } // verify styles int startWidth = 0; foreach (PropertyList.PropertyListColumnDef colDef in setup.ColumnStyles) { if (colDef.MinWindowSize < startWidth) { throw new InternalError($"Column styles in {nameof(PropertyList.PropertyListSetup.ColumnStyles)} are not in ascending order, entry with {nameof(PropertyList.PropertyListColumnDef.MinWindowSize)} = {colDef.MinWindowSize} is out of order"); } startWidth = colDef.MinWindowSize; } // verify order foreach (string cat in setup.CategoryOrder) { if (!categories.Contains(cat)) { throw new InternalError($"Unknown category {cat} is used in {nameof(PropertyList.PropertyListSetup.ExpandableList)} for {objType.FullName}"); } } // verify order List <string> missing = categories.ToList(); foreach (string cat in setup.CategoryOrder) { if (!categories.Contains(cat)) { throw new InternalError($"Category {cat} listed in category order doesn't exist"); } missing.Remove(cat); } setup.CategoryOrder.AddRange(missing);//add remaining categories to list } } else { setup.CategoryOrder = categories; } return(setup); }