Beispiel #1
0
        public CollabHistoryItem(RevisionData data)
        {
            this.m_RevisionId  = data.id;
            this.m_TimeStamp   = data.timeStamp;
            base.name          = "HistoryItem";
            this.m_ActionsTray = new VisualContainer
            {
                name = "HistoryItemActionsTray"
            };
            this.m_ProgressSpinner = new HistoryProgressSpinner();
            this.m_Details         = new VisualElement
            {
                name = "HistoryDetail"
            };
            Label child = new Label(data.authorName)
            {
                name = "Author"
            };

            this.m_TimeAgo         = new Label(TimeAgo.GetString(this.m_TimeStamp));
            this.m_FullDescription = data.comment;
            bool flag = this.ShouldTruncateDescription(this.m_FullDescription);

            if (flag)
            {
                this.m_Description = new Label(this.GetTruncatedDescription(this.m_FullDescription));
            }
            else
            {
                this.m_Description = new Label(this.m_FullDescription);
            }
            this.m_Description.name = "RevisionDescription";
            CollabHistoryDropDown child2 = new CollabHistoryDropDown(data.changes, data.changesTotal, data.changesTruncated);

            if (data.current)
            {
                this.m_Button = new Button(new Action(this.Restore))
                {
                    name = "ActionButton",
                    text = "Restore"
                };
            }
            else if (data.obtained)
            {
                this.m_Button = new Button(new Action(this.GoBackTo))
                {
                    name = "ActionButton",
                    text = "Go back to..."
                };
            }
            else
            {
                this.m_Button = new Button(new Action(this.UpdateTo))
                {
                    name = "ActionButton",
                    text = "Update"
                };
            }
            this.m_Button.SetEnabled(data.enabled);
            this.m_ProgressSpinner.ProgressEnabled = data.inProgress;
            this.m_ActionsTray.Add(this.m_ProgressSpinner);
            this.m_ActionsTray.Add(this.m_Button);
            this.m_Details.Add(child);
            this.m_Details.Add(this.m_TimeAgo);
            this.m_Details.Add(this.m_Description);
            if (flag)
            {
                this.m_ExpandCollapseButton = new Button(new Action(this.ToggleDescription))
                {
                    name = "ToggleDescription",
                    text = "Show More"
                };
                this.m_Details.Add(this.m_ExpandCollapseButton);
            }
            if (data.buildState != BuildState.None)
            {
                BuildStatusButton child3;
                if (data.buildState == BuildState.Configure)
                {
                    child3 = new BuildStatusButton(new Action(this.ShowServicePage));
                }
                else
                {
                    child3 = new BuildStatusButton(new Action(this.ShowBuildForCommit), data.buildState, data.buildFailures);
                }
                this.m_Details.Add(child3);
            }
            this.m_Details.Add(this.m_ActionsTray);
            this.m_Details.Add(child2);
            base.Add(this.m_Details);
            base.schedule.Execute(new Action(this.UpdateTimeAgo)).Every(20000L);
        }
        public CollabHistoryItem(RevisionData data)
        {
            m_RevisionId  = data.id;
            m_TimeStamp   = data.timeStamp;
            name          = "HistoryItem";
            m_ActionsTray = new VisualElement {
                name = "HistoryItemActionsTray"
            };
            m_ProgressSpinner = new HistoryProgressSpinner();
            m_Details         = new VisualElement {
                name = "HistoryDetail"
            };
            var author = new Label(data.authorName)
            {
                name = "Author"
            };

            m_TimeAgo         = new Label(TimeAgo.GetString(m_TimeStamp));
            m_FullDescription = data.comment;
            var shouldTruncate = ShouldTruncateDescription(m_FullDescription);

            if (shouldTruncate)
            {
                m_Description = new Label(GetTruncatedDescription(m_FullDescription));
            }
            else
            {
                m_Description = new Label(m_FullDescription);
            }
            m_Description.name = "RevisionDescription";
            var dropdown = new CollabHistoryDropDown(data.changes, data.changesTotal, data.changesTruncated, data.id);

            if (data.current)
            {
                m_Button = new Button(Restore)
                {
                    name = "ActionButton", text = "Restore"
                };
            }
            else if (data.obtained)
            {
                m_Button = new Button(GoBackTo)
                {
                    name = "ActionButton", text = "Go back to..."
                };
            }
            else
            {
                m_Button = new Button(UpdateTo)
                {
                    name = "ActionButton", text = "Update"
                };
            }
            m_Button.SetEnabled(data.enabled);
            m_ProgressSpinner.ProgressEnabled = data.inProgress;

            m_ActionsTray.Add(m_ProgressSpinner);
            m_ActionsTray.Add(m_Button);

            m_Details.Add(author);
            m_Details.Add(m_TimeAgo);
            m_Details.Add(m_Description);

            if (shouldTruncate)
            {
                m_ExpandCollapseButton = new Button(ToggleDescription)
                {
                    name = "ToggleDescription", text = "Show More"
                };
                m_Details.Add(m_ExpandCollapseButton);
            }

            if (data.buildState != BuildState.None)
            {
                BuildStatusButton buildButton;
                if (data.buildState == BuildState.Configure)
                {
                    buildButton = new BuildStatusButton(ShowServicePage);
                }
                else
                {
                    buildButton = new BuildStatusButton(ShowBuildForCommit, data.buildState, data.buildFailures);
                }

                m_Details.Add(buildButton);
            }

            m_Details.Add(m_ActionsTray);
            m_Details.Add(dropdown);

            Add(m_Details);

            this.schedule.Execute(UpdateTimeAgo).Every(1000 * 20);
        }
        public IEnumerable <RevisionData> GenerateElements(IEnumerable <Revision> revisions, int totalRevisions, int startIndex, string tipRev, string inProgressRevision, bool revisionActionsEnabled, bool buildServiceEnabled, string currentUser)
        {
            int index = startIndex;

            foreach (var rev in revisions)
            {
                index++;
                var current = rev.revisionID == tipRev;

                // Calculate build status
                BuildState buildState    = BuildState.None;
                int        buildFailures = 0;
                if (rev.buildStatuses != null && rev.buildStatuses.Length > 0)
                {
                    bool inProgress = false;
                    foreach (CloudBuildStatus buildStatus in rev.buildStatuses)
                    {
                        if (buildStatus.complete)
                        {
                            if (!buildStatus.success)
                            {
                                buildFailures++;
                            }
                        }
                        else
                        {
                            inProgress = true;
                            break;
                        }
                    }

                    if (inProgress)
                    {
                        buildState = BuildState.InProgress;
                    }
                    else if (buildFailures > 0)
                    {
                        buildState = BuildState.Failed;
                    }
                    else
                    {
                        buildState = BuildState.Success;
                    }
                }
                else if (current && !buildServiceEnabled)
                {
                    buildState = BuildState.Configure;
                }

                // Calculate the number of changes performed on files and folders (not meta files)
                var paths = new Dictionary <string, ChangeData>();
                foreach (ChangeAction change in rev.entries)
                {
                    if (change.path.EndsWith(".meta"))
                    {
                        var path = change.path.Substring(0, change.path.Length - 5);
                        // Actions taken on meta files are secondary to any actions taken on the main file
                        if (!paths.ContainsKey(path))
                        {
                            paths[path] = new ChangeData()
                            {
                                path = path, action = change.action
                            }
                        }
                        ;
                    }
                    else
                    {
                        paths[change.path] = new ChangeData()
                        {
                            path = change.path, action = change.action
                        };
                    }
                }

                var displayName = (rev.author != currentUser) ? rev.authorName : "You";

                var item = new RevisionData
                {
                    id         = rev.revisionID,
                    index      = totalRevisions - index + 1,
                    timeStamp  = TimeStampToDateTime(rev.timeStamp),
                    authorName = displayName,
                    comment    = rev.comment,

                    obtained   = rev.isObtained,
                    current    = current,
                    inProgress = (rev.revisionID == inProgressRevision),
                    enabled    = revisionActionsEnabled,

                    buildState    = buildState,
                    buildFailures = buildFailures,

                    changes          = paths.Values.Take(k_MaxChangesPerRevision).ToList(),
                    changesTotal     = paths.Values.Count,
                    changesTruncated = paths.Values.Count > k_MaxChangesPerRevision,
                };

                yield return(item);
            }
        }