コード例 #1
0
        public IssueLabelsViewModel(IApplicationService applicationService)
        {
            Labels         = new ReactiveList <LabelModel>();
            SelectedLabels = new ReactiveList <LabelModel>();

            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.SimpleCollectionLoad(
                                                              applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Labels.GetAll(),
                                                              t as bool?));
        }
コード例 #2
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()));
        }