2014-06-29 01:36:37 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class LegalpadDocumentSignatureSearchEngine
|
|
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
|
|
|
|
private $document;
|
|
|
|
|
|
|
|
public function getResultTypeDescription() {
|
|
|
|
return pht('Legalpad Signatures');
|
|
|
|
}
|
|
|
|
|
2015-02-05 00:47:48 +01:00
|
|
|
public function getApplicationClassName() {
|
2014-07-23 02:03:09 +02:00
|
|
|
return 'PhabricatorLegalpadApplication';
|
2014-06-29 01:36:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setDocument(LegalpadDocument $document) {
|
|
|
|
$this->document = $document;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
|
|
|
$saved = new PhabricatorSavedQuery();
|
|
|
|
|
|
|
|
$saved->setParameter(
|
|
|
|
'signerPHIDs',
|
|
|
|
$this->readUsersFromRequest($request, 'signers'));
|
|
|
|
|
2014-06-29 01:37:36 +02:00
|
|
|
$saved->setParameter(
|
|
|
|
'documentPHIDs',
|
|
|
|
$this->readPHIDsFromRequest(
|
|
|
|
$request,
|
|
|
|
'documents',
|
|
|
|
array(
|
2014-07-24 00:05:46 +02:00
|
|
|
PhabricatorLegalpadDocumentPHIDType::TYPECONST,
|
2014-06-29 01:37:36 +02:00
|
|
|
)));
|
|
|
|
|
2014-06-29 16:51:03 +02:00
|
|
|
$saved->setParameter('nameContains', $request->getStr('nameContains'));
|
|
|
|
$saved->setParameter('emailContains', $request->getStr('emailContains'));
|
|
|
|
|
2014-06-29 01:36:37 +02:00
|
|
|
return $saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
|
|
|
$query = id(new LegalpadDocumentSignatureQuery());
|
|
|
|
|
|
|
|
$signer_phids = $saved->getParameter('signerPHIDs', array());
|
|
|
|
if ($signer_phids) {
|
|
|
|
$query->withSignerPHIDs($signer_phids);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->document) {
|
|
|
|
$query->withDocumentPHIDs(array($this->document->getPHID()));
|
2014-06-29 01:37:36 +02:00
|
|
|
} else {
|
|
|
|
$document_phids = $saved->getParameter('documentPHIDs', array());
|
|
|
|
if ($document_phids) {
|
|
|
|
$query->withDocumentPHIDs($document_phids);
|
|
|
|
}
|
2014-06-29 01:36:37 +02:00
|
|
|
}
|
|
|
|
|
2014-06-29 16:51:03 +02:00
|
|
|
$name_contains = $saved->getParameter('nameContains');
|
|
|
|
if (strlen($name_contains)) {
|
|
|
|
$query->withNameContains($name_contains);
|
|
|
|
}
|
|
|
|
|
|
|
|
$email_contains = $saved->getParameter('emailContains');
|
|
|
|
if (strlen($email_contains)) {
|
|
|
|
$query->withEmailContains($email_contains);
|
|
|
|
}
|
|
|
|
|
2014-06-29 01:36:37 +02:00
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSearchForm(
|
|
|
|
AphrontFormView $form,
|
|
|
|
PhabricatorSavedQuery $saved_query) {
|
|
|
|
|
2014-06-29 01:37:36 +02:00
|
|
|
$document_phids = $saved_query->getParameter('documentPHIDs', array());
|
2014-06-29 01:36:37 +02:00
|
|
|
$signer_phids = $saved_query->getParameter('signerPHIDs', array());
|
|
|
|
|
2014-06-29 01:37:36 +02:00
|
|
|
if (!$this->document) {
|
|
|
|
$form
|
2015-03-31 23:10:55 +02:00
|
|
|
->appendControl(
|
2014-06-29 01:37:36 +02:00
|
|
|
id(new AphrontFormTokenizerControl())
|
2014-08-08 20:38:18 +02:00
|
|
|
->setDatasource(new LegalpadDocumentDatasource())
|
2014-06-29 01:37:36 +02:00
|
|
|
->setName('documents')
|
|
|
|
->setLabel(pht('Documents'))
|
2015-03-31 23:10:55 +02:00
|
|
|
->setValue($document_phids));
|
2014-06-29 01:37:36 +02:00
|
|
|
}
|
|
|
|
|
2014-06-29 16:51:03 +02:00
|
|
|
$name_contains = $saved_query->getParameter('nameContains', '');
|
|
|
|
$email_contains = $saved_query->getParameter('emailContains', '');
|
|
|
|
|
2014-06-29 01:36:37 +02:00
|
|
|
$form
|
2015-03-31 23:10:55 +02:00
|
|
|
->appendControl(
|
2014-06-29 01:36:37 +02:00
|
|
|
id(new AphrontFormTokenizerControl())
|
2014-07-18 00:44:18 +02:00
|
|
|
->setDatasource(new PhabricatorPeopleDatasource())
|
2014-06-29 01:36:37 +02:00
|
|
|
->setName('signers')
|
|
|
|
->setLabel(pht('Signers'))
|
2015-03-31 23:10:55 +02:00
|
|
|
->setValue($signer_phids))
|
2014-06-29 16:51:03 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setLabel(pht('Name Contains'))
|
|
|
|
->setName('nameContains')
|
|
|
|
->setValue($name_contains))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setLabel(pht('Email Contains'))
|
|
|
|
->setName('emailContains')
|
|
|
|
->setValue($email_contains));
|
2014-06-29 01:36:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getURI($path) {
|
|
|
|
if ($this->document) {
|
|
|
|
return '/legalpad/signatures/'.$this->document->getID().'/'.$path;
|
|
|
|
} else {
|
2014-06-29 01:37:36 +02:00
|
|
|
return '/legalpad/signatures/'.$path;
|
2014-06-29 01:36:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-06 21:34:51 +01:00
|
|
|
protected function getBuiltinQueryNames() {
|
2014-06-29 01:36:37 +02:00
|
|
|
$names = array(
|
|
|
|
'all' => pht('All Signatures'),
|
|
|
|
);
|
|
|
|
|
|
|
|
return $names;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
|
|
|
|
|
|
$query = $this->newSavedQuery();
|
|
|
|
$query->setQueryKey($query_key);
|
|
|
|
|
|
|
|
switch ($query_key) {
|
|
|
|
case 'all':
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getRequiredHandlePHIDsForResultList(
|
2014-06-29 01:37:36 +02:00
|
|
|
array $signatures,
|
2014-06-29 01:36:37 +02:00
|
|
|
PhabricatorSavedQuery $query) {
|
2014-06-29 01:37:36 +02:00
|
|
|
|
|
|
|
return array_merge(
|
|
|
|
mpull($signatures, 'getSignerPHID'),
|
|
|
|
mpull($signatures, 'getDocumentPHID'));
|
2014-06-29 01:36:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderResultList(
|
|
|
|
array $signatures,
|
|
|
|
PhabricatorSavedQuery $query,
|
|
|
|
array $handles) {
|
|
|
|
assert_instances_of($signatures, 'LegalpadDocumentSignature');
|
|
|
|
|
|
|
|
$viewer = $this->requireViewer();
|
|
|
|
|
2014-06-29 01:36:52 +02:00
|
|
|
Javelin::initBehavior('phabricator-tooltips');
|
2014-06-29 01:36:37 +02:00
|
|
|
|
2014-06-29 01:36:52 +02:00
|
|
|
$sig_good = $this->renderIcon(
|
|
|
|
'fa-check',
|
|
|
|
null,
|
|
|
|
pht('Verified, Current'));
|
2014-06-29 01:36:37 +02:00
|
|
|
|
2014-07-04 17:04:28 +02:00
|
|
|
$sig_corp = $this->renderIcon(
|
|
|
|
'fa-building-o',
|
|
|
|
null,
|
|
|
|
pht('Verified, Corporate'));
|
|
|
|
|
2014-06-29 01:36:52 +02:00
|
|
|
$sig_old = $this->renderIcon(
|
|
|
|
'fa-clock-o',
|
|
|
|
'orange',
|
|
|
|
pht('Signed Older Version'));
|
2014-06-29 01:36:37 +02:00
|
|
|
|
2014-06-29 01:36:52 +02:00
|
|
|
$sig_unverified = $this->renderIcon(
|
|
|
|
'fa-envelope',
|
|
|
|
'red',
|
|
|
|
pht('Unverified Email'));
|
|
|
|
|
2014-07-02 13:59:35 +02:00
|
|
|
$sig_exemption = $this->renderIcon(
|
|
|
|
'fa-asterisk',
|
|
|
|
'indigo',
|
|
|
|
pht('Exemption'));
|
|
|
|
|
2014-06-29 01:36:52 +02:00
|
|
|
id(new PHUIIconView())
|
2016-01-28 05:38:01 +01:00
|
|
|
->setIcon('fa-envelope', 'red')
|
2014-06-29 01:36:52 +02:00
|
|
|
->addSigil('has-tooltip')
|
|
|
|
->setMetadata(array('tip' => pht('Unverified Email')));
|
|
|
|
|
2014-07-04 17:04:28 +02:00
|
|
|
$type_corporate = LegalpadDocument::SIGNATURE_TYPE_CORPORATION;
|
|
|
|
|
2014-06-29 01:36:52 +02:00
|
|
|
$rows = array();
|
|
|
|
foreach ($signatures as $signature) {
|
2014-06-29 16:51:03 +02:00
|
|
|
$name = $signature->getSignerName();
|
|
|
|
$email = $signature->getSignerEmail();
|
2014-06-29 01:36:37 +02:00
|
|
|
|
|
|
|
$document = $signature->getDocument();
|
|
|
|
|
2014-07-02 13:59:35 +02:00
|
|
|
if ($signature->getIsExemption()) {
|
2014-07-04 17:04:28 +02:00
|
|
|
$sig_icon = $sig_exemption;
|
2014-07-02 13:59:35 +02:00
|
|
|
} else if (!$signature->isVerified()) {
|
2014-06-29 01:36:52 +02:00
|
|
|
$sig_icon = $sig_unverified;
|
|
|
|
} else if ($signature->getDocumentVersion() != $document->getVersions()) {
|
|
|
|
$sig_icon = $sig_old;
|
2014-07-04 17:04:28 +02:00
|
|
|
} else if ($signature->getSignatureType() == $type_corporate) {
|
|
|
|
$sig_icon = $sig_corp;
|
2014-06-29 01:36:52 +02:00
|
|
|
} else {
|
|
|
|
$sig_icon = $sig_good;
|
2014-06-29 01:36:37 +02:00
|
|
|
}
|
|
|
|
|
2014-07-04 17:04:28 +02:00
|
|
|
$signature_href = $this->getApplicationURI(
|
|
|
|
'signature/'.$signature->getID().'/');
|
|
|
|
|
|
|
|
$sig_icon = javelin_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $signature_href,
|
|
|
|
'sigil' => 'workflow',
|
|
|
|
),
|
|
|
|
$sig_icon);
|
|
|
|
|
|
|
|
$signer_phid = $signature->getSignerPHID();
|
|
|
|
|
2014-06-29 01:36:52 +02:00
|
|
|
$rows[] = array(
|
|
|
|
$sig_icon,
|
2014-06-29 01:37:36 +02:00
|
|
|
$handles[$document->getPHID()]->renderLink(),
|
2014-07-04 17:04:28 +02:00
|
|
|
$signer_phid
|
|
|
|
? $handles[$signer_phid]->renderLink()
|
|
|
|
: null,
|
2014-06-29 01:36:52 +02:00
|
|
|
$name,
|
|
|
|
phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => 'mailto:'.$email,
|
|
|
|
),
|
|
|
|
$email),
|
|
|
|
phabricator_datetime($signature->getDateCreated(), $viewer),
|
|
|
|
);
|
2014-06-29 01:36:37 +02:00
|
|
|
}
|
|
|
|
|
2014-06-29 01:36:52 +02:00
|
|
|
$table = id(new AphrontTableView($rows))
|
2014-06-29 16:51:03 +02:00
|
|
|
->setNoDataString(pht('No signatures match the query.'))
|
2014-06-29 01:36:52 +02:00
|
|
|
->setHeaders(
|
|
|
|
array(
|
|
|
|
'',
|
2014-06-29 01:37:36 +02:00
|
|
|
pht('Document'),
|
2014-06-29 01:36:52 +02:00
|
|
|
pht('Account'),
|
|
|
|
pht('Name'),
|
|
|
|
pht('Email'),
|
|
|
|
pht('Signed'),
|
|
|
|
))
|
2014-06-29 01:37:36 +02:00
|
|
|
->setColumnVisibility(
|
|
|
|
array(
|
|
|
|
true,
|
|
|
|
|
|
|
|
// Only show the "Document" column if we aren't scoped to a
|
|
|
|
// particular document.
|
|
|
|
!$this->document,
|
|
|
|
))
|
2014-06-29 01:36:52 +02:00
|
|
|
->setColumnClasses(
|
|
|
|
array(
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'',
|
2014-06-29 01:37:36 +02:00
|
|
|
'',
|
2014-06-29 01:36:52 +02:00
|
|
|
'wide',
|
|
|
|
'right',
|
|
|
|
));
|
|
|
|
|
2015-06-19 12:46:20 +02:00
|
|
|
$button = null;
|
|
|
|
if ($this->document) {
|
2014-07-02 13:59:35 +02:00
|
|
|
$document_id = $this->document->getID();
|
|
|
|
|
2015-06-19 12:46:20 +02:00
|
|
|
$button = id(new PHUIButtonView())
|
|
|
|
->setText(pht('Add Exemption'))
|
2014-07-02 13:59:35 +02:00
|
|
|
->setTag('a')
|
|
|
|
->setHref($this->getApplicationURI('addsignature/'.$document_id.'/'))
|
|
|
|
->setWorkflow(true)
|
2016-01-28 05:38:01 +01:00
|
|
|
->setIcon('fa-pencil');
|
2015-06-19 12:46:20 +02:00
|
|
|
}
|
2014-06-29 01:36:52 +02:00
|
|
|
|
2014-06-29 01:37:36 +02:00
|
|
|
if (!$this->document) {
|
[Redesign] Put all ApplicationSearch results in an ObjectBox
Summary:
Ref T8099. In most cases we return either an ObjectList or AphrontTable, and can pretty up the UI in ApplicationSearch. There are a few edge cases, like PeopleUserLog, that can be cleanup up individually in the future, but look fine for now.
Also added 'setNotice' for AphrontTable for a few cases where we want to convey addtional information.
TODO: Seems we always pass a Pager Object, which tries to get displayed, I'll redesign that interaction in the future, probably by passing the Pager to the ObjectBox
Test Plan: Went throught most/all ApplicationSearch panels I could find, even edge cases look better.
Reviewers: btrahan, epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T8099
Differential Revision: https://secure.phabricator.com/D12989
2015-05-24 18:13:58 +02:00
|
|
|
$table->setNotice(
|
|
|
|
pht('NOTE: You can only see your own signatures and signatures on '.
|
|
|
|
'documents you have permission to edit.'));
|
2014-06-29 01:37:36 +02:00
|
|
|
}
|
|
|
|
|
2015-06-19 12:46:20 +02:00
|
|
|
$result = new PhabricatorApplicationSearchResultView();
|
|
|
|
$result->setTable($table);
|
|
|
|
if ($button) {
|
|
|
|
$result->addAction($button);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
2014-06-29 01:36:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function renderIcon($icon, $color, $title) {
|
|
|
|
Javelin::initBehavior('phabricator-tooltips');
|
|
|
|
|
|
|
|
return array(
|
|
|
|
id(new PHUIIconView())
|
2016-01-28 05:38:01 +01:00
|
|
|
->setIcon($icon, $color)
|
2014-06-29 01:36:52 +02:00
|
|
|
->addSigil('has-tooltip')
|
|
|
|
->setMetadata(array('tip' => $title)),
|
|
|
|
javelin_tag(
|
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
'aural' => true,
|
|
|
|
),
|
|
|
|
$title),
|
|
|
|
);
|
2014-06-29 01:36:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|