mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 12:00:55 +01:00
Unify "toggle buttons" controls
Summary: This control is a very thin shell right now with Maniphest/Differential code duplication; unify the implemenations better for use in Audit. Test Plan: Clicked toggle buttons in Differential and Maniphest. Reviewers: btrahan, jungejason Reviewed By: btrahan CC: aran, epriestley Differential Revision: https://secure.phabricator.com/D1700
This commit is contained in:
parent
d7a7bca85c
commit
3289059452
4 changed files with 98 additions and 102 deletions
|
@ -312,30 +312,26 @@ class DifferentialRevisionListController extends DifferentialController {
|
|||
->setValue($value)
|
||||
->setLimit(1);
|
||||
case 'status':
|
||||
$links = $this->renderToggleButtons(
|
||||
array(
|
||||
'all' => 'All',
|
||||
'open' => 'Open',
|
||||
'committed' => 'Committed',
|
||||
),
|
||||
$params['status'],
|
||||
$uri,
|
||||
'status');
|
||||
return id(new AphrontFormToggleButtonsControl())
|
||||
->setLabel('Status')
|
||||
->setValue($links);
|
||||
->setValue($params['status'])
|
||||
->setBaseURI($uri, 'status')
|
||||
->setButtons(
|
||||
array(
|
||||
'all' => 'All',
|
||||
'open' => 'Open',
|
||||
'committed' => 'Committed',
|
||||
));
|
||||
case 'order':
|
||||
$links = $this->renderToggleButtons(
|
||||
array(
|
||||
'modified' => 'Modified',
|
||||
'created' => 'Created',
|
||||
),
|
||||
$params['order'],
|
||||
$uri,
|
||||
'order');
|
||||
return id(new AphrontFormToggleButtonsControl())
|
||||
->setLabel('Order')
|
||||
->setValue($links);
|
||||
->setValue($params['order'])
|
||||
->setBaseURI($uri, 'order')
|
||||
->setButtons(
|
||||
array(
|
||||
'modified' => 'Modified',
|
||||
'created' => 'Created',
|
||||
));
|
||||
default:
|
||||
throw new Exception("Unknown control '{$control}'!");
|
||||
}
|
||||
|
@ -417,23 +413,5 @@ class DifferentialRevisionListController extends DifferentialController {
|
|||
return $views;
|
||||
}
|
||||
|
||||
private function renderToggleButtons($buttons, $selected, $uri, $param) {
|
||||
$links = array();
|
||||
foreach ($buttons as $value => $name) {
|
||||
if ($value == $selected) {
|
||||
$more = ' toggle-selected toggle-fixed';
|
||||
} else {
|
||||
$more = null;
|
||||
}
|
||||
$links[] = phutil_render_tag(
|
||||
'a',
|
||||
array(
|
||||
'class' => 'toggle'.$more,
|
||||
'href' => $uri->alter($param, $value),
|
||||
),
|
||||
phutil_escape_html($name));
|
||||
}
|
||||
return implode('', $links);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -77,9 +77,9 @@ class ManiphestTaskListController extends ManiphestController {
|
|||
'triage' => true,
|
||||
);
|
||||
|
||||
list($status_map, $status_links) = $this->renderStatusLinks();
|
||||
list($grouping, $group_links) = $this->renderGroupLinks();
|
||||
list($order, $order_links) = $this->renderOrderLinks();
|
||||
list($status_map, $status_control) = $this->renderStatusLinks();
|
||||
list($grouping, $group_control) = $this->renderGroupLinks();
|
||||
list($order, $order_control) = $this->renderOrderLinks();
|
||||
|
||||
$user_phids = $request->getStr('users');
|
||||
if (strlen($user_phids)) {
|
||||
|
@ -150,18 +150,9 @@ class ManiphestTaskListController extends ManiphestController {
|
|||
->setValue($tokens));
|
||||
|
||||
$form
|
||||
->appendChild(
|
||||
id(new AphrontFormToggleButtonsControl())
|
||||
->setLabel('Status')
|
||||
->setValue($status_links))
|
||||
->appendChild(
|
||||
id(new AphrontFormToggleButtonsControl())
|
||||
->setLabel('Group')
|
||||
->setValue($group_links))
|
||||
->appendChild(
|
||||
id(new AphrontFormToggleButtonsControl())
|
||||
->setLabel('Order')
|
||||
->setValue($order_links));
|
||||
->appendChild($status_control)
|
||||
->appendChild($group_control)
|
||||
->appendChild($order_control);
|
||||
|
||||
$form->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
|
@ -407,15 +398,18 @@ class ManiphestTaskListController extends ManiphestController {
|
|||
$status = 'o';
|
||||
}
|
||||
|
||||
$button_names = array(
|
||||
'Open' => 'o',
|
||||
'Closed' => 'c',
|
||||
'All' => 'oc',
|
||||
);
|
||||
$status_control = id(new AphrontFormToggleButtonsControl())
|
||||
->setLabel('Status')
|
||||
->setValue($status)
|
||||
->setBaseURI($request->getRequestURI(), 's')
|
||||
->setButtons(
|
||||
array(
|
||||
'o' => 'Open',
|
||||
'c' => 'Closed',
|
||||
'oc' => 'All',
|
||||
));
|
||||
|
||||
$status_links = $this->renderFilterLinks($button_names, $status, 's');
|
||||
|
||||
return array($statuses[$status], $status_links);
|
||||
return array($statuses[$status], $status_control);
|
||||
}
|
||||
|
||||
public function renderOrderLinks() {
|
||||
|
@ -432,15 +426,18 @@ class ManiphestTaskListController extends ManiphestController {
|
|||
}
|
||||
$order_by = $orders[$order];
|
||||
|
||||
$order_names = array(
|
||||
'Priority' => 'p',
|
||||
'Updated' => 'u',
|
||||
'Created' => 'c',
|
||||
);
|
||||
$order_control = id(new AphrontFormToggleButtonsControl())
|
||||
->setLabel('Order')
|
||||
->setValue($order)
|
||||
->setBaseURI($request->getRequestURI(), 'o')
|
||||
->setButtons(
|
||||
array(
|
||||
'p' => 'Priority',
|
||||
'u' => 'Updated',
|
||||
'c' => 'Created',
|
||||
));
|
||||
|
||||
$order_links = $this->renderFilterLinks($order_names, $order, 'o');
|
||||
|
||||
return array($order_by, $order_links);
|
||||
return array($order_by, $order_control);
|
||||
}
|
||||
|
||||
public function renderGroupLinks() {
|
||||
|
@ -458,40 +455,20 @@ class ManiphestTaskListController extends ManiphestController {
|
|||
}
|
||||
$group_by = $groups[$group];
|
||||
|
||||
$group_names = array(
|
||||
'Priority' => 'p',
|
||||
'Owner' => 'o',
|
||||
'Status' => 's',
|
||||
'None' => 'n',
|
||||
);
|
||||
|
||||
$group_links = $this->renderFilterLinks($group_names, $group, 'g');
|
||||
|
||||
return array($group_by, $group_links);
|
||||
}
|
||||
|
||||
private function renderFilterLinks($filter_map, $selected, $uri_param) {
|
||||
$request = $this->getRequest();
|
||||
$uri = $request->getRequestURI();
|
||||
|
||||
$links = array();
|
||||
foreach ($filter_map as $name => $value) {
|
||||
if ($value == $selected) {
|
||||
$more = ' toggle-selected toggle-fixed';
|
||||
$href = null;
|
||||
} else {
|
||||
$more = null;
|
||||
$href = $uri->alter($uri_param, $value);
|
||||
}
|
||||
$links[] = phutil_render_tag(
|
||||
'a',
|
||||
$group_control = id(new AphrontFormToggleButtonsControl())
|
||||
->setLabel('Group')
|
||||
->setValue($group)
|
||||
->setBaseURI($request->getRequestURI(), 'g')
|
||||
->setButtons(
|
||||
array(
|
||||
'class' => 'toggle'.$more,
|
||||
'href' => $href,
|
||||
),
|
||||
$name);
|
||||
}
|
||||
return implode("\n", $links);
|
||||
'p' => 'Priority',
|
||||
'o' => 'Owner',
|
||||
's' => 'Status',
|
||||
'n' => 'None',
|
||||
));
|
||||
|
||||
return array($group_by, $group_control);
|
||||
}
|
||||
|
||||
private function renderBatchEditor() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -18,12 +18,51 @@
|
|||
|
||||
class AphrontFormToggleButtonsControl extends AphrontFormControl {
|
||||
|
||||
private $baseURI;
|
||||
private $param;
|
||||
|
||||
private $buttons;
|
||||
|
||||
public function setBaseURI(PhutilURI $uri, $param) {
|
||||
$this->baseURI = $uri;
|
||||
$this->param = $param;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setButtons(array $buttons) {
|
||||
$this->buttons = $buttons;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getCustomControlClass() {
|
||||
return 'aphront-form-control-togglebuttons';
|
||||
}
|
||||
|
||||
protected function renderInput() {
|
||||
return $this->getValue();
|
||||
if (!$this->baseURI) {
|
||||
throw new Exception('Call setBaseURI() before render()!');
|
||||
}
|
||||
|
||||
$selected = $this->getValue();
|
||||
|
||||
$out = array();
|
||||
foreach ($this->buttons as $value => $label) {
|
||||
if ($value == $selected) {
|
||||
$more = ' toggle-selected toggle-fixed';
|
||||
} else {
|
||||
$more = null;
|
||||
}
|
||||
|
||||
$out[] = phutil_render_tag(
|
||||
'a',
|
||||
array(
|
||||
'class' => 'toggle'.$more,
|
||||
'href' => $this->baseURI->alter($this->param, $value),
|
||||
),
|
||||
phutil_escape_html($label));
|
||||
}
|
||||
|
||||
return implode('', $out);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,5 +8,7 @@
|
|||
|
||||
phutil_require_module('phabricator', 'view/form/control/base');
|
||||
|
||||
phutil_require_module('phutil', 'markup');
|
||||
|
||||
|
||||
phutil_require_source('AphrontFormToggleButtonsControl.php');
|
||||
|
|
Loading…
Reference in a new issue