HarbormasterUnitPropertyView.php 3.49 KB
Newer Older
1
2
3
4
<?php

final class HarbormasterUnitPropertyView extends AphrontView {

5
  private $pathURIMap = array();
6
  private $unitMessages = array();
7
  private $limit;
8
  private $fullResultsURI;
9
  private $notice;
10
11
12
13
14
15
16
17
18
19
20
21

  public function setPathURIMap(array $map) {
    $this->pathURIMap = $map;
    return $this;
  }

  public function setUnitMessages(array $messages) {
    assert_instances_of($messages, 'HarbormasterBuildUnitMessage');
    $this->unitMessages = $messages;
    return $this;
  }

22
23
24
25
26
  public function setLimit($limit) {
    $this->limit = $limit;
    return $this;
  }

27
28
29
30
31
  public function setFullResultsURI($full_results_uri) {
    $this->fullResultsURI = $full_results_uri;
    return $this;
  }

32
33
34
35
36
  public function setNotice($notice) {
    $this->notice = $notice;
    return $this;
  }

37
  public function render() {
38
    $viewer = $this->getViewer();
39

40
41
42
    $messages = $this->unitMessages;
    $messages = msort($messages, 'getSortKey');

43
44
    $limit = $this->limit;

45
    if ($this->limit) {
46
47
48
      $display_messages = array_slice($messages, 0, $limit);
    } else {
      $display_messages = $messages;
49
    }
50
51
52

    $rows = array();
    $any_duration = false;
53
54
55
56
57
58
59
60
61
62
63
64
65
66
    foreach ($display_messages as $message) {
      $status = $message->getResult();

      $icon_icon = HarbormasterUnitStatus::getUnitStatusIcon($status);
      $icon_color = HarbormasterUnitStatus::getUnitStatusColor($status);
      $icon_label = HarbormasterUnitStatus::getUnitStatusLabel($status);

      $result_icon = id(new PHUIIconView())
        ->setIcon("{$icon_icon} {$icon_color}")
        ->addSigil('has-tooltip')
        ->setMetadata(
          array(
            'tip' => $icon_label,
          ));
67
68
69
70
71
72
73

      $duration = $message->getDuration();
      if ($duration !== null) {
        $any_duration = true;
        $duration = pht('%s ms', new PhutilNumber((int)(1000 * $duration)));
      }

74
      $name = $message->getUnitMessageDisplayName();
75
      $uri = $message->getURI();
76

77
      if ($uri) {
78
79
80
        $name = phutil_tag(
          'a',
          array(
81
            'href' => $uri,
82
83
84
          ),
          $name);
      }
85

86
87
88
89
      $name = array(
        $name,
        $message->newUnitMessageDetailsView($viewer, true),
      );
90
91

      $rows[] = array(
92
        $result_icon,
93
94
95
96
97
        $duration,
        $name,
      );
    }

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
    $full_uri = $this->fullResultsURI;
    if ($full_uri && (count($messages) > $limit)) {
      $counts = array();

      $groups = mgroup($messages, 'getResult');
      foreach ($groups as $status => $group) {
        $counts[] = HarbormasterUnitStatus::getUnitStatusCountLabel(
          $status,
          count($group));
      }

      $link_text = pht(
        'View Full Test Results (%s)',
        implode(" \xC2\xB7 ", $counts));

      $full_link = phutil_tag(
        'a',
        array(
          'href' => $full_uri,
        ),
        $link_text);

      $link_icon = id(new PHUIIconView())
        ->setIcon('fa-ellipsis-h lightgreytext');

      $rows[] = array($link_icon, null, $full_link);
    }

126
127
128
    $table = id(new AphrontTableView($rows))
      ->setHeaders(
        array(
129
          null,
130
131
132
133
134
          pht('Time'),
          pht('Test'),
        ))
      ->setColumnClasses(
        array(
135
136
          'top center',
          'top right',
137
138
139
140
141
142
          'top wide',
        ))
      ->setColumnWidths(
        array(
          '32px',
          '64px',
143
144
145
146
147
148
149
        ))
      ->setColumnVisibility(
        array(
          true,
          $any_duration,
        ));

150
151
152
153
    if ($this->notice) {
      $table->setNotice($this->notice);
    }

154
155
156
157
    return $table;
  }

}