Esempio n. 1
0
            public async Task WorksIfProviderHasMultipleSuggestions()
            {
                var scheduler   = new TestScheduler();
                var provider    = Substitute.For <ISuggestionProvider>();
                var timeEntries = new[]
                {
                    new TimeEntry {
                        Description = "te1"
                    },
                    new TimeEntry {
                        Description = "te2"
                    },
                    new TimeEntry {
                        Description = "te3"
                    }
                };
                var observableContent = timeEntries
                                        .Select(te => new Recorded <Notification <ITimeEntry> >(1, Notification.CreateOnNext <ITimeEntry>(te)))
                                        .ToArray();
                var observable = scheduler
                                 .CreateColdObservable(observableContent);

                provider.GetSuggestion().Returns(observable);
                var container = new SuggestionProviderContainer(provider);
                var viewmodel = new SuggestionsViewModel(container);

                await viewmodel.Initialize();

                scheduler.AdvanceTo(1);

                viewmodel.Suggestions.Should().HaveCount(timeEntries.Length)
                .And.Contain(timeEntries);
            }
            public async Task WorksIfProviderHasMultipleSuggestions()
            {
                var scheduler   = new TestScheduler();
                var provider    = Substitute.For <ISuggestionProvider>();
                var suggestions = new[]
                {
                    createSuggestion("te1"),
                    createSuggestion("te2"),
                    createSuggestion("te3")
                };
                var observableContent = suggestions
                                        .Select(suggestion => createRecorded(1, suggestion))
                                        .ToArray();
                var observable = scheduler
                                 .CreateColdObservable(observableContent);

                provider.GetSuggestions().Returns(observable);
                var container = new SuggestionProviderContainer(provider);
                var viewmodel = new SuggestionsViewModel(container);

                await viewmodel.Initialize();

                scheduler.AdvanceTo(1);

                viewmodel.Suggestions.Should().HaveCount(suggestions.Length)
                .And.Contain(suggestions);
            }
        public MainLogSuggestionsListViewHolder(View itemView, SuggestionsViewModel suggestionsViewModel) : base(itemView)
        {
            this.suggestionsViewModel = suggestionsViewModel;

            hintTextView            = ItemView.FindViewById <TextView>(Resource.Id.SuggestionsHintTextView);
            indicatorTextView       = ItemView.FindViewById <TextView>(Resource.Id.SuggestionsIndicatorTextView);
            suggestionsRecyclerView = ItemView.FindViewById <RecyclerView>(Resource.Id.SuggestionsRecyclerView);

            var adapter = new SimpleAdapter <Suggestion>(Resource.Layout.MainSuggestionsCard, MainLogSuggestionItemViewHolder.Create);

            suggestionsRecyclerView.SetLayoutManager(new LinearLayoutManager(ItemView.Context));
            suggestionsRecyclerView.SetAdapter(adapter);

            adapter.ItemTapObservable
            .Subscribe(suggestionsViewModel.StartTimeEntry.Inputs)
            .DisposedBy(DisposeBag);

            suggestionsViewModel.Suggestions
            .Select(Enumerable.ToList)
            .Subscribe(adapter.Rx().Items())
            .DisposedBy(DisposeBag);

            suggestionsViewModel.IsEmpty
            .Invert()
            .Subscribe(updateViewVisibility)
            .DisposedBy(DisposeBag);
        }
Esempio n. 4
0
            public async Task WorksWithSeveralProviders()
            {
                var scheduler = new TestScheduler();
                var provider1 = Substitute.For <ISuggestionProvider>();
                var provider2 = Substitute.For <ISuggestionProvider>();
                var te1       = new TimeEntry {
                    Description = "t1", TaskId = 12, ProjectId = 9
                };
                var te2 = new TimeEntry {
                    Description = "t2", TaskId = 9, ProjectId = 12
                };
                var observable1 = scheduler
                                  .CreateColdObservable(new Recorded <Notification <ITimeEntry> >(0, Notification.CreateOnNext <ITimeEntry>(te1)));
                var observable2 = scheduler
                                  .CreateColdObservable(new Recorded <Notification <ITimeEntry> >(1, Notification.CreateOnNext <ITimeEntry>(te2)));

                provider1.GetSuggestion().Returns(observable1);
                provider2.GetSuggestion().Returns(observable2);
                var container = new SuggestionProviderContainer(provider1, provider2);
                var viewModel = new SuggestionsViewModel(container);

                await viewModel.Initialize();

                scheduler.AdvanceTo(1);

                viewModel.Suggestions.Should().HaveCount(2)
                .And.Contain(new[] { te1, te2 });
            }
Esempio n. 5
0
        public ActionResult Index()
        {
            SuggestionsViewModel foRequest = new SuggestionsViewModel();

            foRequest.stSortColumn = "ID DESC";

            return(View(getSuggestionList(foRequest)));
        }
        public MainLogSuggestionsListViewHolder(View itemView, SuggestionsViewModel suggestionsViewModel) : base(itemView)
        {
            this.suggestionsViewModel = suggestionsViewModel;

            hintTextView            = ItemView.FindViewById <TextView>(Resource.Id.SuggestionsHintTextView);
            indicatorTextView       = ItemView.FindViewById <TextView>(Resource.Id.SuggestionsIndicatorTextView);
            suggestionsRecyclerView = ItemView.FindViewById <RecyclerView>(Resource.Id.SuggestionsRecyclerView);

            suggestionsRecyclerView.SetLayoutManager(new LinearLayoutManager(ItemView.Context, LinearLayoutManager.Horizontal, false));
            var snapMargin = 16.DpToPixels(ItemView.Context);
            var snapHelper = new SuggestionsRecyclerViewSnapHelper(snapMargin);

            snapHelper.AttachToRecyclerView(suggestionsRecyclerView);


            mainSuggestionsRecyclerAdapter = new MainSuggestionsRecyclerAdapter();

            mainSuggestionsRecyclerAdapter.SuggestionTaps
            .Subscribe(suggestionsViewModel.StartTimeEntry.Inputs)
            .DisposedBy(DisposeBag);

            suggestionsRecyclerView.SetAdapter(mainSuggestionsRecyclerAdapter);

            suggestionsViewModel.Suggestions
            .Subscribe(onSuggestionsChanged)
            .DisposedBy(DisposeBag);

            suggestionsViewModel.IsEmpty
            .Invert()
            .Subscribe(updateViewVisibility)
            .DisposedBy(DisposeBag);

            var suggestionCount = suggestionsViewModel.Suggestions.Select(s => s.Length);
            var currentIndexAndSuggestionCount =
                Observable.CombineLatest(snapHelper.CurrentIndexObservable, suggestionCount,
                                         (currIndx, count) => (currIndx, count));

            currentIndexAndSuggestionCount.Do(tuple =>
            {
                var currIdx = tuple.Item1;
                var count   = tuple.Item2;
                onCurrentSuggestionIndexChanged(count, currIdx);
            })
            .Subscribe()
            .DisposedBy(DisposeBag);
        }
            public async Task WorksIfProvidersAreEmpty()
            {
                var providers = new[]
                {
                    Substitute.For <ISuggestionProvider>(),
                    Substitute.For <ISuggestionProvider>(),
                    Substitute.For <ISuggestionProvider>()
                };

                foreach (var provider in providers)
                {
                    provider.GetSuggestions().Returns(Observable.Empty <Suggestion>());
                }
                var container = new SuggestionProviderContainer(providers);
                var viewmodel = new SuggestionsViewModel(container);

                await viewmodel.Initialize();

                viewmodel.Suggestions.Should().HaveCount(0);
            }
            public async Task WorksWithSeveralProviders()
            {
                var scheduler   = new TestScheduler();
                var provider1   = Substitute.For <ISuggestionProvider>();
                var provider2   = Substitute.For <ISuggestionProvider>();
                var suggestion1 = createSuggestion("t1", 12, 9);
                var suggestion2 = createSuggestion("t2", 9, 12);
                var observable1 = scheduler.CreateColdObservable(createRecorded(0, suggestion1));
                var observable2 = scheduler.CreateColdObservable(createRecorded(1, suggestion2));

                provider1.GetSuggestions().Returns(observable1);
                provider2.GetSuggestions().Returns(observable2);
                var container = new SuggestionProviderContainer(provider1, provider2);
                var viewModel = new SuggestionsViewModel(container);

                await viewModel.Initialize();

                scheduler.AdvanceTo(1);

                viewModel.Suggestions.Should().HaveCount(2)
                .And.Contain(new[] { suggestion1, suggestion2 });
            }
Esempio n. 9
0
        public MainLogSuggestionsListViewHolder(View itemView, SuggestionsViewModel suggestionsViewModel) : base(itemView)
        {
            this.suggestionsViewModel = suggestionsViewModel;

            hintTextView            = ItemView.FindViewById <TextView>(Resource.Id.SuggestionsHintTextView);
            indicatorTextView       = ItemView.FindViewById <TextView>(Resource.Id.SuggestionsIndicatorTextView);
            suggestionsRecyclerView = ItemView.FindViewById <RecyclerView>(Resource.Id.SuggestionsRecyclerView);

            suggestionsRecyclerView.SetLayoutManager(new LinearLayoutManager(ItemView.Context, LinearLayoutManager.Horizontal, false));
            var snapMargin = 16.DpToPixels(ItemView.Context);
            var snapHelper = new SuggestionsRecyclerViewSnapHelper(snapMargin);

            snapHelper.AttachToRecyclerView(suggestionsRecyclerView);

            this.Bind(snapHelper.CurrentIndexObservable, onCurrentSuggestionIndexChanged);

            mainSuggestionsRecyclerAdapter = new MainSuggestionsRecyclerAdapter();
            this.Bind(mainSuggestionsRecyclerAdapter.SuggestionTaps, onSuggestionTapped);

            suggestionsRecyclerView.SetAdapter(mainSuggestionsRecyclerAdapter);

            var collectionChangesObservable = Observable.FromEventPattern <NotifyCollectionChangedEventHandler, NotifyCollectionChangedEventArgs>(
                e => this.suggestionsViewModel.Suggestions.CollectionChanged += e,
                e => this.suggestionsViewModel.Suggestions.CollectionChanged -= e);

            var collectionChangedObservable = collectionChangesObservable
                                              .Select(args => this.suggestionsViewModel.Suggestions.ToImmutableList())
                                              .StartWith(this.suggestionsViewModel.Suggestions.ToImmutableList());

            var suggestionsCountObservable = collectionChangesObservable
                                             .Select(args => this.suggestionsViewModel.Suggestions.Count)
                                             .StartWith(this.suggestionsViewModel.Suggestions.Count)
                                             .DistinctUntilChanged();

            this.Bind(collectionChangedObservable, onSuggestionsCollectionChanged);
            this.Bind(suggestionsCountObservable, onCollectionCountChanged);
        }
Esempio n. 10
0
        public SuggestionsModel getSuggestionList(SuggestionsViewModel foRequest)
        {
            if (foRequest.inPageSize <= 0)
            {
                foRequest.inPageSize = 10;
            }

            if (foRequest.inPageIndex <= 0)
            {
                foRequest.inPageIndex = 1;
            }

            if (foRequest.stSortColumn == "")
            {
                foRequest.stSortColumn = null;
            }

            if (foRequest.stSearch == "")
            {
                foRequest.stSearch = null;
            }


            List <Expression <Func <Suggestions, Object> > > includes        = new List <Expression <Func <Suggestions, object> > >();
            Expression <Func <Suggestions, object> >         IncludeProducts = (product) => product.Products;
            Expression <Func <Suggestions, object> >         IncludeUser     = (suggestion) => suggestion.AspNetUsers;

            includes.Add(IncludeProducts);
            includes.Add(IncludeUser);

            Func <IQueryable <Suggestions>, IOrderedQueryable <Suggestions> > orderingFunc =
                query => query.OrderBy(x => x.Id);

            Expression <Func <Suggestions, bool> > expression = null;

            //expression = x => x.IsDeleted == false;

            if (!string.IsNullOrEmpty(foRequest.stSortColumn))
            {
                switch (foRequest.stSortColumn)
                {
                case "ID DESC":
                    orderingFunc = q => q.OrderByDescending(s => s.Id);
                    break;

                case "ProductName DESC":
                    orderingFunc = q => q.OrderByDescending(s => s.ProductId);
                    break;

                case "ProductName ASC":
                    orderingFunc = q => q.OrderBy(s => s.ProductId);
                    break;

                case "UserName DESC":
                    orderingFunc = q => q.OrderByDescending(s => s.AspNetUsers.Name);
                    break;

                case "UserName ASC":
                    orderingFunc = q => q.OrderBy(s => s.AspNetUsers.Name);
                    break;

                case "UserEmail DESC":
                    orderingFunc = q => q.OrderByDescending(s => s.AspNetUsers.Email);
                    break;

                case "UserEmail ASC":
                    orderingFunc = q => q.OrderBy(s => s.AspNetUsers.Email);
                    break;

                case "UserContact DESC":
                    orderingFunc = q => q.OrderByDescending(s => s.AspNetUsers.PhoneNumber);
                    break;

                case "UserContact ASC":
                    orderingFunc = q => q.OrderBy(s => s.AspNetUsers.PhoneNumber);
                    break;

                case "Suggestion DESC":
                    orderingFunc = q => q.OrderByDescending(s => s.Suggestion);
                    break;

                case "Suggestion ASC":
                    orderingFunc = q => q.OrderBy(s => s.Suggestion);
                    break;
                }
            }
            (List <Suggestions>, int)objSuggestions = Repository <Suggestions> .GetEntityListForQuery(expression, orderingFunc, includes, foRequest.inPageIndex, foRequest.inPageSize);

            SuggestionsModel objSuggestion = new SuggestionsModel();

            objSuggestion.inRecordCount = objSuggestions.Item2;
            objSuggestion.inPageIndex   = foRequest.inPageIndex;
            objSuggestion.Pager         = new Pager(objSuggestions.Item2, foRequest.inPageIndex);

            if (objSuggestions.Item1.Count > 0)
            {
                foreach (var suggestion in objSuggestions.Item1)
                {
                    objSuggestion.loSuggestionList.Add(new SuggestionsViewModel
                    {
                        Id                = suggestion.Id,
                        ProductName       = suggestion.Products.Name,
                        UserName          = suggestion.AspNetUsers.Name,
                        Email             = suggestion.AspNetUsers.Email,
                        UserContectNumber = suggestion.AspNetUsers.PhoneNumber,
                        Suggestion        = suggestion.Suggestion,
                        IsReplied         = suggestion.IsReplied,
                        ProductImgPath    = getProductImgPath(suggestion.ProductId)
                    });
                }
            }

            return(objSuggestion);
        }
Esempio n. 11
0
        public ActionResult searchSuggestions(SuggestionsViewModel foSearchRequest)
        {
            SuggestionsModel loSuggestionModel = getSuggestionList(foSearchRequest);

            return(PartialView("~/Areas/Admin/Views/Suggestion/_Suggestions.cshtml", loSuggestionModel));
        }