2011-10-02 20:42:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-01-10 20:39:11 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-10-02 20:42:41 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render a table of Differential revisions.
|
|
|
|
*/
|
|
|
|
final class DifferentialRevisionListView extends AphrontView {
|
|
|
|
|
|
|
|
private $revisions;
|
|
|
|
private $handles;
|
|
|
|
private $user;
|
2012-02-20 14:38:21 +01:00
|
|
|
private $fields;
|
2012-05-15 23:44:03 +02:00
|
|
|
const NO_DATA_STRING = 'No revisions found.';
|
2012-02-20 14:38:21 +01:00
|
|
|
|
|
|
|
public function setFields(array $fields) {
|
2012-04-04 22:13:08 +02:00
|
|
|
assert_instances_of($fields, 'DifferentialFieldSpecification');
|
2012-02-20 14:38:21 +01:00
|
|
|
$this->fields = $fields;
|
|
|
|
return $this;
|
|
|
|
}
|
2011-10-02 20:42:41 +02:00
|
|
|
|
|
|
|
public function setRevisions(array $revisions) {
|
2012-04-04 22:13:08 +02:00
|
|
|
assert_instances_of($revisions, 'DifferentialRevision');
|
2011-10-02 20:42:41 +02:00
|
|
|
$this->revisions = $revisions;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRequiredHandlePHIDs() {
|
|
|
|
$phids = array();
|
2012-02-20 14:38:21 +01:00
|
|
|
foreach ($this->fields as $field) {
|
|
|
|
foreach ($this->revisions as $revision) {
|
|
|
|
$phids[] = $field->getRequiredHandlePHIDsForRevisionList($revision);
|
2011-10-02 20:42:41 +02:00
|
|
|
}
|
|
|
|
}
|
2012-02-20 14:38:21 +01:00
|
|
|
return array_mergev($phids);
|
2011-10-02 20:42:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setHandles(array $handles) {
|
2012-04-04 22:13:08 +02:00
|
|
|
assert_instances_of($handles, 'PhabricatorObjectHandle');
|
2011-10-02 20:42:41 +02:00
|
|
|
$this->handles = $handles;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setUser(PhabricatorUser $user) {
|
|
|
|
$this->user = $user;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render() {
|
|
|
|
|
|
|
|
$user = $this->user;
|
|
|
|
if (!$user) {
|
|
|
|
throw new Exception("Call setUser() before render()!");
|
|
|
|
}
|
|
|
|
|
2012-08-01 23:33:30 +02:00
|
|
|
$flags = id(new PhabricatorFlagQuery())
|
2012-08-02 04:03:17 +02:00
|
|
|
->withOwnerPHIDs(array($user->getPHID()))
|
2012-08-01 23:33:30 +02:00
|
|
|
->withObjectPHIDs(mpull($this->revisions, 'getPHID'))
|
|
|
|
->execute();
|
|
|
|
$flagged = mpull($flags, null, 'getObjectPHID');
|
|
|
|
|
2012-02-20 14:38:21 +01:00
|
|
|
foreach ($this->fields as $field) {
|
|
|
|
$field->setUser($this->user);
|
|
|
|
$field->setHandles($this->handles);
|
|
|
|
}
|
|
|
|
|
2011-10-02 20:42:41 +02:00
|
|
|
$rows = array();
|
|
|
|
foreach ($this->revisions as $revision) {
|
2012-08-01 23:33:30 +02:00
|
|
|
$phid = $revision->getPHID();
|
|
|
|
$flag = '';
|
|
|
|
if (isset($flagged[$phid])) {
|
|
|
|
$class = PhabricatorFlagColor::getCSSClass($flagged[$phid]->getColor());
|
|
|
|
$note = $flagged[$phid]->getNote();
|
|
|
|
$flag = phutil_render_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-flag-icon '.$class,
|
|
|
|
'title' => $note,
|
|
|
|
),
|
|
|
|
'');
|
|
|
|
}
|
|
|
|
$row = array($flag);
|
2012-02-20 14:38:21 +01:00
|
|
|
foreach ($this->fields as $field) {
|
|
|
|
$row[] = $field->renderValueForRevisionList($revision);
|
2011-10-02 20:42:41 +02:00
|
|
|
}
|
2012-02-20 14:38:21 +01:00
|
|
|
$rows[] = $row;
|
|
|
|
}
|
2011-10-02 20:42:41 +02:00
|
|
|
|
2012-08-01 23:33:30 +02:00
|
|
|
$headers = array('');
|
|
|
|
$classes = array('');
|
2012-02-20 14:38:21 +01:00
|
|
|
foreach ($this->fields as $field) {
|
|
|
|
$headers[] = $field->renderHeaderForRevisionList();
|
|
|
|
$classes[] = $field->getColumnClassForRevisionList();
|
2011-10-02 20:42:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$table = new AphrontTableView($rows);
|
2012-02-20 14:38:21 +01:00
|
|
|
$table->setHeaders($headers);
|
|
|
|
$table->setColumnClasses($classes);
|
2011-10-02 20:42:41 +02:00
|
|
|
|
2012-05-15 23:44:03 +02:00
|
|
|
$table->setNoDataString(DifferentialRevisionListView::NO_DATA_STRING);
|
2011-10-02 20:42:41 +02:00
|
|
|
|
|
|
|
return $table->render();
|
|
|
|
}
|
|
|
|
|
2012-02-20 14:38:21 +01:00
|
|
|
public static function getDefaultFields() {
|
|
|
|
$selector = DifferentialFieldSelector::newSelector();
|
|
|
|
$fields = $selector->getFieldSpecifications();
|
|
|
|
foreach ($fields as $key => $field) {
|
|
|
|
if (!$field->shouldAppearOnRevisionList()) {
|
|
|
|
unset($fields[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$fields) {
|
|
|
|
throw new Exception(
|
|
|
|
"Phabricator configuration has no fields that appear on the list ".
|
|
|
|
"interface!");
|
|
|
|
}
|
|
|
|
|
|
|
|
return $selector->sortFieldsForRevisionList($fields);
|
|
|
|
}
|
|
|
|
|
2011-10-02 20:42:41 +02:00
|
|
|
}
|