Пример #1
0
 public ClassFieldRemoteMutator <decimal, decimal, ContT> BuildDecimal(
     Expression <Func <ContT, decimal> > getField, InputView view, DecimalFormat format,
     params Validate <decimal>[] validators)
 {
     view.RaisesChangedOnKeyPressed = false;
     return(Build(getField, view, x => I18n.Localize(x, format), x => I18n.ParseDecimal(x), validators));
 }
 public static Tuple <HTMLElement, DataGridColumnControllerResult <bool> > ForBool(
     ITransformationMediator listener,
     params GrouperDefOrAggregatorDef <bool>[] additionalGrouperOrAggr)
 {
     return(Create(
                listener,
                new [] {
         new FilterDef <bool>(
             I18n.Translate("is true"),
             (_, x) => x),
         new FilterDef <bool>(
             I18n.Translate("is false"),
             (_, x) => !x)
     },
                new List <AggregatorDef <bool> > {
         new AggregatorDef <bool>(CountAggregatorLabel, x => I18n.Localize(x.Count())),
         new AggregatorDef <bool>(I18n.Translate("Count ☑"), x => I18n.Localize(x.Count(y => y))),
         new AggregatorDef <bool>(I18n.Translate("Count ☐"), x => I18n.Localize(x.Count(y => !y))),
     }.Concat(additionalGrouperOrAggr.Where(x => x.Aggregator != null).Select(x => x.Aggregator)),
                new List <GrouperDef <bool> > {
         new GrouperDef <bool>(GroupEverythingAsOneGroupLabel,
                               RecordGroupingUtil.GroupAllRecordsAsOneGroup),
         new GrouperDef <bool>(UniqueValueGroupLabel,
                               x => RecordGroupingUtil.GroupRecordsByKey(x, y => y, y => y.KeyData.ToString()))
     }.Concat(additionalGrouperOrAggr.Where(x => x.Grouper != null).Select(x => x.Grouper)),
                x => {
         var val = new InputView("");
         val.Widget.Style.Visibility = Visibility.Hidden;     //occupies space so filters stay aligned
         return val;
     },
                default(bool),
                default(bool),
                Comparer <bool> .Default
                ));
 }
        public static Tuple <HTMLElement, DataGridColumnControllerResult <DateTime?> > ForNullableDateTime(
            DateTimeFormat format,
            ITransformationMediator listener,
            params GrouperDefOrAggregatorDef <DateTime?>[] additionalGrouperOrAggr)
        {
            var EmptyLabel = I18n.Translate("(empty)");
            var groupEverythingAsOneGroupLabel = GroupEverythingAsOneGroupLabel;

            return(Create(
                       listener,
                       new [] {
                new FilterDef <DateTime?>(
                    I18n.Translate("equals"),
                    (filterParam, x) => x.HasValue && x == filterParam),
                new FilterDef <DateTime?>(
                    I18n.Translate("doesn't equal"),
                    (filterParam, x) => x.HasValue && x != filterParam),
                new FilterDef <DateTime?>(
                    I18n.Translate("is after"),
                    (filterParam, x) => x.HasValue && x > filterParam),
                new FilterDef <DateTime?>(
                    I18n.Translate("is before"),
                    (filterParam, x) => x.HasValue && x < filterParam)
            },
                       new List <AggregatorDef <DateTime?> > {
                new AggregatorDef <DateTime?>(CountAggregatorLabel, x => I18n.Localize(x.Count()))
            }.Concat(additionalGrouperOrAggr.Where(x => x.Aggregator != null).Select(x => x.Aggregator)),
                       new List <GrouperDef <DateTime?> > {
                new GrouperDef <DateTime?>(groupEverythingAsOneGroupLabel,
                                           RecordGroupingUtil.GroupAllRecordsAsOneGroup),
                new GrouperDef <DateTime?>(I18n.Translate("year"),
                                           x => RecordGroupingUtil.GroupRecordsByKey(x,
                                                                                     y => ObjectUtil.MapNullAs(y, z => z.Year.ToString(), EmptyLabel),
                                                                                     y => y.KeyData.ToString())),
                new GrouperDef <DateTime?>(I18n.Translate("month"),
                                           x => RecordGroupingUtil.GroupRecordsByKey(x,
                                                                                     y => ObjectUtil.MapNullAs(y,
                                                                                                               z => I18n.Localize(z, DateTimeFormat.YM), EmptyLabel),
                                                                                     y => y.KeyData.ToString())),
                new GrouperDef <DateTime?>(I18n.Translate("day"),
                                           x => RecordGroupingUtil.GroupRecordsByKey(x,
                                                                                     y => ObjectUtil.MapNullAs(y,
                                                                                                               z => I18n.Localize(z, DateTimeFormat.DateOnly), EmptyLabel),
                                                                                     y => y.KeyData.ToString()))
            }.Concat(additionalGrouperOrAggr.Where(x => x.Grouper != null).Select(x => x.Grouper)),
                       x => {
                var val = new InputView("");
                val.PlaceHolder = I18n.Translate("Filter value");
                val.BindReadWriteAndInitialize(x,
                                               y => !y.HasValue ? "" : I18n.Localize(y.Value, format),
                                               y => string.IsNullOrEmpty(y) ? (DateTime?)null : Convert.ToDateTime(y));
                return val;
            },
                       DateTimeExtensions.SmallestDate(),
                       DateTimeExtensions.SmallestDate(),
                       Comparer <DateTime?> .Default
                       ));
        }
Пример #4
0
        public ClassFieldRemoteMutator <decimal?, decimal?, ContT> BuildNullableDecimal(
            Expression <Func <ContT, decimal?> > getField, InputView view, DecimalFormat format,
            params Validate <decimal?>[] validators)
        {
            view.RaisesChangedOnKeyPressed = false;

            return(Build(getField, view,
                         x => x.HasValue ? I18n.Localize(x.Value, format) : "",
                         x => x != "" ? I18n.ParseDecimal(x) : (decimal?)null,
                         validators));
        }
Пример #5
0
        public ClassFieldRemoteMutator <int?, int?, ContT> BuildNullableInt(
            Expression <Func <ContT, int?> > getField, InputView view,
            params Validate <int?>[] validators)
        {
            view.RaisesChangedOnKeyPressed = false;

            return(Build(getField, view,
                         x => x.HasValue ? I18n.Localize(x.Value) : "",
                         x => x != "" ? I18n.ParseInt(x) : (int?)null,
                         validators));
        }
Пример #6
0
 public ClassFieldRemoteMutator <decimal, decimal, ContT> BuildDecimalWithPrecision(
     Expression <Func <ContT, decimal> > getField, InputView view,
     Func <int> getPrecision,
     params Validate <decimal>[] validators)
 {
     view.RaisesChangedOnKeyPressed = false;
     return(Build(
                getField,
                view,
                x => I18n.Localize(x, DecimalFormatExtensions.GetWithPrecision(getPrecision())),
                x => I18n.ParseDecimalWithoutLoss(x, getPrecision()),
                validators));
 }
        public static LocalValue <decimal?> BuildNullableDecimal(
            InputView view, DecimalFormat format, params Validate <decimal?>[] validators)
        {
            view.RaisesChangedOnKeyPressed = false;

            var result = new LocalValue <decimal?>(null);

            view.BindReadWriteAndInitialize(result,
                                            x => !x.HasValue ? "" : I18n.Localize(x.Value, format),
                                            x => string.IsNullOrEmpty(x) ? (decimal?)null : I18n.ParseDecimal(x));
            validators.ForEach(y => result.AddValidatorAndRevalidate(y));
            return(result);
        }
        public static LocalValue <decimal> BuildDecimal(
            InputView view, DecimalFormat format, params Validate <decimal>[] validators)
        {
            view.RaisesChangedOnKeyPressed = false;

            var result = new LocalValue <decimal>(0);

            view.BindReadWriteAndInitialize(result,
                                            x => I18n.Localize(x, format),
                                            x => I18n.ParseDecimal(x));
            validators.ForEach(y => result.AddValidatorAndRevalidate(y));
            return(result);
        }
        public static Tuple <HTMLElement, DataGridColumnControllerResult <decimal?> > ForNullableDecimal(
            DecimalFormat format,
            ITransformationMediator listener,
            params GrouperDefOrAggregatorDef <decimal?>[] additionalGrouperOrAggr)
        {
            var EmptyLabel = I18n.Translate("(empty)");

            return(Create(
                       listener,
                       new [] {
                new FilterDef <decimal?>(
                    I18n.Translate("equals"),
                    (filterParam, x) => x.HasValue && x == filterParam),
                new FilterDef <decimal?>(
                    I18n.Translate("doesn't equal"),
                    (filterParam, x) => x.HasValue && x != filterParam),
                new FilterDef <decimal?>(
                    I18n.Translate("is bigger than"),
                    (filterParam, x) => x.HasValue && x > filterParam),
                new FilterDef <decimal?>(
                    I18n.Translate("is smaller than"),
                    (filterParam, x) => x.HasValue && x < filterParam)
            },
                       new List <AggregatorDef <decimal?> > {
                new AggregatorDef <decimal?>(SumAggregatorLabel, x =>
                                             I18n.Localize(x.Sum().GetValueOrDefault(), DecimalFormat.AsNumber)),
                new AggregatorDef <decimal?>(CountAggregatorLabel, x => I18n.Localize(x.Count())),
                new AggregatorDef <decimal?>(I18n.Translate("Average"),
                                             x => I18n.Localize(x.Average().GetValueOrDefault(), DecimalFormat.AsNumber)),
            }.Concat(additionalGrouperOrAggr.Where(x => x.Aggregator != null).Select(x => x.Aggregator)),
                       new List <GrouperDef <decimal?> > {
                new GrouperDef <decimal?>(GroupEverythingAsOneGroupLabel,
                                          RecordGroupingUtil.GroupAllRecordsAsOneGroup),
                new GrouperDef <decimal?>(UniqueValueGroupLabel,
                                          x => RecordGroupingUtil.GroupRecordsByKey(x,
                                                                                    y => ObjectUtil.MapNullAs(y, (decimal z) => z.ToString(), EmptyLabel),
                                                                                    y => y.KeyData.ToString()))
            }.Concat(additionalGrouperOrAggr.Where(x => x.Grouper != null).Select(x => x.Grouper)),
                       x => {
                var val = new InputView("");
                val.PlaceHolder = I18n.Translate("Filter value");
                val.BindReadWriteAndInitialize(x,
                                               y => !y.HasValue ? "" : I18n.Localize(y.Value, format),
                                               y => string.IsNullOrEmpty(y) ? (decimal?)null : I18n.ParseDecimal(y));
                return val;
            },
                       default(decimal),
                       default(decimal),
                       Comparer <decimal?> .Default
                       ));
        }
Пример #10
0
        public static LocalValue <decimal> BuildDecimalWithPrecision(
            InputView view, decimal defaultValue, Func <int> getPrecision,
            params Validate <decimal>[] validators)
        {
            var result = new LocalValue <decimal>(defaultValue);

            view.RaisesChangedOnKeyPressed = false;

            view.BindReadWriteAndInitialize(result,
                                            x => I18n.Localize(x, DecimalFormatExtensions.GetWithPrecision(getPrecision())),
                                            x => I18n.ParseDecimalWithoutLoss(x, getPrecision()));

            validators.ForEach(y => result.AddValidatorAndRevalidate(y));
            return(result);
        }
 public static Tuple <HTMLElement, DataGridColumnControllerResult <ModelT> > ForTypeTreatedAsString <ModelT>(
     Func <ModelT, string> textValueProvider,
     ITransformationMediator listener,
     params GrouperDefOrAggregatorDef <string>[] additionalGrouperOrAggr)
 {
     return(Create(
                textValueProvider,
                listener,
                new [] {
         new FilterDef <string>(
             I18n.Translate("contains"),
             (filterParam, x) => (x ?? "").ContainsCaseInsensitive(filterParam ?? "")),
         new FilterDef <string>(
             I18n.Translate("doesn't contain"),
             (filterParam, x) => !(x ?? "").ContainsCaseInsensitive(filterParam ?? "")),
         new FilterDef <string>(
             I18n.Translate("equals"),
             (filterParam, x) => (x ?? "").EqualsCaseInsensitive(filterParam ?? "")),
         new FilterDef <string>(
             I18n.Translate("doesn't equal"),
             (filterParam, x) => !(x ?? "").EqualsCaseInsensitive(filterParam ?? "")),
         new FilterDef <string>(
             I18n.Translate("begins with"),
             (filterParam, x) => (x ?? "").StartsWithCaseInsensitive(filterParam ?? "")),
         new FilterDef <string>(
             I18n.Translate("ends with"),
             (filterParam, x) => (x ?? "").EndsWithCaseInsensitive(filterParam ?? ""))
     },
                new List <AggregatorDef <string> > {
         new AggregatorDef <string>(CountAggregatorLabel, x => I18n.Localize(x.Count()))
     }.Concat(additionalGrouperOrAggr.Where(x => x.Aggregator != null).Select(x => x.Aggregator)),
                new List <GrouperDef <string> > {
         new GrouperDef <string>(GroupEverythingAsOneGroupLabel,
                                 RecordGroupingUtil.GroupAllRecordsAsOneGroup),
         new GrouperDef <string>(UniqueValueGroupLabel,
                                 x => RecordGroupingUtil.GroupRecordsByKey(x, y => y, y => y.KeyData.ToString()))
     }.Concat(additionalGrouperOrAggr.Where(x => x.Grouper != null).Select(x => x.Grouper)),
                x => {
         var val = new InputView("");
         val.PlaceHolder = I18n.Translate("Filter value");
         val.BindReadWriteAndInitialize(x, y => y, y => y);
         return val;
     },
                default(string),
                default(string),
                new StringCompareBasedComparer()
                ));
 }
 public static Tuple <HTMLElement, DataGridColumnControllerResult <decimal> > ForDecimal(
     DecimalFormat format,
     ITransformationMediator listener,
     params GrouperDefOrAggregatorDef <decimal>[] additionalGrouperOrAggr)
 {
     return(Create(
                listener,
                new [] {
         new FilterDef <decimal>(
             I18n.Translate("equals"),
             (filterParam, x) => x == filterParam),
         new FilterDef <decimal>(
             I18n.Translate("doesn't equal"),
             (filterParam, x) => x != filterParam),
         new FilterDef <decimal>(
             I18n.Translate("is bigger than"),
             (filterParam, x) => x > filterParam),
         new FilterDef <decimal>(
             I18n.Translate("is smaller than"),
             (filterParam, x) => x < filterParam)
     },
                new List <AggregatorDef <decimal> > {
         new AggregatorDef <decimal>(SumAggregatorLabel, x =>
                                     I18n.Localize(x.Sum(), DecimalFormat.AsNumber)),
         new AggregatorDef <decimal>(CountAggregatorLabel, x => I18n.Localize(x.Count())),
         new AggregatorDef <decimal>(I18n.Translate("Average"),
                                     x => I18n.Localize(x.Average(), DecimalFormat.AsNumber)),
     }.Concat(additionalGrouperOrAggr.Where(x => x.Aggregator != null).Select(x => x.Aggregator)),
                new List <GrouperDef <decimal> > {
         new GrouperDef <decimal>(GroupEverythingAsOneGroupLabel,
                                  RecordGroupingUtil.GroupAllRecordsAsOneGroup),
         new GrouperDef <decimal>(UniqueValueGroupLabel,
                                  x => RecordGroupingUtil.GroupRecordsByKey(x, y => y, y => y.KeyData.ToString()))
     }.Concat(additionalGrouperOrAggr.Where(x => x.Grouper != null).Select(x => x.Grouper)),
                x => {
         var val = new InputView("", InputView.TypeText);
         val.PlaceHolder = I18n.Translate("Filter value");
         val.BindReadWriteAndInitialize(x,
                                        y => I18n.Localize(y, format),
                                        y => Convert.ToDecimal(y));
         return val;
     },
                default(decimal),
                default(decimal),
                Comparer <decimal> .Default
                ));
 }
Пример #13
0
        public static RemoteValueChangeByEntryForm <string, string, RemT> CreateTextEntry <RemT>(
            Func <string, Task <RemT> > remoteChanger, string label, string titleOrNull = null,
            string defaultValue = "", TextType labelTextType = TextType.TreatAsText,
            params Validate <string>[] validators)
        {
            var input = new InputView();

            return(new RemoteValueChangeByEntryForm <string, string, RemT>(
                       remoteChanger,
                       input,
                       x => input.Label = x,
                       x => x,
                       x => x,
                       label,
                       titleOrNull,
                       defaultValue,
                       labelTextType,
                       validators));
        }
Пример #14
0
        public static LocalValue <decimal?> BuildNullableDecimalWithPrecision(
            InputView view, Func <int> getPrecision, params Validate <decimal?>[] validators)
        {
            view.RaisesChangedOnKeyPressed = false;

            var result = new LocalValue <decimal?>(null);

            view.BindReadWriteAndInitialize(result,
                                            x => !x.HasValue ?
                                            ""
                    :
                                            I18n.Localize(x.Value, DecimalFormatExtensions.GetWithPrecision(getPrecision())),
                                            x => string.IsNullOrEmpty(x) ?
                                            (decimal?)null
                    :
                                            I18n.ParseDecimalWithoutLoss(x, getPrecision()));

            validators.ForEach(y => result.AddValidatorAndRevalidate(y));
            return(result);
        }
Пример #15
0
        public static RemoteValueChangeByEntryForm <DomT, string, RemT> CreateTextBasedEntry <DomT, RemT>(
            Func <DomT, Task <RemT> > remoteChanger,
            Func <DomT, string> domainToView,
            Func <string, DomT> viewToDomain,
            string label, string titleOrNull = null,
            DomT defaultValue = default(DomT), TextType labelTextType = TextType.TreatAsText,
            params Validate <DomT>[] validators)
        {
            var input = new InputView(label);

            return(new RemoteValueChangeByEntryForm <DomT, string, RemT>(
                       remoteChanger,
                       input,
                       x => input.Label = x,
                       domainToView,
                       viewToDomain,
                       label,
                       titleOrNull,
                       defaultValue,
                       labelTextType,
                       validators));
        }
 public static Tuple <HTMLElement, DataGridColumnControllerResult <DecimalWithPrecision> > ForDecimalWithPrecision(
     ITransformationMediator listener,
     params GrouperDefOrAggregatorDef <DecimalWithPrecision>[] additionalGrouperOrAggr)
 {
     return(Create(
                listener,
                new [] {
         new FilterDef <DecimalWithPrecision>(
             I18n.Translate("is empty"),
             (filterParam, x) => DecimalWithPrecision.ComparatorImpl(x, null) == 0),
         new FilterDef <DecimalWithPrecision>(
             I18n.Translate("is not empty"),
             (filterParam, x) => DecimalWithPrecision.ComparatorImpl(x, null) != 0),
         new FilterDef <DecimalWithPrecision>(
             I18n.Translate("equals"),
             (filterParam, x) => DecimalWithPrecision.ComparatorImpl(x, filterParam) == 0),
         new FilterDef <DecimalWithPrecision>(
             I18n.Translate("doesn't equal"),
             (filterParam, x) => DecimalWithPrecision.ComparatorImpl(x, filterParam) != 0),
         new FilterDef <DecimalWithPrecision>(
             I18n.Translate("is bigger than"),
             (filterParam, x) => DecimalWithPrecision.ComparatorImpl(x, filterParam) > 0),
         new FilterDef <DecimalWithPrecision>(
             I18n.Translate("is smaller than"),
             (filterParam, x) => DecimalWithPrecision.ComparatorImpl(x, filterParam) < 0)
     },
                new List <AggregatorDef <DecimalWithPrecision> > {
         new AggregatorDef <DecimalWithPrecision>(SumAggregatorLabel, x => {
             var lst = x.Where(y => y != null).ToList();
             var p = lst.Any() ? lst[0].Precision : 0;
             return I18n.Localize(
                 lst.Aggregate(0m, (y, z) => y + z.RoundedValue),
                 DecimalFormatExtensions.GetWithPrecision(p));
         }),
         new AggregatorDef <DecimalWithPrecision>(CountAggregatorLabel,
                                                  x => I18n.Localize(x.Count())),
         new AggregatorDef <DecimalWithPrecision>(I18n.Translate("Average"), x => {
             var lst = x.Where(y => y != null).ToList();
             var p = lst.Any() ? lst[0].Precision : 0;
             return I18n.Localize(
                 lst.Aggregate(0m, (y, z) => y + z.RoundedValue) / lst.Count <= 0 ? 1 : lst.Count,
                 DecimalFormatExtensions.GetWithPrecision(p));
         }),
     }.Concat(additionalGrouperOrAggr.Where(x => x.Aggregator != null).Select(x => x.Aggregator)),
                new List <GrouperDef <DecimalWithPrecision> > {
         new GrouperDef <DecimalWithPrecision>(GroupEverythingAsOneGroupLabel,
                                               RecordGroupingUtil.GroupAllRecordsAsOneGroup),
         new GrouperDef <DecimalWithPrecision>(UniqueValueGroupLabel,
                                               x => RecordGroupingUtil.GroupRecordsByKey(x, y => y, y => y.KeyData.ToString()))
     }.Concat(additionalGrouperOrAggr.Where(x => x.Grouper != null).Select(x => x.Grouper)),
                x => {
         var val = new InputView("", InputView.TypeText);
         val.PlaceHolder = I18n.Translate("Filter value");
         val.BindReadWriteAndInitialize(x,
                                        y => y == null ? "" : I18n.Localize(
                                            y.Value, DecimalFormatExtensions.GetWithPrecision(y.Precision)),
                                        y => {
             if (string.IsNullOrWhiteSpace(y))
             {
                 return null;
             }
             var v = I18n.ParseDecimal(y);
             var s = I18n.Localize(v, DecimalFormat.WithFiveDecPlaces);
             var p = s.Length - s.IndexOf('.') - 1;
             return new DecimalWithPrecision(v, p);
         });
         return val;
     },
                null,
                null,
                new DecimalWithPrecisionDefaultComparer()
                ));
 }