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

View file

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

View file

@ -4,6 +4,7 @@ final class PhabricatorAuditListView extends AphrontView {
private $commits; private $commits;
private $header; private $header;
private $showDrafts;
private $noDataString; private $noDataString;
private $highlightedAudits; private $highlightedAudits;
@ -25,6 +26,15 @@ final class PhabricatorAuditListView extends AphrontView {
return $this->header; 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. * 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')); $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(); $list = new PHUIObjectItemListView();
foreach ($this->commits as $commit) { foreach ($this->commits as $commit) {
$commit_phid = $commit->getPHID(); $commit_phid = $commit->getPHID();
@ -88,7 +108,6 @@ final class PhabricatorAuditListView extends AphrontView {
$audits = mpull($commit->getAudits(), null, 'getAuditorPHID'); $audits = mpull($commit->getAudits(), null, 'getAuditorPHID');
$auditors = array(); $auditors = array();
$reasons = array();
foreach ($audits as $audit) { foreach ($audits as $audit) {
$auditor_phid = $audit->getAuditorPHID(); $auditor_phid = $audit->getAuditorPHID();
$auditors[$auditor_phid] = $viewer->renderHandle($auditor_phid); $auditors[$auditor_phid] = $viewer->renderHandle($auditor_phid);
@ -114,9 +133,16 @@ final class PhabricatorAuditListView extends AphrontView {
$item = id(new PHUIObjectItemView()) $item = id(new PHUIObjectItemView())
->setObjectName($commit_name) ->setObjectName($commit_name)
->setHeader($commit_desc) ->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(pht('Author: %s', $author_name))
->addAttribute($reasons)
->addIcon('none', $committed); ->addIcon('none', $committed);
if (!empty($auditors)) { if (!empty($auditors)) {

View file

@ -473,34 +473,9 @@ final class DifferentialRevisionQuery
} }
if ($this->needDrafts) { if ($this->needDrafts) {
$viewer_phid = $viewer->getPHID(); PhabricatorDraftEngine::attachDrafts(
$draft_type = PhabricatorObjectHasDraftEdgeType::EDGECONST; $viewer,
$revisions);
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);
}
}
} }
return $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 $importing;
private $needCommitData; private $needCommitData;
private $needDrafts;
public function withIDs(array $ids) { public function withIDs(array $ids) {
$this->ids = $ids; $this->ids = $ids;
@ -98,6 +99,11 @@ final class DiffusionCommitQuery
return $this; return $this;
} }
public function needDrafts($need) {
$this->needDrafts = $need;
return $this;
}
public function needAuditRequests($need) { public function needAuditRequests($need) {
$this->needAuditRequests = $need; $this->needAuditRequests = $need;
return $this; return $this;
@ -239,6 +245,8 @@ final class DiffusionCommitQuery
} }
protected function didFilterPage(array $commits) { protected function didFilterPage(array $commits) {
$viewer = $this->getViewer();
if ($this->needCommitData) { if ($this->needCommitData) {
$data = id(new PhabricatorRepositoryCommitData())->loadAllWhere( $data = id(new PhabricatorRepositoryCommitData())->loadAllWhere(
'commitID in (%Ld)', 'commitID in (%Ld)',
@ -268,6 +276,12 @@ final class DiffusionCommitQuery
} }
} }
if ($this->needDrafts) {
PhabricatorDraftEngine::attachDrafts(
$viewer,
$commits);
}
return $commits; return $commits;
} }

View file

@ -14,7 +14,8 @@ final class PhabricatorRepositoryCommit
PhabricatorCustomFieldInterface, PhabricatorCustomFieldInterface,
PhabricatorApplicationTransactionInterface, PhabricatorApplicationTransactionInterface,
PhabricatorFulltextInterface, PhabricatorFulltextInterface,
PhabricatorConduitResultInterface { PhabricatorConduitResultInterface,
PhabricatorDraftInterface {
protected $repositoryID; protected $repositoryID;
protected $phid; protected $phid;
@ -39,6 +40,7 @@ final class PhabricatorRepositoryCommit
private $audits = self::ATTACHABLE; private $audits = self::ATTACHABLE;
private $repository = self::ATTACHABLE; private $repository = self::ATTACHABLE;
private $customFields = self::ATTACHABLE; private $customFields = self::ATTACHABLE;
private $drafts = array();
public function attachRepository(PhabricatorRepository $repository) { public function attachRepository(PhabricatorRepository $repository) {
$this->repository = $repository; $this->repository = $repository;
@ -342,6 +344,7 @@ final class PhabricatorRepositoryCommit
return nonempty($parsed->getDisplayName(), $parsed->getAddress()); return nonempty($parsed->getDisplayName(), $parsed->getAddress());
} }
/* -( PhabricatorPolicyInterface )----------------------------------------- */ /* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() { public function getCapabilities() {
@ -603,4 +606,20 @@ final class PhabricatorRepositoryCommit
return array(); 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(); $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 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;
}
*/