Changeset View
Changeset View
Standalone View
Standalone View
src/applications/herald/adapter/HeraldAdapter.php
Show First 20 Lines • Show All 936 Lines • ▼ Show 20 Lines | public function getEditorValueForAction( | ||||
return $action->getEditorValue( | return $action->getEditorValue( | ||||
$viewer, | $viewer, | ||||
$action_record->getTarget()); | $action_record->getTarget()); | ||||
} | } | ||||
public function renderRuleAsText( | public function renderRuleAsText( | ||||
HeraldRule $rule, | HeraldRule $rule, | ||||
PhabricatorHandleList $handles, | |||||
PhabricatorUser $viewer) { | PhabricatorUser $viewer) { | ||||
require_celerity_resource('herald-css'); | require_celerity_resource('herald-css'); | ||||
$icon = id(new PHUIIconView()) | $icon = id(new PHUIIconView()) | ||||
->setIcon('fa-chevron-circle-right lightgreytext') | ->setIcon('fa-chevron-circle-right lightgreytext') | ||||
->addClass('herald-list-icon'); | ->addClass('herald-list-icon'); | ||||
Show All 14 Lines | public function renderRuleAsText( | ||||
foreach ($rule->getConditions() as $condition) { | foreach ($rule->getConditions() as $condition) { | ||||
$match_list[] = phutil_tag( | $match_list[] = phutil_tag( | ||||
'div', | 'div', | ||||
array( | array( | ||||
'class' => 'herald-list-item', | 'class' => 'herald-list-item', | ||||
), | ), | ||||
array( | array( | ||||
$icon, | $icon, | ||||
$this->renderConditionAsText($condition, $handles, $viewer), | $this->renderConditionAsText($condition, $viewer), | ||||
)); | )); | ||||
} | } | ||||
if ($rule->isRepeatFirst()) { | if ($rule->isRepeatFirst()) { | ||||
$action_text = pht( | $action_text = pht( | ||||
'Take these actions the first time this rule matches:'); | 'Take these actions the first time this rule matches:'); | ||||
} else if ($rule->isRepeatOnChange()) { | } else if ($rule->isRepeatOnChange()) { | ||||
$action_text = pht( | $action_text = pht( | ||||
Show All 14 Lines | public function renderRuleAsText( | ||||
foreach ($rule->getActions() as $action) { | foreach ($rule->getActions() as $action) { | ||||
$action_list[] = phutil_tag( | $action_list[] = phutil_tag( | ||||
'div', | 'div', | ||||
array( | array( | ||||
'class' => 'herald-list-item', | 'class' => 'herald-list-item', | ||||
), | ), | ||||
array( | array( | ||||
$icon, | $icon, | ||||
$this->renderActionAsText($viewer, $action, $handles), | $this->renderActionAsText($viewer, $action), | ||||
)); | )); | ||||
} | } | ||||
return array( | return array( | ||||
$match_title, | $match_title, | ||||
$match_list, | $match_list, | ||||
$action_title, | $action_title, | ||||
$action_list, | $action_list, | ||||
); | ); | ||||
} | } | ||||
private function renderConditionAsText( | private function renderConditionAsText( | ||||
HeraldCondition $condition, | HeraldCondition $condition, | ||||
PhabricatorHandleList $handles, | |||||
PhabricatorUser $viewer) { | PhabricatorUser $viewer) { | ||||
$field_type = $condition->getFieldName(); | $field_type = $condition->getFieldName(); | ||||
$field = $this->getFieldImplementation($field_type); | $field = $this->getFieldImplementation($field_type); | ||||
if (!$field) { | if (!$field) { | ||||
return pht('Unknown Field: "%s"', $field_type); | return pht('Unknown Field: "%s"', $field_type); | ||||
} | } | ||||
$field_name = $field->getHeraldFieldName(); | $field_name = $field->getHeraldFieldName(); | ||||
$condition_type = $condition->getFieldCondition(); | $condition_type = $condition->getFieldCondition(); | ||||
$condition_name = idx($this->getConditionNameMap(), $condition_type); | $condition_name = idx($this->getConditionNameMap(), $condition_type); | ||||
$value = $this->renderConditionValueAsText($condition, $handles, $viewer); | $value = $this->renderConditionValueAsText($condition, $viewer); | ||||
return array( | return array( | ||||
$field_name, | $field_name, | ||||
' ', | ' ', | ||||
$condition_name, | $condition_name, | ||||
' ', | ' ', | ||||
$value, | $value, | ||||
); | ); | ||||
} | } | ||||
private function renderActionAsText( | private function renderActionAsText( | ||||
PhabricatorUser $viewer, | PhabricatorUser $viewer, | ||||
HeraldActionRecord $action, | HeraldActionRecord $action_record) { | ||||
PhabricatorHandleList $handles) { | |||||
$impl = $this->getActionImplementation($action->getAction()); | $action_type = $action_record->getAction(); | ||||
if ($impl) { | $action_value = $action_record->getTarget(); | ||||
$impl->setViewer($viewer); | |||||
$value = $action->getTarget(); | $action = $this->getActionImplementation($action_type); | ||||
return $impl->renderActionDescription($value); | if (!$action) { | ||||
return pht('Unknown Action ("%s")', $action_type); | |||||
} | } | ||||
$rule_global = HeraldRuleTypeConfig::RULE_TYPE_GLOBAL; | $action->setViewer($viewer); | ||||
$action_type = $action->getAction(); | |||||
$default = pht('(Unknown Action "%s") equals', $action_type); | |||||
$action_name = idx( | |||||
$this->getActionNameMap($rule_global), | |||||
$action_type, | |||||
$default); | |||||
$target = $this->renderActionTargetAsText($action, $handles); | return $action->renderActionDescription($action_value); | ||||
return hsprintf(' %s %s', $action_name, $target); | |||||
} | } | ||||
private function renderConditionValueAsText( | private function renderConditionValueAsText( | ||||
HeraldCondition $condition, | HeraldCondition $condition, | ||||
PhabricatorHandleList $handles, | |||||
PhabricatorUser $viewer) { | PhabricatorUser $viewer) { | ||||
$field = $this->requireFieldImplementation($condition->getFieldName()); | $field = $this->requireFieldImplementation($condition->getFieldName()); | ||||
return $field->renderConditionValue( | return $field->renderConditionValue( | ||||
$viewer, | $viewer, | ||||
$condition->getFieldCondition(), | $condition->getFieldCondition(), | ||||
$condition->getValue()); | $condition->getValue()); | ||||
} | } | ||||
private function renderActionTargetAsText( | |||||
HeraldActionRecord $action, | |||||
PhabricatorHandleList $handles) { | |||||
// TODO: This should be driven through HeraldAction. | |||||
$target = $action->getTarget(); | |||||
if (!is_array($target)) { | |||||
$target = array($target); | |||||
} | |||||
foreach ($target as $index => $val) { | |||||
switch ($action->getAction()) { | |||||
default: | |||||
$handle = $handles->getHandleIfExists($val); | |||||
if ($handle) { | |||||
$target[$index] = $handle->renderLink(); | |||||
} | |||||
break; | |||||
} | |||||
} | |||||
$target = phutil_implode_html(', ', $target); | |||||
return $target; | |||||
} | |||||
/** | |||||
* Given a @{class:HeraldRule}, this function extracts all the phids that | |||||
* we'll want to load as handles later. | |||||
* | |||||
* This function performs a somewhat hacky approach to figuring out what | |||||
* is and is not a phid - try to get the phid type and if the type is | |||||
* *not* unknown assume its a valid phid. | |||||
* | |||||
* Don't try this at home. Use more strongly typed data at home. | |||||
* | |||||
* Think of the children. | |||||
*/ | |||||
public static function getHandlePHIDs(HeraldRule $rule) { | |||||
$phids = array($rule->getAuthorPHID()); | |||||
foreach ($rule->getConditions() as $condition) { | |||||
$value = $condition->getValue(); | |||||
if (!is_array($value)) { | |||||
$value = array($value); | |||||
} | |||||
foreach ($value as $val) { | |||||
if (phid_get_type($val) != | |||||
PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN) { | |||||
$phids[] = $val; | |||||
} | |||||
} | |||||
} | |||||
foreach ($rule->getActions() as $action) { | |||||
$target = $action->getTarget(); | |||||
if (!is_array($target)) { | |||||
$target = array($target); | |||||
} | |||||
foreach ($target as $val) { | |||||
if (phid_get_type($val) != | |||||
PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN) { | |||||
$phids[] = $val; | |||||
} | |||||
} | |||||
} | |||||
if ($rule->isObjectRule()) { | |||||
$phids[] = $rule->getTriggerObjectPHID(); | |||||
} | |||||
return $phids; | |||||
} | |||||
/* -( Applying Effects )--------------------------------------------------- */ | /* -( Applying Effects )--------------------------------------------------- */ | ||||
/** | /** | ||||
* @task apply | * @task apply | ||||
*/ | */ | ||||
protected function applyStandardEffect(HeraldEffect $effect) { | protected function applyStandardEffect(HeraldEffect $effect) { | ||||
▲ Show 20 Lines • Show All 109 Lines • Show Last 20 Lines |