public DataboundDatagridItemCreatorForm(ISomeService someService)
        {
            _view = new DataboundDatagridItemCreatorFormView();

            var someText   = LocalValueFieldBuilder.Build(_view.SomeText, Validator.IsNotNullRef);
            var someNumber = LocalValueFieldBuilder.BuildNullableInt(_view.SomeNumber, Validator.IsNotNull, Validator.MustBePositive <int>());
            var someBool   = LocalValueFieldBuilder.Build(_view.SomeBool);

            _view.SomeTrait.PermittedValues = EnumExtensions.GetEnumValues <SomeTraitType>().Select(x => (SomeTraitType?)x);
            var someTrait = LocalValueFieldBuilder.Build(_view.SomeTrait, Validator.IsNotNull);

            var createProduct = RemoteActionBuilder.Build(_view.CreateAction,
                                                          () => someService.Create(
                                                              new SomeDto {
                SomeNumber = someNumber.Value.GetValueOrDefault(),
                SomeText   = someText.Value,
                SomeBool   = someBool.Value,
                SomeTrait  = someTrait.Value.Value
            }),
                                                          x => {
                CreatedItem = x;
                Ended?.Invoke(this, Outcome.Created);
            });

            var isFormValid = new AggregatedErrorsValue <bool>(false, self => !self.Errors.Any(), x => {
                x.Observes(someText);
                x.Observes(someNumber);
                x.Observes(someBool);
                x.Observes(someTrait);
            });

            createProduct.BindEnableAndInitialize(isFormValid);
        }
Esempio n. 2
0
        public UploaderDemoForm(IHttpRequester httpRequester)
        {
            _view = new UploaderDemoFormView();
            _view.Attachments.SetImplementation(new ISomeService_OrderAttachment(httpRequester, () => 124, () => true));
            _attachments = LocalValueFieldBuilder.Build(new List <RemoteFileDescr>(), _view.Attachments,
                                                        (newValue, errors) => {
                errors.IfTrueAdd(newValue.Count > 10, "Maximum 10 files allowed");
            });

            //TODO this is experimental feature. It should be added by the above statement (if BeforeChange is supported in IView)
            _view.Attachments.BeforeChange += (newValue, isUser, preventProp) => {
                if (newValue.Count > 10)
                {
                    preventProp(new HashSet <string> {
                        "Maximum 10 files allowed"
                    });
                }
            };

            var mayConfirm = new AggregatedErrorsValue <bool>(
                false, self => !self.Errors.Any(), x => x.Observes(_attachments));

            var confirm = LocalActionBuilder.Build(_view.Confirm, () => Ended?.Invoke(this, Unit.Instance));

            confirm.BindEnableAndInitialize(mayConfirm);
        }
        public AllFieldsFilledDataEntryForm()
        {
            var view  = new AllFieldsFilledDataEntryFormView();
            var ended = new Observable.Publisher <Unit>();

            Ended = ended;
            View  = view;

            var strEntry = LocalValueFieldBuilder.Build(
                view.StringEntry,
                (x, errors) => errors.IfTrueAdd(
                    string.IsNullOrWhiteSpace(x) || x.Length < 4,
                    "Text must be at least 4 chars long"),
                (x, errors) => errors.IfTrueAdd(
                    string.IsNullOrWhiteSpace(x) || x.Length > 10,
                    "Text must be no longer than 10 chars long")
                );

            var intEntry = LocalValueFieldBuilder.BuildNullableInt(
                view.IntEntry,
                (x, errors) => errors.IfTrueAdd(!x.HasValue || x < 1234, "Number must be bigger than 1234")
                );

            var decEntry = LocalValueFieldBuilder.BuildNullableDecimal(
                view.DecimalEntry,
                DecimalFormat.WithTwoDecPlaces,
                (x, errors) => errors.IfTrueAdd(!x.HasValue || x < 5.6m,
                                                "Number must be bigger than " + I18n.Localize(5.6m, DecimalFormat.WithOneDecPlace))
                );

            //this field is used to show that values on screen are not necessarily values within model.
            //In other words: when validator rejected value from user wrong value and error message stays on screen BUT model keeps its last-accepted-value
            var summaryLine = LocalValueFieldBuilder.Build("", view.SummaryLine);

            void UpdateSummaryLine()
            {
                var decVal = !decEntry.Value.HasValue ? "" : I18n.Localize(decEntry.Value.Value, DecimalFormat.WithOneDecPlace);

                summaryLine.DoProgrammaticChange(
                    $@"Accepted vals: Text={strEntry.Value} Int={intEntry.Value} Decimal={decVal}"
                    );
            }

            strEntry.Changed += (_, __, ___, ____, _____) => UpdateSummaryLine();
            intEntry.Changed += (_, __, ___, ____, _____) => UpdateSummaryLine();
            decEntry.Changed += (_, __, ___, ____, _____) => UpdateSummaryLine();

            UpdateSummaryLine();

            var confirm = LocalActionBuilder.Build(view.ConfirmAction, () => ended.Fire(Unit.Instance));

            confirm.BindEnableAndInitializeAsObserving(x => {
                x.Observes(strEntry);
                x.Observes(intEntry);
                x.Observes(decEntry);
            });
        }
Esempio n. 4
0
        //comment out above declaration and uncomment next line to make form noncloseable
//        public ExternalEventsHandlers ExternalEventsHandlers => ExternalEventsHandlers.Ignore;

        public SomeForm()
        {
            var inp = LocalValueFieldBuilder.Build(_view.Inp,
                                                   (v, errors) => errors.IfTrueAdd(string.IsNullOrWhiteSpace(v),
                                                                                   "Must contain at least one non whitespace character"));

            var conf = LocalActionBuilder.Build(_view.Confirm,
                                                () => Ended?.Invoke(this, CompletedOrCanceled.Completed));

            conf.BindEnableAndInitializeAsObserving(x => x.Observes(inp));
        }
Esempio n. 5
0
        public FlexibleLayoutContentForm()
        {
            _view       = new FlexibleLayoutContentFormView();
            _layoutMode = LocalValueFieldBuilder.BuildEnumBasedChoice(
                LayoutModeType.TitleExtra_Actions_Body, _view.LeftPanelLayout);

            _layoutMode.Changed += (sender, oldValue, newValue, errors, isUserChange) => {
                if (!isUserChange)
                {
                    return;
                }
                Ended?.Invoke(this, Outcome.LeftPanelLayoutChanged);
            };
        }
Esempio n. 6
0
        public DateTimeDemoForm()
        {
            _view = new DateTimeDemoFormView();

            LocalValueFieldBuilder.BuildDateTimePicker(_view.SingleValidation, null, Validator.IsNotNull, (newValue, errors) => {
                if (!newValue.HasValue)
                {
                    return;
                }

                errors.IfTrueAdd(newValue.Value.Day % 2 != 0, "Day must be even");
                errors.IfTrueAdd(newValue.Value.Hour % 2 != 0, "Hour must be even");
            });

            LocalValueFieldBuilder.Build(
                Tuple.Create <DateTime?, DateTime?>(null, null), _view.RangeValidation,
                (newValue, errors) => {
                if (!newValue.Item1.HasValue || !newValue.Item2.HasValue)
                {
                    errors.Add("Range not choosen");
                    return;
                }

                if (!(newValue.Item2.Value - newValue.Item1.Value).TotalDays.AreApproximatellyTheSame(2, 0.1))
                {
                    errors.Add("Exactly three days need");
                    Logger.Debug(GetType(), "Exactly three days need but selected {0} to {1} days={2}",
                                 newValue.Item1.Value, newValue.Item2.Value,
                                 (newValue.Item2.Value - newValue.Item1.Value).TotalDays);
                    return;
                }

                for (var iDay = newValue.Item1.Value; iDay <= newValue.Item2.Value; iDay = iDay.AddDays(1))
                {
                    if (iDay.DayOfWeek == DayOfWeek.Saturday || iDay.DayOfWeek == DayOfWeek.Sunday)
                    {
                        errors.Add("Weekends are not permitted");
                        return;
                    }
                }
            });
        }
Esempio n. 7
0
        public DropdownsDemoForm()
        {
            _view = new DropdownsDemoFormView();

            _view.MultiChoice.PermittedValues = KnownSomeDtos;
            var choosenMultipleCount = LocalValueFieldBuilder.BuildInt(_view.MultiChoiceState);
            var choosenMultiple      = LocalValueFieldBuilder.Build(_view.MultiChoice);

            choosenMultiple.Changed += async(_, __, newValue, ___, ____) => {
                await choosenMultipleCount.DoChange(newValue.Count(), false);
            };

            _view.SingleChoice.PermittedValues = KnownSomeDtos;
            var choosenSingleSomeText = LocalValueFieldBuilder.Build(_view.SingleChoiceState);
            var choosenSingle         = LocalValueFieldBuilder.Build(_view.SingleChoice);

            choosenSingle.Changed += async(_, __, newValue, ___, ____) => {
                await choosenSingleSomeText.DoChange(newValue?.SomeText ?? "(not choosen)", false);
            };
        }
Esempio n. 8
0
        public IntroduceItemForm()
        {
            _view = new IntroduceItemFormView();

            _someText   = LocalValueFieldBuilder.Build(_view.SomeText, Validator.IsNotEmptyOrWhitespaceOnly);
            _someNumber = LocalValueFieldBuilder.BuildInt(_view.SomeNumber, Validator.MustBePositive);
            _someBool   = LocalValueFieldBuilder.Build(_view.SomeBool);

            _view.SomeTrait.PermittedValues = EnumExtensions.GetEnumValues <SomeTraitType>().Select(x => (SomeTraitType?)x);
            _someTrait = LocalValueFieldBuilder.Build(_view.SomeTrait, Validator.IsNotNull);

            var isFormValid = new AggregatedErrorsValue <bool>(false, self => !self.Errors.Any(), x => {
                x.Observes(_someText);
                x.Observes(_someNumber);
                x.Observes(_someBool);
                x.Observes(_someTrait);
            });

            LocalActionBuilder
            .Build(_view.Create, () => Ended?.Invoke(this, Outcome.Saved))
            .With(x => x.BindEnableAndInitialize(isFormValid));
        }