예제 #1
0
        public IssueLabelsViewModel(
            Func<Task<IReadOnlyList<Label>>> loadAllLabelsFunc,
            Func<Task<IReadOnlyList<Label>>> loadSelectedFunc,
            Func<IEnumerable<Label>, Task> saveLabelsFunc)
	    {
            var labels = new ReactiveList<Label>();
            var selected = new ReactiveList<Label>();
            Labels = labels.CreateDerivedCollection(x => 
            {
                var vm = new IssueLabelItemViewModel(x);
                vm.IsSelected = selected.Any(y => y.Url == x.Url);
                return vm;
            });

            SaveCommand = ReactiveCommand.CreateAsyncTask(_ =>
            {
                var currentlySelected = Labels.Where(x => x.IsSelected).ToList();
                var selectedLabelsUrl = currentlySelected.Select(x => x.Label.Url).ToArray();
                var prevSelectedLabelsUrl = selected.Select(x => x.Url).ToArray();
                var intersect = selectedLabelsUrl.Intersect(prevSelectedLabelsUrl).ToArray();
                var different = selectedLabelsUrl.Length != prevSelectedLabelsUrl.Length || intersect.Length != selectedLabelsUrl.Length;
                return different ? saveLabelsFunc(currentlySelected.Select(x => x.Label)) : Task.FromResult(0);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                selected.Clear();
                selected.AddRange((await loadSelectedFunc()) ?? Enumerable.Empty<Label>());
                labels.Reset(await loadAllLabelsFunc());
            });
	    }
예제 #2
0
        public IssueLabelsViewModel(
            Func <Task <IReadOnlyList <Label> > > loadAllLabelsFunc,
            Func <Task <IReadOnlyList <Label> > > loadSelectedFunc,
            Func <IEnumerable <Label>, Task> saveLabelsFunc)
        {
            var labels   = new ReactiveList <Label>();
            var selected = new ReactiveList <Label>();

            Labels = labels.CreateDerivedCollection(x =>
            {
                var vm        = new IssueLabelItemViewModel(x);
                vm.IsSelected = selected.Any(y => y.Url == x.Url);
                return(vm);
            });

            SaveCommand = ReactiveCommand.CreateAsyncTask(_ =>
            {
                var currentlySelected     = Labels.Where(x => x.IsSelected).ToList();
                var selectedLabelsUrl     = currentlySelected.Select(x => x.Label.Url).ToArray();
                var prevSelectedLabelsUrl = selected.Select(x => x.Url).ToArray();
                var intersect             = selectedLabelsUrl.Intersect(prevSelectedLabelsUrl).ToArray();
                var different             = selectedLabelsUrl.Length != prevSelectedLabelsUrl.Length || intersect.Length != selectedLabelsUrl.Length;
                return(different ? saveLabelsFunc(currentlySelected.Select(x => x.Label)) : Task.FromResult(0));
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                selected.Clear();
                selected.AddRange((await loadSelectedFunc()) ?? Enumerable.Empty <Label>());
                labels.Reset(await loadAllLabelsFunc());
            });
        }
예제 #3
0
        public IssueLabelsViewModel(Func<Task<IReadOnlyList<Label>>> loadLabels)
	    {
            var labels = new ReactiveList<Label>();
            Selected = new ReactiveList<Label>();
            Labels = labels.CreateDerivedCollection(x => 
            {
                var vm = new IssueLabelItemViewModel(x);
                vm.IsSelected = Selected.Any(y => string.Equals(y.Name, x.Name));
//                vm.GoToCommand
//                    .Select(_ => x)
//                    .Where(y => vm.IsSelected)
//                    .Where(y => Selected.All(l => l.Url != y.Url))
//                    .Subscribe(Selected.Add);
//                vm.GoToCommand
//                    .Select(_ => x)
//                    .Where(y => !vm.IsSelected)
//                    .Select(y => Selected.Where(l => l.Url == y.Url).ToArray())
//                    .Subscribe(Selected.RemoveAll);
                return vm;
            });

            SelectLabelsCommand = ReactiveCommand.CreateAsyncTask(t => {
                var selectedLabelsUrl = Selected.Select(x => x.Url).ToArray();
                var prevSelectedLabelsUrl = _previouslySelectedLabels.Select(x => x.Url).ToArray();
                var intersect = selectedLabelsUrl.Intersect(prevSelectedLabelsUrl).ToArray();
                var different = selectedLabelsUrl.Length != prevSelectedLabelsUrl.Length || intersect.Length != selectedLabelsUrl.Length;
                return Task.FromResult(0); //different ? updateIssue(new ReadOnlyCollection<Label>(Selected)) : Task.FromResult(0);
	        });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                labels.Reset(await loadLabels());
            });
	    }
예제 #4
0
        public IssueLabelsViewModel(
            Func <Task <IReadOnlyList <Label> > > loadLabels,
            Func <Task <IReadOnlyList <Label> > > currentLabels,
            Func <IReadOnlyList <Label>, Task> updateIssue)
        {
            var labels = new ReactiveList <Label>();

            SelectedLabels = new ReactiveList <Label>();
            Labels         = labels.CreateDerivedCollection(x =>
            {
                var vm        = new IssueLabelItemViewModel(x);
                vm.IsSelected = SelectedLabels.Any(y => string.Equals(y.Name, x.Name));
                vm.GoToCommand
                .Select(_ => x)
                .Where(y => vm.IsSelected)
                .Where(y => SelectedLabels.All(l => l.Url != y.Url))
                .Subscribe(SelectedLabels.Add);
                vm.GoToCommand
                .Select(_ => x)
                .Where(y => !vm.IsSelected)
                .Select(y => SelectedLabels.Where(l => l.Url == y.Url).ToArray())
                .Subscribe(SelectedLabels.RemoveAll);
                return(vm);
            });

            SelectLabelsCommand = ReactiveCommand.CreateAsyncTask(t =>
            {
                var selectedLabelsUrl     = SelectedLabels.Select(x => x.Url).ToArray();
                var prevSelectedLabelsUrl = _previouslySelectedLabels.Select(x => x.Url).ToArray();
                var intersect             = selectedLabelsUrl.Intersect(prevSelectedLabelsUrl).ToArray();
                var different             = selectedLabelsUrl.Length != prevSelectedLabelsUrl.Length || intersect.Length != selectedLabelsUrl.Length;
                return(different ? updateIssue(new ReadOnlyCollection <Label>(SelectedLabels)) : Task.FromResult(0));
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
            {
                var currentlySelectedLabels = (await currentLabels()) ?? Enumerable.Empty <Label>();
                SelectedLabels.Reset(currentlySelectedLabels);

                _previouslySelectedLabels.Clear();
                foreach (var l in currentlySelectedLabels)
                {
                    _previouslySelectedLabels.Add(l);
                }

                labels.Reset(await loadLabels());
            });
        }
예제 #5
0
        public IssueLabelsViewModel(
            Func <Task <IReadOnlyList <Label> > > loadLabels,
            Func <Task <Issue> > loadIssue,
            Func <IssueUpdate, Task <Issue> > updateIssue,
            IGraphicService graphicService)
        {
            var labels = new ReactiveList <Label>();

            Labels = labels.CreateDerivedCollection(x =>
            {
                var vm        = new IssueLabelItemViewModel(graphicService, x);
                vm.IsSelected = _selectedLabels.Any(y => string.Equals(y.Name, x.Name));
                vm.GoToCommand
                .Select(_ => x)
                .Where(y => vm.IsSelected && !_selectedLabels.Contains(y))
                .Subscribe(_selectedLabels.Add);
                vm.GoToCommand
                .Select(_ => x)
                .Where(y => !vm.IsSelected)
                .Subscribe(y => _selectedLabels.Remove(y));
                return(vm);
            });

            SelectLabelsCommand = ReactiveCommand.CreateAsyncTask(t =>
            {
                if (!_selectedLabels.All(_issue.Labels.Contains))
                {
                    return(updateIssue(new IssueUpdate {
                        Labels = _selectedLabels.Select(x => x.Name).ToList()
                    }));
                }
                return(Task.FromResult(0));
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
            {
                _issue = await loadIssue();
                _selectedLabels.Clear();
                foreach (var l in _issue.Labels)
                {
                    _selectedLabels.Add(l);
                }
                labels.Reset(await loadLabels());
            });
        }
예제 #6
0
        public IssueLabelsViewModel(IApplicationService applicationService, IGraphicService graphicService)
        {
            var labels = new ReactiveList <LabelModel>();

            SelectedLabels = new ReactiveList <LabelModel>();

            Labels = labels.CreateDerivedCollection(x =>
            {
                var vm = new IssueLabelItemViewModel(graphicService, x);
                vm.SelectCommand.Subscribe(_ =>
                {
                    var selected = SelectedLabels.FirstOrDefault(y => string.Equals(y.Name, x.Name));
                    if (selected != null)
                    {
                        SelectedLabels.Remove(selected);
                        vm.Selected = false;
                    }
                    else
                    {
                        SelectedLabels.Add(x);
                        vm.Selected = true;
                    }
                });
                return(vm);
            });

            SelectLabelsCommand = ReactiveCommand.CreateAsyncTask(async t =>
            {
                var selectedLabels = t as IEnumerable <LabelModel>;
                if (selectedLabels != null)
                {
                    SelectedLabels.Reset(selectedLabels);
                }

                //If nothing has changed, dont do anything...
                if (OriginalLabels != null && OriginalLabels.Count() == SelectedLabels.Count() &&
                    OriginalLabels.Intersect(SelectedLabels).Count() == SelectedLabels.Count())
                {
                    DismissCommand.ExecuteIfCan();
                    return;
                }

                if (SaveOnSelect)
                {
//	                try
//	                {
//                        var labels = (SelectedLabels != null && SelectedLabels.Count > 0)
//                                    ? SelectedLabels.Select(y => y.Name).ToArray() : null;
//	                    var updateReq =
//	                        applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues[IssueId]
//	                            .UpdateLabels(labels);
//                        await applicationService.Client.ExecuteAsync(updateReq);
//	                }
//	                catch (Exception e)
//	                {
//	                    throw new Exception("Unable to save labels! Please try again.", e);
//	                }
                }

                DismissCommand.ExecuteIfCan();
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(t =>
                                                          labels.LoadAll(applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Labels.GetAll()));
        }