protected override void OnInitialized()
        {
            var configs = ServiceProvider.GetServices <DateRangePickerConfig>();
            var config  = configs?.FirstOrDefault();

            if (!string.IsNullOrEmpty(Config) && configs.Any(c => c.Name == Config))
            {
                config = configs.First(c => c.Name == Config);
            }

            if (config == null)
            {
                config = new DateRangePickerConfig();
            }
            config.CopyProperties(this);

            ConfigAttributes = config.Attributes;

            if (string.IsNullOrEmpty(DateFormat))
            {
                DateFormat = Culture.DateTimeFormat.ShortDatePattern;
            }

            if (SingleDatePicker == true)
            {
                AutoApply = true;
            }
            base.OnInitialized();
        }
Esempio n. 2
0
        protected override void OnInitialized()
        {
            var configs = ServiceProvider.GetServices <DateRangePickerConfig>();
            var config  = configs?.FirstOrDefault();

            if (!string.IsNullOrEmpty(Config) && configs.Any(c => c.Name == Config))
            {
                config = configs.First(c => c.Name == Config);
            }

            if (config == null)
            {
                config = new DateRangePickerConfig();
            }
            config.CopyProperties(this);

            ConfigAttributes = config.Attributes;

            if (string.IsNullOrEmpty(DateFormat))
            {
                DateFormat = Culture.DateTimeFormat.ShortDatePattern;
            }

            if (!TimePicker24Hour.HasValue)
            {
                TimePicker24Hour = Culture.DateTimeFormat.LongTimePattern.EndsWith("tt");
            }

            StartTime = TStartDate.HasValue
                ? TStartDate.Value.TimeOfDay
                : InitialStartTime ?? TimeSpan.Zero;

            EndTime = TEndDate.HasValue
                ? TEndDate.Value.TimeOfDay
                : InitialEndTime ?? TimeSpan.FromDays(1).Add(TimeSpan.FromTicks(-1));

            if (SingleDatePicker == true && TimePicker == false && !AutoApply.HasValue)
            {
                AutoApply = true;
            }

            if (!FirstDayOfWeek.HasValue)
            {
                FirstDayOfWeek = Culture.DateTimeFormat.FirstDayOfWeek;
            }

            if (Inline == true)
            {
                Prerender = true;
            }
            Render = Prerender == true;

            LeftCalendar  = new CalendarType(this, SideType.Left);
            RightCalendar = new CalendarType(this, SideType.Right);

            TStartDate = StartDate?.Date.Add(StartTime);
            TEndDate   = EndDate?.Date.Add(EndTime);
        }
        /// <summary>
        /// Adds a singleton <see cref="DateRangePickerConfig"/> instance to the DI
        /// </summary>
        public static IServiceCollection AddDateRangePicker(this IServiceCollection services,
                                                            DateRangePickerConfig configuration,
                                                            string configName = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            configuration.Name = configName;
            services.AddSingleton(configuration);
            return(services);
        }
        /// <summary>
        /// Adds a singleton <see cref="DateRangePickerConfig"/> instance to the DI
        /// </summary>
        public static IServiceCollection AddDateRangePicker(this IServiceCollection services,
                                                            Action <DateRangePickerConfig> configure,
                                                            string configName = null)
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            var options = new DateRangePickerConfig();

            configure(options);

            return(AddDateRangePicker(services, options, configName));
        }
Esempio n. 5
0
        protected override void OnInitialized()
        {
            var markupAttributes = Attributes;

            var configs = ServiceProvider.GetServices <DateRangePickerConfig>();
            var config  = configs?.FirstOrDefault();

            if (!string.IsNullOrEmpty(Config) && configs.Any(c => c.Name == Config))
            {
                config = configs.First(c => c.Name == Config);
            }

            if (config == null)
            {
                config = new DateRangePickerConfig();
            }
            config.CopyProperties(this);

            if (markupAttributes?.Any() == true)
            {
                if (Attributes == null)
                {
                    Attributes = new Dictionary <string, object>();
                }
                foreach (var ma in markupAttributes)
                {
                    if (!Attributes.ContainsKey(ma.Key))
                    {
                        Attributes[ma.Key] = ma.Value;
                    }
                }
            }

            if (string.IsNullOrEmpty(DateFormat))
            {
                DateFormat = Culture.DateTimeFormat.ShortDatePattern;
            }

            if (SingleDatePicker == true)
            {
                AutoApply = true;
            }
            base.OnInitialized();
        }
        protected override void OnInitialized()
        {
            var configs = ServiceProvider.GetServices <DateRangePickerConfig>();
            var config  = configs?.FirstOrDefault();

            if (!string.IsNullOrEmpty(Config) && configs.Any(c => c.Name == Config))
            {
                config = configs.First(c => c.Name == Config);
            }

            if (config == null)
            {
                config = new DateRangePickerConfig();
            }
            config.CopyProperties(this);

            ConfigAttributes = config.Attributes;

            if (string.IsNullOrEmpty(DateFormat))
            {
                DateFormat = Culture.DateTimeFormat.ShortDatePattern;
            }

            if (SingleDatePicker == true)
            {
                AutoApply = true;
            }

            if (!FirstDayOfWeek.HasValue)
            {
                FirstDayOfWeek = Culture.DateTimeFormat.FirstDayOfWeek;
            }

            LeftCalendar  = new CalendarType(FirstDayOfWeek.Value);
            RightCalendar = new CalendarType(FirstDayOfWeek.Value);

            StartDate = StartDate?.Date;
            EndDate   = EndDate?.Date.AddDays(1).AddTicks(-1);

            AdjustCalendars();

            base.OnInitialized();
        }