/// <summary>
 /// EventHandler that routes the <see cref="FilterEditorControl"/>'s OnQueryOperators event to the ViewModel.
 /// A direct binding using EventToCommand in the view unfortunately doesn't work in all cases.
 /// That's why a non MVVM construction was used here.
 /// </summary>
 /// <param name="sender">The sender</param>
 /// <param name="e">The <see cref="FilterEditorQueryOperatorsEventArgs"/></param>
 private async void FilterEditor_OnQueryOperators(object sender, FilterEditorQueryOperatorsEventArgs e)
 {
     if (this.DataContext is CustomFilterEditorDialogViewModel customFilterEditorDialogViewModel)
     {
         await customFilterEditorDialogViewModel.QueryOperatorsCommand.ExecuteAsyncTask(e);
     }
 }
        public void SetUp()
        {
            this.session = new Mock <ISession>();

            this.category1 = new Category(Guid.NewGuid(), null, null)
            {
                Name = CategoryName1
            };

            this.category2 = new Category(Guid.NewGuid(), null, null)
            {
                Name = CategoryName2
            };

            this.parentRow = new CategoryTestRowViewModel(this.category1, this.session.Object, null);
            this.childRow  = new CategoryTestRowViewModel(this.category2, this.session.Object, this.parentRow);

            this.parentRow.ContainedRows.Add(this.childRow);

            this.filterEditorQueryOperatorsEventArgs =
                this.CreateInstance <FilterEditorQueryOperatorsEventArgs>(CriteriaOperator.And(), nameof(CategoryTestRowViewModel.Category));

            var filterEditorOperatorItem = new List <FilterEditorOperatorItem>
            {
                new FilterEditorOperatorItem(FilterEditorOperatorType.AboveAverage),
                new FilterEditorOperatorItem(FilterEditorOperatorType.Equal),
                new FilterEditorOperatorItem(FilterEditorOperatorType.Greater),
                new FilterEditorOperatorItem(FilterEditorOperatorType.AnyOf)
            };

            this.filterEditorOperatorItemList = this.CreateInstance <FilterEditorOperatorItemList>(filterEditorOperatorItem);
            this.filterEditorQueryOperatorsEventArgs.Operators = this.filterEditorOperatorItemList;
        }
예제 #3
0
        /// <summary>
        /// Set the <see cref="FilterEditorQueryOperatorsEventArgs.Operators"/> property.
        /// </summary>
        /// <param name="filterEditorQueryOperatorsEventArgs">
        /// The <see cref="FilterEditorQueryOperatorsEventArgs"/>.
        /// </param>
        public override void SetOperators(FilterEditorQueryOperatorsEventArgs filterEditorQueryOperatorsEventArgs)
        {
            filterEditorQueryOperatorsEventArgs.Operators.Clear();

            filterEditorQueryOperatorsEventArgs.Operators.Add(
                new FilterEditorOperatorItem(IsMemberOfCategoryName)
            {
                Caption = "Member of Category"
            });

            filterEditorQueryOperatorsEventArgs.Operators.Add(
                new FilterEditorOperatorItem(HasCategoryApplied)
            {
                Caption = "Has Category Applied"
            });
        }
 private void FilterEditorControl_QueryOperators(object sender, FilterEditorQueryOperatorsEventArgs e)
 {
     if (e.FieldName == "fieldOrderDate")
     {
         e.Operators.Clear();
         e.Operators.Add(new FilterEditorOperatorItem(FilterEditorOperatorType.Between)
         {
             Caption = "Between"
         });
         e.Operators.Add(new FilterEditorOperatorItem(FilterEditorOperatorType.NotBetween)
         {
             Caption = "NotBetween"
         });
         e.Operators.Add(CreateLastYearsOperator());
     }
 }
예제 #5
0
        /// <summary>
        ///Customize filter editor operators
        /// </summary>
        /// <param name="sender">Associated control <see cref="FilterEditorControl"/></param>
        /// <param name="e">Associated event <see cref="FilterEditorQueryOperatorsEventArgs"/></param>
        private void OnQueryOperators(object sender, FilterEditorQueryOperatorsEventArgs e)
        {
            if (e.FieldName != "Categories")
            {
                return;
            }

            e.Operators.Clear();

            e.Operators.Add(
                new FilterEditorOperatorItem(IsMemberOfCategoryName)
            {
                Caption = "Member of Category"
            });

            e.Operators.Add(
                new FilterEditorOperatorItem(HasCategoryApplied)
            {
                Caption = "Has Category Applied"
            });
        }
예제 #6
0
        private void AssociatedObject_QueryOperators(object sender, FilterEditorQueryOperatorsEventArgs e)
        {
            if (e.FieldName == "ImdbRating" || e.FieldName == "PersonalRating" || e.FieldName == "Item.VoteAverage")
            {
                e.DefaultOperator = e.Operators[FilterEditorOperatorType.Greater];
                DataTemplate operandTemplate = AssociatedObject.TryFindResource("RatingTemplate") as DataTemplate;
                if (operandTemplate != null)
                {
                    e.Operators[FilterEditorOperatorType.Equal].OperandTemplate          = operandTemplate;
                    e.Operators[FilterEditorOperatorType.NotEqual].OperandTemplate       = operandTemplate;
                    e.Operators[FilterEditorOperatorType.Greater].OperandTemplate        = operandTemplate;
                    e.Operators[FilterEditorOperatorType.GreaterOrEqual].OperandTemplate = operandTemplate;
                    e.Operators[FilterEditorOperatorType.Less].OperandTemplate           = operandTemplate;
                    e.Operators[FilterEditorOperatorType.LessOrEqual].OperandTemplate    = operandTemplate;

                    e.Operators.RemoveAll(x => x.OperatorType == FilterEditorOperatorType.AnyOf || x.OperatorType == FilterEditorOperatorType.NoneOf);
                }

                return;
            }

            IEnumerable <string> uniqueValues = FilterHelper.GetUniqueValues(MediaType, e.FieldName);

            if (uniqueValues != null)
            {
                e.DefaultOperator = e.Operators[FilterEditorOperatorType.Contains];
                RemoveIrrelevantFilters(e.Operators);

                string       filterKey       = FilterHelper.GetFilterKey(MediaType, e.FieldName);
                DataTemplate operandTemplate = AssociatedObject.TryFindResource(filterKey + "FilterTemplate") as DataTemplate;
                if (operandTemplate != null)
                {
                    e.Operators[FilterEditorOperatorType.Equal].OperandTemplate          = operandTemplate;
                    e.Operators[FilterEditorOperatorType.NotEqual].OperandTemplate       = operandTemplate;
                    e.Operators[FilterEditorOperatorType.Contains].OperandTemplate       = operandTemplate;
                    e.Operators[FilterEditorOperatorType.DoesNotContain].OperandTemplate = operandTemplate;
                }
            }
        }
 void OnQueryOperators(object sender, FilterEditorQueryOperatorsEventArgs e)
 {
     if (e.FieldName == "Name")
     {
         e.Operators.Clear();
         e.Operators.Add(new FilterEditorOperatorItem(FilterEditorOperatorType.Equal));
         e.Operators.Add(new FilterEditorOperatorItem(FilterEditorOperatorType.NotEqual));
         e.Operators.Add(new FilterEditorOperatorItem(FilterEditorOperatorType.Contains));
         e.Operators.Add(new FilterEditorOperatorItem(FilterEditorOperatorType.StartsWith));
         e.Operators.Add(new FilterEditorOperatorItem(FilterEditorOperatorType.EndsWith));
         e.DefaultOperator = e.Operators[FilterEditorOperatorType.Contains];
     }
     else if (e.FieldName == "SubscribeNumber")
     {
         e.Operators.Clear();
         e.Operators.Add(new FilterEditorOperatorItem(FilterEditorOperatorType.Equal));
         e.Operators.Add(new FilterEditorOperatorItem(FilterEditorOperatorType.NotEqual));
         e.Operators.Add(new FilterEditorOperatorItem(FilterEditorOperatorType.Greater));
         e.Operators.Add(new FilterEditorOperatorItem(FilterEditorOperatorType.GreaterOrEqual));
         e.Operators.Add(new FilterEditorOperatorItem(FilterEditorOperatorType.Less));
         e.Operators.Add(new FilterEditorOperatorItem(FilterEditorOperatorType.LessOrEqual));
         e.DefaultOperator = e.Operators[FilterEditorOperatorType.LessOrEqual];
     }
 }
예제 #8
0
 /// <summary>
 /// Changes the <see cref="FilterEditorQueryOperatorsEventArgs.Operators"/> list of filter operators
 /// </summary>
 /// <param name="filterEditorQueryOperatorsEventArgs">
 /// The <see cref="FilterEditorQueryOperatorsEventArgs"/>
 /// </param>
 public abstract void SetOperators(FilterEditorQueryOperatorsEventArgs filterEditorQueryOperatorsEventArgs);
        public void SetUp()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;
            this.serviceLocator       = new Mock <IServiceLocator>();

            var treeList = new TreeListControl {
                View = new TreeListView()
            };

            this.dataViewBase      = treeList.View;
            this.dataViewBase.Name = "DataViewBase";

            this.dialogNavigationService = new Mock <IDialogNavigationService>();
            ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object);
            this.serviceLocator.Setup(x => x.GetInstance <IDialogNavigationService>()).Returns(this.dialogNavigationService.Object);

            this.savedUserPreferenceService = new Mock <ISavedUserPreferenceService>();
            ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object);
            this.serviceLocator.Setup(x => x.GetInstance <ISavedUserPreferenceService>()).Returns(this.savedUserPreferenceService.Object);

            this.session = new Mock <ISession>();

            this.category1 = new Category(Guid.NewGuid(), null, null)
            {
                Name = CategoryName1
            };

            this.category2 = new Category(Guid.NewGuid(), null, null)
            {
                Name = CategoryName2
            };

            this.parentRow = new CategoryTestRowViewModel(this.category1, this.session.Object, null);
            this.childRow  = new CategoryTestRowViewModel(this.category2, this.session.Object, this.parentRow);

            this.parentRow.ContainedRows.Add(this.childRow);

            this.filterEditorQueryOperatorsEventArgs =
                this.CreateInstance <FilterEditorQueryOperatorsEventArgs>(CriteriaOperator.And(), nameof(CategoryTestRowViewModel.Category));

            var filterEditorOperatorItem = new List <FilterEditorOperatorItem>
            {
                new FilterEditorOperatorItem(FilterEditorOperatorType.AboveAverage),
                new FilterEditorOperatorItem(FilterEditorOperatorType.Equal),
                new FilterEditorOperatorItem(FilterEditorOperatorType.Greater),
                new FilterEditorOperatorItem(FilterEditorOperatorType.AnyOf)
            };

            this.filterEditorOperatorItemList = this.CreateInstance <FilterEditorOperatorItemList>(filterEditorOperatorItem);
            this.filterEditorQueryOperatorsEventArgs.Operators = this.filterEditorOperatorItemList;

            this.customFilterOperatorsViewModel = new Mock <IHaveCustomFilterOperators>();

            var customFilterOperators = new Dictionary <DataViewBase, Dictionary <string, (CustomFilterOperatorType, IEnumerable <IRowViewModelBase <Thing> >)> >();
            var browserDictionary     = new Dictionary <string, (CustomFilterOperatorType, IEnumerable <IRowViewModelBase <Thing> >)>();

            browserDictionary.Add(nameof(CategoryTestRowViewModel.Category), (CustomFilterOperatorType.Category, new [] { this.parentRow }));

            customFilterOperators.Add(this.dataViewBase, browserDictionary);

            this.customFilterOperatorsViewModel.Setup(x => x.CustomFilterOperators).Returns(customFilterOperators);

            this.dataViewBase.DataContext = this.customFilterOperatorsViewModel.Object;
        }