Esempio n. 1
0
 private static void DoDateFormatColumnUsage <TSourceData, TTableData, TTableColumn>(ColumnUsage <TSourceData, TTableData, TTableColumn> col, string format = null, bool utc = false) where TTableData : new()
 {
     col.Template(
         c =>
         c.EmptyIfNotPresent(col.ColumnConfiguration.RawColumnName)
         .Returns(string.Format("`dateFormat({{{0}}},'{1}',{2})`", col.ColumnConfiguration.RawColumnName, format, utc ? "true" : "false")));
 }
Esempio n. 2
0
        /// <summary>
        /// Shortcut for creating JS function that formats enum-typed column values to specified text specified using enum's fields [Display] attribute.
        /// This method uses MVC GetSelectList function to retrieve enum values.
        /// </summary>
        /// <param name="column">Colum to apply formatting</param>
        /// <param name="content">Content for particular select list item</param>
        /// <returns>Fluent</returns>
        public static ColumnUsage <TSourceData, TTableData, TTableColumn> FormatEnumWithDisplayAttribute
        <TSourceData, TTableData, TTableColumn>(
            this ColumnUsage <TSourceData, TTableData, TTableColumn> column,
            Action <Template, SelectListItem> content
            ) where TTableData : new()
        {
            var enumType = typeof(TTableColumn);

            if (typeof(Nullable <>).IsAssignableFrom(enumType))
            {
                enumType = enumType.GetGenericArguments()[0];
            }
            if (!typeof(Enum).IsAssignableFrom(enumType))
            {
                throw new Exception(
                          String.Format("This method is only applicable for enum columns. {0} column of table {1} is not of enum type",
                                        column.ColumnProperty.Name,
                                        typeof(TTableData).FullName
                                        ));
            }
            var items = EnumHelper.GetSelectList(enumType);

            column.Template(a => a.EmptyIfNotPresent(column.ColumnConfiguration.RawColumnName)
                            .Switch("{" + column.ColumnConfiguration.RawColumnName + "}",
                                    swtch =>
                                    swtch
                                    .Cases(items, c => c.Value, (tpl, v) => content(tpl.Content(v.Text), v))
                                    .DefaultEmpty()
                                    )

                            );
            return(column);
        }
Esempio n. 3
0
 /// <summary>
 /// Shortcut for formatting table cell as link for specified column
 /// </summary>
 /// <typeparam name="TSourceData"></typeparam>
 /// <typeparam name="TTableData"></typeparam>
 /// <typeparam name="TTableColumn"></typeparam>
 /// <param name="col">Column</param>
 /// <param name="linkFormat">Link format. Use " + v.Something + " or "{Something}" to substitute table value</param>
 /// <param name="textFormat">Link text format. Use " + v.Something + " or "{Something}" to substitute table value</param>
 /// <param name="target">Link target. User "_blank" or something similar.</param>
 /// <returns>Fluent</returns>
 public static ColumnUsage <TSourceData, TTableData, TTableColumn> Link <TSourceData, TTableData, TTableColumn>(
     this ColumnUsage <TSourceData, TTableData, TTableColumn> col, string linkFormat, string textFormat, string target = null) where TTableData : new()
 {
     return(col.Template(c =>
     {
         c.EmptyIfNotPresent(col.ColumnConfiguration.RawColumnName);
         c.Returns(a => a.Tag("a").Attr("href", linkFormat).Content(textFormat).Attr("target", target));
     }));
 }
Esempio n. 4
0
 /// <summary>
 /// Shortcut for creating JS function that formats boolean column values to specified text
 /// </summary>
 /// <typeparam name="TSourceData"></typeparam>
 /// <typeparam name="TTableData"></typeparam>
 /// <param name="column">Column</param>
 /// <param name="trueText">Text when value is TRUE</param>
 /// <param name="falseText">Text when value is FALSE</param>
 /// <returns>Fluent</returns>
 public static ColumnUsage <TSourceData, TTableData, bool> TextForBoolean
 <TSourceData, TTableData>(
     this ColumnUsage <TSourceData, TTableData, bool> column, string trueText, string falseText
     ) where TTableData : new()
 {
     column.Template(
         tpl =>
         tpl.ReturnsIf("{" + column.ColumnConfiguration.RawColumnName + "}", v => v.Content(trueText),
                       v => v.Content(falseText)));
     return(column);
 }