private IssueAssigneeItemViewModel CreateItemViewModel(User x)
 {
     var vm = new IssueAssigneeItemViewModel(x);
     vm.IsSelected = x.Id == _selected?.Id;
     vm.GoToCommand.Subscribe(_ => {
         Selected = vm.IsSelected ? x : null;
         SaveCommand.ExecuteIfCan();
     });
     return vm;
 }
Exemple #2
0
        private IssueAssigneeItemViewModel CreateItemViewModel(User x)
        {
            var vm = new IssueAssigneeItemViewModel(x);

            vm.IsSelected = x.Id == _selected?.Id;
            vm.GoToCommand.Subscribe(_ => {
                Selected = vm.IsSelected ? x : null;
                SaveCommand.ExecuteIfCan();
            });
            return(vm);
        }
        public IssueAssigneeViewModel(
            Func <Task <IReadOnlyList <User> > > loadAssignees,
            Func <Task <User> > loadCurrentlyAssigned,
            Func <User, Task> updateIssue
            )
        {
            DismissCommand = ReactiveCommand.Create();

            var derivedFunc = new Func <User, IssueAssigneeItemViewModel>(x =>
            {
                var vm = new IssueAssigneeItemViewModel(x);
                if (_selectedUser != null)
                {
                    vm.IsSelected = x.Id == _selectedUser.Id;
                }

                vm.GoToCommand
                .Select(_ => vm.IsSelected ? x : null)
                .Subscribe(user =>
                {
                    foreach (var a in Assignees.Where(y => y != vm))
                    {
                        a.IsSelected = false;
                    }
                    updateIssue(user).ToBackground();
                    DismissCommand.ExecuteIfCan();
                });
                return(vm);
            });

            var assignees = new ReactiveList <User>();

            Assignees = assignees.CreateDerivedCollection(
                derivedFunc,
                filter: x => x.Name.ContainsKeyword(SearchKeyword),
                signalReset: this.WhenAnyValue(x => x.SearchKeyword));

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
            {
                _selectedUser = (await loadCurrentlyAssigned());
                assignees.Reset(await loadAssignees());
            });
        }
Exemple #4
0
        public IssueAssigneeViewModel(
            Func <Task <IReadOnlyList <User> > > loadAssignees,
            Func <Task <Issue> > loadIssue,
            Func <IssueUpdate, Task <Issue> > updateIssue
            )
        {
            var derivedFunc = new Func <User, IssueAssigneeItemViewModel>(x =>
            {
                var vm = new IssueAssigneeItemViewModel(x);
                if (_selectedUser != null)
                {
                    vm.IsSelected = x.Id == _selectedUser.Id;
                }

                vm.GoToCommand.Subscribe(_ =>
                {
                    var assigneeName = vm.IsSelected ? vm.Name : null;
                    updateIssue(new IssueUpdate {
                        Assignee = assigneeName
                    }).ToBackground();
                });
                return(vm);
            });

            var assignees = new ReactiveList <User>();

            Assignees = assignees.CreateDerivedCollection(
                derivedFunc,
                filter: x => x.Name.ContainsKeyword(SearchKeyword),
                signalReset: this.WhenAnyValue(x => x.SearchKeyword));

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
            {
                _selectedUser = (await loadIssue()).Assignee;
                assignees.Reset(await loadAssignees());
            });
        }