Skip to content

Commit c4e217e

Browse files
AnhNhanepriestley
authored and
epriestley
committedMar 22, 2013
Modernized Phriction Document Index
Summary: Refs T2686 Migrated Document Index to `PhabricatorObjectItemView` //Updates// page currently depicts change type per object bar color. Icons are planned, though their implemention remains unclear. Also, @btrahan mentioned the use of getters over properties (for `$this->documents`, `$this->handles`) Test Plan: Looks good, doesn't it? Reviewers: epriestley, chad, btrahan CC: aran, Korvin Maniphest Tasks: T2686 Differential Revision: https://secure.phabricator.com/D5403
1 parent ecfb720 commit c4e217e

File tree

2 files changed

+131
-90
lines changed

2 files changed

+131
-90
lines changed
 

‎src/applications/phriction/controller/PhrictionListController.php

+130-90
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ final class PhrictionListController
88

99
private $view;
1010

11+
private $documents;
12+
private $handles;
13+
1114
public function willProcessRequest(array $data) {
1215
$this->view = idx($data, 'view');
1316
}
@@ -64,117 +67,154 @@ public function processRequest() {
6467
throw new Exception("Unknown view '{$this->view}'!");
6568
}
6669

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+
}
6885

6986
$phids = array();
70-
foreach ($documents as $document) {
87+
foreach ($this->documents as $document) {
7188
$phids[] = $document->getContent()->getAuthorPHID();
7289
if ($document->hasProject()) {
7390
$phids[] = $document->getProject()->getPHID();
7491
}
7592
}
7693

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);
8695

87-
$content = $document->getContent();
96+
$list = new PhabricatorObjectItemListView();
8897

89-
$change_type = null;
98+
foreach ($this->documents as $document) {
9099
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));
117105
}
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-
);
132106
}
133107

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);
144110

145-
$document_table->setColumnClasses(
111+
return $this->buildApplicationPage(
112+
$nav,
146113
array(
147-
'',
148-
'',
149-
'wide pri',
150-
'',
151-
'right',
152-
'right',
114+
'title' => pht('Document Index'),
115+
'dust' => true,
153116
));
117+
}
154118

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();
164121

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+
}
169127

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+
}
171148

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;
178218
}
179219

180220
}

‎src/applications/phriction/query/PhrictionDocumentQuery.php

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ protected function buildWhereClause(AphrontDatabaseConnection $conn) {
135135
$conn,
136136
'status NOT IN (%Ld)',
137137
array(
138+
PhrictionDocumentStatus::STATUS_MOVED,
138139
PhrictionDocumentStatus::STATUS_STUB,
139140
));
140141
break;

0 commit comments

Comments
 (0)
Failed to load comments.