2014-07-12 04:27:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorProjectBoardReorderController
|
|
|
|
extends PhabricatorProjectBoardController {
|
|
|
|
|
2015-08-08 19:34:55 +02:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
$projectid = $request->getURIData('projectID');
|
2014-07-12 04:27:07 +02:00
|
|
|
|
|
|
|
$project = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
2015-08-08 19:34:55 +02:00
|
|
|
->withIDs(array($projectid))
|
2014-07-12 04:27:07 +02:00
|
|
|
->executeOne();
|
|
|
|
if (!$project) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->setProject($project);
|
|
|
|
$project_id = $project->getID();
|
|
|
|
|
2017-05-14 23:15:06 +02:00
|
|
|
$view_uri = $this->getApplicationURI("board/{$project_id}/");
|
2014-07-12 04:27:07 +02:00
|
|
|
$reorder_uri = $this->getApplicationURI("board/{$project_id}/reorder/");
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
// User clicked "Done", make sure the page reloads to show the new
|
|
|
|
// column order.
|
2017-05-14 23:15:06 +02:00
|
|
|
return id(new AphrontRedirectResponse())->setURI($view_uri);
|
2014-07-12 04:27:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$columns = id(new PhabricatorProjectColumnQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withProjectPHIDs(array($project->getPHID()))
|
|
|
|
->execute();
|
|
|
|
$columns = msort($columns, 'getSequence');
|
|
|
|
|
|
|
|
$column_phid = $request->getStr('columnPHID');
|
|
|
|
if ($column_phid && $request->validateCSRF()) {
|
|
|
|
|
|
|
|
$columns = mpull($columns, null, 'getPHID');
|
|
|
|
if (empty($columns[$column_phid])) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$target_column = $columns[$column_phid];
|
|
|
|
$new_sequence = $request->getInt('sequence');
|
2014-08-09 00:50:36 +02:00
|
|
|
if ($new_sequence < 0) {
|
2014-07-12 04:27:07 +02:00
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: For now, we're not recording any transactions here. We probably
|
|
|
|
// should, but this sort of edit is extremely trivial.
|
|
|
|
|
|
|
|
// Resequence the columns so that the moved column has the correct
|
|
|
|
// sequence number. Move columns after it up one place in the sequence.
|
|
|
|
$new_map = array();
|
|
|
|
foreach ($columns as $phid => $column) {
|
|
|
|
$value = $column->getSequence();
|
|
|
|
if ($column->getPHID() == $column_phid) {
|
|
|
|
$value = $new_sequence;
|
|
|
|
} else if ($column->getSequence() >= $new_sequence) {
|
|
|
|
$value = $value + 1;
|
|
|
|
}
|
|
|
|
$new_map[$phid] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort the columns into their new ordering.
|
|
|
|
asort($new_map);
|
|
|
|
|
|
|
|
// Now, compact the ordering and adjust any columns that need changes.
|
|
|
|
$project->openTransaction();
|
|
|
|
$sequence = 0;
|
|
|
|
foreach ($new_map as $phid => $ignored) {
|
|
|
|
$new_value = $sequence++;
|
|
|
|
$cur_value = $columns[$phid]->getSequence();
|
|
|
|
if ($new_value != $cur_value) {
|
|
|
|
$columns[$phid]->setSequence($new_value)->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$project->saveTransaction();
|
|
|
|
|
|
|
|
return id(new AphrontAjaxResponse())->setContent(
|
|
|
|
array(
|
|
|
|
'sequenceMap' => mpull($columns, 'getSequence', 'getPHID'),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
$list_id = celerity_generate_unique_node_id();
|
|
|
|
|
|
|
|
$list = id(new PHUIObjectItemListView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setID($list_id)
|
[Redesign] New PHUIObjectItemListView
Summary:
New, cleaner, ObjectItemLists. Lots of minor style tweaks, basic overview:
- Remove FootIcons
- Remove Stackable
- Remove Plain List
- Add StatusIcon
- Add setting ObjectList to an ObjectBox
- Minor retouches to Headers
Mostly, this should give us an idea of life with the new Object Lists. I'll take another application by application pass down the road. This mostly looks at implementation in Maniphest, Differential, Audit, Workboards. Checked a few other areas and dialogs while testing, and everything looks square.
Test Plan: Maniphest, Differential, Homepage, Audit, People, and other applications. Drag reorder, etc.
Reviewers: btrahan, epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Differential Revision: https://secure.phabricator.com/D12865
2015-05-15 22:28:59 +02:00
|
|
|
->setFlush(true);
|
2014-07-12 04:27:07 +02:00
|
|
|
|
|
|
|
foreach ($columns as $column) {
|
2016-02-04 16:50:58 +01:00
|
|
|
// Don't allow milestone columns to be reordered.
|
|
|
|
$proxy = $column->getProxy();
|
|
|
|
if ($proxy && $proxy->isMilestone()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// At least for now, don't show subproject column.
|
|
|
|
if ($proxy) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-07-12 04:27:07 +02:00
|
|
|
$item = id(new PHUIObjectItemView())
|
2014-11-04 20:11:15 +01:00
|
|
|
->setHeader($column->getDisplayName())
|
2016-02-04 16:50:58 +01:00
|
|
|
->addIcon($column->getHeaderIcon(), $column->getDisplayType());
|
2014-07-12 04:27:07 +02:00
|
|
|
|
|
|
|
if ($column->isHidden()) {
|
|
|
|
$item->setDisabled(true);
|
|
|
|
}
|
|
|
|
|
2014-08-09 00:50:36 +02:00
|
|
|
$item->setGrippable(true);
|
|
|
|
$item->addSigil('board-column');
|
|
|
|
$item->setMetadata(
|
|
|
|
array(
|
|
|
|
'columnPHID' => $column->getPHID(),
|
|
|
|
'columnSequence' => $column->getSequence(),
|
|
|
|
));
|
2014-07-12 04:27:07 +02:00
|
|
|
|
2014-08-09 00:50:36 +02:00
|
|
|
$list->addItem($item);
|
2014-07-12 04:27:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Javelin::initBehavior(
|
|
|
|
'reorder-columns',
|
|
|
|
array(
|
|
|
|
'listID' => $list_id,
|
|
|
|
'reorderURI' => $reorder_uri,
|
|
|
|
));
|
|
|
|
|
[Redesign] New PHUIObjectItemListView
Summary:
New, cleaner, ObjectItemLists. Lots of minor style tweaks, basic overview:
- Remove FootIcons
- Remove Stackable
- Remove Plain List
- Add StatusIcon
- Add setting ObjectList to an ObjectBox
- Minor retouches to Headers
Mostly, this should give us an idea of life with the new Object Lists. I'll take another application by application pass down the road. This mostly looks at implementation in Maniphest, Differential, Audit, Workboards. Checked a few other areas and dialogs while testing, and everything looks square.
Test Plan: Maniphest, Differential, Homepage, Audit, People, and other applications. Drag reorder, etc.
Reviewers: btrahan, epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Differential Revision: https://secure.phabricator.com/D12865
2015-05-15 22:28:59 +02:00
|
|
|
$note = id(new PHUIInfoView())
|
|
|
|
->appendChild(pht('Drag and drop columns to reorder them.'))
|
|
|
|
->setSeverity(PHUIInfoView::SEVERITY_NOTICE);
|
|
|
|
|
2014-07-12 04:27:07 +02:00
|
|
|
return $this->newDialog()
|
|
|
|
->setTitle(pht('Reorder Columns'))
|
|
|
|
->setWidth(AphrontDialogView::WIDTH_FORM)
|
[Redesign] New PHUIObjectItemListView
Summary:
New, cleaner, ObjectItemLists. Lots of minor style tweaks, basic overview:
- Remove FootIcons
- Remove Stackable
- Remove Plain List
- Add StatusIcon
- Add setting ObjectList to an ObjectBox
- Minor retouches to Headers
Mostly, this should give us an idea of life with the new Object Lists. I'll take another application by application pass down the road. This mostly looks at implementation in Maniphest, Differential, Audit, Workboards. Checked a few other areas and dialogs while testing, and everything looks square.
Test Plan: Maniphest, Differential, Homepage, Audit, People, and other applications. Drag reorder, etc.
Reviewers: btrahan, epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Differential Revision: https://secure.phabricator.com/D12865
2015-05-15 22:28:59 +02:00
|
|
|
->appendChild($note)
|
2014-07-12 04:27:07 +02:00
|
|
|
->appendChild($list)
|
|
|
|
->addSubmitButton(pht('Done'));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|