@@ -8,6 +8,9 @@ final class PhrictionListController
8
8
9
9
private $ view ;
10
10
11
+ private $ documents ;
12
+ private $ handles ;
13
+
11
14
public function willProcessRequest (array $ data ) {
12
15
$ this ->view = idx ($ data , 'view ' );
13
16
}
@@ -64,117 +67,154 @@ public function processRequest() {
64
67
throw new Exception ("Unknown view ' {$ this ->view }'! " );
65
68
}
66
69
67
- $ documents = $ query ->executeWithCursorPager ($ pager );
70
+ $ this ->documents = $ query ->executeWithCursorPager ($ pager );
71
+
72
+ $ changeref_docs = array ();
73
+ if ($ this ->view == 'updates ' ) {
74
+ // Loading some documents here since they may not appear in the query
75
+ // results.
76
+ $ changeref_ids = array_filter (mpull (
77
+ mpull ($ this ->documents , 'getContent ' ), 'getChangeRef ' ));
78
+ if ($ changeref_ids ) {
79
+ $ changeref_docs = id (new PhrictionDocumentQuery ())
80
+ ->setViewer ($ user )
81
+ ->withIDs ($ changeref_ids )
82
+ ->execute ();
83
+ }
84
+ }
68
85
69
86
$ phids = array ();
70
- foreach ($ documents as $ document ) {
87
+ foreach ($ this -> documents as $ document ) {
71
88
$ phids [] = $ document ->getContent ()->getAuthorPHID ();
72
89
if ($ document ->hasProject ()) {
73
90
$ phids [] = $ document ->getProject ()->getPHID ();
74
91
}
75
92
}
76
93
77
- $ handles = $ this ->loadViewerHandles ($ phids );
78
-
79
- $ rows = array ();
80
- foreach ($ documents as $ document ) {
81
- $ project_link = 'None ' ;
82
- if ($ document ->hasProject ()) {
83
- $ project_phid = $ document ->getProject ()->getPHID ();
84
- $ project_link = $ handles [$ project_phid ]->renderLink ();
85
- }
94
+ $ this ->handles = $ this ->loadViewerHandles ($ phids );
86
95
87
- $ content = $ document -> getContent ();
96
+ $ list = new PhabricatorObjectItemListView ();
88
97
89
- $ change_type = null ;
98
+ foreach ( $ this -> documents as $ document ) {
90
99
if ($ this ->view == 'updates ' ) {
91
- $ change_type = $ content ->getChangeType ();
92
- switch ($ content ->getChangeType ()) {
93
- case PhrictionChangeType::CHANGE_DELETE :
94
- case PhrictionChangeType::CHANGE_EDIT :
95
- $ change_type = PhrictionChangeType::getChangeTypeLabel (
96
- $ change_type );
97
- break ;
98
- case PhrictionChangeType::CHANGE_MOVE_HERE :
99
- case PhrictionChangeType::CHANGE_MOVE_AWAY :
100
- $ change_ref = $ content ->getChangeRef ();
101
- $ ref_doc = $ documents [$ change_ref ];
102
- $ ref_doc_slug = PhrictionDocument::getSlugURI (
103
- $ ref_doc ->getSlug ());
104
- $ ref_doc_link = hsprintf ('<br /><a href="%s">%s</a> ' , $ ref_doc_slug ,
105
- phutil_utf8_shorten ($ ref_doc_slug , 15 ));
106
-
107
- if ($ change_type == PhrictionChangeType::CHANGE_MOVE_HERE ) {
108
- $ change_type = pht ('Moved from %s ' , $ ref_doc_link );
109
- } else {
110
- $ change_type = pht ('Moved to %s ' , $ ref_doc_link );
111
- }
112
- break ;
113
- default :
114
- throw new Exception ("Unknown change type! " );
115
- break ;
116
- }
100
+ $ list ->addItem (
101
+ $ this ->buildItemForUpdates ($ document , $ changeref_docs ));
102
+ } else {
103
+ $ list ->addItem (
104
+ $ this ->buildItemTheCasualWay ($ document ));
117
105
}
118
-
119
- $ rows [] = array (
120
- $ handles [$ content ->getAuthorPHID ()]->renderLink (),
121
- $ change_type ,
122
- phutil_tag (
123
- 'a ' ,
124
- array (
125
- 'href ' => PhrictionDocument::getSlugURI ($ document ->getSlug ()),
126
- ),
127
- $ content ->getTitle ()),
128
- $ project_link ,
129
- phabricator_date ($ content ->getDateCreated (), $ user ),
130
- phabricator_time ($ content ->getDateCreated (), $ user ),
131
- );
132
106
}
133
107
134
- $ document_table = new AphrontTableView ($ rows );
135
- $ document_table ->setHeaders (
136
- array (
137
- pht ('Last Editor ' ),
138
- pht ('Change Type ' ),
139
- pht ('Title ' ),
140
- pht ('Project ' ),
141
- pht ('Last Update ' ),
142
- pht ('Time ' ),
143
- ));
108
+ $ nav ->appendChild ($ list );
109
+ $ nav ->appendChild ($ pager );
144
110
145
- $ document_table ->setColumnClasses (
111
+ return $ this ->buildApplicationPage (
112
+ $ nav ,
146
113
array (
147
- '' ,
148
- '' ,
149
- 'wide pri ' ,
150
- '' ,
151
- 'right ' ,
152
- 'right ' ,
114
+ 'title ' => pht ('Document Index ' ),
115
+ 'dust ' => true ,
153
116
));
117
+ }
154
118
155
- $ document_table ->setColumnVisibility (
156
- array (
157
- true ,
158
- $ this ->view == 'updates ' ,
159
- true ,
160
- true ,
161
- true ,
162
- true ,
163
- ));
119
+ private function buildItemTheCasualWay (PhrictionDocument $ document ) {
120
+ $ user = $ this ->getRequest ()->getUser ();
164
121
165
- $ panel = new AphrontPanelView ();
166
- $ panel ->setNoBackground ();
167
- $ panel ->appendChild ($ document_table );
168
- $ panel ->appendChild ($ pager );
122
+ $ project_link = null ;
123
+ if ($ document ->hasProject ()) {
124
+ $ project_phid = $ document ->getProject ()->getPHID ();
125
+ $ project_link = $ this ->handles [$ project_phid ]->renderLink ();
126
+ }
169
127
170
- $ nav ->appendChild ($ panel );
128
+ $ content = $ document ->getContent ();
129
+ $ author = $ this ->handles [$ content ->getAuthorPHID ()]->renderLink ();
130
+ $ title = $ content ->getTitle ();
131
+
132
+ $ slug = $ document ->getSlug ();
133
+ $ slug_uri = PhrictionDocument::getSlugURI ($ slug );
134
+ $ edit_uri = '/phriction/edit/ ' . $ document ->getID () . '/ ' ;
135
+ $ history_uri = PhrictionDocument::getSlugURI ($ slug , 'history ' );
136
+
137
+ $ item = id (new PhabricatorObjectItemView ())
138
+ ->setHeader ($ title )
139
+ ->setHref ($ slug_uri )
140
+ ->addAttribute (pht ('By %s ' , $ author ))
141
+ ->addAttribute (pht ('Updated: %s ' ,
142
+ phabricator_datetime ($ content ->getDateCreated (), $ user )))
143
+ ->addAttribute ($ slug_uri );
144
+
145
+ if ($ project_link ) {
146
+ $ item ->addAttribute (pht ('Project %s ' , $ project_link ));
147
+ }
171
148
172
- return $ this ->buildApplicationPage (
173
- $ nav ,
174
- array (
175
- 'title ' => pht ('Phriction Main ' ),
176
- 'dust ' => true ,
177
- ));
149
+ return $ item ;
150
+ }
151
+
152
+ private function buildItemForUpdates (PhrictionDocument $ document ,
153
+ array $ docs_from_refs ) {
154
+
155
+ $ user = $ this ->getRequest ()->getUser ();
156
+
157
+ $ content = $ document ->getContent ();
158
+ $ version = $ content ->getVersion ();
159
+ $ author = $ this ->handles [$ content ->getAuthorPHID ()]->renderLink ();
160
+ $ title = $ content ->getTitle ();
161
+
162
+ $ slug = $ document ->getSlug ();
163
+ $ slug_uri = PhrictionDocument::getSlugURI ($ slug );
164
+ $ document_link = hsprintf ('<a href="%s">%s</a> ' , $ slug_uri , $ title );
165
+
166
+ $ change_type = $ content ->getChangeType ();
167
+ switch ($ content ->getChangeType ()) {
168
+ case PhrictionChangeType::CHANGE_DELETE :
169
+ $ change_type = pht ('%s deleted %s ' , $ author , $ document_link );
170
+ $ color = 'red ' ;
171
+ break ;
172
+ case PhrictionChangeType::CHANGE_EDIT :
173
+ $ change_type = pht ('%s edited %s ' , $ author , $ document_link );
174
+ $ color = 'blue ' ;
175
+ break ;
176
+ case PhrictionChangeType::CHANGE_MOVE_HERE :
177
+ case PhrictionChangeType::CHANGE_MOVE_AWAY :
178
+ $ change_ref = $ content ->getChangeRef ();
179
+ $ ref_doc = $ docs_from_refs [$ change_ref ];
180
+ $ ref_doc_slug = PhrictionDocument::getSlugURI (
181
+ $ ref_doc ->getSlug ());
182
+ $ ref_doc_link = hsprintf ('<a href="%s">%1$s</a> ' , $ ref_doc_slug );
183
+
184
+ if ($ change_type == PhrictionChangeType::CHANGE_MOVE_HERE ) {
185
+ $ change_type = pht ('%s moved %s from %s ' , $ author , $ document_link ,
186
+ $ ref_doc_link );
187
+ $ color = 'yellow ' ;
188
+ } else {
189
+ $ change_type = pht ('%s moved %s to %s ' , $ author , $ document_link ,
190
+ $ ref_doc_link );
191
+ $ color = 'orange ' ;
192
+ }
193
+ break ;
194
+ default :
195
+ throw new Exception ("Unknown change type! " );
196
+ break ;
197
+ }
198
+
199
+ $ item = id (new PhabricatorObjectItemView ())
200
+ ->setHeader ($ change_type )
201
+ ->setBarColor ($ color )
202
+ ->addAttribute (phabricator_datetime ($ content ->getDateCreated (), $ user ))
203
+ ->addAttribute ($ slug_uri );
204
+
205
+ if ($ content ->getDescription ()) {
206
+ $ item ->addAttribute ($ content ->getDescription ());
207
+ }
208
+
209
+ if ($ version > 1 ) {
210
+ $ diff_uri = new PhutilURI ('/phriction/diff/ ' .$ document ->getID ().'/ ' );
211
+ $ uri = $ diff_uri ->alter ('l ' , $ version - 1 )->alter ('r ' , $ version );
212
+ $ item ->addIcon ('history ' , pht ('View Change ' ), $ uri );
213
+ } else {
214
+ $ item ->addIcon ('history ' , pht ('No diff available ' ));
215
+ }
216
+
217
+ return $ item ;
178
218
}
179
219
180
220
}
0 commit comments