11<?php
22
3- final class PhabricatorMacroListController
4- extends PhabricatorMacroController {
3+ final class PhabricatorMacroListController extends PhabricatorMacroController
4+ implements PhabricatorApplicationSearchResultsControllerInterface {
55
6- private $ filter ;
6+ private $ key ;
7+
8+ public function shouldAllowPublic () {
9+ return true ;
10+ }
711
812 public function willProcessRequest (array $ data ) {
9- $ this ->filter = idx ($ data , 'filter ' , 'active ' );
13+ $ this ->key = idx ($ data , 'key ' , 'active ' );
1014 }
1115
1216 public function processRequest () {
13-
1417 $ request = $ this ->getRequest ();
15- $ viewer = $ request ->getUser ();
16-
17- $ pager = id (new AphrontCursorPagerView ())
18- ->readFromRequest ($ request );
19-
20- $ query = new PhabricatorMacroQuery ();
21- $ query ->setViewer ($ viewer );
22-
23- $ filter = $ request ->getStr ('name ' );
24- if (strlen ($ filter )) {
25- $ query ->withNameLike ($ filter );
26- }
27-
28- $ authors = $ request ->getArr ('authors ' );
29-
30- if ($ authors ) {
31- $ query ->withAuthorPHIDs ($ authors );
32- }
33-
34- $ has_search = $ filter || $ authors ;
35-
36- if ($ this ->filter == 'my ' ) {
37- $ query ->withAuthorPHIDs (array ($ viewer ->getPHID ()));
38- // For pre-filling the tokenizer
39- $ authors = array ($ viewer ->getPHID ());
40- }
41-
42- if ($ this ->filter == 'active ' ) {
43- $ query ->withStatus (PhabricatorMacroQuery::STATUS_ACTIVE );
44- }
45-
46- $ macros = $ query ->executeWithCursorPager ($ pager );
47- if ($ has_search ) {
48- $ nodata = pht ('There are no macros matching the filter. ' );
49- } else {
50- $ nodata = pht ('There are no image macros yet. ' );
51- }
18+ $ controller = id (new PhabricatorApplicationSearchController ($ request ))
19+ ->setQueryKey ($ this ->key )
20+ ->setSearchEngine (new PhabricatorMacroSearchEngine ())
21+ ->setNavigation ($ this ->buildSideNavView ());
5222
53- if ($ authors ) {
54- $ author_phids = array_fuse ($ authors );
55- } else {
56- $ author_phids = array ();
57- }
23+ return $ this ->delegateToController ($ controller );
24+ }
5825
59- $ author_phids += mpull ($ macros , 'getAuthorPHID ' , 'getAuthorPHID ' );
26+ public function renderResultsList (array $ macros ) {
27+ assert_instances_of ($ macros , 'PhabricatorFileImageMacro ' );
28+ $ viewer = $ this ->getRequest ()->getUser ();
6029
30+ $ author_phids = mpull ($ macros , 'getAuthorPHID ' , 'getAuthorPHID ' );
6131 $ this ->loadHandles ($ author_phids );
62- $ author_handles = array_select_keys ($ this ->getLoadedHandles (), $ authors );
63-
64- $ filter_form = id (new AphrontFormView ())
65- ->setMethod ('GET ' )
66- ->setUser ($ request ->getUser ())
67- ->setNoShading (true )
68- ->appendChild (
69- id (new AphrontFormTextControl ())
70- ->setName ('name ' )
71- ->setLabel (pht ('Name ' ))
72- ->setValue ($ filter ))
73- ->appendChild (
74- id (new AphrontFormTokenizerControl ())
75- ->setName ('authors ' )
76- ->setLabel (pht ('Authors ' ))
77- ->setDatasource ('/typeahead/common/users/ ' )
78- ->setValue (mpull ($ author_handles , 'getFullName ' )))
79- ->appendChild (
80- id (new AphrontFormSubmitControl ())
81- ->setValue (pht ('Filter Image Macros ' )));
82-
83- $ filter_view = new AphrontListFilterView ();
84- $ filter_view ->appendChild ($ filter_form );
85-
86- $ nav = $ this ->buildSideNavView (
87- $ for_app = false ,
88- $ has_search );
89- $ nav ->selectFilter ($ has_search ? 'search ' : $ this ->filter );
90-
91- $ nav ->appendChild ($ filter_view );
32+ $ author_handles = array_select_keys (
33+ $ this ->getLoadedHandles (),
34+ $ author_phids );
9235
9336 $ pinboard = new PhabricatorPinboardView ();
94- $ pinboard ->setNoDataString ($ nodata );
9537 foreach ($ macros as $ macro ) {
9638 $ file = $ macro ->getFile ();
9739
@@ -108,6 +50,14 @@ public function processRequest() {
10850 'div ' ,
10951 array (),
11052 pht ('Created on %s ' , $ datetime )));
53+ } else {
54+ // Very old macros don't have a creation date. Rendering something
55+ // keeps all the pins at the same height and avoids flow issues.
56+ $ item ->appendChild (
57+ phutil_tag (
58+ 'div ' ,
59+ array (),
60+ pht ('Created in ages long past ' )));
11161 }
11262
11363 if ($ macro ->getAuthorPHID ()) {
@@ -117,45 +67,17 @@ public function processRequest() {
11767 }
11868
11969 $ item ->setURI ($ this ->getApplicationURI ('/view/ ' .$ macro ->getID ().'/ ' ));
120- $ item ->setHeader ($ macro ->getName ());
12170
122- $ pinboard ->addItem ($ item );
123- }
124- $ nav ->appendChild ($ pinboard );
125-
126- if (!$ has_search ) {
127- $ nav ->appendChild ($ pager );
128- switch ($ this ->filter ) {
129- case 'all ' :
130- $ name = pht ('All Macros ' );
131- break ;
132- case 'my ' :
133- $ name = pht ('My Macros ' );
134- break ;
135- case 'active ' :
136- $ name = pht ('Active Macros ' );
137- break ;
138- default :
139- throw new Exception ("Unknown filter $ this ->filter " );
140- break ;
71+ $ name = $ macro ->getName ();
72+ if ($ macro ->getIsDisabled ()) {
73+ $ name = pht ('%s (Disabled) ' , $ name );
14174 }
142- } else {
143- $ name = pht ('Search ' );
75+ $ item ->setHeader ($ name );
76+
77+ $ pinboard ->addItem ($ item );
14478 }
14579
146- $ crumbs = $ this ->buildApplicationCrumbs ();
147- $ crumbs ->addCrumb (
148- id (new PhabricatorCrumbView ())
149- ->setName ($ name )
150- ->setHref ($ request ->getRequestURI ()));
151- $ nav ->setCrumbs ($ crumbs );
152-
153- return $ this ->buildApplicationPage (
154- $ nav ,
155- array (
156- 'device ' => true ,
157- 'title ' => pht ('Image Macros ' ),
158- 'dust ' => true ,
159- ));
80+ return $ pinboard ;
81+
16082 }
16183}
0 commit comments