Exemple #1
0
        protected IssueModifyViewController()
        {
            _descriptionElement.AccessoryView = x => new MarkdownAccessoryView(x);
            _milestoneElement = new StringElement("Milestone", string.Empty, UITableViewCellStyle.Value1);
            _assigneeElement  = new StringElement("Assigned", string.Empty, UITableViewCellStyle.Value1);
            _labelsElement    = new StringElement("Labels", string.Empty, UITableViewCellStyle.Value1);

            OnActivation(d => {
                d(this.WhenAnyObservable(x => x.ViewModel.GoToAssigneesCommand)
                  .Subscribe(_ => IssueAssigneeViewController.Show(this, ViewModel.CreateAssigneeViewModel())));

                d(this.WhenAnyObservable(x => x.ViewModel.GoToMilestonesCommand)
                  .Subscribe(_ => IssueMilestonesViewController.Show(this, ViewModel.CreateMilestonesViewModel())));

                d(this.WhenAnyObservable(x => x.ViewModel.GoToLabelsCommand)
                  .Subscribe(_ => IssueLabelsViewController.Show(this, ViewModel.CreateLabelsViewModel())));

                d(this.WhenAnyValue(x => x.ViewModel.SaveCommand)
                  .ToBarButtonItem(Images.SaveButton, x => NavigationItem.RightBarButtonItem = x));

                d(this.WhenAnyValue(x => x.ViewModel.DismissCommand)
                  .ToBarButtonItem(Images.Cancel, x => NavigationItem.LeftBarButtonItem = x));

                d(_milestoneElement.Clicked.InvokeCommand(ViewModel.GoToMilestonesCommand));
                d(_assigneeElement.Clicked.InvokeCommand(ViewModel.GoToAssigneesCommand));
                d(_labelsElement.Clicked.InvokeCommand(ViewModel.GoToLabelsCommand));

                d(this.WhenAnyValue(x => x.ViewModel.Subject).Subscribe(x => _titleElement.Value = x));
                d(_titleElement.Changed.Subscribe(x => ViewModel.Subject = x));

                d(this.WhenAnyValue(x => x.ViewModel.Content).Subscribe(x => _descriptionElement.Value = x));
                d(_descriptionElement.Changed.Subscribe(x => ViewModel.Content = x));

                d(this.WhenAnyValue(x => x.ViewModel.Milestone)
                  .Select(x => x == null ? "No Milestone" : x.Title)
                  .Subscribe(x => _milestoneElement.Value = x));

                d(this.WhenAnyValue(x => x.ViewModel.Assignee)
                  .Select(x => x == null ? "Unassigned" : x.Login)
                  .Subscribe(x => _assigneeElement.Value = x));

                d(this.WhenAnyValue(x => x.ViewModel.Labels)
                  .Select(x => (x == null || x.Count == 0) ? "None" : string.Join(",", x.Select(y => y.Name)))
                  .Subscribe(x => _labelsElement.Value = x));
            });
        }
Exemple #2
0
        protected IssueModifyViewController()
        {
            _descriptionElement.AccessoryView = x => new MarkdownAccessoryView(x);

            this.WhenAnyObservable(x => x.ViewModel.GoToAssigneesCommand)
            .Subscribe(_ => IssueAssigneeViewController.Show(this, ViewModel.CreateAssigneeViewModel()));

            this.WhenAnyObservable(x => x.ViewModel.GoToMilestonesCommand)
            .Subscribe(_ => IssueMilestonesViewController.Show(this, ViewModel.CreateMilestonesViewModel()));

            this.WhenAnyObservable(x => x.ViewModel.GoToLabelsCommand)
            .Subscribe(_ => IssueLabelsViewController.Show(this, ViewModel.CreateLabelsViewModel()));

            this.WhenAnyValue(x => x.ViewModel.Subject).Subscribe(x => _titleElement.Value = x);
            _titleElement.Changed += (sender, e) => ViewModel.Subject = _titleElement.Value;

            this.WhenAnyValue(x => x.ViewModel.Content).Subscribe(x => _descriptionElement.Value = x);
            _descriptionElement.ValueChanged += (sender, e) => ViewModel.Content = _descriptionElement.Value;

            this.WhenAnyValue(x => x.ViewModel.SaveCommand)
            .Select(x => x.ToBarButtonItem(UIBarButtonSystemItem.Save))
            .Subscribe(x => NavigationItem.RightBarButtonItem = x);

            _milestoneElement        = new StringElement("Milestone", string.Empty, UITableViewCellStyle.Value1);
            _milestoneElement.Tapped = () => ViewModel.GoToMilestonesCommand.ExecuteIfCan();
            this.WhenAnyValue(x => x.ViewModel.Milestone)
            .Select(x => x == null ? "No Milestone" : x.Title)
            .Subscribe(x => _milestoneElement.Value = x);

            _assigneeElement        = new StringElement("Assigned", string.Empty, UITableViewCellStyle.Value1);
            _assigneeElement.Tapped = () => ViewModel.GoToAssigneesCommand.ExecuteIfCan();
            this.WhenAnyValue(x => x.ViewModel.Assignee)
            .Select(x => x == null ? "Unassigned" : x.Login)
            .Subscribe(x => _assigneeElement.Value = x);

            _labelsElement        = new StringElement("Labels", string.Empty, UITableViewCellStyle.Value1);
            _labelsElement.Tapped = () => ViewModel.GoToLabelsCommand.ExecuteIfCan();
            this.WhenAnyValue(x => x.ViewModel.Labels)
            .Select(x => (x == null || x.Count == 0) ? "None" : string.Join(",", x.Select(y => y.Name)))
            .Subscribe(x => _labelsElement.Value = x);

            this.WhenAnyValue(x => x.ViewModel.DismissCommand)
            .Select(x => x.ToBarButtonItem(Images.Cancel))
            .Subscribe(x => NavigationItem.LeftBarButtonItem = x);
        }
Exemple #3
0
        protected BaseIssueViewController()
        {
            CommentsElement = new HtmlElement("comments");
            this.WhenAnyValue(x => x.ViewModel.GoToUrlCommand)
            .Subscribe(x => CommentsElement.UrlRequested = x.ExecuteIfCan);

            DescriptionElement = new HtmlElement("description");
            this.WhenAnyValue(x => x.ViewModel.GoToUrlCommand)
            .Subscribe(x => DescriptionElement.UrlRequested = x.ExecuteIfCan);

            this.WhenAnyValue(x => x.ViewModel.ShowMenuCommand)
            .Select(x => x.ToBarButtonItem(UIBarButtonSystemItem.Action))
            .Subscribe(x => NavigationItem.RightBarButtonItem = x);

            this.WhenAnyObservable(x => x.ViewModel.GoToAssigneesCommand)
            .Subscribe(_ => IssueAssigneeViewController.Show(this, ViewModel.CreateAssigneeViewModel()));

            this.WhenAnyObservable(x => x.ViewModel.GoToMilestonesCommand)
            .Subscribe(_ => IssueMilestonesViewController.Show(this, ViewModel.CreateMilestonesViewModel()));

            this.WhenAnyObservable(x => x.ViewModel.GoToLabelsCommand)
            .Subscribe(_ => IssueLabelsViewController.Show(this, ViewModel.CreateLabelsViewModel()));

            this.WhenAnyValue(x => x.ViewModel.GoToOwnerCommand)
            .Subscribe(x => HeaderView.ImageButtonAction = x != null ? new Action(() => ViewModel.GoToOwnerCommand.ExecuteIfCan()) : null);

            Appeared.Take(1)
            .Select(_ => Observable.Timer(TimeSpan.FromSeconds(0.2f)))
            .Switch()
            .ObserveOn(RxApp.MainThreadScheduler)
            .Select(_ => this.WhenAnyValue(x => x.ViewModel.IsClosed))
            .Switch()
            .Subscribe(x =>
            {
                HeaderView.SubImageView.TintColor = x ? UIColor.FromRGB(0xbd, 0x2c, 0) : UIColor.FromRGB(0x6c, 0xc6, 0x44);
                HeaderView.SetSubImage((x ? Octicon.IssueClosed :Octicon.IssueOpened).ToImage());
            });

            MilestoneElement = new StringElement("Milestone", string.Empty, UITableViewCellStyle.Value1)
            {
                Image = Octicon.Milestone.ToImage()
            };
            MilestoneElement.Tapped = () => ViewModel.GoToMilestonesCommand.ExecuteIfCan();
            this.WhenAnyValue(x => x.ViewModel.AssignedMilestone)
            .Select(x => x == null ? "No Milestone" : x.Title)
            .Subscribe(x => MilestoneElement.Value = x);

            AssigneeElement = new StringElement("Assigned", string.Empty, UITableViewCellStyle.Value1)
            {
                Image = Octicon.Person.ToImage()
            };
            AssigneeElement.Tapped = () => ViewModel.GoToAssigneesCommand.ExecuteIfCan();
            this.WhenAnyValue(x => x.ViewModel.AssignedUser)
            .Select(x => x == null ? "Unassigned" : x.Login)
            .Subscribe(x => AssigneeElement.Value = x);

            LabelsElement = new StringElement("Labels", string.Empty, UITableViewCellStyle.Value1)
            {
                Image = Octicon.Tag.ToImage()
            };
            LabelsElement.Tapped = () => ViewModel.GoToLabelsCommand.ExecuteIfCan();
            this.WhenAnyValue(x => x.ViewModel.AssignedLabels)
            .Select(x => (x == null || x.Count == 0) ? "None" : string.Join(",", x.Select(y => y.Name)))
            .Subscribe(x => LabelsElement.Value = x);

            this.WhenAnyValue(x => x.ViewModel.CanModify)
            .Select(x => x ? UITableViewCellAccessory.DisclosureIndicator : UITableViewCellAccessory.None)
            .Subscribe(x => MilestoneElement.Accessory = AssigneeElement.Accessory = LabelsElement.Accessory = x);

            DetailsSection.Add(MilestoneElement);
            DetailsSection.Add(AssigneeElement);
            DetailsSection.Add(LabelsElement);

            this.WhenAnyValue(x => x.ViewModel.Avatar)
            .SubscribeSafe(x => HeaderView.SetImage(x?.ToUri(128), Images.LoginUserUnknown));

            this.WhenAnyValue(x => x.ViewModel.Issue)
            .IsNotNull()
            .Subscribe(x => {
                HeaderView.Text    = x.Title;
                HeaderView.SubText = x.UpdatedAt.HasValue ?
                                     ("Updated " + x.UpdatedAt.Value.UtcDateTime.Humanize()) :
                                     ("Created " + x.CreatedAt.UtcDateTime.Humanize());
                RefreshHeaderView();
            });

            this.WhenAnyValue(x => x.ViewModel.MarkdownDescription)
            .Subscribe(x =>
            {
                if (string.IsNullOrEmpty(x))
                {
                    DetailsSection.Remove(DescriptionElement);
                }
                else
                {
                    var model    = new DescriptionModel(x, (int)UIFont.PreferredSubheadline.PointSize);
                    var markdown = new MarkdownView {
                        Model = model
                    };
                    var html = markdown.GenerateString();
                    DescriptionElement.Value = html;

                    if (!DetailsSection.Contains(DescriptionElement))
                    {
                        DetailsSection.Insert(0, UITableViewRowAnimation.Fade, DescriptionElement);
                    }
                }
            });

            CommentsSection.FooterView = new TableFooterButton("Add Comment", () => ViewModel.AddCommentCommand.ExecuteIfCan());

            this.WhenAnyValue(x => x.ViewModel.Events)
            .Select(x => x.Changed)
            .Switch()
            .Select(x => ViewModel.Events)
            .Subscribe(events =>
            {
                var comments = events.Select(x =>
                {
                    var body    = string.Empty;
                    var comment = x as IssueCommentItemViewModel;
                    var @event  = x as IssueEventItemViewModel;

                    if (comment != null)
                    {
                        body = comment.Comment;
                    }
                    else if (@event != null)
                    {
                        body = CreateEventBody(@event.EventInfo, @event.Commit);
                    }

                    return(new Comment(x.AvatarUrl.ToUri(), x.Actor, body, x.CreatedAt.Humanize()));
                })
                               .Where(x => !string.IsNullOrEmpty(x.Body))
                               .ToList();

                if (comments.Count > 0)
                {
                    var commentModel = new CommentModel(comments, (int)UIFont.PreferredSubheadline.PointSize);
                    var razorView    = new CommentsView {
                        Model = commentModel
                    };
                    var html = razorView.GenerateString();
                    CommentsElement.Value = html;

                    if (!CommentsSection.Contains(CommentsElement))
                    {
                        CommentsSection.Insert(0, UITableViewRowAnimation.Fade, CommentsElement);
                    }
                }
                else
                {
                    CommentsSection.Remove(CommentsElement);
                }
            });

            var commentsButton     = SplitButton.AddButton("Comments", "-");
            var participantsButton = SplitButton.AddButton("Participants", "-");

            this.WhenAnyValue(x => x.ViewModel.CommentCount)
            .Subscribe(x => commentsButton.Text = x.ToString());

            this.WhenAnyValue(x => x.ViewModel.Participants)
            .Subscribe(x => participantsButton.Text = x.ToString());
        }
Exemple #4
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var source = new DialogTableViewSource(TableView);

            TableView.Source = source;

            var stateElement = new StringElement("State", () => ViewModel.SelectStateCommand.ExecuteIfCan());

            stateElement.Style = UITableViewCellStyle.Value1;

            var cmd          = ViewModel.SelectLabelsCommand;
            var labelElement = new StringElement("Labels", () => cmd.ExecuteIfCan());

            labelElement.Style = UITableViewCellStyle.Value1;

            var mentionedElement = new EntryElement("Mentioned", "username", string.Empty)
            {
                TextAlignment = UITextAlignment.Right, AutocorrectionType = UITextAutocorrectionType.No, AutocapitalizationType = UITextAutocapitalizationType.None
            };

            mentionedElement.Changed += (sender, e) => ViewModel.Mentioned = mentionedElement.Value;

            var creatorElement = new EntryElement("Creator", "username", string.Empty)
            {
                TextAlignment = UITextAlignment.Right, AutocorrectionType = UITextAutocorrectionType.No, AutocapitalizationType = UITextAutocapitalizationType.None
            };

            creatorElement.Changed += (sender, e) => ViewModel.Creator = creatorElement.Value;

            var assigneeElement = new StringElement("Assignee", () => ViewModel.SelectAssigneeCommand.ExecuteIfCan());

            assigneeElement.Style = UITableViewCellStyle.Value1;

            var milestoneElement = new StringElement("Milestone", () => ViewModel.SelectMilestoneCommand.ExecuteIfCan());

            milestoneElement.Style = UITableViewCellStyle.Value1;

            var fieldElement = new StringElement("Field", () => ViewModel.SelectSortCommand.ExecuteIfCan());

            fieldElement.Style = UITableViewCellStyle.Value1;

            var ascElement = new BooleanElement("Ascending", false, x => ViewModel.Ascending = x.Value);

            var filterSection = new Section("Filter")
            {
                stateElement, mentionedElement, creatorElement, labelElement, assigneeElement, milestoneElement
            };
            var orderSection = new Section("Order By")
            {
                fieldElement, ascElement
            };
            var searchSection = new Section();

            searchSection.FooterView = new TableFooterButton("Search!", () => ViewModel.SaveCommand.ExecuteIfCan());
            source.Root.Add(filterSection, orderSection, searchSection);

            this.WhenAnyObservable(x => x.ViewModel.SelectAssigneeCommand)
            .Subscribe(_ => IssueAssigneeViewController.Show(this, ViewModel.CreateAssigneeViewModel()));

            this.WhenAnyObservable(x => x.ViewModel.SelectMilestoneCommand)
            .Subscribe(_ => IssueMilestonesViewController.Show(this, ViewModel.CreateMilestonesViewModel()));

            this.WhenAnyObservable(x => x.ViewModel.SelectLabelsCommand)
            .Subscribe(_ => IssueLabelsViewController.Show(this, ViewModel.CreateLabelsViewModel()));

            this.WhenAnyValue(x => x.ViewModel.State).Subscribe(x => stateElement.Value               = x.Humanize());
            this.WhenAnyValue(x => x.ViewModel.LabelsString).Subscribe(x => labelElement.Value        = x);
            this.WhenAnyValue(x => x.ViewModel.Mentioned).Subscribe(x => mentionedElement.Value       = x);
            this.WhenAnyValue(x => x.ViewModel.Creator).Subscribe(x => creatorElement.Value           = x);
            this.WhenAnyValue(x => x.ViewModel.AssigneeString).Subscribe(x => assigneeElement.Value   = x);
            this.WhenAnyValue(x => x.ViewModel.MilestoneString).Subscribe(x => milestoneElement.Value = x);
            this.WhenAnyValue(x => x.ViewModel.SortType).Subscribe(x => fieldElement.Value            = x.Humanize());
            this.WhenAnyValue(x => x.ViewModel.Ascending).Subscribe(x => ascElement.Value             = x);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var source = new DialogTableViewSource(TableView);

            TableView.Source = source;

            var mentionedElement = new EntryElement("Mentioned", "username", string.Empty)
            {
                TextAlignment = UITextAlignment.Right, AutocorrectionType = UITextAutocorrectionType.No, AutocapitalizationType = UITextAutocapitalizationType.None
            };

            var creatorElement = new EntryElement("Creator", "username", string.Empty)
            {
                TextAlignment = UITextAlignment.Right, AutocorrectionType = UITextAutocorrectionType.No, AutocapitalizationType = UITextAutocapitalizationType.None
            };

            var stateElement     = new ButtonElement("State");
            var labelElement     = new ButtonElement("Labels");
            var assigneeElement  = new ButtonElement("Assignee");
            var milestoneElement = new ButtonElement("Milestone");
            var fieldElement     = new ButtonElement("Field");
            var ascElement       = new BooleanElement("Ascending");

            var filterSection = new Section("Filter")
            {
                stateElement, mentionedElement, creatorElement, labelElement, assigneeElement, milestoneElement
            };
            var orderSection = new Section("Order By")
            {
                fieldElement, ascElement
            };
            var searchSection = new Section();
            var footerButton  = new TableFooterButton("Search!");

            searchSection.FooterView = footerButton;
            source.Root.Add(filterSection, orderSection, searchSection);

            OnActivation(d => {
                d(assigneeElement.Clicked.InvokeCommand(ViewModel.SelectAssigneeCommand));
                d(milestoneElement.Clicked.InvokeCommand(ViewModel.SelectMilestoneCommand));
                d(fieldElement.Clicked.InvokeCommand(ViewModel.SelectSortCommand));
                d(stateElement.Clicked.InvokeCommand(ViewModel.SelectStateCommand));
                d(labelElement.Clicked.InvokeCommand(ViewModel.SelectLabelsCommand));
                d(footerButton.Clicked.InvokeCommand(ViewModel.SaveCommand));
                d(ascElement.Changed.Subscribe(x => ViewModel.Ascending       = x));
                d(mentionedElement.Changed.Subscribe(x => ViewModel.Mentioned = x));
                d(creatorElement.Changed.Subscribe(x => ViewModel.Creator     = x));

                d(this.WhenAnyValue(x => x.ViewModel.DismissCommand)
                  .ToBarButtonItem(Images.Cancel, x => NavigationItem.LeftBarButtonItem = x));

                d(this.WhenAnyValue(x => x.ViewModel.SaveCommand)
                  .ToBarButtonItem(Images.Search, x => NavigationItem.RightBarButtonItem = x));

                d(this.WhenAnyValue(x => x.ViewModel.State).Subscribe(x => stateElement.Value               = x.Humanize()));
                d(this.WhenAnyValue(x => x.ViewModel.LabelsString).Subscribe(x => labelElement.Value        = x));
                d(this.WhenAnyValue(x => x.ViewModel.Mentioned).Subscribe(x => mentionedElement.Value       = x));
                d(this.WhenAnyValue(x => x.ViewModel.Creator).Subscribe(x => creatorElement.Value           = x));
                d(this.WhenAnyValue(x => x.ViewModel.AssigneeString).Subscribe(x => assigneeElement.Value   = x));
                d(this.WhenAnyValue(x => x.ViewModel.MilestoneString).Subscribe(x => milestoneElement.Value = x));
                d(this.WhenAnyValue(x => x.ViewModel.SortType).Subscribe(x => fieldElement.Value            = x.Humanize()));
                d(this.WhenAnyValue(x => x.ViewModel.Ascending).Subscribe(x => ascElement.Value             = x));

                d(this.WhenAnyObservable(x => x.ViewModel.SelectAssigneeCommand)
                  .Subscribe(_ => IssueAssigneeViewController.Show(this, ViewModel.CreateAssigneeViewModel())));

                d(this.WhenAnyObservable(x => x.ViewModel.SelectMilestoneCommand)
                  .Subscribe(_ => IssueMilestonesViewController.Show(this, ViewModel.CreateMilestonesViewModel())));

                d(this.WhenAnyObservable(x => x.ViewModel.SelectLabelsCommand)
                  .Subscribe(_ => IssueLabelsViewController.Show(this, ViewModel.CreateLabelsViewModel())));
            });
        }