1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +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:
epriestley 2014-06-28 16:37:04 -07:00
parent 8887febd84
commit af9d6f593e
3 changed files with 70 additions and 7 deletions

View file

@ -14,6 +14,7 @@ final class LegalpadDocumentQuery
private $needDocumentBodies;
private $needContributors;
private $needSignatures;
private $needViewerSignatures;
public function withIDs(array $ids) {
$this->ids = $ids;
@ -65,6 +66,11 @@ final class LegalpadDocumentQuery
return $this;
}
public function needViewerSignatures($need) {
$this->needViewerSignatures = $need;
return $this;
}
protected function loadPage() {
$table = new LegalpadDocument();
$conn_r = $table->establishConnection('r');
@ -118,6 +124,29 @@ final class LegalpadDocumentQuery
$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;
}

View file

@ -29,6 +29,7 @@ final class LegalpadDocumentSearchEngine
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new LegalpadDocumentQuery())
->needViewerSignatures(true)
->withCreatorPHIDs($saved->getParameter('creatorPHIDs', array()))
->withContributorPHIDs($saved->getParameter('contributorPHIDs', array()));
@ -111,7 +112,7 @@ final class LegalpadDocumentSearchEngine
protected function getRequiredHandlePHIDsForResultList(
array $documents,
PhabricatorSavedQuery $query) {
return array_mergev(mpull($documents, 'getRecentContributorPHIDs'));
return array();
}
protected function renderResultList(
@ -126,8 +127,6 @@ final class LegalpadDocumentSearchEngine
$list->setUser($viewer);
foreach ($documents as $document) {
$last_updated = phabricator_date($document->getDateModified(), $viewer);
$recent_contributors = $document->getRecentContributorPHIDs();
$updater = $handles[reset($recent_contributors)]->renderLink();
$title = $document->getTitle();
@ -136,9 +135,32 @@ final class LegalpadDocumentSearchEngine
->setHeader($title)
->setHref('/'.$document->getMonogram())
->setObject($document)
->addIcon('none', pht('Last updated: %s', $last_updated))
->addByline(pht('Updated by: %s', $updater))
->addAttribute(pht('Versions: %d', $document->getVersions()));
->addIcon('none', pht('Version %d', $document->getVersions()))
->addIcon('none', pht('Updated %s', $last_updated));
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);
}

View file

@ -18,7 +18,8 @@ final class LegalpadDocument extends LegalpadDAO
private $documentBody = self::ATTACHABLE;
private $contributors = self::ATTACHABLE;
private $signatures = self::ATTACHABLE;
private $signatures = self::ATTACHABLE;
private $userSignatures = array();
public static function initializeNewDocument(PhabricatorUser $actor) {
$app = id(new PhabricatorApplicationQuery())
@ -91,6 +92,17 @@ final class LegalpadDocument extends LegalpadDAO
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 )----------------------------------- */