mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-30 02:32:42 +01:00
Show signature status on Legalpad main view
Summary: Ref T3116. Tweak the main Legalpad view a bit -- in particular, show signature status. Test Plan: {F171641} Reviewers: chad Reviewed By: chad Subscribers: epriestley Maniphest Tasks: T3116 Differential Revision: https://secure.phabricator.com/D9768
This commit is contained in:
parent
8887febd84
commit
af9d6f593e
3 changed files with 70 additions and 7 deletions
|
@ -14,6 +14,7 @@ final class LegalpadDocumentQuery
|
||||||
private $needDocumentBodies;
|
private $needDocumentBodies;
|
||||||
private $needContributors;
|
private $needContributors;
|
||||||
private $needSignatures;
|
private $needSignatures;
|
||||||
|
private $needViewerSignatures;
|
||||||
|
|
||||||
public function withIDs(array $ids) {
|
public function withIDs(array $ids) {
|
||||||
$this->ids = $ids;
|
$this->ids = $ids;
|
||||||
|
@ -65,6 +66,11 @@ final class LegalpadDocumentQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function needViewerSignatures($need) {
|
||||||
|
$this->needViewerSignatures = $need;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
protected function loadPage() {
|
protected function loadPage() {
|
||||||
$table = new LegalpadDocument();
|
$table = new LegalpadDocument();
|
||||||
$conn_r = $table->establishConnection('r');
|
$conn_r = $table->establishConnection('r');
|
||||||
|
@ -118,6 +124,29 @@ final class LegalpadDocumentQuery
|
||||||
$documents = $this->loadSignatures($documents);
|
$documents = $this->loadSignatures($documents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->needViewerSignatures) {
|
||||||
|
if ($documents) {
|
||||||
|
|
||||||
|
if ($this->getViewer()->getPHID()) {
|
||||||
|
$signatures = id(new LegalpadDocumentSignatureQuery())
|
||||||
|
->setViewer($this->getViewer())
|
||||||
|
->withSignerPHIDs(array($this->getViewer()->getPHID()))
|
||||||
|
->withDocumentPHIDs(mpull($documents, 'getPHID'))
|
||||||
|
->execute();
|
||||||
|
$signatures = mpull($signatures, null, 'getDocumentPHID');
|
||||||
|
} else {
|
||||||
|
$signatures = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($documents as $document) {
|
||||||
|
$signature = idx($signatures, $document->getPHID());
|
||||||
|
$document->attachUserSignature(
|
||||||
|
$this->getViewer()->getPHID(),
|
||||||
|
$signature);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $documents;
|
return $documents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ final class LegalpadDocumentSearchEngine
|
||||||
|
|
||||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||||
$query = id(new LegalpadDocumentQuery())
|
$query = id(new LegalpadDocumentQuery())
|
||||||
|
->needViewerSignatures(true)
|
||||||
->withCreatorPHIDs($saved->getParameter('creatorPHIDs', array()))
|
->withCreatorPHIDs($saved->getParameter('creatorPHIDs', array()))
|
||||||
->withContributorPHIDs($saved->getParameter('contributorPHIDs', array()));
|
->withContributorPHIDs($saved->getParameter('contributorPHIDs', array()));
|
||||||
|
|
||||||
|
@ -111,7 +112,7 @@ final class LegalpadDocumentSearchEngine
|
||||||
protected function getRequiredHandlePHIDsForResultList(
|
protected function getRequiredHandlePHIDsForResultList(
|
||||||
array $documents,
|
array $documents,
|
||||||
PhabricatorSavedQuery $query) {
|
PhabricatorSavedQuery $query) {
|
||||||
return array_mergev(mpull($documents, 'getRecentContributorPHIDs'));
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function renderResultList(
|
protected function renderResultList(
|
||||||
|
@ -126,8 +127,6 @@ final class LegalpadDocumentSearchEngine
|
||||||
$list->setUser($viewer);
|
$list->setUser($viewer);
|
||||||
foreach ($documents as $document) {
|
foreach ($documents as $document) {
|
||||||
$last_updated = phabricator_date($document->getDateModified(), $viewer);
|
$last_updated = phabricator_date($document->getDateModified(), $viewer);
|
||||||
$recent_contributors = $document->getRecentContributorPHIDs();
|
|
||||||
$updater = $handles[reset($recent_contributors)]->renderLink();
|
|
||||||
|
|
||||||
$title = $document->getTitle();
|
$title = $document->getTitle();
|
||||||
|
|
||||||
|
@ -136,9 +135,32 @@ final class LegalpadDocumentSearchEngine
|
||||||
->setHeader($title)
|
->setHeader($title)
|
||||||
->setHref('/'.$document->getMonogram())
|
->setHref('/'.$document->getMonogram())
|
||||||
->setObject($document)
|
->setObject($document)
|
||||||
->addIcon('none', pht('Last updated: %s', $last_updated))
|
->addIcon('none', pht('Version %d', $document->getVersions()))
|
||||||
->addByline(pht('Updated by: %s', $updater))
|
->addIcon('none', pht('Updated %s', $last_updated));
|
||||||
->addAttribute(pht('Versions: %d', $document->getVersions()));
|
|
||||||
|
if ($viewer->getPHID()) {
|
||||||
|
$signature = $document->getUserSignature($viewer->getPHID());
|
||||||
|
} else {
|
||||||
|
$signature = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($signature) {
|
||||||
|
$item->addAttribute(
|
||||||
|
array(
|
||||||
|
id(new PHUIIconView())->setIconFont('fa-check-square-o', 'green'),
|
||||||
|
' ',
|
||||||
|
pht(
|
||||||
|
'Signed on %s',
|
||||||
|
phabricator_date($signature->getDateCreated(), $viewer)),
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
$item->addAttribute(
|
||||||
|
array(
|
||||||
|
id(new PHUIIconView())->setIconFont('fa-square-o', 'grey'),
|
||||||
|
' ',
|
||||||
|
pht('Not Signed'),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
$list->addItem($item);
|
$list->addItem($item);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,8 @@ final class LegalpadDocument extends LegalpadDAO
|
||||||
|
|
||||||
private $documentBody = self::ATTACHABLE;
|
private $documentBody = self::ATTACHABLE;
|
||||||
private $contributors = self::ATTACHABLE;
|
private $contributors = self::ATTACHABLE;
|
||||||
private $signatures = self::ATTACHABLE;
|
private $signatures = self::ATTACHABLE;
|
||||||
|
private $userSignatures = array();
|
||||||
|
|
||||||
public static function initializeNewDocument(PhabricatorUser $actor) {
|
public static function initializeNewDocument(PhabricatorUser $actor) {
|
||||||
$app = id(new PhabricatorApplicationQuery())
|
$app = id(new PhabricatorApplicationQuery())
|
||||||
|
@ -91,6 +92,17 @@ final class LegalpadDocument extends LegalpadDAO
|
||||||
return 'L'.$this->getID();
|
return 'L'.$this->getID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getUserSignature($phid) {
|
||||||
|
return $this->assertAttachedKey($this->userSignatures, $phid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function attachUserSignature(
|
||||||
|
$user_phid,
|
||||||
|
LegalpadDocumentSignature $signature = null) {
|
||||||
|
$this->userSignatures[$user_phid] = $signature;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -( PhabricatorSubscribableInterface )----------------------------------- */
|
/* -( PhabricatorSubscribableInterface )----------------------------------- */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue