Esempio n. 1
0
        void setupRx()
        {
            var countAsBehavior = Observable.Concat(
                Observable.Defer(() => Observable.Return(_NavigationStack.Count)),
                NavigationStack.CountChanged);

            NavigateBack = ReactiveCommand.CreateAsyncObservable(
                countAsBehavior.Select(x => x > 1),
                _ => Observable.Return(Unit.Default));

            NavigateBack.Subscribe(_ =>
                                   NavigationStack.RemoveAt(NavigationStack.Count - 1));

            Navigate = new ReactiveCommand <object>(Observable.Return(true), x => Observable.Return(x));
            Navigate.Subscribe(x => {
                var vm = x as IRoutableViewModel;
                if (vm == null)
                {
                    throw new Exception("Navigate must be called on an IRoutableViewModel");
                }

                NavigationStack.Add(vm);
            });

            NavigateAndReset = new ReactiveCommand <object>(Observable.Return(true), x => Observable.Return(x));
            NavigateAndReset
            .SelectMany(x => {
                NavigationStack.Clear();
                return(Navigate.ExecuteAsync(x));
            }).Subscribe();

            CurrentViewModel = Observable.Concat(
                Observable.Defer(() => Observable.Return(NavigationStack.LastOrDefault())),
                NavigationStack.Changed.Select(_ => NavigationStack.LastOrDefault()));
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NavigationViewModel"/> class.
        /// </summary>
        public NavigationViewModel()
        {
            history = new ReactiveList <IPanePageViewModel>();
            history.Changing.Subscribe(CollectionChanging);
            history.Changed.Subscribe(CollectionChanged);

            var pos = this.WhenAnyValue(
                x => x.Index,
                x => x.History.Count,
                (i, c) => new { Index = i, Count = c });

            content = pos
                      .Where(x => x.Index < x.Count)
                      .Select(x => x.Index != -1 ? history[x.Index] : null)
                      .StartWith((IPanePageViewModel)null)
                      .ToProperty(this, x => x.Content);

            this.WhenAnyValue(x => x.Content)
            .Buffer(2, 1)
            .Subscribe(x => {
                if (x[0] != null && history.Contains(x[0]))
                {
                    x[0].Deactivated();
                }
                x[1]?.Activated();
            });

            NavigateBack = ReactiveCommand.Create(() => { }, pos.Select(x => x.Index > 0));
            NavigateBack.Subscribe(_ => Back());
            NavigateForward = ReactiveCommand.Create(() => { }, pos.Select(x => x.Index < x.Count - 1));
            NavigateForward.Subscribe(_ => Forward());
        }
        public async void CreateTicketCommandExecute()
        {
            if (string.IsNullOrWhiteSpace(TicketTitle))
            {
                ServiceBus.AlertService.ShowMessageBox("Add Review", "Please fill the title of your review");
                return;
            }
            if (string.IsNullOrWhiteSpace(Details))
            {
                ServiceBus.AlertService.ShowMessageBox("Add Review", "Please fill the description of your review");
                return;
            }
            if ((Date - DateTime.Now).TotalHours < 1)
            {
                ServiceBus.AlertService.ShowMessageBox("Add Review", "Please check the date of your review");
                return;
            }
            if (Group == ReviewerGroup.None)
            {
                ServiceBus.AlertService.ShowMessageBox("Add Review", "Please select a category");
                return;
            }

            try
            {
                var ticket = new Ticket
                {
                    TitleName  = TicketTitle,
                    DateReview = Date,
                    ReviewText = Details,
                    GroupId    = ((int)Group).ToString()
                };


                var s = Tags.Replace(" ", ",")
                        .Replace(",,", ",")
                        .Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var t in s)
                {
                    ticket.ListOfTagTitles.Add(t);
                }

                await ServiceBus.ReviewerService.CreateReviewTicketAsync(ticket);

                NavigateBack?.Invoke();
                //ShowViewModel<ReviewerViewModel>();
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                ServiceBus.AlertService.ShowConnectionLostMessage();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Update the person with the service
        /// </summary>
        /// <returns></returns>
        private async Task SavePerson()
        {
            // Simplistic avoidance of duplicate calls
            if (this.IsBusy)
            {
                return;
            }

            // Validation
            if (string.IsNullOrEmpty(this.Person.FirstName) || string.IsNullOrEmpty(this.Person.LastName))
            {
                this.NotValid = true;
                return;
            }

            this.IsBusy = true;

            try
            {
                // Save the person and navigate back
                if (this.Person.Id == 0)
                {
                    await PersonService.AddPersonAsync(this.Person);
                }
                else
                {
                    await PersonService.UpdatePersonAsync(this.Person);
                }

                NavigateBack?.Invoke(this, new EventArgs());
            }
            catch (Exception ex)
            {
                // Placeholder error handling
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NavigationViewModel"/> class.
        /// </summary>
        public NavigationViewModel()
        {
            history = new ReactiveList <IPanePageViewModel>();
            history.BeforeItemsAdded.Subscribe(BeforeItemAdded);
            history.CollectionChanged += CollectionChanged;

            var pos = this.WhenAnyValue(
                x => x.Index,
                x => x.History.Count,
                (i, c) => new { Index = i, Count = c });

            content = pos
                      .Where(x => x.Index < x.Count)
                      .Select(x => x.Index != -1 ? history[x.Index] : null)
                      .StartWith((IPanePageViewModel)null)
                      .ToProperty(this, x => x.Content);

            NavigateBack = ReactiveCommand.Create(pos.Select(x => x.Index > 0));
            NavigateBack.Subscribe(_ => Back());
            NavigateForward = ReactiveCommand.Create(pos.Select(x => x.Index < x.Count - 1));
            NavigateForward.Subscribe(_ => Forward());
        }
        /// <summary>
        /// Provides different key shortcuts
        /// </summary>
        /// <param name="key"></param>
        public void KeyDown(VirtualKey key)
        {
            switch (key)
            {
            case VirtualKey.Left:
                NavigateBack.ExecuteWhen();
                break;

            case VirtualKey.Right:
                NavigateForward.ExecuteWhen();
                break;

            case VirtualKey.Back:
                NavigateBack.ExecuteWhen();
                break;

            case VirtualKey.F5:
                Refresh();
                break;

            case VirtualKey.F2:
                RenameStorageItemSelectedAsync();
                break;

            case VirtualKey.Delete:
                DeleteStorageItemSelected();
                break;
            }


            var ctrlDown = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);

            if (!ctrlDown)
            {
                return;
            }

            switch (key)
            {
            case VirtualKey.R:
                Refresh();
                break;

            case VirtualKey.C:
                CopyStorageItemSelected();
                break;

            case VirtualKey.X:
                CutStorageItemSelected();
                break;

            case VirtualKey.V:
                PasteStorageItemSelected();
                break;

            case VirtualKey.A:
                if (SelectedItems.Count == FileSystemElements.Count)
                {
                    SelectedItems.Clear();
                }
                else
                {
                    for (int i = 0; i < FileSystemElements.Count; i++)
                    {
                        if (!SelectedItems.Contains(FileSystemElements[i]))
                        {
                            SelectedItems.Add(FileSystemElements[i]);
                        }
                    }
                }

                break;
            }
        }
Esempio n. 7
0
 public static void RaiseNavigateBack() => NavigateBack?.Invoke(null, EventArgs.Empty);
Esempio n. 8
0
 /// <summary>
 /// Send command to navigate back
 /// </summary>
 public void GoBack()
 {
     NavigateBack?.Invoke();
 }
Esempio n. 9
0
 public void BackButtonClick()
 {
     NavigateBack?.Invoke(this, null);
 }
Esempio n. 10
0
 public void NavigateToPreviousScreen()
 {
     NavigateBack?.Invoke();
 }
Esempio n. 11
0
 public void Handle(NavigateBack message)
 {
     this.Content = this.previousContent;
 }