private static string Label( Context context, Column groupBy, string selectedValue, Dictionary <string, string> linkedLabelHash) { if (groupBy.Type != Column.Types.Normal) { return(SiteInfo.Name( context: context, id: selectedValue.ToInt(), type: groupBy.Type)); } else if (groupBy.HasChoices()) { var label = linkedLabelHash != null ? linkedLabelHash?.Get(selectedValue) : groupBy.Choice(selectedValue).TextMini; return(label.IsNullOrEmpty() ? NumericZero(groupBy, selectedValue) ? Displays.NotSet(context: context) : StringEmpty(groupBy, selectedValue) ? Displays.NotSet(context: context) : "? " + selectedValue : label); } else { return(selectedValue); } }
public object ToApiDisplayValue(Context context, SiteSettings ss, Column column) { var name = SiteInfo.Name( context: context, id: Id, type: Column.Types.User); return(!name.IsNullOrEmpty() ? name : null); }
private string GetDisplayValue( Context context, SiteSettings ss, Column column, Dictionary <string, string> data, bool getLinkedTitle = false) { switch (column.TypeName.CsTypeSummary()) { case Types.CsNumeric: return(column.HasChoices() ? column.Type != Column.Types.Normal ? SiteInfo.Name( context: context, id: data.Get(column.ColumnName).ToInt(), type: column.Type) : column.Choice(data.Get(column.ColumnName)).Text : column.Display( context: context, value: data.Get(column.ColumnName).ToDecimal(), unit: true)); case Types.CsDateTime: switch (column.ColumnName) { case "CompletionTime": return(column.DisplayControl( context: context, value: new CompletionTime( context: context, ss: ss, value: data.Get(column.ColumnName).ToDateTime()).DisplayValue)); default: return(column.DisplayControl( context: context, value: data.Get(column.ColumnName) .ToDateTime() .ToLocal(context: context))); } case Types.CsString: return(column.HasChoices() ? getLinkedTitle ? column.LinkedTitleChoice( context: context, selectedValue: data.Get(column.ColumnName)).Text : column.Choice(selectedValue: data.Get(column.ColumnName)).Text : data.Get(column.ColumnName)); default: return(data.Get(column.ColumnName)); } }
private string GetDisplayValue( Context context, SiteSettings ss, Column column, DataRow dataRow, string path) { switch (column.TypeName.CsTypeSummary()) { case Types.CsNumeric: return(column.HasChoices() ? column.Type != Column.Types.Normal ? SiteInfo.Name( context: context, id: dataRow.Int(path), type: column.Type) : column.Choice(dataRow.Long(path).ToString()).Text : column.Display( context: context, value: dataRow.Decimal(path), unit: true)); case Types.CsDateTime: switch (path) { case "CompletionTime": return(column.DisplayControl( context: context, value: new CompletionTime( context: context, ss: ss, dataRow: dataRow, column: new ColumnNameInfo(path)).DisplayValue)); default: return(column.DisplayControl( context: context, value: dataRow.DateTime(path).ToLocal(context: context))); } case Types.CsString: return(column.HasChoices() ? column.Choice(dataRow.String(path)).Text : dataRow.String(path)); default: return(dataRow.String(path)); } }
public static HtmlBuilder Td( this HtmlBuilder hb, Context context, Column column, string value, int?tabIndex) { return(column.HasChoices() ? hb.Td( css: column.CellCss(), action: () => { if (column.Type != Column.Types.Normal && !value.IsNullOrEmpty() && !column.ChoiceHash.ContainsKey(value)) { column.ChoiceHash.AddIfNotConainsKey( value, new Choice(SiteInfo.Name( context: context, id: value.ToInt(), type: column.Type))); } var choice = column.Choice( value, nullCase: value.IsNullOrEmpty() ? null : "? " + value); hb.P( attributes: new HtmlAttributes() .Class(choice.CssClass) .Style(choice.Style), action: () => hb .Text(choice.TextMini)); }) : column.ControlType == "MarkDown" ? hb.Td( css: column.CellCss(), action: () => hb .Div(css: "grid-title-body", action: () => hb .P(css: "body markup", action: () => hb .Text(text: value)))) : hb.Td( css: column.CellCss(), action: () => hb .Text(text: value))); }
private static Dictionary<string, ControlData> OptionCollection( Context context, Dictionary<string, ControlData> optionCollection = null, string selectedValue = null, bool multiple = false, bool addSelectedValue = true, bool insertBlank = false, Column column = null) { if (insertBlank) { optionCollection = InsertBlank(optionCollection); } if (selectedValue == null || selectedValue == string.Empty || optionCollection?.ContainsKey(selectedValue) == true || selectedValue == "0" || multiple || !addSelectedValue) { return optionCollection; } else { var selectedId = selectedValue.ToInt(); optionCollection?.Add( selectedValue, column != null && column.Type != Column.Types.Normal ? new ControlData(SiteInfo.Name( context: context, id: selectedId, type: column.Type)) : new ControlData("? " + selectedValue)); return optionCollection; } }
private string GetDisplayValue( Context context, SiteSettings ss, Column column, Dictionary <string, string> data, bool getLinkedTitle = false) { if (column.Type != Column.Types.Normal) { return(column.MultipleSelections == true ? data.Get(column.ColumnName).Deserialize <List <string> >() ?.Select(col => SiteInfo.Name( context: context, id: col.ToInt(), type: column.Type)) .Join() : SiteInfo.Name( context: context, id: data.Get(column.ColumnName).ToInt(), type: column.Type)); } switch (column.TypeName.CsTypeSummary()) { case Types.CsNumeric: return(column.HasChoices() ? column.Choice(data.Get(column.ColumnName)).Text : column.Display( context: context, value: data.Get(column.ColumnName).ToDecimal(), unit: true)); case Types.CsDateTime: switch (column.ColumnName) { case "CompletionTime": return(column.DisplayControl( context: context, value: new CompletionTime( context: context, ss: ss, value: data.Get(column.ColumnName).ToDateTime()).DisplayValue)); default: return(column.DisplayControl( context: context, value: data.Get(column.ColumnName) .ToDateTime() .ToLocal(context: context))); } case Types.CsString: return(column.HasChoices() ? getLinkedTitle || column.Linked(withoutWiki: true) ? column.LinkedTitleChoice( context: context, selectedValues: data.Get(column.ColumnName)).Text : column.MultipleSelections == true ? data.Get(column.ColumnName).Deserialize <List <string> >() ?.Select(col => column.Choice(selectedValue: col).Text) .Join() : column.Choice(selectedValue: data.Get(column.ColumnName)).Text : data.Get(column.ColumnName)); default: return(data.Get(column.ColumnName)); } }
private static HtmlBuilder DropDown( this HtmlBuilder hb, Context context, SiteSettings ss, Column column, View view, Dictionary <string, ControlData> optionCollection, string idPrefix = "ViewFilters__", string action = null, bool controlOnly = false) { var selectedValue = view.ColumnFilter(column.ColumnName); if (column.UseSearch == true) { selectedValue?.Deserialize <List <string> >()?.ForEach(value => { if (column.Type != Settings.Column.Types.Normal) { var id = value.ToInt(); if (id > 0 && !(column.Type == Settings.Column.Types.User && id == User.UserTypes.Anonymous.ToInt())) { optionCollection.AddIfNotConainsKey( value, new ControlData(SiteInfo.Name( context: context, id: id, type: column.Type))); } } else { HtmlFields.EditChoices( context: context, ss: ss, column: column, value: value) .ForEach(data => optionCollection.AddIfNotConainsKey(data.Key, data.Value)); } }); } return(hb.FieldDropDown( context: context, controlId: idPrefix + column.ColumnName, fieldCss: "field-auto-thin", controlCss: " auto-postback" + (column.UseSearch == true ? " search" : string.Empty), labelText: Displays.Get( context: context, id: column.GridLabelText), labelTitle: ss.LabelTitle(column), controlOnly: controlOnly, action: action, optionCollection: optionCollection, selectedValue: selectedValue, multiple: true, addSelectedValue: false, method: "post", column: column)); }
private static string SelectSearchDropDownResponse( Context context, string controlId, Column column, List <string> selected, bool filter, bool multiple) { if (selected.Any() && column.UseSearch == true && column.Type != Column.Types.Normal && !selected.All(o => column.ChoiceHash.ContainsKey(o))) { switch (column.Type) { case Column.Types.User: selected .Select(userId => SiteInfo.User( context: context, userId: userId.ToInt())) .Where(o => !o.Anonymous()) .ForEach(user => column.ChoiceHash.AddIfNotConainsKey( user.Id.ToString(), new Choice( value: user.Id.ToString(), text: user.Name))); break; default: selected .Select(id => new { Id = id.ToInt(), Name = SiteInfo.Name( context: context, id: id.ToInt(), type: column.Type) }) .Where(o => o.Id != 0 && !o.Name.IsNullOrEmpty()) .ForEach(data => column.ChoiceHash.AddIfNotConainsKey( data.Id.ToString(), new Choice( value: data.Id.ToString(), text: data.Name))); break; } } if (selected.Any() && !selected.All(o => column.ChoiceHash.ContainsKey(o))) { column.SiteSettings.SetChoiceHash( context: context, columnName: column.ColumnName, selectedValues: selected); } var optionCollection = column?.EditChoices( context: context, addNotSet: true)? .Where(o => selected.Contains(o.Key)) .ToDictionary(o => o.Key, o => o.Value); return(optionCollection?.Any() == true || !selected.Any() ? new ResponseCollection() .CloseDialog("#DropDownSearchDialog") .Html("[id=\"" + controlId + "\"]", new HtmlBuilder() .OptionCollection( context: context, optionCollection: optionCollection, selectedValue: SelectSearchDropDownSelectedValue( context: context, selected: selected, filter: filter, multiple: multiple), multiple: multiple, insertBlank: !filter)) .Invoke("setDropDownSearch") .Trigger("#" + controlId, "change") .ToJson() : new ResponseCollection() .Message(Messages.NotFound(context: context)) .ToJson()); }