1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-23 15:22:41 +01:00

Modernizing Flag Application

Summary:
Fixes a weird string in the flag dialog

Migrated to ObjectItemView (Cards)

Removed filters from side nav (unnecessary)

Go away, go away, panel. Nobody will miss you.

Adding sorting/ordering to Flag (separation like in Maniphest ordering still remaining)

Hacking our way in DifferentialRevisionListController thanks to panels (who added `->setFlush()` btw? It's awesome!)

Test Plan: I would not dare to stand here if it did not work.

Reviewers: epriestley, chad, btrahan

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5449
This commit is contained in:
Anh Nhan Nguyen 2013-03-26 14:05:45 -07:00 committed by epriestley
parent 8fc94b02a9
commit 9a6c912ef6
6 changed files with 137 additions and 98 deletions

View file

@ -146,9 +146,7 @@ final class DifferentialRevisionListController extends DifferentialController {
$handles = $this->loadViewerHandles($phids); $handles = $this->loadViewerHandles($phids);
foreach ($views as $view) { foreach ($views as $view) {
if (empty($view['special'])) {
$view['view']->setHandles($handles); $view['view']->setHandles($handles);
}
$panel = new AphrontPanelView(); $panel = new AphrontPanelView();
$panel->setHeader($view['title']); $panel->setHeader($view['title']);
$panel->appendChild($view['view']); $panel->appendChild($view['view']);
@ -460,29 +458,6 @@ final class DifferentialRevisionListController extends DifferentialController {
'view' => $view, 'view' => $view,
); );
// Flags are sort of private, so only show the flag panel if you're
// looking at your own requests.
if (in_array($user->getPHID(), $user_phids)) {
$flags = id(new PhabricatorFlagQuery())
->setViewer($user)
->withOwnerPHIDs(array($user->getPHID()))
->withTypes(array(PhabricatorPHIDConstants::PHID_TYPE_DREV))
->needHandles(true)
->execute();
if ($flags) {
$view = id(new PhabricatorFlagListView())
->setFlags($flags)
->setUser($user);
$views[] = array(
'title' => pht('Flagged Revisions'),
'view' => $view,
'special' => true,
);
}
}
$view = id(clone $template) $view = id(clone $template)
->setRevisions($waiting) ->setRevisions($waiting)
->loadAssets(); ->loadAssets();

View file

@ -54,8 +54,8 @@ final class PhabricatorFlagEditController extends PhabricatorFlagController {
$form $form
->appendChild(hsprintf( ->appendChild(hsprintf(
"<p>%s</p><br />", "<p>%s</p><br />",
pht('You can flag this %s if you want to remember to look ". pht('You can flag this %s if you want to remember to look '.
"at it later.', 'at it later.',
$type_name))); $type_name)));
} }

View file

@ -7,33 +7,67 @@ final class PhabricatorFlagListController extends PhabricatorFlagController {
$user = $request->getUser(); $user = $request->getUser();
$nav = new AphrontSideNavFilterView(); $nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI('/flag/view/'));
$nav->addLabel(pht('Flags')); $filter_form = new AphrontFormView();
$nav->addFilter('all', pht('Your Flags')); $filter_form->setUser($user);
$nav->selectFilter('all', 'all'); $filter_form->appendChild(
id(new AphrontFormToggleButtonsControl())
->setName('o')
->setLabel(pht('Sort Order'))
->setBaseURI($request->getRequestURI(), 'o')
->setValue($request->getStr('o', 'n'))
->setButtons(
array(
'n' => pht('Date'),
'c' => pht('Color'),
'o' => pht('Object Type'),
'r' => pht('Reason'),
)));
$filter = new AphrontListFilterView();
$filter->appendChild($filter_form);
$query = new PhabricatorFlagQuery(); $query = new PhabricatorFlagQuery();
$query->withOwnerPHIDs(array($user->getPHID())); $query->withOwnerPHIDs(array($user->getPHID()));
$query->setViewer($user); $query->setViewer($user);
$query->needHandles(true); $query->needHandles(true);
switch ($request->getStr('o', 'n')) {
case 'n':
$order = PhabricatorFlagQuery::ORDER_ID;
break;
case 'c':
$order = PhabricatorFlagQuery::ORDER_COLOR;
break;
case 'o':
$order = PhabricatorFlagQuery::ORDER_OBJECT;
break;
case 'r':
$order = PhabricatorFlagQuery::ORDER_REASON;
break;
default:
throw new Exception("Unknown order!");
}
$query->withOrder($order);
$flags = $query->execute(); $flags = $query->execute();
$view = new PhabricatorFlagListView(); $view = new PhabricatorFlagListView();
$view->setFlags($flags); $view->setFlags($flags);
$view->setUser($user); $view->setUser($user);
$panel = new AphrontPanelView(); $header = new PhabricatorHeaderView();
$panel->setHeader(pht('Flags')); $header->setHeader(pht('Flags'));
$panel->appendChild($view);
$panel->setNoBackground();
$nav->appendChild($panel); $nav->appendChild($header);
$nav->appendChild($filter);
$nav->appendChild($view);
return $this->buildStandardPageResponse( return $this->buildApplicationPage(
$nav, $nav,
array( array(
'title' => pht('Flags'), 'title' => pht('Flags'),
'dust' => true,
)); ));
} }

View file

@ -13,6 +13,12 @@ final class PhabricatorFlagQuery {
private $needObjects; private $needObjects;
private $viewer; private $viewer;
private $order = 'order-id';
const ORDER_ID = 'order-id';
const ORDER_COLOR = 'order-color';
const ORDER_OBJECT = 'order-object';
const ORDER_REASON = 'order-reason';
public function setViewer($viewer) { public function setViewer($viewer) {
$this->viewer = $viewer; $this->viewer = $viewer;
return $this; return $this;
@ -33,6 +39,11 @@ final class PhabricatorFlagQuery {
return $this; return $this;
} }
public function withOrder($order) {
$this->order = $order;
return $this;
}
public function needHandles($need) { public function needHandles($need) {
$this->needHandles = $need; $this->needHandles = $need;
return $this; return $this;
@ -143,7 +154,29 @@ final class PhabricatorFlagQuery {
} }
private function buildOrderClause($conn_r) { private function buildOrderClause($conn_r) {
return 'ORDER BY id DESC'; return qsprintf($conn_r,
'ORDER BY %Q',
$this->getOrderColumn($conn_r));
}
private function getOrderColumn($conn_r) {
switch ($this->order) {
case self::ORDER_ID:
return 'id DESC';
break;
case self::ORDER_COLOR:
return 'color DESC';
break;
case self::ORDER_OBJECT:
return 'type ASC';
break;
case self::ORDER_REASON:
return 'reasonPHID DESC';
break;
default:
throw new Exception("Unknown order {$this->order}!");
break;
}
} }
private function buildLimitClause($conn_r) { private function buildLimitClause($conn_r) {

View file

@ -3,6 +3,7 @@
final class PhabricatorFlagListView extends AphrontView { final class PhabricatorFlagListView extends AphrontView {
private $flags; private $flags;
private $flush = false;
public function setFlags(array $flags) { public function setFlags(array $flags) {
assert_instances_of($flags, 'PhabricatorFlag'); assert_instances_of($flags, 'PhabricatorFlag');
@ -10,75 +11,64 @@ final class PhabricatorFlagListView extends AphrontView {
return $this; return $this;
} }
public function setFlush($flush) {
$this->flush = $flush;
return $this;
}
public function render() { public function render() {
$user = $this->user; $user = $this->user;
require_celerity_resource('phabricator-flag-css'); require_celerity_resource('phabricator-flag-css');
$list = new PhabricatorObjectItemListView();
$list->setCards(true);
$list->setNoDataString(pht('No flags.'));
$list->setFlush($this->flush);
$rows = array(); $rows = array();
foreach ($this->flags as $flag) { foreach ($this->flags as $flag) {
$class = PhabricatorFlagColor::getCSSClass($flag->getColor()); $class = PhabricatorFlagColor::getCSSClass($flag->getColor());
$rows[] = array( $flag_icon = phutil_tag(
phutil_tag(
'div', 'div',
array( array(
'class' => 'phabricator-flag-icon '.$class, 'class' => 'phabricator-flag-icon '.$class,
), ),
''), '');
$flag->getHandle()->renderLink(),
$flag->getNote(), $edit_link = javelin_tag(
phabricator_datetime($flag->getDateCreated(), $user), 'a',
phabricator_form(
$user,
array( array(
'method' => 'POST', 'href' => '/flag/edit/'.$flag->getObjectPHID().'/',
'action' => '/flag/edit/'.$flag->getObjectPHID().'/',
'sigil' => 'workflow', 'sigil' => 'workflow',
), ),
phutil_tag( pht('Edit'));
'button',
$remove_link = javelin_tag(
'a',
array( array(
'class' => 'small grey', 'href' => '/flag/delete/'.$flag->getID().'/',
),
pht('Edit Flag'))),
phabricator_form(
$user,
array(
'method' => 'POST',
'action' => '/flag/delete/'.$flag->getID().'/',
'sigil' => 'workflow', 'sigil' => 'workflow',
), ),
phutil_tag( pht('Remove'));
'button',
array( $item = new PhabricatorObjectItemView();
'class' => 'small grey', $item->addIcon('edit', $edit_link);
), $item->addIcon('delete', $remove_link);
pht('Remove Flag'))),
); $item->setHeader(hsprintf('%s %s',
$flag_icon, $flag->getHandle()->renderLink()));
$item->addAttribute(phabricator_datetime($flag->getDateCreated(), $user));
if ($flag->getNote()) {
$item->addAttribute($flag->getNote());
} }
$table = new AphrontTableView($rows); $list->addItem($item);
$table->setHeaders( }
array(
'',
pht('Flagged Object'),
pht('Note'),
pht('Flagged On'),
'',
'',
));
$table->setColumnClasses(
array(
'narrow',
'wrap pri',
'wrap',
'narrow',
'narrow action',
'narrow action',
));
$table->setNoDataString(pht('No flags.'));
return $table->render(); return $list;
} }
} }

View file

@ -7,6 +7,13 @@
background: transparent 0 0 no-repeat; background: transparent 0 0 no-repeat;
} }
.phabricator-object-item .phabricator-flag-icon {
float: left;
margin: 2px;
margin-right: 8px;
margin-bottom: 0;
}
.phabricator-flag-radio { .phabricator-flag-radio {
padding-left: 18px; padding-left: 18px;
margin: 1px; margin: 1px;