Changeset View
Changeset View
Standalone View
Standalone View
src/applications/meta/view/PhabricatorApplicationLaunchView.php
<?php | <?php | ||||
final class PhabricatorApplicationLaunchView extends AphrontTagView { | final class PhabricatorApplicationLaunchView extends AphrontTagView { | ||||
private $application; | private $application; | ||||
private $status; | |||||
public function setApplication(PhabricatorApplication $application) { | public function setApplication(PhabricatorApplication $application) { | ||||
$this->application = $application; | $this->application = $application; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setApplicationStatus(array $status) { | |||||
$this->status = $status; | |||||
return $this; | |||||
} | |||||
protected function getTagName() { | protected function getTagName() { | ||||
return $this->application ? 'a' : 'div'; | return $this->application ? 'a' : 'div'; | ||||
} | } | ||||
protected function getTagAttributes() { | protected function getTagAttributes() { | ||||
$application = $this->application; | $application = $this->application; | ||||
return array( | return array( | ||||
'class' => array('phabricator-application-launch-container'), | 'class' => array('phabricator-application-launch-container'), | ||||
Show All 18 Lines | if ($application) { | ||||
$content[] = phutil_tag( | $content[] = phutil_tag( | ||||
'span', | 'span', | ||||
array( | array( | ||||
'class' => 'phabricator-application-launch-description', | 'class' => 'phabricator-application-launch-description', | ||||
), | ), | ||||
$application->getShortDescription()); | $application->getShortDescription()); | ||||
$counts = array(); | |||||
$text = array(); | |||||
if ($this->status) { | |||||
foreach ($this->status as $status) { | |||||
$type = $status->getType(); | |||||
$counts[$type] = idx($counts, $type, 0) + $status->getCount(); | |||||
if ($status->getCount()) { | |||||
$text[] = $status->getText(); | |||||
} | |||||
} | |||||
} | |||||
$attention = PhabricatorApplicationStatusView::TYPE_NEEDS_ATTENTION; | |||||
$warning = PhabricatorApplicationStatusView::TYPE_WARNING; | |||||
if (!empty($counts[$attention]) || !empty($counts[$warning])) { | |||||
$count = idx($counts, $attention, 0); | |||||
$count1 = $count2 = ''; | |||||
if ($count > 0) { | |||||
$count1 = phutil_tag( | |||||
'span', | |||||
array( | |||||
'class' => 'phabricator-application-attention-count', | |||||
), | |||||
$this->formatStatusItemCount($count)); | |||||
} | |||||
if (!empty($counts[$warning])) { | |||||
$count2 = phutil_tag( | |||||
'span', | |||||
array( | |||||
'class' => 'phabricator-application-warning-count', | |||||
), | |||||
$this->formatStatusItemCount($counts[$warning])); | |||||
} | |||||
if (nonempty($count1) && nonempty($count2)) { | |||||
$numbers = array($count1, ' / ', $count2); | |||||
} else { | |||||
$numbers = array($count1, $count2); | |||||
} | |||||
Javelin::initBehavior('phabricator-tooltips'); | |||||
$content[] = javelin_tag( | |||||
'span', | |||||
array( | |||||
'sigil' => 'has-tooltip', | |||||
'meta' => array( | |||||
'tip' => implode("\n", $text), | |||||
'size' => 300, | |||||
'align' => 'E', | |||||
), | |||||
'class' => 'phabricator-application-launch-attention', | |||||
), | |||||
$numbers); | |||||
} | |||||
$classes = array(); | $classes = array(); | ||||
$classes[] = 'phabricator-application-launch-icon'; | $classes[] = 'phabricator-application-launch-icon'; | ||||
$styles = array(); | $styles = array(); | ||||
$classes[] = $application->getIcon(); | $classes[] = $application->getIcon(); | ||||
$classes[] = 'phui-icon-view'; | $classes[] = 'phui-icon-view'; | ||||
$classes[] = 'phui-font-fa'; | $classes[] = 'phui-font-fa'; | ||||
$icon = phutil_tag( | $icon = phutil_tag( | ||||
'span', | 'span', | ||||
array( | array( | ||||
'class' => implode(' ', $classes), | 'class' => implode(' ', $classes), | ||||
'style' => nonempty(implode('; ', $styles), null), | 'style' => nonempty(implode('; ', $styles), null), | ||||
), | ), | ||||
''); | ''); | ||||
} | } | ||||
return array( | return array( | ||||
$icon, | $icon, | ||||
$content, | $content, | ||||
); | ); | ||||
} | } | ||||
private function formatStatusItemCount($count) { | |||||
$limit = PhabricatorApplication::MAX_STATUS_ITEMS; | |||||
if ($count >= $limit) { | |||||
return pht('%s+', new PhutilNumber($limit - 1)); | |||||
} else { | |||||
return pht('%s', new PhutilNumber($count)); | |||||
} | |||||
} | |||||
} | } |