private function buildPropertyList(HarbormasterBuildStep $step, PhabricatorCustomFieldList $field_list)
 {
     $viewer = $this->getViewer();
     $view = id(new PHUIPropertyListView())->setUser($viewer)->setObject($step);
     try {
         $implementation = $step->getStepImplementation();
     } catch (Exception $ex) {
         $implementation = null;
     }
     if ($implementation) {
         $type = $implementation->getName();
     } else {
         $type = phutil_tag('em', array(), pht('Invalid Implementation ("%s")!', $step->getClassName()));
     }
     $view->addProperty(pht('Step Type'), $type);
     $view->addProperty(pht('Created'), phabricator_datetime($step->getDateCreated(), $viewer));
     $field_list->appendFieldsToPropertyList($step, $viewer, $view);
     $view->invokeWillRenderEvent();
     $description = $step->getDescription();
     if (strlen($description)) {
         $view->addSectionHeader(pht('Description'), PHUIPropertyListView::ICON_SUMMARY);
         $view->addTextContent(new PHUIRemarkupView($viewer, $description));
     }
     return $view;
 }
 private function buildPropertyList(HarbormasterBuildStep $step, PhabricatorCustomFieldList $field_list)
 {
     $viewer = $this->getViewer();
     $view = id(new PHUIPropertyListView())->setUser($viewer)->setObject($step);
     $view->addProperty(pht('Created'), phabricator_datetime($step->getDateCreated(), $viewer));
     $field_list->appendFieldsToPropertyList($step, $viewer, $view);
     $view->invokeWillRenderEvent();
     $description = $step->getDescription();
     if (strlen($description)) {
         $view->addSectionHeader(pht('Description'), PHUIPropertyListView::ICON_SUMMARY);
         $view->addTextContent(new PHUIRemarkupView($viewer, $description));
     }
     return $view;
 }
 private function buildPackagePropertyView(PhabricatorOwnersPackage $package, PhabricatorCustomFieldList $field_list)
 {
     $viewer = $this->getViewer();
     $view = id(new PHUIPropertyListView())->setUser($viewer);
     $owners = $package->getOwners();
     if ($owners) {
         $owner_list = $viewer->renderHandleList(mpull($owners, 'getUserPHID'));
     } else {
         $owner_list = phutil_tag('em', array(), pht('None'));
     }
     $view->addProperty(pht('Owners'), $owner_list);
     if ($package->getAuditingEnabled()) {
         $auditing = pht('Enabled');
     } else {
         $auditing = pht('Disabled');
     }
     $view->addProperty(pht('Auditing'), $auditing);
     $description = $package->getDescription();
     if (strlen($description)) {
         $view->addSectionHeader(pht('Description'));
         $view->addTextContent($output = PhabricatorMarkupEngine::renderOneObject(id(new PhabricatorMarkupOneOff())->setContent($description), 'default', $viewer));
     }
     $view->invokeWillRenderEvent();
     $field_list->appendFieldsToPropertyList($package, $viewer, $view);
     return $view;
 }
 private function buildLabelMap(PhabricatorCustomFieldList $field_list)
 {
     $label_map = array();
     foreach ($field_list->getFields() as $key => $field) {
         $labels = $field->getCommitMessageLabels();
         $key = $field->getFieldKeyForConduit();
         foreach ($labels as $label) {
             $normal_label = DifferentialCommitMessageParser::normalizeFieldLabel($label);
             if (!empty($label_map[$normal_label])) {
                 throw new Exception(pht('Field label "%s" is parsed by two custom fields: "%s" and ' . '"%s". Each label must be parsed by only one field.', $label, $key, $label_map[$normal_label]));
             }
             $label_map[$normal_label] = $key;
         }
     }
     return $label_map;
 }
 private function buildPropertyView(ManiphestTask $task, PhabricatorCustomFieldList $field_list, array $edges, PhabricatorActionListView $actions, $handles)
 {
     $viewer = $this->getRequest()->getUser();
     $view = id(new PHUIPropertyListView())->setUser($viewer)->setObject($task)->setActionList($actions);
     $owner_phid = $task->getOwnerPHID();
     if ($owner_phid) {
         $assigned_to = $handles->renderHandle($owner_phid)->setShowHovercard(true);
     } else {
         $assigned_to = phutil_tag('em', array(), pht('None'));
     }
     $view->addProperty(pht('Assigned To'), $assigned_to);
     $view->addProperty(pht('Priority'), ManiphestTaskPriority::getTaskPriorityName($task->getPriority()));
     $author = $handles->renderHandle($task->getAuthorPHID())->setShowHovercard(true);
     $view->addProperty(pht('Author'), $author);
     if (ManiphestTaskPoints::getIsEnabled()) {
         $points = $task->getPoints();
         if ($points !== null) {
             $view->addProperty(ManiphestTaskPoints::getPointsLabel(), $task->getPoints());
         }
     }
     $source = $task->getOriginalEmailSource();
     if ($source) {
         $subject = '[T' . $task->getID() . '] ' . $task->getTitle();
         $view->addProperty(pht('From Email'), phutil_tag('a', array('href' => 'mailto:' . $source . '?subject=' . $subject), $source));
     }
     $edge_types = array(ManiphestTaskDependedOnByTaskEdgeType::EDGECONST => pht('Blocks'), ManiphestTaskDependsOnTaskEdgeType::EDGECONST => pht('Blocked By'), ManiphestTaskHasRevisionEdgeType::EDGECONST => pht('Differential Revisions'), ManiphestTaskHasMockEdgeType::EDGECONST => pht('Pholio Mocks'));
     $revisions_commits = array();
     $commit_phids = array_keys($edges[ManiphestTaskHasCommitEdgeType::EDGECONST]);
     if ($commit_phids) {
         $commit_drev = DiffusionCommitHasRevisionEdgeType::EDGECONST;
         $drev_edges = id(new PhabricatorEdgeQuery())->withSourcePHIDs($commit_phids)->withEdgeTypes(array($commit_drev))->execute();
         foreach ($commit_phids as $phid) {
             $revisions_commits[$phid] = $handles->renderHandle($phid)->setShowHovercard(true);
             $revision_phid = key($drev_edges[$phid][$commit_drev]);
             $revision_handle = $handles->getHandleIfExists($revision_phid);
             if ($revision_handle) {
                 $task_drev = ManiphestTaskHasRevisionEdgeType::EDGECONST;
                 unset($edges[$task_drev][$revision_phid]);
                 $revisions_commits[$phid] = hsprintf('%s / %s', $revision_handle->renderHovercardLink($revision_handle->getName()), $revisions_commits[$phid]);
             }
         }
     }
     foreach ($edge_types as $edge_type => $edge_name) {
         if ($edges[$edge_type]) {
             $edge_handles = $viewer->loadHandles(array_keys($edges[$edge_type]));
             $view->addProperty($edge_name, $edge_handles->renderList());
         }
     }
     if ($revisions_commits) {
         $view->addProperty(pht('Commits'), phutil_implode_html(phutil_tag('br'), $revisions_commits));
     }
     $view->invokeWillRenderEvent();
     $field_list->appendFieldsToPropertyList($task, $viewer, $view);
     return $view;
 }
 public function initializeFieldsFromRequest(PhabricatorDashboardPanel $panel, PhabricatorCustomFieldList $field_list, AphrontRequest $request)
 {
     $map = array();
     if (strlen($request->getStr('engine'))) {
         $map['class'] = $request->getStr('engine');
     }
     if (strlen($request->getStr('query'))) {
         $map['key'] = $request->getStr('query');
     }
     $full_map = array();
     foreach ($map as $key => $value) {
         $full_map["std:dashboard:core:{$key}"] = $value;
     }
     foreach ($field_list->getFields() as $field) {
         $field_key = $field->getFieldKey();
         if (isset($full_map[$field_key])) {
             $field->setValueFromStorage($full_map[$field_key]);
         }
     }
 }
 private function buildPackageDetailView(PhabricatorOwnersPackage $package, PhabricatorCustomFieldList $field_list)
 {
     $viewer = $this->getViewer();
     $view = id(new PHUIPropertyListView())->setUser($viewer);
     $owners = $package->getOwners();
     if ($owners) {
         $owner_list = $viewer->renderHandleList(mpull($owners, 'getUserPHID'));
     } else {
         $owner_list = phutil_tag('em', array(), pht('None'));
     }
     $view->addProperty(pht('Owners'), $owner_list);
     $dominion = $package->getDominion();
     $dominion_map = PhabricatorOwnersPackage::getDominionOptionsMap();
     $spec = idx($dominion_map, $dominion, array());
     $name = idx($spec, 'short', $dominion);
     $view->addProperty(pht('Dominion'), $name);
     $auto = $package->getAutoReview();
     $autoreview_map = PhabricatorOwnersPackage::getAutoreviewOptionsMap();
     $spec = idx($autoreview_map, $auto, array());
     $name = idx($spec, 'name', $auto);
     $view->addProperty(pht('Auto Review'), $name);
     if ($package->getAuditingEnabled()) {
         $auditing = pht('Enabled');
     } else {
         $auditing = pht('Disabled');
     }
     $view->addProperty(pht('Auditing'), $auditing);
     $description = $package->getDescription();
     if (strlen($description)) {
         $description = new PHUIRemarkupView($viewer, $description);
         $view->addSectionHeader(pht('Description'));
         $view->addTextContent($description);
     }
     $field_list->appendFieldsToPropertyList($package, $viewer, $view);
     return $view;
 }
 private function buildDiffDetailView(array $diffs, DifferentialRevision $revision, PhabricatorCustomFieldList $field_list)
 {
     $viewer = $this->getViewer();
     $fields = array();
     foreach ($field_list->getFields() as $field) {
         if ($field->shouldAppearInDiffPropertyView()) {
             $fields[] = $field;
         }
     }
     if (!$fields) {
         return null;
     }
     // Make sure we're only going to render unique diffs.
     $diffs = mpull($diffs, null, 'getID');
     $labels = array(pht('Left'), pht('Right'));
     $property_lists = array();
     foreach ($diffs as $diff) {
         if (count($diffs) == 2) {
             $label = array_shift($labels);
             $label = pht('%s (Diff %d)', $label, $diff->getID());
         } else {
             $label = pht('Diff %d', $diff->getID());
         }
         $property_lists[] = array($label, $this->buildDiffPropertyList($diff, $revision, $fields));
     }
     $box = id(new PHUIObjectBoxView())->setHeaderText(pht('Diff Detail'))->setUser($viewer);
     $last_tab = null;
     foreach ($property_lists as $key => $property_list) {
         list($tab_name, $list_view) = $property_list;
         $tab = id(new PHUIListItemView())->setKey($key)->setName($tab_name);
         $box->addPropertyList($list_view, $tab);
         $last_tab = $tab;
     }
     if ($last_tab) {
         $last_tab->setSelected(true);
     }
     return $box;
 }
 private function buildRevisionWarnings(DifferentialRevision $revision, PhabricatorCustomFieldList $field_list, array $warning_handle_map, array $handles)
 {
     $warnings = array();
     foreach ($field_list->getFields() as $key => $field) {
         $phids = idx($warning_handle_map, $key, array());
         $field_handles = array_select_keys($handles, $phids);
         $field_warnings = $field->getWarningsForRevisionHeader($field_handles);
         foreach ($field_warnings as $warning) {
             $warnings[] = $warning;
         }
     }
     return $warnings;
 }
 private function buildPropertyView(ManiphestTask $task, PhabricatorCustomFieldList $field_list, array $edges, $handles)
 {
     $viewer = $this->getRequest()->getUser();
     $view = id(new PHUIPropertyListView())->setUser($viewer);
     $source = $task->getOriginalEmailSource();
     if ($source) {
         $subject = '[T' . $task->getID() . '] ' . $task->getTitle();
         $view->addProperty(pht('From Email'), phutil_tag('a', array('href' => 'mailto:' . $source . '?subject=' . $subject), $source));
     }
     $edge_types = array(ManiphestTaskHasRevisionEdgeType::EDGECONST => pht('Differential Revisions'), ManiphestTaskHasMockEdgeType::EDGECONST => pht('Pholio Mocks'));
     $revisions_commits = array();
     $commit_phids = array_keys($edges[ManiphestTaskHasCommitEdgeType::EDGECONST]);
     if ($commit_phids) {
         $commit_drev = DiffusionCommitHasRevisionEdgeType::EDGECONST;
         $drev_edges = id(new PhabricatorEdgeQuery())->withSourcePHIDs($commit_phids)->withEdgeTypes(array($commit_drev))->execute();
         foreach ($commit_phids as $phid) {
             $revisions_commits[$phid] = $handles->renderHandle($phid)->setShowHovercard(true);
             $revision_phid = key($drev_edges[$phid][$commit_drev]);
             $revision_handle = $handles->getHandleIfExists($revision_phid);
             if ($revision_handle) {
                 $task_drev = ManiphestTaskHasRevisionEdgeType::EDGECONST;
                 unset($edges[$task_drev][$revision_phid]);
                 $revisions_commits[$phid] = hsprintf('%s / %s', $revision_handle->renderHovercardLink($revision_handle->getName()), $revisions_commits[$phid]);
             }
         }
     }
     foreach ($edge_types as $edge_type => $edge_name) {
         if ($edges[$edge_type]) {
             $edge_handles = $viewer->loadHandles(array_keys($edges[$edge_type]));
             $view->addProperty($edge_name, $edge_handles->renderList());
         }
     }
     if ($revisions_commits) {
         $view->addProperty(pht('Commits'), phutil_implode_html(phutil_tag('br'), $revisions_commits));
     }
     $field_list->appendFieldsToPropertyList($task, $viewer, $view);
     if ($view->hasAnyProperties()) {
         return $view;
     }
     return null;
 }
 private function buildPropertyView(ManiphestTask $task, PhabricatorCustomFieldList $field_list, array $edges, PhabricatorActionListView $actions, $handles)
 {
     $viewer = $this->getRequest()->getUser();
     $view = id(new PHUIPropertyListView())->setUser($viewer)->setObject($task)->setActionList($actions);
     $view->addProperty(pht('Assigned To'), $task->getOwnerPHID() ? $handles->renderHandle($task->getOwnerPHID()) : phutil_tag('em', array(), pht('None')));
     $view->addProperty(pht('Priority'), ManiphestTaskPriority::getTaskPriorityName($task->getPriority()));
     $view->addProperty(pht('Author'), $handles->renderHandle($task->getAuthorPHID()));
     $source = $task->getOriginalEmailSource();
     if ($source) {
         $subject = '[T' . $task->getID() . '] ' . $task->getTitle();
         $view->addProperty(pht('From Email'), phutil_tag('a', array('href' => 'mailto:' . $source . '?subject=' . $subject), $source));
     }
     $edge_types = array(ManiphestTaskDependedOnByTaskEdgeType::EDGECONST => pht('Blocks'), ManiphestTaskDependsOnTaskEdgeType::EDGECONST => pht('Blocked By'), ManiphestTaskHasRevisionEdgeType::EDGECONST => pht('Differential Revisions'), ManiphestTaskHasMockEdgeType::EDGECONST => pht('Pholio Mocks'));
     $revisions_commits = array();
     $commit_phids = array_keys($edges[ManiphestTaskHasCommitEdgeType::EDGECONST]);
     if ($commit_phids) {
         $commit_drev = DiffusionCommitHasRevisionEdgeType::EDGECONST;
         $drev_edges = id(new PhabricatorEdgeQuery())->withSourcePHIDs($commit_phids)->withEdgeTypes(array($commit_drev))->execute();
         foreach ($commit_phids as $phid) {
             $revisions_commits[$phid] = $handles->renderHandle($phid);
             $revision_phid = key($drev_edges[$phid][$commit_drev]);
             $revision_handle = $handles->getHandleIfExists($revision_phid);
             if ($revision_handle) {
                 $task_drev = ManiphestTaskHasRevisionEdgeType::EDGECONST;
                 unset($edges[$task_drev][$revision_phid]);
                 $revisions_commits[$phid] = hsprintf('%s / %s', $revision_handle->renderLink($revision_handle->getName()), $revisions_commits[$phid]);
             }
         }
     }
     foreach ($edge_types as $edge_type => $edge_name) {
         if ($edges[$edge_type]) {
             $edge_handles = $viewer->loadHandles(array_keys($edges[$edge_type]));
             $view->addProperty($edge_name, $edge_handles->renderList());
         }
     }
     if ($revisions_commits) {
         $view->addProperty(pht('Commits'), phutil_implode_html(phutil_tag('br'), $revisions_commits));
     }
     $attached = $task->getAttached();
     if (!is_array($attached)) {
         $attached = array();
     }
     $file_infos = idx($attached, PhabricatorFileFilePHIDType::TYPECONST);
     if ($file_infos) {
         $file_phids = array_keys($file_infos);
         // TODO: These should probably be handles or something; clean this up
         // as we sort out file attachments.
         $files = id(new PhabricatorFileQuery())->setViewer($viewer)->withPHIDs($file_phids)->execute();
         $file_view = new PhabricatorFileLinkListView();
         $file_view->setFiles($files);
         $view->addProperty(pht('Files'), $file_view->render());
     }
     $view->invokeWillRenderEvent();
     $field_list->appendFieldsToPropertyList($task, $viewer, $view);
     return $view;
 }
 private function buildDiffDetailView(array $diffs, DifferentialRevision $revision, PhabricatorCustomFieldList $field_list)
 {
     $viewer = $this->getViewer();
     $fields = array();
     foreach ($field_list->getFields() as $field) {
         if ($field->shouldAppearInDiffPropertyView()) {
             $fields[] = $field;
         }
     }
     if (!$fields) {
         return null;
     }
     $property_lists = array();
     foreach ($this->getDiffTabLabels($diffs) as $tab) {
         list($label, $diff) = $tab;
         $property_lists[] = array($label, $this->buildDiffPropertyList($diff, $revision, $fields));
     }
     $tab_group = id(new PHUITabGroupView())->setHideSingleTab(true);
     foreach ($property_lists as $key => $property_list) {
         list($tab_name, $list_view) = $property_list;
         $tab = id(new PHUITabView())->setKey($key)->setName($tab_name)->appendChild($list_view);
         $tab_group->addTab($tab);
         $tab_group->selectTab($key);
     }
     return id(new PHUIObjectBoxView())->setHeaderText(pht('Diff Detail'))->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setUser($viewer)->addTabGroup($tab_group);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $object = id(new PhabricatorObjectQuery())->setViewer($viewer)->withPHIDs(array($request->getStr('objectPHID')))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$object) {
         return new Aphront404Response();
     }
     if (!$object instanceof AlmanacPropertyInterface) {
         return new Aphront404Response();
     }
     $cancel_uri = $object->getURI();
     $key = $request->getStr('key');
     if ($key) {
         $property_key = $key;
         $is_new = false;
         $title = pht('Edit Property');
         $save_button = pht('Save Changes');
     } else {
         $property_key = null;
         $is_new = true;
         $title = pht('Add Property');
         $save_button = pht('Add Property');
     }
     if ($is_new) {
         $errors = array();
         $property = null;
         $v_name = null;
         $e_name = true;
         if ($request->isFormPost()) {
             $name = $request->getStr('name');
             if (!strlen($name)) {
                 $e_name = pht('Required');
                 $errors[] = pht('You must provide a property name.');
             } else {
                 $caught = null;
                 try {
                     AlmanacNames::validateServiceOrDeviceName($name);
                 } catch (Exception $ex) {
                     $caught = $ex;
                 }
                 if ($caught) {
                     $e_name = pht('Invalid');
                     $errors[] = $caught->getMessage();
                 }
             }
             if (!$errors) {
                 $property_key = $name;
             }
         }
         if ($property_key === null) {
             $form = id(new AphrontFormView())->setUser($viewer)->appendChild(id(new AphrontFormTextControl())->setName('name')->setLabel(pht('Name'))->setValue($v_name)->setError($e_name));
             return $this->newDialog()->setTitle($title)->setErrors($errors)->addHiddenInput('objectPHID', $request->getStr('objectPHID'))->appendForm($form)->addSubmitButton(pht('Continue'))->addCancelButton($cancel_uri);
         }
     }
     // Make sure property key is appropriate.
     // TODO: It would be cleaner to put this safety check in the Editor.
     AlmanacNames::validateServiceOrDeviceName($property_key);
     // If we're adding a new property, put a placeholder on the object so
     // that we can build a CustomField for it.
     if (!$object->hasAlmanacProperty($property_key)) {
         $temporary_property = id(new AlmanacProperty())->setObjectPHID($object->getPHID())->setFieldName($property_key);
         $object->attachAlmanacProperties(array($temporary_property));
     }
     $field_list = PhabricatorCustomField::getObjectFields($object, PhabricatorCustomField::ROLE_DEFAULT);
     // Select only the field being edited.
     $fields = $field_list->getFields();
     $fields = array_select_keys($fields, array($property_key));
     $field_list = new PhabricatorCustomFieldList($fields);
     $field_list->setViewer($viewer)->readFieldsFromStorage($object);
     $validation_exception = null;
     if ($request->isFormPost() && $request->getStr('isValueEdit')) {
         $xactions = $field_list->buildFieldTransactionsFromRequest($object->getApplicationTransactionTemplate(), $request);
         $editor = $object->getApplicationTransactionEditor()->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true)->setContinueOnMissingFields(true);
         try {
             $editor->applyTransactions($object, $xactions);
             return id(new AphrontRedirectResponse())->setURI($cancel_uri);
         } catch (PhabricatorApplicationTransactionValidationException $ex) {
             $validation_exception = $ex;
         }
     }
     $form = id(new AphrontFormView())->setUser($viewer)->addHiddenInput('objectPHID', $request->getStr('objectPHID'))->addHiddenInput('key', $request->getStr('key'))->addHiddenInput('name', $property_key)->addHiddenInput('isValueEdit', true);
     $field_list->appendFieldsToForm($form);
     return $this->newDialog()->setTitle($title)->setValidationException($validation_exception)->appendForm($form)->addSubmitButton($save_button)->addCancelButton($cancel_uri);
 }
 private function buildDiffDetailView(array $diffs, DifferentialRevision $revision, PhabricatorCustomFieldList $field_list)
 {
     $viewer = $this->getViewer();
     $fields = array();
     foreach ($field_list->getFields() as $field) {
         if ($field->shouldAppearInDiffPropertyView()) {
             $fields[] = $field;
         }
     }
     if (!$fields) {
         return null;
     }
     $property_lists = array();
     foreach ($this->getDiffTabLabels($diffs) as $tab) {
         list($label, $diff) = $tab;
         $property_lists[] = array($label, $this->buildDiffPropertyList($diff, $revision, $fields));
     }
     $box = id(new PHUIObjectBoxView())->setHeaderText(pht('Diff Detail'))->setUser($viewer);
     $last_tab = null;
     foreach ($property_lists as $key => $property_list) {
         list($tab_name, $list_view) = $property_list;
         $tab = id(new PHUIListItemView())->setKey($key)->setName($tab_name);
         $box->addPropertyList($list_view, $tab);
         $last_tab = $tab;
     }
     if ($last_tab) {
         $last_tab->setSelected(true);
     }
     return $box;
 }