1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 05:50:55 +01:00

Show yellow "draft" bubble in Audit

Summary: Fixes T6660. Uses the new stuff in Audit to build an EditEngine-aware icon.

Test Plan: {F2364304}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T6660

Differential Revision: https://secure.phabricator.com/D17208
This commit is contained in:
epriestley 2017-01-14 09:22:51 -08:00
parent 62cf4e6b95
commit 903e37a21b
9 changed files with 149 additions and 34 deletions

View file

@ -629,6 +629,7 @@ phutil_register_library_map(array(
'DiffusionCommitDiffContentHeraldField' => 'applications/diffusion/herald/DiffusionCommitDiffContentHeraldField.php',
'DiffusionCommitDiffContentRemovedHeraldField' => 'applications/diffusion/herald/DiffusionCommitDiffContentRemovedHeraldField.php',
'DiffusionCommitDiffEnormousHeraldField' => 'applications/diffusion/herald/DiffusionCommitDiffEnormousHeraldField.php',
'DiffusionCommitDraftEngine' => 'applications/diffusion/engine/DiffusionCommitDraftEngine.php',
'DiffusionCommitEditConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionCommitEditConduitAPIMethod.php',
'DiffusionCommitEditController' => 'applications/diffusion/controller/DiffusionCommitEditController.php',
'DiffusionCommitEditEngine' => 'applications/diffusion/editor/DiffusionCommitEditEngine.php',
@ -5341,6 +5342,7 @@ phutil_register_library_map(array(
'DiffusionCommitDiffContentHeraldField' => 'DiffusionCommitHeraldField',
'DiffusionCommitDiffContentRemovedHeraldField' => 'DiffusionCommitHeraldField',
'DiffusionCommitDiffEnormousHeraldField' => 'DiffusionCommitHeraldField',
'DiffusionCommitDraftEngine' => 'PhabricatorDraftEngine',
'DiffusionCommitEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
'DiffusionCommitEditController' => 'DiffusionController',
'DiffusionCommitEditEngine' => 'PhabricatorEditEngine',
@ -8794,6 +8796,7 @@ phutil_register_library_map(array(
'PhabricatorApplicationTransactionInterface',
'PhabricatorFulltextInterface',
'PhabricatorConduitResultInterface',
'PhabricatorDraftInterface',
),
'PhabricatorRepositoryCommitChangeParserWorker' => 'PhabricatorRepositoryCommitParserWorker',
'PhabricatorRepositoryCommitData' => 'PhabricatorRepositoryDAO',

View file

@ -14,7 +14,8 @@ final class PhabricatorCommitSearchEngine
public function newQuery() {
return id(new DiffusionCommitQuery())
->needAuditRequests(true)
->needCommitData(true);
->needCommitData(true)
->needDrafts(true);
}
protected function newResultBuckets() {
@ -140,7 +141,8 @@ final class PhabricatorCommitSearchEngine
$bucket = $this->getResultBucket($query);
$template = id(new PhabricatorAuditListView())
->setViewer($viewer);
->setViewer($viewer)
->setShowDrafts(true);
$views = array();
if ($bucket) {

View file

@ -4,6 +4,7 @@ final class PhabricatorAuditListView extends AphrontView {
private $commits;
private $header;
private $showDrafts;
private $noDataString;
private $highlightedAudits;
@ -25,6 +26,15 @@ final class PhabricatorAuditListView extends AphrontView {
return $this->header;
}
public function setShowDrafts($show_drafts) {
$this->showDrafts = $show_drafts;
return $this;
}
public function getShowDrafts() {
return $this->showDrafts;
}
/**
* These commits should have both commit data and audit requests attached.
*/
@ -75,6 +85,16 @@ final class PhabricatorAuditListView extends AphrontView {
$handles = $viewer->loadHandles(mpull($this->commits, 'getPHID'));
$show_drafts = $this->getShowDrafts();
$draft_icon = id(new PHUIIconView())
->setIcon('fa-comment yellow')
->addSigil('has-tooltip')
->setMetadata(
array(
'tip' => pht('Unsubmitted Comments'),
));
$list = new PHUIObjectItemListView();
foreach ($this->commits as $commit) {
$commit_phid = $commit->getPHID();
@ -88,7 +108,6 @@ final class PhabricatorAuditListView extends AphrontView {
$audits = mpull($commit->getAudits(), null, 'getAuditorPHID');
$auditors = array();
$reasons = array();
foreach ($audits as $audit) {
$auditor_phid = $audit->getAuditorPHID();
$auditors[$auditor_phid] = $viewer->renderHandle($auditor_phid);
@ -114,9 +133,16 @@ final class PhabricatorAuditListView extends AphrontView {
$item = id(new PHUIObjectItemView())
->setObjectName($commit_name)
->setHeader($commit_desc)
->setHref($commit_link)
->setHref($commit_link);
if ($show_drafts) {
if ($commit->getHasDraft($viewer)) {
$item->addAttribute($draft_icon);
}
}
$item
->addAttribute(pht('Author: %s', $author_name))
->addAttribute($reasons)
->addIcon('none', $committed);
if (!empty($auditors)) {

View file

@ -473,34 +473,9 @@ final class DifferentialRevisionQuery
}
if ($this->needDrafts) {
$viewer_phid = $viewer->getPHID();
$draft_type = PhabricatorObjectHasDraftEdgeType::EDGECONST;
if (!$viewer_phid) {
// Viewers without a valid PHID can never have drafts.
foreach ($revisions as $revision) {
$revision->attachHasDraft($viewer, false);
}
} else {
$edge_query = id(new PhabricatorEdgeQuery())
->withSourcePHIDs(mpull($revisions, 'getPHID'))
->withEdgeTypes(
array(
$draft_type,
))
->withDestinationPHIDs(array($viewer_phid));
$edge_query->execute();
foreach ($revisions as $revision) {
$has_draft = (bool)$edge_query->getDestinationPHIDs(
array(
$revision->getPHID(),
));
$revision->attachHasDraft($viewer, $has_draft);
}
}
PhabricatorDraftEngine::attachDrafts(
$viewer,
$revisions);
}
return $revisions;

View file

@ -0,0 +1,18 @@
<?php
final class DiffusionCommitDraftEngine
extends PhabricatorDraftEngine {
protected function hasCustomDraftContent() {
$viewer = $this->getViewer();
$commit = $this->getObject();
$inlines = PhabricatorAuditInlineComment::loadDraftComments(
$viewer,
$commit->getPHID(),
$raw = true);
return (bool)$inlines;
}
}

View file

@ -22,6 +22,7 @@ final class DiffusionCommitQuery
private $importing;
private $needCommitData;
private $needDrafts;
public function withIDs(array $ids) {
$this->ids = $ids;
@ -98,6 +99,11 @@ final class DiffusionCommitQuery
return $this;
}
public function needDrafts($need) {
$this->needDrafts = $need;
return $this;
}
public function needAuditRequests($need) {
$this->needAuditRequests = $need;
return $this;
@ -239,6 +245,8 @@ final class DiffusionCommitQuery
}
protected function didFilterPage(array $commits) {
$viewer = $this->getViewer();
if ($this->needCommitData) {
$data = id(new PhabricatorRepositoryCommitData())->loadAllWhere(
'commitID in (%Ld)',
@ -268,6 +276,12 @@ final class DiffusionCommitQuery
}
}
if ($this->needDrafts) {
PhabricatorDraftEngine::attachDrafts(
$viewer,
$commits);
}
return $commits;
}

View file

@ -14,7 +14,8 @@ final class PhabricatorRepositoryCommit
PhabricatorCustomFieldInterface,
PhabricatorApplicationTransactionInterface,
PhabricatorFulltextInterface,
PhabricatorConduitResultInterface {
PhabricatorConduitResultInterface,
PhabricatorDraftInterface {
protected $repositoryID;
protected $phid;
@ -39,6 +40,7 @@ final class PhabricatorRepositoryCommit
private $audits = self::ATTACHABLE;
private $repository = self::ATTACHABLE;
private $customFields = self::ATTACHABLE;
private $drafts = array();
public function attachRepository(PhabricatorRepository $repository) {
$this->repository = $repository;
@ -342,6 +344,7 @@ final class PhabricatorRepositoryCommit
return nonempty($parsed->getDisplayName(), $parsed->getAddress());
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
@ -603,4 +606,20 @@ final class PhabricatorRepositoryCommit
return array();
}
/* -( PhabricatorDraftInterface )------------------------------------------ */
public function newDraftEngine() {
return new DiffusionCommitDraftEngine();
}
public function getHasDraft(PhabricatorUser $viewer) {
return $this->assertAttachedKey($this->drafts, $viewer->getCacheFragment());
}
public function attachHasDraft(PhabricatorUser $viewer, $has_draft) {
$this->drafts[$viewer->getCacheFragment()] = $has_draft;
return $this;
}
}

View file

@ -95,4 +95,41 @@ abstract class PhabricatorDraftEngine
$editor->save();
}
final public static function attachDrafts(
PhabricatorUser $viewer,
array $objects) {
assert_instances_of($objects, 'PhabricatorDraftInterface');
$viewer_phid = $viewer->getPHID();
if (!$viewer_phid) {
// Viewers without a valid PHID can never have drafts.
foreach ($objects as $object) {
$object->attachHasDraft($viewer, false);
}
return;
} else {
$draft_type = PhabricatorObjectHasDraftEdgeType::EDGECONST;
$edge_query = id(new PhabricatorEdgeQuery())
->withSourcePHIDs(mpull($objects, 'getPHID'))
->withEdgeTypes(
array(
$draft_type,
))
->withDestinationPHIDs(array($viewer_phid));
$edge_query->execute();
foreach ($objects as $object) {
$has_draft = (bool)$edge_query->getDestinationPHIDs(
array(
$object->getPHID(),
));
$object->attachHasDraft($viewer, $has_draft);
}
}
}
}

View file

@ -4,4 +4,25 @@ interface PhabricatorDraftInterface {
public function newDraftEngine();
public function getHasDraft(PhabricatorUser $viewer);
public function attachHasDraft(PhabricatorUser $viewer, $has_draft);
}
/* -( PhabricatorDraftInterface )------------------------------------------ */
/*
public function newDraftEngine() {
return new <...>DraftEngine();
}
public function getHasDraft(PhabricatorUser $viewer) {
return $this->assertAttachedKey($this->drafts, $viewer->getCacheFragment());
}
public function attachHasDraft(PhabricatorUser $viewer, $has_draft) {
$this->drafts[$viewer->getCacheFragment()] = $has_draft;
return $this;
}
*/