From 8834b318ddba5315f802ebcaefb5c511b97bf116 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 28 Jul 2013 13:07:30 -0700 Subject: [PATCH] Diviner: improve links, book index, and atom view Summary: Ref T988. Minor improvements to diviner: link stuff to a valid endpoint which actually works; fix group names on the book index; improve the topics index for atom views. Test Plan: Clicked links in an article, viewed book index, viewed an article with long headers. Reviewers: btrahan, chad Reviewed By: chad CC: aran Maniphest Tasks: T988 Differential Revision: https://secure.phabricator.com/D6598 --- src/__celerity_resource_map__.php | 2 +- src/__phutil_library_map__.php | 2 + .../PhabricatorApplicationDiviner.php | 1 + .../controller/DivinerFindController.php | 72 +++++++++++++++++++ .../markup/DivinerRemarkupRuleSymbol.php | 13 +++- .../diviner/storage/DivinerLiveBook.php | 2 +- .../diviner/storage/DivinerLiveSymbol.php | 2 +- webroot/rsrc/css/phui/phui-list.css | 5 +- 8 files changed, 90 insertions(+), 9 deletions(-) create mode 100644 src/applications/diviner/controller/DivinerFindController.php diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php index 1aad9fadf3..71a81f989b 100644 --- a/src/__celerity_resource_map__.php +++ b/src/__celerity_resource_map__.php @@ -3857,7 +3857,7 @@ celerity_register_resource_map(array( ), 'phui-list-view-css' => array( - 'uri' => '/res/09f24365/rsrc/css/phui/phui-list.css', + 'uri' => '/res/3235e888/rsrc/css/phui/phui-list.css', 'type' => 'css', 'requires' => array( diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index c69ea801af..e4e76d0dd2 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -526,6 +526,7 @@ phutil_register_library_map(array( 'DivinerDefaultRenderer' => 'applications/diviner/renderer/DivinerDefaultRenderer.php', 'DivinerDiskCache' => 'applications/diviner/cache/DivinerDiskCache.php', 'DivinerFileAtomizer' => 'applications/diviner/atomizer/DivinerFileAtomizer.php', + 'DivinerFindController' => 'applications/diviner/controller/DivinerFindController.php', 'DivinerGenerateWorkflow' => 'applications/diviner/workflow/DivinerGenerateWorkflow.php', 'DivinerLegacyController' => 'applications/diviner/controller/DivinerLegacyController.php', 'DivinerLiveAtom' => 'applications/diviner/storage/DivinerLiveAtom.php', @@ -2519,6 +2520,7 @@ phutil_register_library_map(array( 'DivinerDAO' => 'PhabricatorLiskDAO', 'DivinerDefaultRenderer' => 'DivinerRenderer', 'DivinerFileAtomizer' => 'DivinerAtomizer', + 'DivinerFindController' => 'DivinerController', 'DivinerGenerateWorkflow' => 'DivinerWorkflow', 'DivinerLegacyController' => 'DivinerController', 'DivinerLiveAtom' => 'DivinerDAO', diff --git a/src/applications/diviner/application/PhabricatorApplicationDiviner.php b/src/applications/diviner/application/PhabricatorApplicationDiviner.php index e698a25fb1..79ad9d02d4 100644 --- a/src/applications/diviner/application/PhabricatorApplicationDiviner.php +++ b/src/applications/diviner/application/PhabricatorApplicationDiviner.php @@ -23,6 +23,7 @@ final class PhabricatorApplicationDiviner extends PhabricatorApplication { '/diviner/' => array( '' => 'DivinerLegacyController', 'query/((?[^/]+)/)?' => 'DivinerAtomListController', + 'find/' => 'DivinerFindController', ), '/docs/(?P[^/]+)/' => 'DivinerJumpController', '/book/(?P[^/]+)/' => 'DivinerBookController', diff --git a/src/applications/diviner/controller/DivinerFindController.php b/src/applications/diviner/controller/DivinerFindController.php new file mode 100644 index 0000000000..3728a52f32 --- /dev/null +++ b/src/applications/diviner/controller/DivinerFindController.php @@ -0,0 +1,72 @@ +getRequest(); + $viewer = $request->getUser(); + + $book_name = $request->getStr('book'); + + $book = null; + if ($book_name) { + $book = id(new DivinerBookQuery()) + ->setViewer($viewer) + ->withNames(array($book_name)) + ->executeOne(); + if (!$book) { + return new Aphront404Response(); + } + } + + $query = id(new DivinerAtomQuery()) + ->setViewer($viewer) + ->withNames( + array( + $request->getStr('name'), + // TODO: This could probably be more smartly normalized in the DB, + // but just fake it for now. + phutil_utf8_strtolower($request->getStr('name')), + )); + + if ($book) { + $query->withBookPHIDs(array($book->getPHID())); + } + + $context = $request->getStr('context'); + if (strlen($context)) { + $query->withContexts(array($context)); + } + + $type = $request->getStr('type'); + if (strlen($type)) { + $query->withTypes(array($type)); + } + + $atoms = $query->execute(); + + if (!$atoms) { + return new Aphront404Response(); + } + + if (count($atoms) == 1 && $request->getBool('jump')) { + $atom_uri = head($atoms)->getURI(); + return id(new AphrontRedirectResponse())->setURI($atom_uri); + } + + $list = $this->renderAtomList($atoms); + + return $this->buildApplicationPage( + $list, + array( + 'title' => 'derp', + 'dust' => true, + 'device' => true, + )); + } + +} diff --git a/src/applications/diviner/markup/DivinerRemarkupRuleSymbol.php b/src/applications/diviner/markup/DivinerRemarkupRuleSymbol.php index 81e3a70cc3..ca345d81d4 100644 --- a/src/applications/diviner/markup/DivinerRemarkupRuleSymbol.php +++ b/src/applications/diviner/markup/DivinerRemarkupRuleSymbol.php @@ -57,7 +57,7 @@ final class DivinerRemarkupRuleSymbol extends PhutilRemarkupRule { $ref['name'] = $name; } - $ref['title'] = $title; + $ref['title'] = nonempty($title, $name); foreach ($ref as $key => $value) { if ($value === '') { @@ -86,7 +86,7 @@ final class DivinerRemarkupRuleSymbol extends PhutilRemarkupRule { foreach ($data as $token => $ref_dict) { $ref = DivinerAtomRef::newFromDictionary($ref_dict); - $title = nonempty($ref->getTitle(), $ref->getName()); + $title = $ref->getTitle(); $href = null; if ($renderer) { @@ -104,7 +104,14 @@ final class DivinerRemarkupRuleSymbol extends PhutilRemarkupRule { // link to Diviner and let it sort things out. $href = id(new PhutilURI('/diviner/find/')) - ->setQueryParams($ref_dict + array('jump' => true)); + ->setQueryParams( + array( + 'book' => $ref->getBook(), + 'name' => $ref->getName(), + 'type' => $ref->getType(), + 'context' => $ref->getContext(), + 'jump' => true, + )); } if ($this->getEngine()->isTextMode()) { diff --git a/src/applications/diviner/storage/DivinerLiveBook.php b/src/applications/diviner/storage/DivinerLiveBook.php index 25e2cbaf49..844dcd6a65 100644 --- a/src/applications/diviner/storage/DivinerLiveBook.php +++ b/src/applications/diviner/storage/DivinerLiveBook.php @@ -42,7 +42,7 @@ final class DivinerLiveBook extends DivinerDAO public function getGroupName($group) { $groups = $this->getConfig('groups'); $spec = idx($groups, $group, array()); - return idx($spec, 'name', pht('Free Radicals')); + return idx($spec, 'name', $group); } /* -( PhabricatorPolicyInterface )----------------------------------------- */ diff --git a/src/applications/diviner/storage/DivinerLiveSymbol.php b/src/applications/diviner/storage/DivinerLiveSymbol.php index aee5aa3203..c1d6f8387d 100644 --- a/src/applications/diviner/storage/DivinerLiveSymbol.php +++ b/src/applications/diviner/storage/DivinerLiveSymbol.php @@ -160,7 +160,7 @@ final class DivinerLiveSymbol extends DivinerDAO public function shouldUseMarkupCache($field) { - return true; + return false; } } diff --git a/webroot/rsrc/css/phui/phui-list.css b/webroot/rsrc/css/phui/phui-list.css index d49c63e3fa..0f8317d71a 100644 --- a/webroot/rsrc/css/phui/phui-list.css +++ b/webroot/rsrc/css/phui/phui-list.css @@ -58,11 +58,10 @@ .phui-list-sidenav .phui-list-item-href { display: block; - padding: 2px 16px; + padding: 4px 16px; clear: both; - line-height: 20px; color: #333333; - white-space: nowrap; + line-height: 18px; } .phui-list-sidenav .phui-list-item-has-icon .phui-list-item-href {